irqbalance: use add_one_node() to create unspecified node for numa
Use add_one_node(NUMA_NO_NODE) to create a unspecified node instead of global variable. It can reuse the function add_one_node() and delete two global variable unspecified_node_template and unspecified_node. Also it can reuse the function free_cpu_topo() instead of free_numa_node(). Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
This commit is contained in:
parent
47137bb3e7
commit
4f361d0a7c
|
@ -508,7 +508,7 @@ void parse_cpu_tree(void)
|
|||
|
||||
}
|
||||
|
||||
static void free_cpu_topo(gpointer data)
|
||||
void free_cpu_topo(gpointer data)
|
||||
{
|
||||
struct topo_obj *obj = data;
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ void dump_tree(void);
|
|||
|
||||
void activate_mappings(void);
|
||||
void clear_cpu_tree(void);
|
||||
void free_cpu_topo(gpointer data);
|
||||
|
||||
/*===================NEW BALANCER FUNCTIONS============================*/
|
||||
|
||||
|
|
58
numa.c
58
numa.c
|
@ -39,20 +39,7 @@
|
|||
|
||||
GList *numa_nodes = NULL;
|
||||
|
||||
static struct topo_obj unspecified_node_template = {
|
||||
.load = 0,
|
||||
.number = NUMA_NO_NODE,
|
||||
.obj_type = OBJ_TYPE_NODE,
|
||||
.mask = CPU_MASK_ALL,
|
||||
.interrupts = NULL,
|
||||
.children = NULL,
|
||||
.parent = NULL,
|
||||
.obj_type_list = &numa_nodes,
|
||||
};
|
||||
|
||||
static struct topo_obj unspecified_node;
|
||||
|
||||
static void add_one_node(const char *nodename)
|
||||
static void add_one_node(int nodeid)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
struct topo_obj *new;
|
||||
|
@ -63,12 +50,16 @@ static void add_one_node(const char *nodename)
|
|||
return;
|
||||
}
|
||||
|
||||
if (nodeid == NUMA_NO_NODE) {
|
||||
cpus_setall(new->mask);
|
||||
} else {
|
||||
cpus_clear(new->mask);
|
||||
sprintf(path, "%s/%s/cpumap", SYSFS_NODE_PATH, nodename);
|
||||
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 = strtoul(&nodename[4], NULL, 10);
|
||||
new->number = nodeid;
|
||||
new->obj_type_list = &numa_nodes;
|
||||
numa_nodes = g_list_append(numa_nodes, new);
|
||||
}
|
||||
|
@ -78,17 +69,8 @@ void build_numa_node_list(void)
|
|||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
/*
|
||||
* Note that we copy the unspcified node from the template here
|
||||
* in the event we just freed the object tree during a rescan.
|
||||
* This ensures we don't get stale list pointers anywhere
|
||||
*/
|
||||
memcpy(&unspecified_node, &unspecified_node_template, sizeof (struct topo_obj));
|
||||
|
||||
/*
|
||||
* Add the unspecified node
|
||||
*/
|
||||
numa_nodes = g_list_append(numa_nodes, &unspecified_node);
|
||||
/* Add the unspecified node */
|
||||
add_one_node(NUMA_NO_NODE);
|
||||
|
||||
if (!numa_avail)
|
||||
return;
|
||||
|
@ -104,25 +86,15 @@ void build_numa_node_list(void)
|
|||
if ((entry->d_type == DT_DIR) &&
|
||||
(strncmp(entry->d_name, "node", 4) == 0) &&
|
||||
isdigit(entry->d_name[4])) {
|
||||
add_one_node(entry->d_name);
|
||||
add_one_node(strtoul(&entry->d_name[4], NULL, 10));
|
||||
}
|
||||
} while (entry);
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
static void free_numa_node(gpointer data)
|
||||
{
|
||||
struct topo_obj *obj = data;
|
||||
g_list_free(obj->children);
|
||||
g_list_free(obj->interrupts);
|
||||
|
||||
if (data != &unspecified_node)
|
||||
free(data);
|
||||
}
|
||||
|
||||
void free_numa_node_list(void)
|
||||
{
|
||||
g_list_free_full(numa_nodes, free_numa_node);
|
||||
g_list_free_full(numa_nodes, free_cpu_topo);
|
||||
numa_nodes = NULL;
|
||||
}
|
||||
|
||||
|
@ -175,13 +147,7 @@ struct topo_obj *get_numa_node(int nodeid)
|
|||
struct topo_obj find;
|
||||
GList *entry;
|
||||
|
||||
if (!numa_avail)
|
||||
return &unspecified_node;
|
||||
|
||||
if (nodeid == NUMA_NO_NODE)
|
||||
return &unspecified_node;
|
||||
|
||||
find.number = nodeid;
|
||||
find.number = numa_avail ? nodeid : NUMA_NO_NODE;
|
||||
|
||||
entry = g_list_find_custom(numa_nodes, &find, compare_node);
|
||||
return entry ? entry->data : NULL;
|
||||
|
|
Loading…
Reference in a new issue