Blame SOURCES/0017-tests-Update-utility-to-get-free-and-total-huge-page.patch

0dfa60
From 421dbc6d9dfc66f249dde787a69327d22979ca74 Mon Sep 17 00:00:00 2001
0dfa60
Message-Id: <421dbc6d9dfc66f249dde787a69327d22979ca74.1566225007.git.aquini@redhat.com>
0dfa60
In-Reply-To: <d42f467a923dfc09309acb7a83b42e3285fbd8f4.1566225007.git.aquini@redhat.com>
0dfa60
References: <d42f467a923dfc09309acb7a83b42e3285fbd8f4.1566225007.git.aquini@redhat.com>
0dfa60
From: Sandipan Das <sandipan@linux.ibm.com>
0dfa60
Date: Fri, 16 Aug 2019 11:45:07 +0530
0dfa60
Subject: [RHEL7 PATCH 17/31] tests: Update utility to get free and total huge
0dfa60
 pages by size
0dfa60
0dfa60
This makes the utilities to get the number of free and total
0dfa60
huge pages multi-size aware. If a page size is specified, they
0dfa60
will return counts corresponding to that. Otherwise, they will
0dfa60
return counts for the kernel's default huge page size.
0dfa60
0dfa60
Signed-off-by: Sandipan Das <sandipan@linux.ibm.com>
0dfa60
Signed-off-by: Eric B Munson <eric@munsonfam.org>
0dfa60
Signed-off-by: Rafael Aquini <aquini@redhat.com>
0dfa60
---
0dfa60
 tests/run_tests.py | 30 ++++++++++++++++++------------
0dfa60
 1 file changed, 18 insertions(+), 12 deletions(-)
0dfa60
0dfa60
diff --git a/tests/run_tests.py b/tests/run_tests.py
0dfa60
index 94000ea..f19024f 100755
0dfa60
--- a/tests/run_tests.py
0dfa60
+++ b/tests/run_tests.py
0dfa60
@@ -172,26 +172,32 @@ def results_summary():
0dfa60
     print_per_size("Strange test result", R["strange"])
0dfa60
     print "**********"
0dfa60
 
0dfa60
-def free_hpages():
0dfa60
+def free_hpages(size=None):
0dfa60
     """
0dfa60
-    Return the number of free huge pages.
0dfa60
+    Return the number of free huge pages for a given size. If size is not
0dfa60
+    passed, use the default huge page size.
0dfa60
 
0dfa60
-    Parse /proc/meminfo to obtain the number of free huge pages for
0dfa60
-    the default page size.
0dfa60
-    XXX: This function is not multi-size aware yet.
0dfa60
+    Parse /sys/kernel/mm/hugepages/hugepages-<size-in-kB>/free_hugepages to
0dfa60
+    obtain the number of free huge pages for the given page size.
0dfa60
     """
0dfa60
-    (rc, out) = bash("grep 'HugePages_Free:' /proc/meminfo | cut -f2 -d:")
0dfa60
+    if size == None: size = system_default_hpage_size
0dfa60
+    size_kb = size / 1024
0dfa60
+    cmd = "cat /sys/kernel/mm/hugepages/hugepages-%dkB/free_hugepages" % size_kb
0dfa60
+    (rc, out) = bash(cmd)
0dfa60
     return (rc, int(out))
0dfa60
 
0dfa60
-def total_hpages():
0dfa60
+def total_hpages(size=None):
0dfa60
     """
0dfa60
-    Return the total number of huge pages in the pool.
0dfa60
+    Return the total number of huge pages in the pool for a given size. If
0dfa60
+    size is not passed, use the default huge page size.
0dfa60
 
0dfa60
-    Parse /proc/meminfo to obtain the number of huge pages for the default
0dfa60
-    page size.
0dfa60
-    XXX: This function is not multi-size aware yet.
0dfa60
+    Parse /sys/kernel/mm/hugepages/hugepages-<size-in-kB>/nr_hugepages to
0dfa60
+    obtain the number of huge pages for the given page size.
0dfa60
     """
0dfa60
-    (rc, out) = bash("grep 'HugePages_Total:' /proc/meminfo | cut -f2 -d:")
0dfa60
+    if size == None: size = system_default_hpage_size
0dfa60
+    size_kb = size / 1024
0dfa60
+    cmd = "cat /sys/kernel/mm/hugepages/hugepages-%dkB/nr_hugepages" % size_kb
0dfa60
+    (rc, out) = bash(cmd)
0dfa60
     return (rc, int(out))
0dfa60
 
0dfa60
 def hpage_size():
0dfa60
-- 
0dfa60
1.8.3.1
0dfa60