Re: [libvirt] [RFC PATCH v2 1/4] PowerPC : Use Sysfs to gather host topology

2011-11-21 Thread Eric Blake
On 11/14/2011 07:46 AM, Prerna Saxena wrote:
From 9084802bdf7a2c10d6a913cb7dde001ab6ab3543 Mon Sep 17 00:00:00 2001
 From: Prerna Saxena pre...@linux.vnet.ibm.com
 Date: Mon, 3 Oct 2011 05:45:30 -0700
 Subject: [PATCH 1/4] Use sysfs to gather host topology, in place of
  /proc/cpuinfo

Are we sure that sysfs has this information for all kernels as far back
as RHEL 5?  Or should this patch be doing conditionals; probing sysfs
first but falling back to /proc/cpuinfo otherwise?

I tried compiling things, but got this warning:

nodeinfo.c: In function 'linuxNodeInfoCPUPopulate':
nodeinfo.c:287:5: error: suggest parentheses around assignment used as
truth value [-Werror=parentheses]
nodeinfo.c:202:36: error: unused parameter 'need_hyperthreads'
[-Werror=unused-parameter]

and seeing other comments in this thread, I didn't review it very
closely (this is more a chance to revive the thread after a week, to see
if you are planning on a resubmission before we consider a freeze for
0.9.8).

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [RFC PATCH v2 1/4] PowerPC : Use Sysfs to gather host topology

2011-11-14 Thread Prerna Saxena
From 9084802bdf7a2c10d6a913cb7dde001ab6ab3543 Mon Sep 17 00:00:00 2001
From: Prerna Saxena pre...@linux.vnet.ibm.com
Date: Mon, 3 Oct 2011 05:45:30 -0700
Subject: [PATCH 1/4] Use sysfs to gather host topology, in place of
 /proc/cpuinfo


Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com
---
 src/nodeinfo.c |  106 +++-
 1 files changed, 36 insertions(+), 70 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 6448b79..cdd339d 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -30,6 +30,7 @@
 #include errno.h
 #include dirent.h
 #include sys/utsname.h
+#include sched.h
 
 #if HAVE_NUMACTL
 # define NUMA_VERSION1_COMPATIBILITY 1
@@ -191,6 +192,11 @@ static int parse_socket(unsigned int cpu)
 return ret;
 }
 
+static int parse_core(unsigned int cpu)
+{
+return get_cpu_value(cpu, topology/core_id, false);
+}
+
 int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
  virNodeInfoPtr nodeinfo,
  bool need_hyperthreads)
@@ -199,15 +205,14 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
 DIR *cpudir = NULL;
 struct dirent *cpudirent = NULL;
 unsigned int cpu;
-unsigned long cur_threads;
-int socket;
-unsigned long long socket_mask = 0;
-unsigned int remaining;
+unsigned long core, socket, cur_threads;
+cpu_set_t core_mask;
+cpu_set_t socket_mask;
 int online;
 
 nodeinfo-cpus = 0;
 nodeinfo-mhz = 0;
-nodeinfo-cores = 1;
+nodeinfo-cores = 0;
 
 nodeinfo-nodes = 1;
 # if HAVE_NUMACTL
@@ -221,20 +226,10 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
 /* NOTE: hyperthreads are ignored here; they are parsed out of /sys */
 while (fgets(line, sizeof(line), cpuinfo) != NULL) {
 char *buf = line;
-if (STRPREFIX(buf, processor)) { /* aka a single logical CPU */
-buf += 9;
-while (*buf  c_isspace(*buf))
-buf++;
-if (*buf != ':') {
-nodeReportError(VIR_ERR_INTERNAL_ERROR,
-%s, _(parsing cpuinfo processor));
-return -1;
-}
-nodeinfo-cpus++;
 # if defined(__x86_64__) || \
 defined(__amd64__)  || \
 defined(__i386__)
-} else if (STRPREFIX(buf, cpu MHz)) {
+if (STRPREFIX(buf, cpu MHz)) {
 char *p;
 unsigned int ui;
 buf += 9;
@@ -249,24 +244,9 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
 /* Accept trailing fractional part.  */
  (*p == '\0' || *p == '.' || c_isspace(*p)))
 nodeinfo-mhz = ui;
-} else if (STRPREFIX(buf, cpu cores)) { /* aka cores */
-char *p;
-unsigned int id;
-buf += 9;
-while (*buf  c_isspace(*buf))
-buf++;
-if (*buf != ':' || !buf[1]) {
-nodeReportError(VIR_ERR_INTERNAL_ERROR,
-_(parsing cpuinfo cpu cores %c), *buf);
-return -1;
-}
-if (virStrToLong_ui(buf+1, p, 10, id) == 0
- (*p == '\0' || c_isspace(*p))
- id  nodeinfo-cores)
-nodeinfo-cores = id;
 # elif defined(__powerpc__) || \
   defined(__powerpc64__)
-} else if (STRPREFIX(buf, clock)) {
+if (STRPREFIX(buf, clock)) {
 char *p;
 unsigned int ui;
 buf += 5;
@@ -281,53 +261,30 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
 /* Accept trailing fractional part.  */
  (*p == '\0' || *p == '.' || c_isspace(*p)))
 nodeinfo-mhz = ui;
-# elif defined(__s390__) || \
-defined(__s390x__)
-} else if (STRPREFIX(buf, # processors)) {
-char *p;
-unsigned int ui;
-buf += 12;
-while (*buf  c_isspace(*buf))
-buf++;
-if (*buf != ':' || !buf[1]) {
-nodeReportError(VIR_ERR_INTERNAL_ERROR,
-_(parsing number of processors %c), *buf);
-return -1;
-}
-if (virStrToLong_ui(buf+1, p, 10, ui) == 0
- (*p == '\0' || c_isspace(*p)))
-nodeinfo-cpus = ui;
 /* No other interesting infos are available in /proc/cpuinfo.
  * However, there is a line identifying processor's version,
  * identification and machine, but we don't want it to be caught
  * and parsed in next iteration, because it is not in expected
  * format and thus lead to error. */
-break;
 # else
 #  warning Parser for /proc/cpuinfo needs to be adapted for your architecture
 # endif
 }
 }
 
-if (!nodeinfo-cpus) {
-nodeReportError(VIR_ERR_INTERNAL_ERROR,
-%s, _(no cpus found));
-return -1;
-}
-
-if