blob: 6338bc73c864b2fe6fcf3aa6d5424198efc8c856 [file] [log] [blame]
subrata_modakadc21b62007-12-13 10:11:34 +00001/******************************************************************************/
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 Gao4548c6c2012-10-19 18:03:36 +080017/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modakadc21b62007-12-13 10:11:34 +000018/* */
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 Liucbd60192012-03-02 19:32:28 +080034#include "config.h"
subrata_modakadc21b62007-12-13 10:11:34 +000035#include <stdio.h>
36#include <stdlib.h>
Zhouping Liucbd60192012-03-02 19:32:28 +080037#if HAVE_NUMA_H
yaberauneyaef772532009-10-09 17:55:43 +000038#include <numa.h>
39#endif
40
subrata_modak883f8342008-01-31 10:56:26 +000041int numa_exit_on_error = 0;
subrata_modakadc21b62007-12-13 10:11:34 +000042char *fmt_mem(unsigned long long mem, char *buf)
43{
Wanlong Gao354ebb42012-12-07 10:10:04 +080044 if (mem == -1L)
45 sprintf(buf, "<not available>");
46 else
47 sprintf(buf, "%Lu MB", mem >> 20);
48 return buf;
subrata_modakadc21b62007-12-13 10:11:34 +000049}
Wanlong Gao354ebb42012-12-07 10:10:04 +080050
subrata_modakadc21b62007-12-13 10:11:34 +000051void hardware(void)
52{
Zhouping Liucbd60192012-03-02 19:32:28 +080053#if HAVE_NUMA_H
Wanlong Gao354ebb42012-12-07 10:10:04 +080054 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 }
yaberauneyaef772532009-10-09 17:55:43 +000065#endif
subrata_modakadc21b62007-12-13 10:11:34 +000066}
Wanlong Gao354ebb42012-12-07 10:10:04 +080067
Mike Frysinger829ac9d2015-03-07 21:09:17 -050068int main(void)
subrata_modakadc21b62007-12-13 10:11:34 +000069{
Zhouping Liucbd60192012-03-02 19:32:28 +080070#if HAVE_NUMA_H
Wanlong Gao354ebb42012-12-07 10:10:04 +080071 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;
yaberauneyaef772532009-10-09 17:55:43 +000084#else
Wanlong Gao354ebb42012-12-07 10:10:04 +080085 printf("NUMA is not available\n");
86 return 1;
yaberauneyaef772532009-10-09 17:55:43 +000087#endif
Zhouping Liucbd60192012-03-02 19:32:28 +080088}