WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 5/6] xen, tools: add nr_cpus field to fix nr_cpus cal

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 5/6] xen, tools: add nr_cpus field to fix nr_cpus calc
From: Ryan Harper <ryanh@xxxxxxxxxx>
Date: Mon, 23 Oct 2006 13:09:25 -0500
Delivery-date: Mon, 23 Oct 2006 11:13:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.6+20040907i
This patch adds a new field, nr_cpus, to the physinfo hcall and removes
code which used to calculate this number.  On some systems, for
instance, an opteron 2-way, the sockets-per-node calculation is bogus.
Rather than trying to calculate this number, just add a nr_cpus field
based on num_online_cpus().  This patch touches ia64 and ppc physinfo to
add the nr_cpus field, but it has only been tested on x86.

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
ryanh@xxxxxxxxxx


diffstat output:
 tools/python/xen/lowlevel/xc/xc.c      |   11 ++++-------
 tools/python/xen/xend/XendNode.py      |    4 ----
 tools/xenmon/xenbaked.c                |    5 +----
 tools/xenstat/libxenstat/src/xenstat.c |    4 +---
 tools/xentrace/xentrace.c              |    5 +----
 xen/arch/ia64/xen/dom0_ops.c           |    1 +
 xen/arch/powerpc/sysctl.c              |    1 +
 xen/arch/x86/sysctl.c                  |    1 +
 xen/include/public/sysctl.h            |    1 +
 9 files changed, 11 insertions(+), 22 deletions(-)

Signed-off-by: Ryan Harper <ryanh@xxxxxxxxxx>
---
Add nr_cpus field to physinfo; remove calculation

diff -r 3afd2fd370b6 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Wed Oct 18 16:30:30 2006 -0500
+++ b/tools/python/xen/lowlevel/xc/xc.c Wed Oct 18 16:31:18 2006 -0500
@@ -474,7 +474,7 @@ static PyObject *pyxc_physinfo(XcObject 
 {
     xc_physinfo_t info;
     char cpu_cap[128], *p=cpu_cap, *q=cpu_cap;
-    int i,j, nr_cpus;
+    int i,j;
     PyObject *ret_obj, *memchunk_obj, *node_to_cpu_obj;
     xc_memory_chunk_t *chunks;
     xc_cpu_to_node_t  *map;
@@ -491,10 +491,6 @@ static PyObject *pyxc_physinfo(XcObject 
 
     if ( xc_physinfo(self->xc_handle, &info) != 0 )
         return PyErr_SetFromErrno(xc_error);
-
-    /* calc number of cpus, ignore nr_nodes since sockets_per node is bogus */
-    nr_cpus = info.threads_per_core * info.cores_per_socket *
-       info.sockets_per_node;
 
     *q=0;
     for(i=0;i<sizeof(info.hw_cap)/4;i++)
@@ -506,10 +502,11 @@ static PyObject *pyxc_physinfo(XcObject 
     if(q>cpu_cap)
         *(q-1)=0;
 
-    ret_obj = Py_BuildValue("{s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",
+    ret_obj = Py_BuildValue("{s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",
                             "threads_per_core", info.threads_per_core,
                             "cores_per_socket", info.cores_per_socket,
                             "sockets_per_node", info.sockets_per_node,
+                            "nr_cpus"         , info.nr_cpus,
                             "total_memory",     pages_to_kib(info.total_pages),
                             "free_memory",      pages_to_kib(info.free_pages),
                             "scrub_memory",     pages_to_kib(info.scrub_pages),
@@ -540,7 +537,7 @@ static PyObject *pyxc_physinfo(XcObject 
  
         /* walk the cpu_to_node array, for each cpu
            which maps to node i, add to cpus list */
-        for ( j=0; j<nr_cpus; j++)
+        for ( j=0; j<info.nr_cpus; j++)
         {
             /* this cpu j maps to node i */
             if ( i == (uint32_t)map[j])
diff -r 3afd2fd370b6 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Wed Oct 18 16:30:30 2006 -0500
+++ b/tools/python/xen/xend/XendNode.py Wed Oct 18 16:30:33 2006 -0500
@@ -117,10 +117,6 @@ class XendNode:
     def physinfo(self):
         info = self.xc.physinfo()
 
-        info['nr_cpus'] = (info['nr_nodes'] *
-                           info['sockets_per_node'] *
-                           info['cores_per_socket'] *
-                           info['threads_per_core'])
         info['cpu_mhz'] = info['cpu_khz'] / 1000
         # physinfo is in KiB
         info['total_memory'] = info['total_memory'] / 1024
diff -r 3afd2fd370b6 tools/xenmon/xenbaked.c
--- a/tools/xenmon/xenbaked.c   Wed Oct 18 16:30:30 2006 -0500
+++ b/tools/xenmon/xenbaked.c   Wed Oct 18 16:30:33 2006 -0500
@@ -462,10 +462,7 @@ unsigned int get_num_cpus(void)
     xc_interface_close(xc_handle);
     opts.cpu_freq = (double)physinfo.cpu_khz/1000.0;
 
-    return (physinfo.threads_per_core *
-            physinfo.cores_per_socket *
-            physinfo.sockets_per_node *
-            physinfo.nr_nodes);
+    return physinfo.nr_cpus;
 }
 
 
diff -r 3afd2fd370b6 tools/xenstat/libxenstat/src/xenstat.c
--- a/tools/xenstat/libxenstat/src/xenstat.c    Wed Oct 18 16:30:30 2006 -0500
+++ b/tools/xenstat/libxenstat/src/xenstat.c    Wed Oct 18 16:30:33 2006 -0500
@@ -233,9 +233,7 @@ xenstat_node *xenstat_get_node(xenstat_h
        }
 
        node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL;
-       node->num_cpus =
-           (physinfo.threads_per_core * physinfo.cores_per_socket *
-            physinfo.sockets_per_node * physinfo.nr_nodes);
+       node->num_cpus = physinfo.nr_cpus;
        node->tot_mem = ((unsigned long long)physinfo.total_pages)
            * handle->page_size;
        node->free_mem = ((unsigned long long)physinfo.free_pages)
diff -r 3afd2fd370b6 tools/xentrace/xentrace.c
--- a/tools/xentrace/xentrace.c Wed Oct 18 16:30:30 2006 -0500
+++ b/tools/xentrace/xentrace.c Wed Oct 18 16:30:33 2006 -0500
@@ -272,10 +272,7 @@ unsigned int get_num_cpus(void)
 
     xc_interface_close(xc_handle);
 
-    return (physinfo.threads_per_core *
-            physinfo.cores_per_socket *
-            physinfo.sockets_per_node *
-            physinfo.nr_nodes);
+    return physinfo.nr_cpus;
 }
 
 
diff -r 3afd2fd370b6 xen/arch/ia64/xen/dom0_ops.c
--- a/xen/arch/ia64/xen/dom0_ops.c      Wed Oct 18 16:30:30 2006 -0500
+++ b/xen/arch/ia64/xen/dom0_ops.c      Wed Oct 18 16:30:33 2006 -0500
@@ -198,6 +198,7 @@ long arch_do_sysctl(xen_sysctl_t *op, XE
             cpus_weight(cpu_core_map[0]) / pi->threads_per_core;
         pi->sockets_per_node = 
             num_online_cpus() / cpus_weight(cpu_core_map[0]);
+        pi->nr_cpus          = (u32)num_online_cpus();
         pi->nr_nodes         = 1;
         pi->total_pages      = total_pages; 
         pi->free_pages       = avail_domheap_pages();
diff -r 3afd2fd370b6 xen/arch/powerpc/sysctl.c
--- a/xen/arch/powerpc/sysctl.c Wed Oct 18 16:30:30 2006 -0500
+++ b/xen/arch/powerpc/sysctl.c Wed Oct 18 16:30:33 2006 -0500
@@ -44,6 +44,7 @@ long arch_do_sysctl(struct xen_sysctl *s
         pi->threads_per_core = 1;
         pi->cores_per_socket = 1;
         pi->sockets_per_node = 1;
+        pi->nr_cpus          = (u32)num_online_cpus();
         pi->nr_nodes         = 1;
         pi->total_pages      = total_pages;
         pi->free_pages       = avail_domheap_pages();
diff -r 3afd2fd370b6 xen/arch/x86/sysctl.c
--- a/xen/arch/x86/sysctl.c     Wed Oct 18 16:30:30 2006 -0500
+++ b/xen/arch/x86/sysctl.c     Wed Oct 18 16:30:33 2006 -0500
@@ -52,6 +52,7 @@ long arch_do_sysctl(
         pi->sockets_per_node = 
             num_online_cpus() / cpus_weight(cpu_core_map[0]);
 
+        pi->nr_cpus          = (u32)num_online_cpus();
         pi->total_pages      = total_pages;
         pi->free_pages       = avail_domheap_pages();
         pi->scrub_pages      = avail_scrub_pages();
diff -r 3afd2fd370b6 xen/include/public/sysctl.h
--- a/xen/include/public/sysctl.h       Wed Oct 18 16:30:30 2006 -0500
+++ b/xen/include/public/sysctl.h       Wed Oct 18 16:30:33 2006 -0500
@@ -62,6 +62,7 @@ struct xen_sysctl_physinfo {
     uint32_t threads_per_core;
     uint32_t cores_per_socket;
     uint32_t sockets_per_node;
+    uint32_t nr_cpus;
     uint32_t nr_nodes;
     uint32_t cpu_khz;
     uint64_t total_pages;

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 5/6] xen, tools: add nr_cpus field to fix nr_cpus calc, Ryan Harper <=