Skip to content

Commit

Permalink
irqbalance: use add_one_node() to create unspecified node for numa
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yeyunfeng-dev committed Nov 7, 2019
1 parent 47137bb commit 4f361d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cputree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions irqbalance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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============================*/

Expand Down
62 changes: 14 additions & 48 deletions numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,12 +50,16 @@ static void add_one_node(const char *nodename)
return;
}

cpus_clear(new->mask);
sprintf(path, "%s/%s/cpumap", SYSFS_NODE_PATH, nodename);
process_one_line(path, get_mask_from_bitmap, &new->mask);
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 = strtoul(&nodename[4], NULL, 10);
new->number = nodeid;
new->obj_type_list = &numa_nodes;
numa_nodes = g_list_append(numa_nodes, new);
}
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4f361d0

Please sign in to comment.