numa_node_size.c revision adc21b6b3c26d1021d1a3a3742fbb03110524e04
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               */
17/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    */
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
34#define _GNU_SOURCE
35#include <stdio.h>
36#include <stdlib.h>
37#include "numa.h"
38char *fmt_mem(unsigned long long mem, char *buf)
39{
40        if (mem == -1L)
41                sprintf(buf, "<not available>");
42        else
43                sprintf(buf, "%Lu MB", mem >> 20);
44        return buf;
45}
46void hardware(void)
47{
48        int i;
49        int maxnode = numa_max_node();
50        printf("available: %d nodes (0-%d)\n", 1+maxnode, maxnode);
51        for (i = 0; i <= maxnode; i++) {
52                char buf[64];
53                long fr;
54                unsigned long sz = numa_node_size(i, &fr);
55                printf("node %d cpus:", i);
56                printf("node %d size: %s\n", i, fmt_mem(sz, buf));
57                printf("node %d free: %s\n", i, fmt_mem(fr, buf));
58        }
59}
60int main()
61{
62        void hardware();
63	 if (numa_available() < 0)
64	 {
65         	printf("This system does not support NUMA policy");
66		 exit(1);
67    	 }
68	hardware();
69	return 0;
70}
71
72