linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* find the node that a cpu belongs to
@ 2009-03-17  1:09 Kornilios Kourtis
  2009-03-17 10:45 ` Andi Kleen
  0 siblings, 1 reply; 6+ messages in thread
From: Kornilios Kourtis @ 2009-03-17  1:09 UTC (permalink / raw)
  To: linux-numa

Hi,

I was wondering if you would be interested in adding a libnuma function
for determing the node that a cpu belongs to.

Something like this maybe ?

I could write a more complete patch if needed
(libnuma.h,version.ldscript,numa.3 ?)

--- libnuma.c.2	2009-03-16 23:32:52.000000000 +0000
+++ libnuma.c	2009-03-17 00:28:21.000000000 +0000
@@ -1784,3 +1784,34 @@ err:
 	numa_bitmask_free(mask);
 	return NULL;
 }
+
+int numa_node_from_cpu_v2(int cpu)
+{
+	struct bitmask *bmp;
+	int ncpus, nnodes, node, ret;
+
+	ncpus = numa_num_possible_cpus();
+	if (cpu > ncpus){
+		errno = ERANGE;
+		return -1;
+	}
+
+	bmp = numa_bitmask_alloc(ncpus);
+	nnodes = numa_num_configured_nodes();
+	for (node = 0; node < nnodes; node++){
+		numa_node_to_cpus_v2(node, bmp);
+		if (numa_bitmask_isbitset(bmp, cpu)){
+			ret = node;
+			goto end;
+		}
+	}
+
+	/* I don't think this is supposed to happen */
+	ret = -1;
+	errno = EINVAL;
+end:
+	numa_bitmask_free(bmp);
+	return ret;
+}
+__asm__(".symver numa_node_from_cpu_v2,numa_node_from_cpu@@libnuma_1.2");

-- 
Kornilios Kourtis

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-03-19 14:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2009-03-19 14:16     ` Cliff Wickman

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).