From 343f9e764f4d06209051d5b15d71d0012596762b Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Mon, 6 Nov 2023 07:21:17 +0000 Subject: [PATCH] video: tegra: nvmap: Add NUMA aware query heap API Add a new API to query the heap params for an input heap present on the given input numa node. e.g. User may specify to query heap information of GPU carveout on numa node 0 or numa node 1 etc. Bug 4231517 Change-Id: I9622828b6a28984564b4c7f17b88b4d38bbd4684 Signed-off-by: Ketan Patil Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3010795 Reviewed-by: Pritesh Raithatha Reviewed-by: Krishna Reddy GVS: Gerrit_Virtual_Submit --- drivers/video/tegra/nvmap/nvmap_dev.c | 5 +++++ drivers/video/tegra/nvmap/nvmap_ioctl.c | 25 +++++++++++++++++++++---- drivers/video/tegra/nvmap/nvmap_ioctl.h | 2 ++ include/uapi/linux/nvmap.h | 7 ++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index 45f57ef9..71f64393 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c @@ -488,6 +488,11 @@ static long nvmap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case NVMAP_IOC_QUERY_HEAP_PARAMS: err = nvmap_ioctl_query_heap_params(filp, uarg); break; + + case NVMAP_IOC_QUERY_HEAP_PARAMS_NUMA: + err = nvmap_ioctl_query_heap_params_numa(filp, uarg); + break; + case NVMAP_IOC_GET_FD_FOR_RANGE_FROM_LIST: err = nvmap_ioctl_get_fd_from_list(filp, uarg); break; diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index 6d6d0923..7e4c4609 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c @@ -1365,7 +1365,7 @@ static unsigned long system_heap_total_mem(void) return sys_heap.totalram << PAGE_SHIFT; } -int nvmap_ioctl_query_heap_params(struct file *filp, void __user *arg) +static int nvmap_query_heap_params(void __user *arg, bool is_numa_aware) { unsigned int carveout_mask = NVMAP_HEAP_CARVEOUT_MASK; unsigned int iovmm_mask = NVMAP_HEAP_IOVMM; @@ -1374,6 +1374,7 @@ int nvmap_ioctl_query_heap_params(struct file *filp, void __user *arg) unsigned int type; int ret = 0; int i; + int numa_id; unsigned long free_mem = 0; memset(&op, 0, sizeof(op)); @@ -1384,6 +1385,8 @@ int nvmap_ioctl_query_heap_params(struct file *filp, void __user *arg) type = op.heap_mask; WARN_ON(type & (type - 1)); + if (is_numa_aware) + numa_id = op.numa_id; if (nvmap_convert_carveout_to_iovmm) { carveout_mask &= ~NVMAP_HEAP_CARVEOUT_GENERIC; @@ -1400,12 +1403,16 @@ int nvmap_ioctl_query_heap_params(struct file *filp, void __user *arg) if (type & NVMAP_HEAP_CARVEOUT_MASK) { for (i = 0; i < nvmap_dev->nr_carveouts; i++) { - if (type & nvmap_dev->heaps[i].heap_bit) { + if ((type & nvmap_dev->heaps[i].heap_bit) && + (is_numa_aware ? + (numa_id == nvmap_dev->heaps[i].carveout->numa_node_id) : true)) { heap = nvmap_dev->heaps[i].carveout; op.total = nvmap_query_heap_size(heap); op.free = heap->free_size; - if (nvmap_dev->heaps[i].carveout->is_gpu_co) - op.granule_size = nvmap_dev->heaps[i].carveout->granule_size; + if (nvmap_dev->heaps[i].carveout->is_gpu_co) { + op.granule_size = + nvmap_dev->heaps[i].carveout->granule_size; + } break; } } @@ -1428,6 +1435,16 @@ exit: return ret; } +int nvmap_ioctl_query_heap_params(struct file *filp, void __user *arg) +{ + return nvmap_query_heap_params(arg, false); +} + +int nvmap_ioctl_query_heap_params_numa(struct file *filp, void __user *arg) +{ + return nvmap_query_heap_params(arg, true); +} + int nvmap_ioctl_dup_handle(struct file *filp, void __user *arg) { struct nvmap_client *client = filp->private_data; diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.h b/drivers/video/tegra/nvmap/nvmap_ioctl.h index 919f4dbd..694a8c47 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.h +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.h @@ -64,6 +64,8 @@ int nvmap_ioctl_handle_from_sci_ipc_id(struct file *filp, void __user *arg); int nvmap_ioctl_query_heap_params(struct file *filp, void __user *arg); +int nvmap_ioctl_query_heap_params_numa(struct file *filp, void __user *arg); + int nvmap_ioctl_dup_handle(struct file *filp, void __user *arg); int nvmap_ioctl_get_fd_from_list(struct file *filp, void __user *arg); diff --git a/include/uapi/linux/nvmap.h b/include/uapi/linux/nvmap.h index 16af5f5a..5bd92a6d 100644 --- a/include/uapi/linux/nvmap.h +++ b/include/uapi/linux/nvmap.h @@ -241,6 +241,7 @@ struct nvmap_query_heap_params { __u64 free; __u64 largest_free_block; __u32 granule_size; + __s32 numa_id; }; /** @@ -369,6 +370,10 @@ struct nvmap_fd_for_range_from_list { #define NVMAP_IOC_GET_FD_FOR_RANGE_FROM_LIST _IOR(NVMAP_IOC_MAGIC, 107, \ struct nvmap_fd_for_range_from_list) -#define NVMAP_IOC_MAXNR (_IOC_NR(NVMAP_IOC_GET_FD_FOR_RANGE_FROM_LIST)) +/* NUMA aware query heap params */ +#define NVMAP_IOC_QUERY_HEAP_PARAMS_NUMA _IOR(NVMAP_IOC_MAGIC, 108, \ + struct nvmap_query_heap_params) + +#define NVMAP_IOC_MAXNR (_IOC_NR(NVMAP_IOC_QUERY_HEAP_PARAMS_NUMA)) #endif /* __UAPI_LINUX_NVMAP_H */