subrata_modak | 2b11124 | 2009-01-27 13:36:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2009 |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | */ |
| 19 | |
| 20 | /* |
| 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 |
| 26 | */ |
| 27 | |
| 28 | #include <fcntl.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <test.h> |
| 31 | |
| 32 | #define BUFSIZE 512 |
| 33 | |
| 34 | int get_no_of_hugepages() { |
| 35 | #ifdef __linux__ |
| 36 | FILE *f; |
| 37 | char buf[BUFSIZ]; |
| 38 | |
| 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(); |
| 43 | } |
| 44 | if (!fgets(buf, 10, f)) { |
| 45 | fclose(f); |
| 46 | tst_resm(TBROK, "Could not read Total_Hugepages from /proc/meminfo"); |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 47 | tst_exit(); |
subrata_modak | 2b11124 | 2009-01-27 13:36:23 +0000 | [diff] [blame] | 48 | } |
| 49 | pclose(f); |
| 50 | return(atoi(buf)); |
| 51 | #else |
| 52 | return -1; |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | |
| 57 | int hugepages_size() { |
| 58 | #ifdef __linux__ |
| 59 | FILE *f; |
| 60 | char buf[BUFSIZ]; |
| 61 | |
| 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(); |
| 66 | } |
| 67 | if (!fgets(buf, 10, f)) { |
| 68 | fclose(f); |
| 69 | tst_resm(TBROK, "Could not read HugePages_Size from /proc/meminfo"); |
| 70 | tst_exit(); |
| 71 | } |
| 72 | pclose(f); |
| 73 | return(atoi(buf)); |
| 74 | #else |
| 75 | return -1; |
| 76 | #endif |
| 77 | } |
| 78 | |