Blame SOURCES/052-hotplug-cpus.patch

60de42
From a882a3ff25bcae8d703277ebd850fde0b1128ce9 Mon Sep 17 00:00:00 2001
60de42
From: Ken Gaillot <kgaillot@redhat.com>
60de42
Date: Tue, 25 Apr 2017 17:23:04 -0500
60de42
Subject: [PATCH 1/5] Refactor: crmd: functionize setting throttle load target
60de42
60de42
Make as much in throttle.c static as possible, for better isolation.
60de42
---
60de42
 crmd/control.c  |  4 ++--
60de42
 crmd/throttle.c | 46 ++++++++++++++++++++++++++--------------------
60de42
 crmd/throttle.h |  4 +---
60de42
 3 files changed, 29 insertions(+), 25 deletions(-)
60de42
60de42
diff --git a/crmd/control.c b/crmd/control.c
60de42
index f4823b9..af9c2c2 100644
60de42
--- a/crmd/control.c
60de42
+++ b/crmd/control.c
60de42
@@ -1046,7 +1046,7 @@ config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void
60de42
 
60de42
     value = crmd_pref(config_hash, "load-threshold");
60de42
     if(value) {
60de42
-        throttle_load_target = strtof(value, NULL) / 100;
60de42
+        throttle_set_load_target(strtof(value, NULL) / 100.0);
60de42
     }
60de42
 
60de42
     value = crmd_pref(config_hash, "no-quorum-policy");
60de42
 
60de42
diff --git a/crmd/throttle.c b/crmd/throttle.c
60de42
index ce330fe..b9add7d 100644
60de42
--- a/crmd/throttle.c
60de42
+++ b/crmd/throttle.c
60de42
@@ -33,8 +33,7 @@
60de42
 #include <throttle.h>
60de42
 
60de42
 
60de42
-enum throttle_state_e 
60de42
-{
60de42
+enum throttle_state_e {
60de42
     throttle_extreme = 0x1000,
60de42
     throttle_high = 0x0100,
60de42
     throttle_med  = 0x0010,
60de42
@@ -42,24 +41,24 @@ enum throttle_state_e
60de42
     throttle_none = 0x0000,
60de42
 };
60de42
 
60de42
-struct throttle_record_s 
60de42
-{
60de42
-        int max;
60de42
-        enum throttle_state_e mode;
60de42
-        char *node;
60de42
+struct throttle_record_s {
60de42
+    int max;
60de42
+    enum throttle_state_e mode;
60de42
+    char *node;
60de42
 };
60de42
 
60de42
-int throttle_job_max = 0;
60de42
-float throttle_load_target = 0.0;
60de42
+static int throttle_job_max = 0;
60de42
+static float throttle_load_target = 0.0;
60de42
 
60de42
 #define THROTTLE_FACTOR_LOW    1.2
60de42
 #define THROTTLE_FACTOR_MEDIUM 1.6
60de42
 #define THROTTLE_FACTOR_HIGH   2.0
60de42
 
60de42
-GHashTable *throttle_records = NULL;
60de42
-mainloop_timer_t *throttle_timer = NULL;
60de42
+static GHashTable *throttle_records = NULL;
60de42
+static mainloop_timer_t *throttle_timer = NULL;
60de42
 
60de42
-int throttle_num_cores(void)
60de42
+static int
60de42
+throttle_num_cores(void)
60de42
 {
60de42
     static int cores = 0;
60de42
     char buffer[256];
60de42
@@ -102,14 +101,16 @@ int throttle_num_cores(void)
60de42
  *       This will return NULL if the daemon is being run via valgrind.
60de42
  *       This should be called only on Linux systems.
60de42
  */
60de42
-static char *find_cib_loadfile(void) 
60de42
+static char *
60de42
+find_cib_loadfile(void)
60de42
 {
60de42
     int pid = crm_procfs_pid_of("cib");
60de42
 
60de42
     return pid? crm_strdup_printf("/proc/%d/stat", pid) : NULL;
60de42
 }
60de42
 
60de42
-static bool throttle_cib_load(float *load) 
60de42
+static bool
60de42
+throttle_cib_load(float *load)
60de42
 {
60de42
 /*
60de42
        /proc/[pid]/stat
60de42
@@ -233,7 +234,8 @@ static bool throttle_cib_load(float *load)
60de42
     return FALSE;
60de42
 }
60de42
 
60de42
-static bool throttle_load_avg(float *load)
60de42
+static bool
60de42
+throttle_load_avg(float *load)
60de42
 {
60de42
     char buffer[256];
60de42
     FILE *stream = NULL;
60de42
@@ -266,7 +268,8 @@ static bool throttle_load_avg(float *load)
60de42
     return FALSE;
60de42
 }
60de42
 
60de42
-static bool throttle_io_load(float *load, unsigned int *blocked)
60de42
+static bool
60de42
+throttle_io_load(float *load, unsigned int *blocked)
60de42
 {
60de42
     char buffer[64*1024];
60de42
     FILE *stream = NULL;
60de42
@@ -514,7 +517,13 @@ throttle_record_free(gpointer p)
60de42
 }
60de42
 
60de42
 void
60de42
-throttle_update_job_max(const char *preference) 
60de42
+throttle_set_load_target(float target)
60de42
+{
60de42
+    throttle_load_target = target;
60de42
+}
60de42
+
60de42
+void
60de42
+throttle_update_job_max(const char *preference)
60de42
 {
60de42
     int max = 0;
60de42
 
60de42
@@ -547,7 +556,6 @@ throttle_update_job_max(const char *preference)
60de42
     }
60de42
 }
60de42
 
60de42
-
60de42
 void
60de42
 throttle_init(void)
60de42
 {
60de42
@@ -568,7 +576,6 @@ throttle_fini(void)
60de42
     g_hash_table_destroy(throttle_records); throttle_records = NULL;
60de42
 }
60de42
 
60de42
-
60de42
 int
60de42
 throttle_get_total_job_limit(int l)
60de42
 {
60de42
@@ -673,4 +680,3 @@ throttle_update(xmlNode *xml)
60de42
     crm_debug("Host %s supports a maximum of %d jobs and throttle mode %.4x.  New job limit is %d",
60de42
               from, max, mode, throttle_get_job_limit(from));
60de42
 }
60de42
-
60de42
diff --git a/crmd/throttle.h b/crmd/throttle.h
60de42
index bdb33e7..9d1b97b 100644
60de42
--- a/crmd/throttle.h
60de42
+++ b/crmd/throttle.h
60de42
@@ -17,12 +17,10 @@
60de42
  */
60de42
 
60de42
 
60de42
-extern float throttle_load_target;
60de42
-
60de42
 void throttle_init(void);
60de42
 void throttle_fini(void);
60de42
 
60de42
-int throttle_num_cores(void);
60de42
+void throttle_set_load_target(float target);
60de42
 void throttle_update(xmlNode *xml);
60de42
 void throttle_update_job_max(const char *preference);
60de42
 int throttle_get_job_limit(const char *node);
60de42
-- 
60de42
1.8.3.1
60de42
60de42
60de42
From acbbca50ab2fc9f71b9517d62e22bde7891ee67d Mon Sep 17 00:00:00 2001
60de42
From: Ken Gaillot <kgaillot@redhat.com>
60de42
Date: Fri, 28 Apr 2017 14:09:36 -0500
60de42
Subject: [PATCH 2/5] Refactor: crmd: functionize checking throttle thresholds
60de42
60de42
... to reduce code duplication
60de42
---
60de42
 crmd/throttle.c | 92 ++++++++++++++++++++++++++++++++-------------------------
60de42
 1 file changed, 51 insertions(+), 41 deletions(-)
60de42
60de42
diff --git a/crmd/throttle.c b/crmd/throttle.c
60de42
index b9add7d..8ab6f01 100644
60de42
--- a/crmd/throttle.c
60de42
+++ b/crmd/throttle.c
60de42
@@ -350,45 +350,68 @@ throttle_io_load(float *load, unsigned int *blocked)
60de42
     return FALSE;
60de42
 }
60de42
 
60de42
+/*!
60de42
+ * \internal
60de42
+ * \brief Check a load value against throttling thresholds
60de42
+ *
60de42
+ * \param[in] load        Load value to check
60de42
+ * \param[in] desc        Description of metric (for logging)
60de42
+ * \param[in] thresholds  Low/medium/high/extreme thresholds
60de42
+ *
60de42
+ * \return Throttle mode corresponding to load value
60de42
+ */
60de42
 static enum throttle_state_e
60de42
-throttle_handle_load(float load, const char *desc, int cores)
60de42
+throttle_check_thresholds(float load, const char *desc, float thresholds[4])
60de42
 {
60de42
-    float adjusted_load = load;
60de42
-
60de42
-    if(cores <= 0) {
60de42
-        /* No fudging of the supplied load value */
60de42
-
60de42
-    } else if(cores == 1) {
60de42
-        /* On a single core machine, a load of 1.0 is already too high */
60de42
-        adjusted_load = load * THROTTLE_FACTOR_MEDIUM;
60de42
-
60de42
-    } else {
60de42
-        /* Normalize the load to be per-core */
60de42
-        adjusted_load = load / cores;
60de42
-    }
60de42
+    if (load > thresholds[3]) {
60de42
+        crm_notice("Extreme %s detected: %f", desc, load);
60de42
+        return throttle_extreme;
60de42
 
60de42
-    if(adjusted_load > THROTTLE_FACTOR_HIGH * throttle_load_target) {
60de42
+    } else if (load > thresholds[2]) {
60de42
         crm_notice("High %s detected: %f", desc, load);
60de42
         return throttle_high;
60de42
 
60de42
-    } else if(adjusted_load > THROTTLE_FACTOR_MEDIUM * throttle_load_target) {
60de42
+    } else if (load > thresholds[1]) {
60de42
         crm_info("Moderate %s detected: %f", desc, load);
60de42
         return throttle_med;
60de42
 
60de42
-    } else if(adjusted_load > THROTTLE_FACTOR_LOW * throttle_load_target) {
60de42
+    } else if (load > thresholds[0]) {
60de42
         crm_debug("Noticeable %s detected: %f", desc, load);
60de42
         return throttle_low;
60de42
     }
60de42
 
60de42
-    crm_trace("Negligible %s detected: %f", desc, adjusted_load);
60de42
+    crm_trace("Negligible %s detected: %f", desc, load);
60de42
     return throttle_none;
60de42
 }
60de42
 
60de42
 static enum throttle_state_e
60de42
+throttle_handle_load(float load, const char *desc, int cores)
60de42
+{
60de42
+    float normalize;
60de42
+    float thresholds[4];
60de42
+
60de42
+    if (cores == 1) {
60de42
+        /* On a single core machine, a load of 1.0 is already too high */
60de42
+        normalize = 0.6;
60de42
+
60de42
+    } else {
60de42
+        /* Normalize the load to be per-core */
60de42
+        normalize = cores;
60de42
+    }
60de42
+    thresholds[0] = throttle_load_target * normalize * THROTTLE_FACTOR_LOW;
60de42
+    thresholds[1] = throttle_load_target * normalize * THROTTLE_FACTOR_MEDIUM;
60de42
+    thresholds[2] = throttle_load_target * normalize * THROTTLE_FACTOR_HIGH;
60de42
+    thresholds[3] = load + 1.0; /* never extreme */
60de42
+
60de42
+    return throttle_check_thresholds(load, desc, thresholds);
60de42
+}
60de42
+
60de42
+static enum throttle_state_e
60de42
 throttle_mode(void)
60de42
 {
60de42
     int cores;
60de42
     float load;
60de42
+    float thresholds[4];
60de42
     unsigned int blocked = 0;
60de42
     enum throttle_state_e mode = throttle_none;
60de42
 
60de42
@@ -399,16 +422,16 @@ throttle_mode(void)
60de42
     cores = throttle_num_cores();
60de42
     if(throttle_cib_load(&load)) {
60de42
         float cib_max_cpu = 0.95;
60de42
-        const char *desc = "CIB load";
60de42
-        /* The CIB is a single threaded task and thus cannot consume
60de42
+
60de42
+        /* The CIB is a single-threaded task and thus cannot consume
60de42
          * more than 100% of a CPU (and 1/cores of the overall system
60de42
          * load).
60de42
          *
60de42
-         * On a many cored system, the CIB might therefor be maxed out
60de42
+         * On a many-cored system, the CIB might therefore be maxed out
60de42
          * (causing operations to fail or appear to fail) even though
60de42
          * the overall system load is still reasonable.
60de42
          *
60de42
-         * Therefor the 'normal' thresholds can not apply here and we
60de42
+         * Therefore, the 'normal' thresholds can not apply here, and we
60de42
          * need a special case.
60de42
          */
60de42
         if(cores == 1) {
60de42
@@ -418,26 +441,13 @@ throttle_mode(void)
60de42
             cib_max_cpu = throttle_load_target;
60de42
         }
60de42
 
60de42
-        if(load > 1.5 * cib_max_cpu) {
60de42
-            /* Can only happen on machines with a low number of cores */
60de42
-            crm_notice("Extreme %s detected: %f", desc, load);
60de42
-            mode |= throttle_extreme;
60de42
-
60de42
-        } else if(load > cib_max_cpu) {
60de42
-            crm_notice("High %s detected: %f", desc, load);
60de42
-            mode |= throttle_high;
60de42
+        thresholds[0] = cib_max_cpu * 0.8;
60de42
+        thresholds[1] = cib_max_cpu * 0.9;
60de42
+        thresholds[2] = cib_max_cpu;
60de42
+        /* Can only happen on machines with a low number of cores */
60de42
+        thresholds[3] = cib_max_cpu * 1.5;
60de42
 
60de42
-        } else if(load > cib_max_cpu * 0.9) {
60de42
-            crm_info("Moderate %s detected: %f", desc, load);
60de42
-            mode |= throttle_med;
60de42
-
60de42
-        } else if(load > cib_max_cpu * 0.8) {
60de42
-            crm_debug("Noticeable %s detected: %f", desc, load);
60de42
-            mode |= throttle_low;
60de42
-
60de42
-        } else {
60de42
-            crm_trace("Negligible %s detected: %f", desc, load);
60de42
-        }
60de42
+        mode |= throttle_check_thresholds(load, "CIB load", thresholds);
60de42
     }
60de42
 
60de42
     if(throttle_load_target <= 0) {
60de42
-- 
60de42
1.8.3.1
60de42
60de42
60de42
From 89175e75f3b38b10ea163c1a8d621d1296570e7f Mon Sep 17 00:00:00 2001
60de42
From: Ken Gaillot <kgaillot@redhat.com>
60de42
Date: Fri, 28 Apr 2017 14:30:55 -0500
60de42
Subject: [PATCH 3/5] Feature: libcrmcommon: add function to get number of CPU
60de42
 cores
60de42
60de42
Compared to the previous implementation in crmd/throttle.c, this
60de42
parses /proc/stat, which is smaller than /proc/cpuinfo.
60de42
---
60de42
 include/crm/common/internal.h |  1 +
60de42
 lib/common/procfs.c           | 30 ++++++++++++++++++++++++++++++
60de42
 2 files changed, 31 insertions(+)
60de42
60de42
diff --git a/include/crm/common/internal.h b/include/crm/common/internal.h
60de42
index 475128f..c34b03b 100644
60de42
--- a/include/crm/common/internal.h
60de42
+++ b/include/crm/common/internal.h
60de42
@@ -54,6 +54,7 @@ int crm_write_sync(int fd, const char *contents);
60de42
 
60de42
 int crm_procfs_process_info(struct dirent *entry, char *name, int *pid);
60de42
 int crm_procfs_pid_of(const char *name);
60de42
+unsigned int crm_procfs_num_cores(void);
60de42
 
60de42
 
60de42
 /* internal XML schema functions (from xml.c) */
60de42
diff --git a/lib/common/procfs.c b/lib/common/procfs.c
60de42
index 12d01ff..fbbf9eb 100644
60de42
--- a/lib/common/procfs.c
60de42
+++ b/lib/common/procfs.c
60de42
@@ -28,6 +28,7 @@
60de42
 #include <sys/stat.h>
60de42
 #include <sys/types.h>
60de42
 #include <dirent.h>
60de42
+#include <ctype.h>
60de42
 
60de42
 /*!
60de42
  * \internal
60de42
@@ -140,3 +141,32 @@ crm_procfs_pid_of(const char *name)
60de42
     closedir(dp);
60de42
     return pid;
60de42
 }
60de42
+
60de42
+/*!
60de42
+ * \internal
60de42
+ * \brief Calculate number of logical CPU cores from procfs
60de42
+ *
60de42
+ * \return Number of cores (or 1 if unable to determine)
60de42
+ */
60de42
+unsigned int
60de42
+crm_procfs_num_cores(void)
60de42
+{
60de42
+    int cores = 0;
60de42
+    FILE *stream = NULL;
60de42
+
60de42
+    /* Parse /proc/stat instead of /proc/cpuinfo because it's smaller */
60de42
+    stream = fopen("/proc/stat", "r");
60de42
+    if (stream == NULL) {
60de42
+        crm_perror(LOG_INFO, "Could not open /proc/stat");
60de42
+    } else {
60de42
+        char buffer[2048];
60de42
+
60de42
+        while (fgets(buffer, sizeof(buffer), stream)) {
60de42
+            if (!strncmp(buffer, "cpu", 3) && isdigit(buffer[3])) {
60de42
+                ++cores;
60de42
+            }
60de42
+        }
60de42
+        fclose(stream);
60de42
+    }
60de42
+    return cores? cores : 1;
60de42
+}
60de42
-- 
60de42
1.8.3.1
60de42
60de42
60de42
From 0307614c92664078ffae0566324de85c2f990353 Mon Sep 17 00:00:00 2001
60de42
From: Ken Gaillot <kgaillot@redhat.com>
60de42
Date: Fri, 28 Apr 2017 14:41:50 -0500
60de42
Subject: [PATCH 4/5] Low: crmd: remove I/O load checks
60de42
60de42
Due to bugs, the crmd's throttling checks for I/O load and blocked processes
60de42
would always get 0. In any case, both are already included in the load average
60de42
checked elsewhere, so there is no need to check them.
60de42
---
60de42
 crmd/throttle.c | 88 ---------------------------------------------------------
60de42
 1 file changed, 88 deletions(-)
60de42
60de42
diff --git a/crmd/throttle.c b/crmd/throttle.c
60de42
index 8ab6f01..387e58d 100644
60de42
--- a/crmd/throttle.c
60de42
+++ b/crmd/throttle.c
60de42
@@ -268,88 +268,6 @@ throttle_load_avg(float *load)
60de42
     return FALSE;
60de42
 }
60de42
 
60de42
-static bool
60de42
-throttle_io_load(float *load, unsigned int *blocked)
60de42
-{
60de42
-    char buffer[64*1024];
60de42
-    FILE *stream = NULL;
60de42
-    const char *loadfile = "/proc/stat";
60de42
-
60de42
-    if(load == NULL) {
60de42
-        return FALSE;
60de42
-    }
60de42
-
60de42
-    stream = fopen(loadfile, "r");
60de42
-    if(stream == NULL) {
60de42
-        int rc = errno;
60de42
-        crm_warn("Couldn't read %s: %s (%d)", loadfile, pcmk_strerror(rc), rc);
60de42
-        return FALSE;
60de42
-    }
60de42
-
60de42
-    if(fgets(buffer, sizeof(buffer), stream)) {
60de42
-        /* Borrowed from procps-ng's sysinfo.c */
60de42
-
60de42
-        char *b = NULL;
60de42
-        unsigned long long cpu_use = 0;
60de42
-        unsigned long long cpu_nic = 0;
60de42
-        unsigned long long cpu_sys = 0;
60de42
-        unsigned long long cpu_idl = 0;
60de42
-        unsigned long long cpu_iow = 0; /* not separated out until the 2.5.41 kernel */
60de42
-        unsigned long long cpu_xxx = 0; /* not separated out until the 2.6.0-test4 kernel */
60de42
-        unsigned long long cpu_yyy = 0; /* not separated out until the 2.6.0-test4 kernel */
60de42
-        unsigned long long cpu_zzz = 0; /* not separated out until the 2.6.11 kernel */
60de42
-
60de42
-        long long divo2 = 0;
60de42
-        long long duse = 0;
60de42
-        long long dsys = 0;
60de42
-        long long didl =0;
60de42
-        long long diow =0;
60de42
-        long long dstl = 0;
60de42
-        long long Div = 0;
60de42
-
60de42
-        b = strstr(buffer, "cpu ");
60de42
-        if(b) sscanf(b,  "cpu  %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
60de42
-               &cpu_use, &cpu_nic, &cpu_sys, &cpu_idl, &cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz);
60de42
-
60de42
-        if(blocked) {
60de42
-            b = strstr(buffer, "procs_blocked ");
60de42
-            if(b) sscanf(b,  "procs_blocked %u", blocked);
60de42
-        }
60de42
-
60de42
-        duse = cpu_use + cpu_nic;
60de42
-        dsys = cpu_sys + cpu_xxx + cpu_yyy;
60de42
-        didl = cpu_idl;
60de42
-        diow = cpu_iow;
60de42
-        dstl = cpu_zzz;
60de42
-        Div = duse + dsys + didl + diow + dstl;
60de42
-        if (!Div) Div = 1, didl = 1;
60de42
-        divo2 = Div / 2UL;
60de42
-
60de42
-        /* vmstat output:
60de42
-         *
60de42
-         * procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- 
60de42
-         * r  b   swpd   free   buff  cache     si   so    bi    bo   in   cs us sy id wa
60de42
-         * 1  0 5537800 958592 204180 1737740    1    1    12    15    0    0  2  1 97  0
60de42
-         *
60de42
-         * The last four columns are calculated as:
60de42
-         *
60de42
-         * (unsigned)( (100*duse			+ divo2) / Div ),
60de42
-         * (unsigned)( (100*dsys			+ divo2) / Div ),
60de42
-         * (unsigned)( (100*didl			+ divo2) / Div ),
60de42
-         * (unsigned)( (100*diow			+ divo2) / Div )
60de42
-         *
60de42
-         */
60de42
-        *load = (diow + divo2) / Div;
60de42
-        crm_debug("Current IO load is %f", *load);
60de42
-
60de42
-        fclose(stream);
60de42
-        return TRUE;
60de42
-    }
60de42
-
60de42
-    fclose(stream);
60de42
-    return FALSE;
60de42
-}
60de42
-
60de42
 /*!
60de42
  * \internal
60de42
  * \brief Check a load value against throttling thresholds
60de42
@@ -412,7 +330,6 @@ throttle_mode(void)
60de42
     int cores;
60de42
     float load;
60de42
     float thresholds[4];
60de42
-    unsigned int blocked = 0;
60de42
     enum throttle_state_e mode = throttle_none;
60de42
 
60de42
 #if defined(ON_BSD) || defined(ON_SOLARIS)
60de42
@@ -459,11 +376,6 @@ throttle_mode(void)
60de42
         mode |= throttle_handle_load(load, "CPU load", cores);
60de42
     }
60de42
 
60de42
-    if(throttle_io_load(&load, &blocked)) {
60de42
-        mode |= throttle_handle_load(load, "IO load", 0);
60de42
-        mode |= throttle_handle_load(blocked, "blocked IO ratio", cores);
60de42
-    }
60de42
-
60de42
     if(mode & throttle_extreme) {
60de42
         return throttle_extreme;
60de42
     } else if(mode & throttle_high) {
60de42
-- 
60de42
1.8.3.1
60de42
60de42
60de42
From da00177e186dc7b7e63fecb7e0d461003eda2eea Mon Sep 17 00:00:00 2001
60de42
From: Ken Gaillot <kgaillot@redhat.com>
60de42
Date: Fri, 28 Apr 2017 14:56:12 -0500
60de42
Subject: [PATCH 5/5] Fix: crmd,libcrmcommon: update throttle when CPUs are
60de42
 hot-plugged
60de42
60de42
Previously, the number of CPU cores was determined the first time it was
60de42
needed, and remembered permanently after that. That becomes inaccurate when
60de42
cores are hot-plugged in and out of a virtual machine. Now, the number of cores
60de42
is parsed each time it is needed (using the new libcrmcommon function).
60de42
---
60de42
 crmd/throttle.c | 42 ++++--------------------------------------
60de42
 1 file changed, 4 insertions(+), 38 deletions(-)
60de42
60de42
diff --git a/crmd/throttle.c b/crmd/throttle.c
60de42
index 387e58d..90ddb90 100644
60de42
--- a/crmd/throttle.c
60de42
+++ b/crmd/throttle.c
60de42
@@ -57,40 +57,6 @@ static float throttle_load_target = 0.0;
60de42
 static GHashTable *throttle_records = NULL;
60de42
 static mainloop_timer_t *throttle_timer = NULL;
60de42
 
60de42
-static int
60de42
-throttle_num_cores(void)
60de42
-{
60de42
-    static int cores = 0;
60de42
-    char buffer[256];
60de42
-    FILE *stream = NULL;
60de42
-    const char *cpufile = "/proc/cpuinfo";
60de42
-
60de42
-    if(cores) {
60de42
-        return cores;
60de42
-    }
60de42
-    stream = fopen(cpufile, "r");
60de42
-    if(stream == NULL) {
60de42
-        int rc = errno;
60de42
-        crm_warn("Couldn't read %s, assuming a single processor: %s (%d)", cpufile, pcmk_strerror(rc), rc);
60de42
-        return 1;
60de42
-    }
60de42
-
60de42
-    while (fgets(buffer, sizeof(buffer), stream)) {
60de42
-        if(strstr(buffer, "processor") == buffer) {
60de42
-            cores++;
60de42
-        }
60de42
-    }
60de42
-
60de42
-    fclose(stream);
60de42
-
60de42
-    if(cores == 0) {
60de42
-        crm_warn("No processors found in %s, assuming 1", cpufile);
60de42
-        return 1;
60de42
-    }
60de42
-
60de42
-    return cores;
60de42
-}
60de42
-
60de42
 /*!
60de42
  * \internal
60de42
  * \brief Return name of /proc file containing the CIB deamon's load statistics
60de42
@@ -259,7 +225,6 @@ throttle_load_avg(float *load)
60de42
         *load = strtof(buffer, NULL);
60de42
         if(nl) { nl[0] = 0; }
60de42
 
60de42
-        crm_debug("Current load is %f (full: %s)", *load, buffer);
60de42
         fclose(stream);
60de42
         return TRUE;
60de42
     }
60de42
@@ -327,7 +292,7 @@ throttle_handle_load(float load, const char *desc, int cores)
60de42
 static enum throttle_state_e
60de42
 throttle_mode(void)
60de42
 {
60de42
-    int cores;
60de42
+    unsigned int cores;
60de42
     float load;
60de42
     float thresholds[4];
60de42
     enum throttle_state_e mode = throttle_none;
60de42
@@ -336,7 +301,7 @@ throttle_mode(void)
60de42
     return throttle_none;
60de42
 #endif
60de42
 
60de42
-    cores = throttle_num_cores();
60de42
+    cores = crm_procfs_num_cores();
60de42
     if(throttle_cib_load(&load)) {
60de42
         float cib_max_cpu = 0.95;
60de42
 
60de42
@@ -373,6 +338,7 @@ throttle_mode(void)
60de42
     }
60de42
 
60de42
     if(throttle_load_avg(&load)) {
60de42
+        crm_debug("Current load is %f across %u core(s)", load, cores);
60de42
         mode |= throttle_handle_load(load, "CPU load", cores);
60de42
     }
60de42
 
60de42
@@ -449,7 +415,7 @@ throttle_update_job_max(const char *preference)
60de42
 {
60de42
     int max = 0;
60de42
 
60de42
-    throttle_job_max = 2 * throttle_num_cores();
60de42
+    throttle_job_max = 2 * crm_procfs_num_cores();
60de42
 
60de42
     if(preference) {
60de42
         /* Global preference from the CIB */
60de42
-- 
60de42
1.8.3.1
60de42