diff mbox

[PATCHv2,1/2] linux-generic: use default huge page size

Message ID 1462892884-9610-2-git-send-email-maxim.uvarov@linaro.org
State Superseded
Headers show

Commit Message

Maxim Uvarov May 10, 2016, 3:08 p.m. UTC
odp_shm_reserve() relays on huge page size to round up
requested size. If 1 Gb pages present than parser takes
it first as first alphabetical file name in sysfs. That
lead to issue where all allocations wants 1 GB HP. This
patch takes system default huge pages which are usually 2Mb,
and has to be enough for existence odp example apps and
validation tests.

Reported-by: B.Nousilal <bnousilal@gmail.com>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_system_info.c | 46 +++++++++++++-------------------
 1 file changed, 18 insertions(+), 28 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 0f1f3c7..14244c3 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -24,12 +24,9 @@ 
 #include <sys/types.h>
 #include <dirent.h>
 
-
 #define CACHE_LNSZ_FILE \
 	"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
 
-#define HUGE_PAGE_DIR "/sys/kernel/mm/hugepages"
-
 /*
  * Report the number of logical CPUs detected at boot time
  */
@@ -77,37 +74,30 @@  static int systemcpu_cache_line_size(void)
 #endif
 
 
-static int huge_page_size(void)
+static int default_huge_page_size(void)
 {
-	DIR *dir;
-	struct dirent *dirent;
-	int size = 0;
+	char str[1024];
+	char *pos;
+	uint64_t sz;
+	FILE *file;
 
-	dir = opendir(HUGE_PAGE_DIR);
-	if (dir == NULL) {
-		ODP_ERR("%s not found\n", HUGE_PAGE_DIR);
-		return 0;
-	}
-
-	while ((dirent = readdir(dir)) != NULL) {
-		int temp = 0;
-
-		if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1)
-			continue;
-
-		if (temp > size)
-			size = temp;
-	}
+	file = fopen("/proc/meminfo", "rt");
 
-	if (closedir(dir)) {
-		ODP_ERR("closedir failed\n");
-		return 0;
+	while (fgets(str, sizeof(str), file) != NULL) {
+		pos = strstr(str, "Hugepagesize:");
+		if (pos) {
+			*(pos - 1) = '\0';
+			if (sscanf(pos, "@ %ld kB", &sz) == 1) {
+				fclose(file);
+				return sz * 1024;
+			}
+		}
 	}
 
-	return size * 1024;
+	fclose(file);
+	return 0;
 }
 
-
 /*
  * Analysis of /sys/devices/system/cpu/ files
  */
@@ -137,7 +127,7 @@  static int systemcpu(odp_system_info_t *sysinfo)
 		return -1;
 	}
 
-	sysinfo->huge_page_size = huge_page_size();
+	sysinfo->huge_page_size = default_huge_page_size();
 
 	return 0;
 }