Skip to content

Commit

Permalink
libnuma: Small refactor in set_preferred
Browse files Browse the repository at this point in the history
This refactor makes the next patch a little cleaner.

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 9f0d8a6 commit 060c092
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,25 +1768,23 @@ int numa_run_on_node(int node)
int numa_preferred(void)
{
int policy;
int ret;
struct bitmask *bmp;
/* could read the current CPU from /proc/self/status. Probably
not worth it. */
int ret = 0;

bmp = numa_allocate_nodemask();
getpol(&policy, bmp);
if (policy == MPOL_PREFERRED || policy == MPOL_BIND) {
int i;
int max = numa_num_possible_nodes();
for (i = 0; i < max ; i++)
if (numa_bitmask_isbitset(bmp, i)){
ret = i;
goto end;
}
}
/* could read the current CPU from /proc/self/status. Probably
not worth it. */
ret = 0; /* or random one? */
end:
numa_bitmask_free(bmp);

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

int i;
int max = numa_num_possible_nodes();
for (i = 0; i < max ; i++)
if (numa_bitmask_isbitset(bmp, i))
ret = i;

return ret;
}

Expand Down

0 comments on commit 060c092

Please sign in to comment.