I want to enable using hugepage releated functions in
$(topdir)/lib/system_specific_hugepages_info.c and I added a function to
get No. of free_hugepages.
Signed-off-by: Caspar Zhang <[email protected]>
---
include/system_specific_hugepages_info.h | 4 ++-
lib/system_specific_hugepages_info.c | 44 ++++++++++++++++++++---------
2 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/include/system_specific_hugepages_info.h b/include/system_specific_hugepages_info.h
index 43c5ddc..f5e3c46 100644
--- a/include/system_specific_hugepages_info.h
+++ b/include/system_specific_hugepages_info.h
@@ -22,7 +22,9 @@
/*Returns Total No. of available Hugepages in the system from /proc/meminfo*/
int get_no_of_hugepages(void);
+/*Returns No. of Hugepages_Free from /proc/meminfo*/
+int get_no_of_free_hugepages(void);
/*Returns Hugepages Size from /proc/meminfo*/
int hugepages_size(void);
-#endif
+#endif
diff --git a/lib/system_specific_hugepages_info.c b/lib/system_specific_hugepages_info.c
index 7e9be3b..2344add 100644
--- a/lib/system_specific_hugepages_info.c
+++ b/lib/system_specific_hugepages_info.c
@@ -29,22 +29,19 @@
#include <sys/types.h>
#include <test.h>
-#define BUFSIZE 512
-
int get_no_of_hugepages() {
#ifdef __linux__
FILE *f;
char buf[BUFSIZ];
f = popen("grep 'HugePages_Total' /proc/meminfo | cut -d ':' -f2 | tr -d ' \n'", "r");
- if (!f) {
- tst_resm(TBROK, "Could not get info about Total_Hugepages from /proc/meminfo");
- tst_exit();
- }
+ if (!f)
+ tst_brkm(TBROK, NULL,
+ "Could not get info about Total_Hugepages from /proc/meminfo");
if (!fgets(buf, 10, f)) {
fclose(f);
- tst_resm(TBROK, "Could not read Total_Hugepages from /proc/meminfo");
- tst_exit();
+ tst_brkm(TBROK, NULL,
+ "Could not read Total_Hugepages from /proc/meminfo");
}
pclose(f);
return(atoi(buf));
@@ -53,6 +50,26 @@ int get_no_of_hugepages() {
#endif
}
+int get_no_of_free_hugepages() {
+ #ifdef __linux__
+ FILE *f;
+ char buf[BUFSIZ];
+
+ f = popen("grep 'HugePages_Free' /proc/meminfo | cut -d ':' -f2 | tr -d ' \n'", "r");
+ if (!f)
+ tst_brkm(TBROK, NULL,
+ "Could not get info about HugePages_Free from /proc/meminfo");
+ if (!fgets(buf, 10, f)) {
+ fclose(f);
+ tst_brkm(TBROK, NULL,
+ "Could not read HugePages_Free from /proc/meminfo");
+ }
+ pclose(f);
+ return(atoi(buf));
+ #else
+ return -1;
+ #endif
+}
int hugepages_size() {
#ifdef __linux__
@@ -60,14 +77,13 @@ int hugepages_size() {
char buf[BUFSIZ];
f = popen("grep 'Hugepagesize' /proc/meminfo | cut -d ':' -f2 | tr -d 'kB \n'", "r");
- if (!f) {
- tst_resm(TBROK, "Could not get info about HugePages_Size from /proc/meminfo");
- tst_exit();
- }
+ if (!f)
+ tst_brkm(TBROK, NULL,
+ "Could not get info about HugePages_Size from /proc/meminfo");
if (!fgets(buf, 10, f)) {
fclose(f);
- tst_resm(TBROK, "Could not read HugePages_Size from /proc/meminfo");
- tst_exit();
+ tst_brkm(TBROK, NULL,
+ "Could not read HugePages_Size from /proc/meminfo");
}
pclose(f);
return(atoi(buf));
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list