Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumpuser Always use sysconf() to query host processor...



details:   https://anonhg.NetBSD.org/src/rev/3bf350c545d7
branches:  trunk
changeset: 328398:3bf350c545d7
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed Apr 02 13:54:42 2014 +0000

description:
Always use sysconf() to query host processor count instead of separate
tricks for each platform.

diffstat:

 lib/librumpuser/rumpuser.c |  31 ++++---------------------------
 1 files changed, 4 insertions(+), 27 deletions(-)

diffs (53 lines):

diff -r 5879952088f8 -r 3bf350c545d7 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Wed Apr 02 13:26:22 2014 +0000
+++ b/lib/librumpuser/rumpuser.c        Wed Apr 02 13:54:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.58 2014/03/16 10:23:59 njoly Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.59 2014/04/02 13:54:42 pooka Exp $      */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.58 2014/03/16 10:23:59 njoly Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.59 2014/04/02 13:54:42 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -536,32 +536,9 @@
 static int
 gethostncpu(void)
 {
-       int ncpu = 1;
-
-#if defined(__BSD__)
-       size_t sz = sizeof(ncpu);
-
-       sysctlbyname("hw.ncpu", &ncpu, &sz, NULL, 0);
-#elif defined(__linux__) || defined(__CYGWIN__)
-       FILE *fp;
-       char *line = NULL;
-       size_t n = 0;
+       int ncpu = 1; /* unknown, really */
 
-       /* If anyone knows a better way, I'm all ears */
-       if ((fp = fopen("/proc/cpuinfo", "r")) != NULL) {
-               ncpu = 0;
-               while (getline(&line, &n, fp) != -1) {
-                       if (strncmp(line,
-                           "processor", sizeof("processor")-1) == 0)
-                               ncpu++;
-               }
-               if (ncpu == 0)
-                       ncpu = 1;
-               free(line);
-               fclose(fp);
-       }
-#elif __sun__
-       /* XXX: this is just a rough estimate ... */
+#ifdef _SC_NPROCESSORS_ONLN
        ncpu = sysconf(_SC_NPROCESSORS_ONLN);
 #endif
        



Home | Main Index | Thread Index | Old Index