Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / lib / system_specific_hugepages_info.c
bloba3ee584def65cd2946dc3d46cd2255a6a3100a3d
1 /*
3 * Copyright (c) International Business Machines Corp., 2009
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * DESCRIPTION
22 * get_no_of_hugepages() --> Return No. of hugepages for this systems
23 * from /proc/meminfo
24 * hugepages_size() --> Return Hugepages Size for this system
25 * from /proc/meminfo
28 #include <fcntl.h>
29 #include <sys/types.h>
30 #include <test.h>
32 #define BUFSIZE 512
34 int get_no_of_hugepages() {
35 #ifdef __linux__
36 FILE *f;
37 char buf[BUFSIZ];
39 f = popen("grep 'HugePages_Total' /proc/meminfo | cut -d ':' -f2 | tr -d ' \n'", "r");
40 if (!f) {
41 tst_resm(TBROK, "Could not get info about Total_Hugepages from /proc/meminfo");
42 tst_exit();
44 if (!fgets(buf, 10, f)) {
45 fclose(f);
46 tst_resm(TBROK, "Could not read Total_Hugepages from /proc/meminfo");
47 tst_exit();
49 pclose(f);
50 return(atoi(buf));
51 #else
52 return -1;
53 #endif
57 int hugepages_size() {
58 #ifdef __linux__
59 FILE *f;
60 char buf[BUFSIZ];
62 f = popen("grep 'Hugepagesize' /proc/meminfo | cut -d ':' -f2 | tr -d 'kB \n'", "r");
63 if (!f) {
64 tst_resm(TBROK, "Could not get info about HugePages_Size from /proc/meminfo");
65 tst_exit();
67 if (!fgets(buf, 10, f)) {
68 fclose(f);
69 tst_resm(TBROK, "Could not read HugePages_Size from /proc/meminfo");
70 tst_exit();
72 pclose(f);
73 return(atoi(buf));
74 #else
75 return -1;
76 #endif