forked from Irqbalance/irqbalance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numa.c
155 lines (127 loc) · 3.58 KB
/
numa.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (C) 2006, Intel Corporation
* Copyright (C) 2012, Neil Horman <[email protected]>
*
* This file is part of irqbalance
*
* This program file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/*
* This file tries to map numa affinity of pci devices to their interrupts
* In addition the PCI class information is used to refine the classification
* of interrupt sources
*/
#include "config.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <dirent.h>
#include "irqbalance.h"
#define SYSFS_NODE_PATH "/sys/devices/system/node"
GList *numa_nodes = NULL;
static void add_one_node(int nodeid)
{
char path[PATH_MAX];
struct topo_obj *new;
new = calloc(1, sizeof(struct topo_obj));
if (!new) {
need_rebuild = 1;
return;
}
if (nodeid == NUMA_NO_NODE) {
cpus_setall(new->mask);
} else {
cpus_clear(new->mask);
sprintf(path, "%s/node%d/cpumap", SYSFS_NODE_PATH, nodeid);
process_one_line(path, get_mask_from_bitmap, &new->mask);
}
new->obj_type = OBJ_TYPE_NODE;
new->number = nodeid;
new->obj_type_list = &numa_nodes;
numa_nodes = g_list_append(numa_nodes, new);
}
void build_numa_node_list(void)
{
DIR *dir;
struct dirent *entry;
/* Add the unspecified node */
add_one_node(NUMA_NO_NODE);
if (!numa_avail)
return;
dir = opendir(SYSFS_NODE_PATH);
if (!dir)
return;
do {
entry = readdir(dir);
if (!entry)
break;
if ((entry->d_type == DT_DIR) &&
g_str_has_prefix(entry->d_name, "node") &&
isdigit(entry->d_name[4])) {
add_one_node(strtoul(&entry->d_name[4], NULL, 10));
}
} while (entry);
closedir(dir);
}
void free_numa_node_list(void)
{
g_list_free_full(numa_nodes, free_cpu_topo);
numa_nodes = NULL;
}
static gint compare_node(gconstpointer a, gconstpointer b)
{
const struct topo_obj *ai = a;
const struct topo_obj *bi = b;
return (ai->number == bi->number) ? 0 : 1;
}
void connect_cpu_mem_topo(struct topo_obj *p, void *data __attribute__((unused)))
{
GList *entry;
struct topo_obj *node;
int len;
len = g_list_length(p->numa_nodes);
if (len == 0) {
return;
} if (len > 1) {
for_each_object(p->children, connect_cpu_mem_topo, NULL);
return;
}
entry = g_list_first(p->numa_nodes);
node = entry->data;
if (p->obj_type == OBJ_TYPE_PACKAGE && !p->parent)
p->parent = node;
entry = g_list_find(node->children, p);
if (!entry)
node->children = g_list_append(node->children, p);
}
void dump_numa_node_info(struct topo_obj *d, void *unused __attribute__((unused)))
{
char buffer[4096];
log(TO_CONSOLE, LOG_INFO, "NUMA NODE NUMBER: %d\n", d->number);
cpumask_scnprintf(buffer, 4096, d->mask);
log(TO_CONSOLE, LOG_INFO, "LOCAL CPU MASK: %s\n", buffer);
log(TO_CONSOLE, LOG_INFO, "\n");
}
struct topo_obj *get_numa_node(int nodeid)
{
struct topo_obj find;
GList *entry;
find.number = numa_avail ? nodeid : NUMA_NO_NODE;
entry = g_list_find_custom(numa_nodes, &find, compare_node);
return entry ? entry->data : NULL;
}