subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 2 | /* */ |
| 3 | /* Copyright (c) International Business Machines Corp., 2007 */ |
| 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 */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 18 | /* */ |
| 19 | /******************************************************************************/ |
| 20 | |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: numa_node_size.c */ |
| 24 | /* */ |
| 25 | /* Description: Invokes numa_node_size() API */ |
| 26 | /* */ |
| 27 | /* Author: Pradeep Kumar Surisetty pradeepkumars@in.ibm.com */ |
| 28 | /* */ |
| 29 | /* History: Created - Nov 28 2007 - Pradeep Kumar Surisetty */ |
| 30 | /* pradeepkumars@in.ibm.com */ |
| 31 | /* */ |
| 32 | /******************************************************************************/ |
| 33 | |
Zhouping Liu | cbd6019 | 2012-03-02 19:32:28 +0800 | [diff] [blame] | 34 | #include "config.h" |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
Zhouping Liu | cbd6019 | 2012-03-02 19:32:28 +0800 | [diff] [blame] | 37 | #if HAVE_NUMA_H |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 38 | #include <numa.h> |
| 39 | #endif |
| 40 | |
subrata_modak | 883f834 | 2008-01-31 10:56:26 +0000 | [diff] [blame] | 41 | int numa_exit_on_error = 0; |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 42 | char *fmt_mem(unsigned long long mem, char *buf) |
| 43 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 44 | if (mem == -1L) |
| 45 | sprintf(buf, "<not available>"); |
| 46 | else |
| 47 | sprintf(buf, "%Lu MB", mem >> 20); |
| 48 | return buf; |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 49 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 50 | |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 51 | void hardware(void) |
| 52 | { |
Zhouping Liu | cbd6019 | 2012-03-02 19:32:28 +0800 | [diff] [blame] | 53 | #if HAVE_NUMA_H |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 54 | int i; |
| 55 | int maxnode = numa_max_node(); |
| 56 | printf("available: %d nodes (0-%d)\n", 1 + maxnode, maxnode); |
| 57 | for (i = 0; i <= maxnode; i++) { |
| 58 | char buf[64]; |
| 59 | long fr; |
| 60 | unsigned long sz = numa_node_size(i, &fr); |
| 61 | printf("node %d cpus:", i); |
| 62 | printf("node %d size: %s\n", i, fmt_mem(sz, buf)); |
| 63 | printf("node %d free: %s\n", i, fmt_mem(fr, buf)); |
| 64 | } |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 65 | #endif |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 66 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 67 | |
Mike Frysinger | 829ac9d | 2015-03-07 21:09:17 -0500 | [diff] [blame] | 68 | int main(void) |
subrata_modak | adc21b6 | 2007-12-13 10:11:34 +0000 | [diff] [blame] | 69 | { |
Zhouping Liu | cbd6019 | 2012-03-02 19:32:28 +0800 | [diff] [blame] | 70 | #if HAVE_NUMA_H |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | nodemask_t nodemask; |
| 72 | void hardware(); |
| 73 | if (numa_available() < 0) { |
| 74 | printf("This system does not support NUMA policy\n"); |
| 75 | numa_error("numa_available"); |
| 76 | numa_exit_on_error = 1; |
| 77 | exit(numa_exit_on_error); |
| 78 | } |
| 79 | nodemask_zero(&nodemask); |
| 80 | nodemask_set(&nodemask, 1); |
| 81 | numa_bind(&nodemask); |
| 82 | hardware(); |
| 83 | return numa_exit_on_error; |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 84 | #else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | printf("NUMA is not available\n"); |
| 86 | return 1; |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 87 | #endif |
Zhouping Liu | cbd6019 | 2012-03-02 19:32:28 +0800 | [diff] [blame] | 88 | } |