Skip to content

Commit

Permalink
libnuma: Convert preferred node into a mask
Browse files Browse the repository at this point in the history
This helps converge code for supporting upcoming MPOL_PREFERRED_MANY
interface.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Signed-off-by: Feng Tang <feng.tang@intel.com>
  • Loading branch information
Ben Widawsky authored and andikleen committed Dec 9, 2021
1 parent 060c092 commit 87c6834
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,39 +1765,44 @@ int numa_run_on_node(int node)
return ret;
}

int numa_preferred(void)
static struct bitmask *__numa_preferred(void)
{
int policy;
struct bitmask *bmp;
/* could read the current CPU from /proc/self/status. Probably
not worth it. */
int ret = 0;

bmp = numa_allocate_nodemask();
/* could read the current CPU from /proc/self/status. Probably
not worth it. */
numa_bitmask_clearall(bmp);
getpol(&policy, bmp);

if (policy != MPOL_PREFERRED && policy != MPOL_BIND)
return ret;
return bmp;

int i;
int max = numa_num_possible_nodes();
for (i = 0; i < max ; i++)
if (numa_bitmask_isbitset(bmp, i))
ret = i;
if (numa_bitmask_weight(bmp) > 1)
numa_error(__FILE__);

return ret;
return bmp;
}

void numa_set_preferred(int node)
int numa_preferred(void)
{
struct bitmask *bmp;
return find_first(__numa_preferred());
}

bmp = numa_allocate_nodemask();
if (node >= 0) {
numa_bitmask_setbit(bmp, node);
setpol(MPOL_PREFERRED, bmp);
} else
setpol(MPOL_LOCAL, bmp);
static void __numa_set_preferred(struct bitmask *bmp)
{
int nodes = numa_bitmask_weight(bmp);
if (nodes > 1)
numa_error(__FILE__);
setpol(nodes ? MPOL_PREFERRED : MPOL_LOCAL, bmp);
}

void numa_set_preferred(int node)
{
struct bitmask *bmp = numa_allocate_nodemask();
numa_bitmask_setbit(bmp, node);
__numa_set_preferred(bmp);
numa_bitmask_free(bmp);
}

Expand Down

0 comments on commit 87c6834

Please sign in to comment.