linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Holasek <pholasek@redhat.com>
To: linux-numa@vger.kernel.org
Cc: Cliff Wickman <cpw@sgi.com>, Petr Holasek <pholasek@redhat.com>
Subject: [PATCH] libnuma: add check for return value of numa_node_to_cpus
Date: Wed, 14 Jan 2015 09:53:47 +0100	[thread overview]
Message-ID: <1421225627-9272-1-git-send-email-pholasek@redhat.com> (raw)

When numa_node_to_cpu() has been called on machine with non-contiguous
nodes, it returned the first node which wasn't present on machine.
Now, return code is checked and code skips over non-existing nodes to
the right one.

Also, caching of numa_node_to_cpus_v2() result while non-zero error had
been returned was disabled.

Signed-off-by: Petr Holasek <pholasek@redhat.com>
---
 libnuma.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libnuma.c b/libnuma.c
index 91425ae..8d7bf13 100644
--- a/libnuma.c
+++ b/libnuma.c
@@ -1382,8 +1382,12 @@ numa_node_to_cpus_v2(int node, struct bitmask *buffer)
 		if (mask != buffer)
 			numa_bitmask_free(mask);
 	} else {
-		node_cpu_mask_v2[node] = mask;
-	} 
+		/* we don't want to cache faulty result */
+		if (!err)
+			node_cpu_mask_v2[node] = mask;
+		else
+			numa_bitmask_free(mask);
+	}
 	return err; 
 }
 __asm__(".symver numa_node_to_cpus_v2,numa_node_to_cpus@@libnuma_1.2");
@@ -1405,7 +1409,10 @@ int numa_node_of_cpu(int cpu)
 	bmp = numa_bitmask_alloc(ncpus);
 	nnodes = numa_max_node();
 	for (node = 0; node <= nnodes; node++){
-		numa_node_to_cpus_v2_int(node, bmp);
+		if (numa_node_to_cpus_v2_int(node, bmp) < 0) {
+			/* It's possible for the node to not exist */
+			continue;
+		}
 		if (numa_bitmask_isbitset(bmp, cpu)){
 			ret = node;
 			goto end;
-- 
2.1.0

             reply	other threads:[~2015-01-14  8:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14  8:53 Petr Holasek [this message]
2015-01-19 16:44 ` [PATCH] libnuma: add check for return value of numa_node_to_cpus 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=1421225627-9272-1-git-send-email-pholasek@redhat.com \
    --to=pholasek@redhat.com \
    --cc=cpw@sgi.com \
    --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).