linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kornilios Kourtis <kkourt@cslab.ece.ntua.gr>
To: linux-numa@vger.kernel.org
Subject: find the node that a cpu belongs to
Date: Tue, 17 Mar 2009 03:09:10 +0200	[thread overview]
Message-ID: <20090317010910.GA9590@solar.cslab.ece.ntua.gr> (raw)

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

             reply	other threads:[~2009-03-17  1:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-17  1:09 Kornilios Kourtis [this message]
2009-03-17 10:45 ` find the node that a cpu belongs to 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

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=20090317010910.GA9590@solar.cslab.ece.ntua.gr \
    --to=kkourt@cslab.ece.ntua.gr \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).