[PATCH 28/37] drm/amdkfd: Add support for displaying VRAM usage

Oded Gabbay oded.gabbay at gmail.com
Mon Dec 11 15:32:21 UTC 2017


On Sat, Dec 9, 2017 at 6:09 AM, Felix Kuehling <Felix.Kuehling at amd.com> wrote:
> From: Kent Russell <kent.russell at amd.com>
>
> Add a sysfs file in topology (node/x/memory_banks/X/used_memory) that
> reports the current VRAM usage for that node. Only works for GPU nodes
> at this time.
>

As with patch 22 (perf counters), I would not expect this information
to be included in the topology. It doesn't describe the properties of
the device, but a current state.
Oded

> Signed-off-by: Kent Russell <kent.russell at amd.com>
> Signed-off-by: Felix Kuehling <Felix.Kuehling at amd.com>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 49 +++++++++++++++++++++++++++----
>  drivers/gpu/drm/amd/amdkfd/kfd_topology.h |  4 ++-
>  2 files changed, 46 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> index 7f0d41e..7f04038 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> @@ -186,6 +186,8 @@ struct kfd_topology_device *kfd_create_topology_device(
>                 sysfs_show_gen_prop(buffer, "%s %llu\n", name, value)
>  #define sysfs_show_32bit_val(buffer, value) \
>                 sysfs_show_gen_prop(buffer, "%u\n", value)
> +#define sysfs_show_64bit_val(buffer, value) \
> +               sysfs_show_gen_prop(buffer, "%llu\n", value)
>  #define sysfs_show_str_val(buffer, value) \
>                 sysfs_show_gen_prop(buffer, "%s\n", value)
>
> @@ -268,11 +270,23 @@ static ssize_t mem_show(struct kobject *kobj, struct attribute *attr,
>  {
>         ssize_t ret;
>         struct kfd_mem_properties *mem;
> +       uint64_t used_mem;
>
>         /* Making sure that the buffer is an empty string */
>         buffer[0] = 0;
>
> -       mem = container_of(attr, struct kfd_mem_properties, attr);
> +       if (strcmp(attr->name, "used_memory") == 0) {
> +               mem = container_of(attr, struct kfd_mem_properties, attr_used);
> +               if (mem->gpu) {
> +                       used_mem = mem->gpu->kfd2kgd->get_vram_usage(
> +                                                               mem->gpu->kgd);
> +                       return sysfs_show_64bit_val(buffer, used_mem);
> +               }
> +               /* TODO: Report APU/CPU-allocated memory; For now return 0 */
> +               return 0;
> +       }
> +
> +       mem = container_of(attr, struct kfd_mem_properties, attr_props);
>         sysfs_show_32bit_prop(buffer, "heap_type", mem->heap_type);
>         sysfs_show_64bit_prop(buffer, "size_in_bytes", mem->size_in_bytes);
>         sysfs_show_32bit_prop(buffer, "flags", mem->flags);
> @@ -527,7 +541,12 @@ static void kfd_remove_sysfs_node_entry(struct kfd_topology_device *dev)
>         if (dev->kobj_mem) {
>                 list_for_each_entry(mem, &dev->mem_props, list)
>                         if (mem->kobj) {
> -                               kfd_remove_sysfs_file(mem->kobj, &mem->attr);
> +                               /* TODO: Remove when CPU/APU supported */
> +                               if (dev->node_props.cpu_cores_count == 0)
> +                                       sysfs_remove_file(mem->kobj,
> +                                                       &mem->attr_used);
> +                               kfd_remove_sysfs_file(mem->kobj,
> +                                               &mem->attr_props);
>                                 mem->kobj = NULL;
>                         }
>                 kobject_del(dev->kobj_mem);
> @@ -629,12 +648,23 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
>                 if (ret < 0)
>                         return ret;
>
> -               mem->attr.name = "properties";
> -               mem->attr.mode = KFD_SYSFS_FILE_MODE;
> -               sysfs_attr_init(&mem->attr);
> -               ret = sysfs_create_file(mem->kobj, &mem->attr);
> +               mem->attr_props.name = "properties";
> +               mem->attr_props.mode = KFD_SYSFS_FILE_MODE;
> +               sysfs_attr_init(&mem->attr_props);
> +               ret = sysfs_create_file(mem->kobj, &mem->attr_props);
>                 if (ret < 0)
>                         return ret;
> +
> +               /* TODO: Support APU/CPU memory usage */
> +               if (dev->node_props.cpu_cores_count == 0) {
> +                       mem->attr_used.name = "used_memory";
> +                       mem->attr_used.mode = KFD_SYSFS_FILE_MODE;
> +                       sysfs_attr_init(&mem->attr_used);
> +                       ret = sysfs_create_file(mem->kobj, &mem->attr_used);
> +                       if (ret < 0)
> +                               return ret;
> +               }
> +
>                 i++;
>         }
>
> @@ -1075,15 +1105,22 @@ static struct kfd_topology_device *kfd_assign_gpu(struct kfd_dev *gpu)
>  {
>         struct kfd_topology_device *dev;
>         struct kfd_topology_device *out_dev = NULL;
> +       struct kfd_mem_properties *mem;
>
>         down_write(&topology_lock);
>         list_for_each_entry(dev, &topology_device_list, list)
>                 if (!dev->gpu && (dev->node_props.simd_count > 0)) {
>                         dev->gpu = gpu;
>                         out_dev = dev;
> +
> +                       /* Assign mem->gpu */
> +                       list_for_each_entry(mem, &dev->mem_props, list)
> +                               mem->gpu = dev->gpu;
> +
>                         break;
>                 }
>         up_write(&topology_lock);
> +
>         return out_dev;
>  }
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.h b/drivers/gpu/drm/amd/amdkfd/kfd_topology.h
> index 53fca1f..0f698d8 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.h
> @@ -93,7 +93,9 @@ struct kfd_mem_properties {
>         uint32_t                width;
>         uint32_t                mem_clk_max;
>         struct kobject          *kobj;
> -       struct attribute        attr;
> +       struct kfd_dev          *gpu;
> +       struct attribute        attr_props;
> +       struct attribute        attr_used;
>  };
>
>  #define HSA_CACHE_TYPE_DATA            0x00000001
> --
> 2.7.4
>


More information about the amd-gfx mailing list