blob: 04c497af1ee4bc57503da6ee0c56dd7e006b587b [file] [log] [blame]
subrata_modak0a1e45f2009-05-29 10:26:02 +00001/*
2 * Crackerjack Project
3 *
4 * Copyright (C) 2007-2008, Hitachi, Ltd.
5 * Author(s): Yumiko Sugita <yumiko.sugita.yf@hitachi.com>,
6 * Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp>
7 *
8 * Derived from 'numa.h' in numactl-0.9.8
9 * Copyright (C) 2003,2004 Andi Kleen, SuSE Labs.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 *
yaberauneya5f5ea1f2009-11-09 18:36:06 +000025 * $Id: numaif.h,v 1.4 2009/11/09 18:36:06 yaberauneya Exp $
subrata_modak0a1e45f2009-05-29 10:26:02 +000026 *
27 */
28
yaberauneya5766cd92009-11-09 05:39:52 +000029#include "config.h"
30#include "include_j_h.h"
subrata_modakd0762042009-06-23 14:21:32 +000031#include "linux_syscall_numbers.h"
subrata_modak0a1e45f2009-05-29 10:26:02 +000032
yaberauneya5766cd92009-11-09 05:39:52 +000033#if HAVE_NUMA_H
34#include <numa.h>
35#endif
36
subrata_modak0a1e45f2009-05-29 10:26:02 +000037#define NUMA_NUM_NODES 128
yaberauneya5f5ea1f2009-11-09 18:36:06 +000038
39#if HAVE_NUMA_H
40#include <numa.h>
41#else /* The following symbols clash with the numa.h ones. */
42
subrata_modak0a1e45f2009-05-29 10:26:02 +000043typedef struct {
44 unsigned long n[NUMA_NUM_NODES/(sizeof(unsigned long)*8)];
45} nodemask_t;
46
47static inline void nodemask_zero(nodemask_t *mask)
48{
49 memset(mask->n, 0, sizeof(mask->n));
50}
51
52static inline void nodemask_set(nodemask_t *mask, int node)
53{
54 mask->n[node / (8*sizeof(unsigned long))] |=
55 (1UL << (node % (8*sizeof(unsigned long))));
56}
57
58static inline void nodemask_clr(nodemask_t *mask, int node)
59{
60 mask->n[node / (8*sizeof(unsigned long))] &=
61 ~(1UL << (node % (8*sizeof(unsigned long))));
62}
63
64static inline int nodemask_isset(const nodemask_t *mask, int node)
65{
66 if ((unsigned)node >= NUMA_NUM_NODES)
67 return 0;
68 if (mask->n[node / (8*sizeof(unsigned long))] &
69 (1UL << (node % (8*sizeof(unsigned long)))))
70 return 1;
71 return 0;
72}
73
74static inline int nodemask_equal(const nodemask_t *a, const nodemask_t *b)
75{
76 int i;
77 for (i = 0; i < NUMA_NUM_NODES/(sizeof(unsigned long)*8); i++)
78 if (a->n[i] != b->n[i])
79 return 0;
80 return 1;
81}
yaberauneya5f5ea1f2009-11-09 18:36:06 +000082#endif
subrata_modak0a1e45f2009-05-29 10:26:02 +000083
84static inline void nodemask_dump(const char *header, const nodemask_t *mask)
85{
86 int i;
87 EPRINTF("%s", header);
88 for (i = 0; i < NUMA_NUM_NODES/(sizeof(unsigned long)*8); i++)
89 EPRINTF(" 0x%08lx", mask->n[i]);
90 EPRINTF("\n");
91}
92
subrata_modak0a1e45f2009-05-29 10:26:02 +000093#ifndef MPOL_DEFAULT
94 // Policies
95# define MPOL_DEFAULT 0
96# define MPOL_PREFERRED 1
97# define MPOL_BIND 2
98# define MPOL_INTERLEAVE 3
99 // Flags for get_mem_policy
100# define MPOL_F_NODE (1<<0)
101# define MPOL_F_ADDR (1<<1)
102 // Flags for mbind
103# define MPOL_MF_STRICT (1<<0)
104# define MPOL_MF_MOVE (1<<1)
105# define MPOL_MF_MOVE_ALL (1<<2)
106#endif