From: Kornilios Kourtis <kkourt@cslab.ece.ntua.gr>
To: linux-numa@vger.kernel.org
Cc: Andi Kleen <andi@firstfloor.org>
Subject: Re: find the node that a cpu belongs to
Date: Wed, 18 Mar 2009 17:19:37 +0200 [thread overview]
Message-ID: <20090318151937.GA21217@solar.cslab.ece.ntua.gr> (raw)
In-Reply-To: <20090317115907.GS11935@one.firstfloor.org>
On Tue, Mar 17, 2009 at 12:59:07PM +0100, Andi Kleen wrote:
> Normally the number of threads is dependent on the data layout, isn't it?
> It seems like a backwards way of doing things, but ok.
I'm including a better patch for this.
> BTW another known topology reporting hole is there is currently no way
> to report number of CPUs for a given node. Normally it's just max/cpus,
> but that can change with CPU hotplug. On the other hand CPU/node hotplug
> is currently not really supported anyways.
I took a quick look at this and I guess the most straightforward way
would be to intersect the set of numa_node_to_cpus() with the set of
online cpus (/sys/devices/system/cpu/online). I'm not exactly sure about
the format of this file and a quick grep at kernel sources didn't reveal
much. I might take another look if I find some idle time.
cheers,
Add a numa_node_of_cpu() function for retrieving the local node of a cpu.
diff -uprN numactl-2.0.3-rc2.orig/libnuma.c numactl-2.0.3-rc2/libnuma.c
--- numactl-2.0.3-rc2.orig/libnuma.c 2009-03-17 14:37:14.000000000 +0200
+++ numactl-2.0.3-rc2/libnuma.c 2009-03-18 16:44:29.000000000 +0200
@@ -1310,6 +1310,33 @@ __asm__(".symver numa_node_to_cpus_v2,nu
make_internal_alias(numa_node_to_cpus_v1);
make_internal_alias(numa_node_to_cpus_v2);
+/* report the node of the specified cpu */
+int numa_node_of_cpu(int cpu)
+{
+ struct bitmask *bmp;
+ int ncpus, nnodes, node, ret;
+
+ ncpus = numa_num_possible_cpus();
+ if (cpu > ncpus){
+ errno = EINVAL;
+ return -1;
+ }
+ bmp = numa_bitmask_alloc(ncpus);
+ nnodes = numa_num_configured_nodes();
+ for (node = 0; node < nnodes; node++){
+ numa_node_to_cpus_v2_int(node, bmp);
+ if (numa_bitmask_isbitset(bmp, cpu)){
+ ret = node;
+ goto end;
+ }
+ }
+ ret = -1;
+ errno = EINVAL;
+end:
+ numa_bitmask_free(bmp);
+ return ret;
+}
+
int
numa_run_on_node_mask_v1(const nodemask_t *mask)
diff -uprN numactl-2.0.3-rc2.orig/numa.3 numactl-2.0.3-rc2/numa.3
--- numactl-2.0.3-rc2.orig/numa.3 2009-03-17 14:37:14.000000000 +0200
+++ numactl-2.0.3-rc2/numa.3 2009-03-18 16:54:29.000000000 +0200
@@ -115,6 +115,8 @@ numa \- NUMA policy library
.BI "int numa_sched_setaffinity(pid_t " pid ", struct bitmask *" mask );
.br
.BI "int numa_node_to_cpus(int " node ", unsigned long *" buffer ", int " bufferlen );
+.br
+.BI "int numa_node_of_cpu(int " cpu ");
.sp
.BI "struct bitmask *numa_allocate_cpumask();"
.sp
@@ -220,6 +222,7 @@ Most functions in this library are only
their memory.
The exceptions to this are:
.IR numa_node_to_cpus (),
+.IR numa_node_of_cpu (),
.IR numa_bind (),
.IR numa_run_on_node (),
.IR numa_run_on_node_mask ()
@@ -730,6 +733,13 @@ will be set to
.I ERANGE
and \-1 returned. On success 0 is returned.
+.BR numa_node_of_cpu ()
+returns the node that a cpu belongs to. If the user supplies an invalid cpu
+.I errno
+will be set to
+.I EINVAL
+and \-1 will be returned.
+
.BR numa_allocate_cpumask
() returns a bitmask of a size equal to the kernel's cpu
mask (kernel type cpumask_t). In other words, large enough to represent
diff -uprN numactl-2.0.3-rc2.orig/numa.h numactl-2.0.3-rc2/numa.h
--- numactl-2.0.3-rc2.orig/numa.h 2009-03-17 14:37:14.000000000 +0200
+++ numactl-2.0.3-rc2/numa.h 2009-03-18 14:44:07.000000000 +0200
@@ -273,6 +273,9 @@ static inline void numa_free_cpumask(str
/* Convert node to CPU mask. -1/errno on failure, otherwise 0. */
int numa_node_to_cpus(int, struct bitmask *);
+/* report the node of the specified cpu. -1/errno on invalid cpu. */
+int numa_node_of_cpu(int cpu);
+
/* Report distance of node1 from node2. 0 on error.*/
int numa_distance(int node1, int node2);
diff -uprN numactl-2.0.3-rc2.orig/versions.ldscript numactl-2.0.3-rc2/versions.ldscript
--- numactl-2.0.3-rc2.orig/versions.ldscript 2009-03-17 14:37:14.000000000 +0200
+++ numactl-2.0.3-rc2/versions.ldscript 2009-03-18 14:33:02.000000000 +0200
@@ -118,6 +118,7 @@ libnuma_1.2 {
numa_node_size64;
numa_node_size;
numa_node_to_cpus;
+ numa_node_of_cpu;
numa_num_configured_cpus;
numa_num_configured_nodes;
numa_num_possible_nodes;
--
Kornilios Kourtis
next prev parent reply other threads:[~2009-03-18 15:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-17 1:09 find the node that a cpu belongs to Kornilios Kourtis
2009-03-17 10:45 ` Andi Kleen
2009-03-17 11:32 ` Kornilios Kourtis
2009-03-17 11:59 ` Andi Kleen
2009-03-18 15:19 ` Kornilios Kourtis [this message]
2009-03-19 14:16 ` Cliff Wickman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090318151937.GA21217@solar.cslab.ece.ntua.gr \
--to=kkourt@cslab.ece.ntua.gr \
--cc=andi@firstfloor.org \
--cc=linux-numa@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).