subrata_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
yaberauneya | 5f5ea1f | 2009-11-09 18:36:06 +0000 | [diff] [blame^] | 25 | * $Id: numaif.h,v 1.4 2009/11/09 18:36:06 yaberauneya Exp $ |
subrata_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 26 | * |
| 27 | */ |
| 28 | |
yaberauneya | 5766cd9 | 2009-11-09 05:39:52 +0000 | [diff] [blame] | 29 | #include "config.h" |
| 30 | #include "include_j_h.h" |
subrata_modak | d076204 | 2009-06-23 14:21:32 +0000 | [diff] [blame] | 31 | #include "linux_syscall_numbers.h" |
subrata_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 32 | |
yaberauneya | 5766cd9 | 2009-11-09 05:39:52 +0000 | [diff] [blame] | 33 | #if HAVE_NUMA_H |
| 34 | #include <numa.h> |
| 35 | #endif |
| 36 | |
subrata_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 37 | #define NUMA_NUM_NODES 128 |
yaberauneya | 5f5ea1f | 2009-11-09 18:36:06 +0000 | [diff] [blame^] | 38 | |
| 39 | #if HAVE_NUMA_H |
| 40 | #include <numa.h> |
| 41 | #else /* The following symbols clash with the numa.h ones. */ |
| 42 | |
subrata_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 43 | typedef struct { |
| 44 | unsigned long n[NUMA_NUM_NODES/(sizeof(unsigned long)*8)]; |
| 45 | } nodemask_t; |
| 46 | |
| 47 | static inline void nodemask_zero(nodemask_t *mask) |
| 48 | { |
| 49 | memset(mask->n, 0, sizeof(mask->n)); |
| 50 | } |
| 51 | |
| 52 | static 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 | |
| 58 | static 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 | |
| 64 | static 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 | |
| 74 | static 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 | } |
yaberauneya | 5f5ea1f | 2009-11-09 18:36:06 +0000 | [diff] [blame^] | 82 | #endif |
subrata_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 83 | |
| 84 | static 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_modak | 0a1e45f | 2009-05-29 10:26:02 +0000 | [diff] [blame] | 93 | #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 |