答复: [PATCH 1/3] drm/amdgpu: added AMD GPU instance counting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



See comments in line.

Thanks
JimQu

________________________________________
发件人: amd-gfx <amd-gfx-bounces@xxxxxxxxxxxxxxxxxxxxx> 代表 Flora Cui <fcui@xxxxxxx>
发送时间: 2018年9月28日 10:46
收件人: Quan, Evan; amd-gfx@xxxxxxxxxxxxxxxxxxxxx
抄送: Deucher, Alexander
主题: Re: [PATCH 1/3] drm/amdgpu: added AMD GPU instance counting



On 2018年09月28日 10:03, Evan Quan wrote:
> Count all GPU instances from AMD(including iGPUs and
> dGPUs) in the system.
>
> Change-Id: If62a0873c64857a3fcdf9785557e24cb3456c12e
> Signed-off-by: Evan Quan <evan.quan@xxxxxxx>
> Reviewed-by: Alex Deucher <alexander.deucher@xxxxxxx>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 18 +++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  7 ++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 52 +++++++++++++++++++++++++
>   3 files changed, 77 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index daadf3b8bec0..6583a68b7ee9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -81,6 +81,23 @@
>   #include "amdgpu_bo_list.h"
>   #include "amdgpu_gem.h"
>
> +#define MAX_GPU_INSTANCE             16
> +
> +struct amdgpu_gpu_instance
> +{
> +     struct amdgpu_device            *adev;
> +     int                             mgpu_fan_enabled;
> +};
> +
> +struct amdgpu_mgpu_info
> +{
> +     struct amdgpu_gpu_instance      gpu_ins[MAX_GPU_INSTANCE];
> +     struct mutex                    mutex;
> +     uint32_t                        num_gpu;
> +     uint32_t                        num_dgpu;
> +     uint32_t                        num_apu;
> +};
> +
>   /*
>    * Modules parameters.
>    */
> @@ -134,6 +151,7 @@ extern int amdgpu_compute_multipipe;
>   extern int amdgpu_gpu_recovery;
>   extern int amdgpu_emu_mode;
>   extern uint amdgpu_smu_memory_pool_size;
> +extern struct amdgpu_mgpu_info mgpu_info;
>
>   #ifdef CONFIG_DRM_AMDGPU_SI
>   extern int amdgpu_si_support;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index b536808f62ec..c6da46f1d7fa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -127,6 +127,13 @@ int amdgpu_compute_multipipe = -1;
>   int amdgpu_gpu_recovery = -1; /* auto */
>   int amdgpu_emu_mode = 0;
>   uint amdgpu_smu_memory_pool_size = 0;
> +struct amdgpu_mgpu_info mgpu_info = {
> +     .gpu_ins = {0},
> +     .mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
> +     .num_gpu = 0,
> +     .num_apu = 0,
> +     .num_dgpu = 0,
> +};
you could init mutex only.
>
>   /**
>    * DOC: vramlimit (int)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 64cc483db973..50ece76131a3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -40,6 +40,30 @@
>   #include "amdgpu_gem.h"
>   #include "amdgpu_display.h"
>
> +static void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
> +{
> +     struct amdgpu_gpu_instance *gpu_instance;
> +     int i;
> +
> +     mutex_lock(&mgpu_info.mutex);
> +
> +     for (i = 0; i < mgpu_info.num_gpu; i++) {
> +             gpu_instance = &(mgpu_info.gpu_ins[i]);
> +             if (gpu_instance->adev == adev) {
> +                     mgpu_info.gpu_ins[i] =
> +                             mgpu_info.gpu_ins[mgpu_info.num_gpu - 1];

What is about set  gpu_instance->adev to NULL and gpu_instance->mgpu_fan_enabled to 0, like

gpu_instance->adev = NULL;
gpu_instance->mgpu_fan_enabled = 0;

Thanks
JimQu

> +                     mgpu_info.num_gpu--;
> +                     if (adev->flags & AMD_IS_APU)
> +                             mgpu_info.num_apu--;
> +                     else
> +                             mgpu_info.num_dgpu--;
> +                     break;
> +             }
> +     }
> +
> +     mutex_unlock(&mgpu_info.mutex);
> +}
> +
>   /**
>    * amdgpu_driver_unload_kms - Main unload function for KMS.
>    *
> @@ -55,6 +79,8 @@ void amdgpu_driver_unload_kms(struct drm_device *dev)
>       if (adev == NULL)
>               return;
>
> +     amdgpu_unregister_gpu_instance(adev);
> +
>       if (adev->rmmio == NULL)
>               goto done_free;
>
> @@ -75,6 +101,31 @@ void amdgpu_driver_unload_kms(struct drm_device *dev)
>       dev->dev_private = NULL;
>   }
>
> +static void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
> +{
> +     struct amdgpu_gpu_instance *gpu_instance;
> +
> +     mutex_lock(&mgpu_info.mutex);
> +
> +     if (mgpu_info.num_gpu >= MAX_GPU_INSTANCE) {
> +             DRM_ERROR("Cannot register more gpu instance\n");
> +             mutex_unlock(&mgpu_info.mutex);
> +             return;
> +     }
> +
> +     gpu_instance = &(mgpu_info.gpu_ins[mgpu_info.num_gpu]);
> +     gpu_instance->adev = adev;
> +     gpu_instance->mgpu_fan_enabled = 0;
> +
> +     mgpu_info.num_gpu++;
> +     if (adev->flags & AMD_IS_APU)
> +             mgpu_info.num_apu++;
> +     else
> +             mgpu_info.num_dgpu++;
> +
> +     mutex_unlock(&mgpu_info.mutex);
> +}
> +
>   /**
>    * amdgpu_driver_load_kms - Main load function for KMS.
>    *
> @@ -169,6 +220,7 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
>               pm_runtime_put_autosuspend(dev->dev);
>       }
>
> +     amdgpu_register_gpu_instance(adev);
>   out:
>       if (r) {
>               /* balance pm_runtime_get_sync in amdgpu_driver_unload_kms */

_______________________________________________
amd-gfx mailing list
amd-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/amd-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux