All of lore.kernel.org
 help / color / mirror / Atom feed
From: vijay.kilari@gmail.com
To: xen-devel@lists.xen.org
Cc: kevin.tian@intel.com, sstabellini@kernel.org,
	wei.liu2@citrix.com, George.Dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, dario.faggioli@citrix.com,
	ian.jackson@eu.citrix.com, tim@xen.org, julien.grall@arm.com,
	jbeulich@suse.com, Vijaya Kumar K <Vijaya.Kumar@cavium.com>
Subject: [RFC PATCH v3 04/24] x86: NUMA: Rename and sanitize memnode shift code
Date: Tue, 18 Jul 2017 17:11:26 +0530	[thread overview]
Message-ID: <1500378106-2620-5-git-send-email-vijay.kilari@gmail.com> (raw)
In-Reply-To: <1500378106-2620-1-git-send-email-vijay.kilari@gmail.com>

From: Vijaya Kumar K <Vijaya.Kumar@cavium.com>

memnode_shift variable is changed from int to unsigned int.
With this change, compute_memnode_shift() returns error value
instead of returning shift value. The memnode_shift is updated inside
compute_memnode_shift().

Also, following changes are made
  - Rename compute_hash_shift to compute_memnode_shift
  - Update int to unsigned int for params in extract_lsb_from_nodes()
  - Return values of populate_memnodemap() is changed

Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
---
v3:
  - Update int to unsigned int for params in extract_lsb_from_nodes()
  - Return values of populate_memnodemap() is changed
---
 xen/arch/x86/numa.c        | 53 ++++++++++++++++++++++++----------------------
 xen/arch/x86/srat.c        |  7 +++---
 xen/include/asm-x86/numa.h |  6 +++---
 3 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/numa.c b/xen/arch/x86/numa.c
index aa4a7c1..2ea2ec0 100644
--- a/xen/arch/x86/numa.c
+++ b/xen/arch/x86/numa.c
@@ -24,7 +24,7 @@ custom_param("numa", numa_setup);
 struct node_data node_data[MAX_NUMNODES];
 
 /* Mapping from pdx to node id */
-int memnode_shift;
+unsigned int memnode_shift;
 
 /*
  * In case of numa init failure or numa off,
@@ -59,15 +59,16 @@ int srat_disabled(void)
 /*
  * Given a shift value, try to populate memnodemap[]
  * Returns :
- * 1 if OK
- * 0 if memnodmap[] too small (of shift too small)
- * -1 if node overlap or lost ram (shift too big)
+ * 0 if OK
+ * -ENOSPC if memnodmap[] too small (or shift too small)
+ * -EINVAL if node overlap or lost ram (shift too big)
  */
 static int __init populate_memnodemap(const struct node *nodes,
-                                      int numnodes, int shift, nodeid_t *nodeids)
+                                      unsigned int numnodes, unsigned int shift,
+                                      nodeid_t *nodeids)
 {
     unsigned long spdx, epdx;
-    int i, res = -1;
+    int i, res = -EINVAL;
 
     memset(memnodemap, NUMA_NO_NODE, memnodemapsize * sizeof(*memnodemap));
     for ( i = 0; i < numnodes; i++ )
@@ -77,10 +78,10 @@ static int __init populate_memnodemap(const struct node *nodes,
         if ( spdx >= epdx )
             continue;
         if ( (epdx >> shift) >= memnodemapsize )
-            return 0;
+            return -ENOSPC;
         do {
             if ( memnodemap[spdx >> shift] != NUMA_NO_NODE )
-                return -1;
+                return -EINVAL;
 
             if ( !nodeids )
                 memnodemap[spdx >> shift] = i;
@@ -89,7 +90,7 @@ static int __init populate_memnodemap(const struct node *nodes,
 
             spdx += (1UL << shift);
         } while ( spdx < epdx );
-        res = 1;
+        res = 0;
     }
 
     return res;
@@ -105,7 +106,7 @@ static int __init allocate_cachealigned_memnodemap(void)
         printk(KERN_ERR
                "NUMA: Unable to allocate Memory to Node hash map\n");
         memnodemapsize = 0;
-        return -1;
+        return -ENOMEM;
     }
 
     memnodemap = mfn_to_virt(mfn);
@@ -122,10 +123,10 @@ static int __init allocate_cachealigned_memnodemap(void)
  * The LSB of all start and end addresses in the node map is the value of the
  * maximum possible shift.
  */
-static int __init extract_lsb_from_nodes(const struct node *nodes,
-                                         int numnodes)
+static unsigned int __init extract_lsb_from_nodes(const struct node *nodes,
+                                                  unsigned int numnodes)
 {
-    int i, nodes_used = 0;
+    unsigned int i, nodes_used = 0;
     unsigned long spdx, epdx;
     unsigned long bitfield = 0, memtop = 0;
 
@@ -149,27 +150,30 @@ static int __init extract_lsb_from_nodes(const struct node *nodes,
     return i;
 }
 
-int __init compute_hash_shift(struct node *nodes, int numnodes,
-                              nodeid_t *nodeids)
+int __init compute_memnode_shift(struct node *nodes, unsigned int numnodes,
+                                 nodeid_t *nodeids)
 {
-    int shift;
+    int ret;
+
+    memnode_shift = extract_lsb_from_nodes(nodes, numnodes);
 
-    shift = extract_lsb_from_nodes(nodes, numnodes);
     if ( memnodemapsize <= ARRAY_SIZE(_memnodemap) )
         memnodemap = _memnodemap;
     else if ( allocate_cachealigned_memnodemap() )
-        return -1;
-    printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n", shift);
+        return -ENOMEM;
 
-    if ( populate_memnodemap(nodes, numnodes, shift, nodeids) != 1 )
+    printk(KERN_DEBUG "NUMA: Using %u for the hash shift.\n", memnode_shift);
+
+    ret = populate_memnodemap(nodes, numnodes, memnode_shift, nodeids);
+    if ( ret )
     {
         printk(KERN_INFO "Your memory is not aligned you need to "
                "rebuild your hypervisor with a bigger NODEMAPSIZE "
-               "shift=%d\n", shift);
-        return -1;
+               "shift=%u\n", memnode_shift);
+        return ret;
     }
 
-    return shift;
+    return 0;
 }
 /* initialize NODE_DATA given nodeid and start/end */
 void __init setup_node_bootmem(nodeid_t nodeid, paddr_t start, paddr_t end)
@@ -242,8 +246,7 @@ static int __init numa_emulation(uint64_t start_pfn, uint64_t end_pfn)
                (nodes[i].end - nodes[i].start) >> 20);
         node_set_online(i);
     }
-    memnode_shift = compute_hash_shift(nodes, numa_fake, NULL);
-    if ( memnode_shift < 0 )
+    if ( compute_memnode_shift(nodes, numa_fake, NULL) )
     {
         memnode_shift = 0;
         printk(KERN_ERR "No NUMA hash function found. Emulation disabled.\n");
diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
index 209ffc7..535c9d7 100644
--- a/xen/arch/x86/srat.c
+++ b/xen/arch/x86/srat.c
@@ -470,10 +470,9 @@ int __init acpi_scan_nodes(paddr_t start, paddr_t end)
 		return -1;
 	}
 
-	memnode_shift = compute_hash_shift(node_memblk_range, num_node_memblks,
-				memblk_nodeid);
-
-	if (memnode_shift < 0) {
+	if (compute_memnode_shift(node_memblk_range, num_node_memblks,
+				  memblk_nodeid)) {
+		memnode_shift = 0;
 		printk(KERN_ERR
 		     "SRAT: No NUMA node hash function found. Contact maintainer\n");
 		bad_srat();
diff --git a/xen/include/asm-x86/numa.h b/xen/include/asm-x86/numa.h
index 5e8474f..1bac25c 100644
--- a/xen/include/asm-x86/numa.h
+++ b/xen/include/asm-x86/numa.h
@@ -23,8 +23,8 @@ struct node {
     paddr_t end;
 };
 
-extern int compute_hash_shift(struct node *nodes, int numnodes,
-                              nodeid_t *nodeids);
+extern int compute_memnode_shift(struct node *nodes, unsigned int numnodes,
+                                 nodeid_t *nodeids);
 extern nodeid_t pxm_to_node(unsigned int pxm);
 
 #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
@@ -44,7 +44,7 @@ extern nodeid_t apicid_to_node[];
 extern void init_cpu_to_node(void);
 
 /* Simple perfect hash to map pdx to node numbers */
-extern int memnode_shift;
+extern unsigned int memnode_shift;
 extern unsigned long memnodemapsize;
 extern uint8_t *memnodemap;
 
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-07-18 11:41 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 11:41 [RFC PATCH v3 00/24] ARM: Add Xen NUMA support vijay.kilari
2017-07-18 11:41 ` [RFC PATCH v3 01/24] NUMA: Make number of NUMA nodes configurable vijay.kilari
2017-07-18 15:29   ` Wei Liu
2017-07-18 17:52     ` Julien Grall
2017-07-19  8:17       ` Wei Liu
2017-07-19 15:48         ` Julien Grall
2017-07-28 10:11     ` Jan Beulich
2017-07-18 17:55   ` Julien Grall
2017-07-19  7:00     ` Vijay Kilari
2017-07-19 15:55       ` Julien Grall
2017-07-20  7:30         ` Vijay Kilari
2017-07-20 10:57           ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 02/24] x86: NUMA: Clean up: Fix coding styles and drop unused code vijay.kilari
2017-07-19 16:23   ` Julien Grall
2017-07-19 16:27     ` Wei Liu
2017-07-19 16:34       ` Julien Grall
2017-07-20  7:00     ` Vijay Kilari
2017-07-20 11:00       ` Julien Grall
2017-07-20 12:05         ` Vijay Kilari
2017-07-20 12:09           ` Julien Grall
2017-07-20 12:29             ` Vijay Kilari
2017-07-20 12:33               ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 03/24] x86: NUMA: Fix datatypes and attributes vijay.kilari
2017-07-18 15:29   ` Wei Liu
2017-07-18 11:41 ` vijay.kilari [this message]
2017-07-18 15:29   ` [RFC PATCH v3 04/24] x86: NUMA: Rename and sanitize memnode shift code Wei Liu
2017-07-19 17:12   ` Julien Grall
2017-07-20  6:56     ` Vijay Kilari
2017-07-18 11:41 ` [RFC PATCH v3 05/24] x86: NUMA: Add accessors for nodes[] and node_memblk_range[] structs vijay.kilari
2017-07-18 15:29   ` Wei Liu
2017-07-19  6:40     ` Vijay Kilari
2017-07-19 17:18       ` Julien Grall
2017-07-20  7:41         ` Vijay Kilari
2017-07-20 11:03           ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 06/24] x86: NUMA: Rename some generic functions vijay.kilari
2017-07-19 17:23   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 07/24] ARM: NUMA: Add existing ARM numa code under CONFIG_NUMA vijay.kilari
2017-07-18 18:06   ` Julien Grall
2017-07-20  9:31     ` Vijay Kilari
2017-07-20 11:10       ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 08/24] NUMA: x86: Move numa code and make it generic vijay.kilari
2017-07-18 15:29   ` Wei Liu
2017-07-18 18:16     ` Julien Grall
2017-07-19  6:47       ` Vijay Kilari
2017-07-19 17:41   ` Julien Grall
2017-07-20  8:55     ` Vijay Kilari
2017-07-20 11:14       ` Julien Grall
2017-07-24 20:28     ` Stefano Stabellini
2017-07-18 11:41 ` [RFC PATCH v3 09/24] NUMA: x86: Move common code from srat.c vijay.kilari
2017-07-20 11:17   ` Julien Grall
2017-07-20 11:43     ` Vijay Kilari
2017-07-24 20:35     ` Stefano Stabellini
2017-07-18 11:41 ` [RFC PATCH v3 10/24] NUMA: Allow numa initialization with DT vijay.kilari
2017-07-19 17:58   ` Julien Grall
2017-07-20 10:28     ` Vijay Kilari
2017-07-20 11:20       ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 11/24] ARM: fdt: Export and introduce new fdt functions vijay.kilari
2017-07-18 15:29   ` Wei Liu
2017-07-18 16:29     ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 12/24] ARM: NUMA: DT: Parse CPU NUMA information vijay.kilari
2017-07-19 18:26   ` Julien Grall
2017-07-20  9:20     ` Vijay Kilari
2017-07-18 11:41 ` [RFC PATCH v3 13/24] ARM: NUMA: DT: Parse memory " vijay.kilari
2017-07-19 18:39   ` Julien Grall
2017-07-20 10:37     ` Vijay Kilari
2017-07-20 11:24       ` Julien Grall
2017-07-20 11:26     ` Julien Grall
2017-07-21 11:10       ` Vijay Kilari
2017-07-21 12:35         ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 14/24] ARM: NUMA: DT: Parse NUMA distance information vijay.kilari
2017-07-20 13:02   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 15/24] ARM: NUMA: DT: Add CPU NUMA support vijay.kilari
2017-07-24 11:24   ` Julien Grall
2017-07-25  6:47     ` Vijay Kilari
2017-07-25 18:38       ` Julien Grall
2017-07-25 18:48         ` Stefano Stabellini
2017-07-25 18:51           ` Julien Grall
2017-07-25 19:06             ` Stefano Stabellini
2017-07-26 17:18               ` Julien Grall
2017-07-26 17:21                 ` Stefano Stabellini
2017-07-18 11:41 ` [RFC PATCH v3 16/24] ARM: NUMA: Add memory " vijay.kilari
2017-07-24 12:43   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 17/24] ARM: NUMA: DT: Do not expose numa info to DOM0 vijay.kilari
2017-07-24 20:48   ` Stefano Stabellini
2017-07-26 17:22   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 18/24] ACPI: Refactor acpi SRAT and SLIT table handling code vijay.kilari
2017-07-18 15:36   ` Wei Liu
2017-07-19  6:33     ` Vijay Kilari
2017-07-18 11:41 ` [RFC PATCH v3 19/24] ARM: NUMA: Extract MPIDR from MADT table vijay.kilari
2017-07-24 22:17   ` Stefano Stabellini
2017-07-26 18:12   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 20/24] ACPI: Move arch specific SRAT parsing vijay.kilari
2017-07-24 21:15   ` Stefano Stabellini
2017-07-18 11:41 ` [RFC PATCH v3 21/24] ARM: NUMA: ACPI: Extract proximity from SRAT table vijay.kilari
2017-07-24 22:17   ` Stefano Stabellini
2017-07-26 18:18   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 22/24] ARM: NUMA: Initialize ACPI NUMA vijay.kilari
2017-07-24 22:11   ` Stefano Stabellini
2017-07-26 18:23   ` Julien Grall
2017-07-18 11:41 ` [RFC PATCH v3 23/24] NUMA: Move CONFIG_NUMA to common Kconfig vijay.kilari
2017-07-18 16:25   ` Julien Grall
2017-07-18 18:00     ` Julien Grall
2017-07-28 10:08     ` Jan Beulich
2017-07-18 11:41 ` [RFC PATCH v3 24/24] NUMA: Enable ACPI_NUMA config vijay.kilari
2017-07-18 16:18 ` [RFC PATCH v3 00/24] ARM: Add Xen NUMA support Julien Grall
2017-07-19  6:31   ` Vijay Kilari
2017-07-19  7:18     ` Julien Grall
     [not found]       ` <CALicx6svuo3JXik=8bYuciFzWDu6qmwVi1VXdBgjLp_f_YUhqQ@mail.gmail.com>
2017-10-06 17:09         ` vkilari
2017-10-06 17:30           ` Julien Grall

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=1500378106-2620-5-git-send-email-vijay.kilari@gmail.com \
    --to=vijay.kilari@gmail.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Vijaya.Kumar@cavium.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dario.faggioli@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=kevin.tian@intel.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.