From 93fde3b573c6988b24d8cca189ecb5a4fd17a50f Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Fri, 11 Apr 2025 11:23:31 +0000 Subject: [PATCH] video: tegra: nvmap: Add numa checks Android builds don't have CONFIG_NUMA enabled hence /sys/devices/system/node/node0/meminfo is not present on android. While nvscibuf calls the QueryHeapParams to check presence of the hugetlbfs based carveout, the error prints will be seen due to absence of the above sysfs file. Hence first check whethere there are multiple numa nodes are not. If not, then use /proc/meminfo file to retrieve the hugetlbfs size otherwise use the meminfo sysfs node from the corresponding numa node. Bug 5200644 Change-Id: I5495de91726d323210807e86f22757b798226fca Signed-off-by: Ketan Patil Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3338255 Reviewed-by: Pritesh Raithatha Reviewed-by: mobile promotions Reviewed-by: svcacv Tested-by: mobile promotions Reviewed-by: Jian-Min Liu GVS: buildbot_gerritrpt --- drivers/video/tegra/nvmap/nvmap_heap.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/video/tegra/nvmap/nvmap_heap.c b/drivers/video/tegra/nvmap/nvmap_heap.c index c1a62d0e..13836f70 100644 --- a/drivers/video/tegra/nvmap/nvmap_heap.c +++ b/drivers/video/tegra/nvmap/nvmap_heap.c @@ -178,7 +178,16 @@ static int compute_hugetlbfs_stat(u64 *total, u64 *free, int numa_id) bool total_found = false, free_found = false; int nid, rc; - sprintf(meminfo_path, "/sys/devices/system/node/node%d/meminfo", numa_id); + if (num_online_nodes() > 1) { + sprintf(meminfo_path, "/sys/devices/system/node/node%d/meminfo", numa_id); + } else { + if (numa_id != 0) { + pr_err("Incorrect input for numa_id:%d\n", numa_id); + return -EINVAL; + } + sprintf(meminfo_path, "/proc/meminfo"); + } + file = filp_open(meminfo_path, O_RDONLY, 0); if (IS_ERR(file)) { pr_err("Could not open file:%s\n", meminfo_path); @@ -200,10 +209,17 @@ static int compute_hugetlbfs_stat(u64 *total, u64 *free, int numa_id) while ((ptr = strsep(&buffer, "\n")) != NULL) { if (!ptr[0]) continue; - else if (sscanf(ptr, "Node %d HugePages_Total: %u\n", &nid, &huge_total) == 2) - total_found = true; - else if (sscanf(ptr, "Node %d HugePages_Free: %u\n", &nid, &huge_free) == 2) - free_found = true; + if (num_online_nodes() > 1) { + if (sscanf(ptr, "Node %d HugePages_Total: %u\n", &nid, &huge_total) == 2) + total_found = true; + else if (sscanf(ptr, "Node %d HugePages_Free: %u\n", &nid, &huge_free) == 2) + free_found = true; + } else { + if (sscanf(ptr, "HugePages_Total: %u\n", &huge_total) == 1) + total_found = true; + else if (sscanf(ptr, "HugePages_Free: %u\n", &huge_free) == 1) + free_found = true; + } } nvmap_altfree(buf, MEMINFO_SIZE * sizeof(*buf));