[PATCH V3] drm/amdgpu: Surface svm_default_granularity, a RW module parameter

Chen, Xiaogang xiaogang.chen at amd.com
Thu Aug 29 22:31:59 UTC 2024



On 8/29/2024 5:13 PM, Ramesh Errabolu wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
>
>
> Enables users to update SVM's default granularity, used in
> buffer migration and handling of recoverable page faults.
> Param value is set in terms of log(numPages(buffer)),
> e.g. 9 for a 2 MIB buffer

Forgot asking if this parameter is request from customer or used for 
debug/experiment purpose? If it is later, how about put it at debug fs? 
There are already many driver parameters.

Regards

Xiaogang

> Signed-off-by: Ramesh Errabolu <Ramesh.Errabolu at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  1 +
>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 17 +++++++++++++++++
>   drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |  6 ++++++
>   drivers/gpu/drm/amd/amdkfd/kfd_svm.c    | 25 +++++++++++++++----------
>   4 files changed, 39 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index e8c284aea1f2..8eb934af02f2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -237,6 +237,7 @@ extern int sched_policy;
>   extern bool debug_evictions;
>   extern bool no_system_mem_limit;
>   extern int halt_if_hws_hang;
> +extern uint amdgpu_svm_default_granularity;
>   #else
>   static const int __maybe_unused sched_policy = KFD_SCHED_POLICY_HWS;
>   static const bool __maybe_unused debug_evictions; /* = false */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index b9529948f2b2..442039436cb3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -169,6 +169,16 @@ uint amdgpu_sdma_phase_quantum = 32;
>   char *amdgpu_disable_cu;
>   char *amdgpu_virtual_display;
>   bool enforce_isolation;
> +
> +/* Specifies the default granularity for SVM, used in buffer
> + * migration and restoration of backing memory when handling
> + * recoverable page faults.
> + *
> + * The value is given as log(numPages(buffer)); for a 2 MiB
> + * buffer it computes to be 9
> + */
> +uint amdgpu_svm_default_granularity = 9;
> +
>   /*
>    * OverDrive(bit 14) disabled by default
>    * GFX DCS(bit 19) disabled by default
> @@ -320,6 +330,13 @@ module_param_named(pcie_gen2, amdgpu_pcie_gen2, int, 0444);
>   MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
>   module_param_named(msi, amdgpu_msi, int, 0444);
>
> +/**
> + * DOC: svm_default_granularity (uint)
> + * Used in buffer migration and handling of recoverable page faults
> + */
> +MODULE_PARM_DESC(svm_default_granularity, "SVM's default granularity in log(2^Pages), default 9 = 2^9 = 2 MiB");
> +module_param_named(svm_default_granularity, amdgpu_svm_default_granularity, uint, 0644);
> +
>   /**
>    * DOC: lockup_timeout (string)
>    * Set GPU scheduler timeout value in ms.
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index 9ae9abc6eb43..d6530febabad 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -868,6 +868,12 @@ struct svm_range_list {
>          struct task_struct              *faulting_task;
>          /* check point ts decides if page fault recovery need be dropped */
>          uint64_t                        checkpoint_ts[MAX_GPU_INSTANCE];
> +
> +       /* Default granularity to use in buffer migration
> +        * and restoration of backing memory while handling
> +        * recoverable page faults
> +        */
> +       uint8_t default_granularity;
>   };
>
>   /* Process data */
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index b44dec90969f..624bfe317c9c 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -309,12 +309,13 @@ static void svm_range_free(struct svm_range *prange, bool do_unmap)
>   }
>
>   static void
> -svm_range_set_default_attributes(int32_t *location, int32_t *prefetch_loc,
> -                                uint8_t *granularity, uint32_t *flags)
> +svm_range_set_default_attributes(struct svm_range_list *svms,
> +                       int32_t *location, uint8_t *granularity,
> +                       int32_t *prefetch_loc, uint32_t *flags)
>   {
>          *location = KFD_IOCTL_SVM_LOCATION_UNDEFINED;
>          *prefetch_loc = KFD_IOCTL_SVM_LOCATION_UNDEFINED;
> -       *granularity = 9;
> +       *granularity = svms->default_granularity;
>          *flags =
>                  KFD_IOCTL_SVM_FLAG_HOST_ACCESS | KFD_IOCTL_SVM_FLAG_COHERENT;
>   }
> @@ -358,9 +359,8 @@ svm_range *svm_range_new(struct svm_range_list *svms, uint64_t start,
>                  bitmap_copy(prange->bitmap_access, svms->bitmap_supported,
>                              MAX_GPU_INSTANCE);
>
> -       svm_range_set_default_attributes(&prange->preferred_loc,
> -                                        &prange->prefetch_loc,
> -                                        &prange->granularity, &prange->flags);
> +       svm_range_set_default_attributes(svms, &prange->preferred_loc,
> +               &prange->granularity, &prange->prefetch_loc, &prange->flags);
>
>          pr_debug("svms 0x%p [0x%llx 0x%llx]\n", svms, start, last);
>
> @@ -2694,9 +2694,10 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,
>          *is_heap_stack = vma_is_initial_heap(vma) || vma_is_initial_stack(vma);
>
>          start_limit = max(vma->vm_start >> PAGE_SHIFT,
> -                     (unsigned long)ALIGN_DOWN(addr, 2UL << 8));
> +                     (unsigned long)ALIGN_DOWN(addr, 1UL << p->svms.default_granularity));
>          end_limit = min(vma->vm_end >> PAGE_SHIFT,
> -                   (unsigned long)ALIGN(addr + 1, 2UL << 8));
> +                   (unsigned long)ALIGN(addr + 1, 1UL << p->svms.default_granularity));
> +
>          /* First range that starts after the fault address */
>          node = interval_tree_iter_first(&p->svms.objects, addr + 1, ULONG_MAX);
>          if (node) {
> @@ -3240,6 +3241,10 @@ int svm_range_list_init(struct kfd_process *p)
>                  if (KFD_IS_SVM_API_SUPPORTED(p->pdds[i]->dev->adev))
>                          bitmap_set(svms->bitmap_supported, i, 1);
>
> +       /* Update default granularity to one bound by user/driver */
> +       svms->default_granularity = min_t(u8, amdgpu_svm_default_granularity, 0x1B);
> +       pr_debug("Default SVM Granularity to use: %d\n", svms->default_granularity);
> +
>          return 0;
>   }
>
> @@ -3767,8 +3772,8 @@ svm_range_get_attr(struct kfd_process *p, struct mm_struct *mm,
>          node = interval_tree_iter_first(&svms->objects, start, last);
>          if (!node) {
>                  pr_debug("range attrs not found return default values\n");
> -               svm_range_set_default_attributes(&location, &prefetch_loc,
> -                                                &granularity, &flags_and);
> +               svm_range_set_default_attributes(svms, &location,
> +                               &granularity, &prefetch_loc, &flags_and);
>                  flags_or = flags_and;
>                  if (p->xnack_enabled)
>                          bitmap_copy(bitmap_access, svms->bitmap_supported,
> --
> 2.34.1
>


More information about the amd-gfx mailing list