Skip to content

Commit da00177

Browse files
committed
Fix: crmd,libcrmcommon: update throttle when CPUs are hot-plugged
Previously, the number of CPU cores was determined the first time it was needed, and remembered permanently after that. That becomes inaccurate when cores are hot-plugged in and out of a virtual machine. Now, the number of cores is parsed each time it is needed (using the new libcrmcommon function).
1 parent 0307614 commit da00177

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

crmd/throttle.c

+4-38
Original file line numberDiff line numberDiff line change
@@ -57,40 +57,6 @@ static float throttle_load_target = 0.0;
5757
static GHashTable *throttle_records = NULL;
5858
static mainloop_timer_t *throttle_timer = NULL;
5959

60-
static int
61-
throttle_num_cores(void)
62-
{
63-
static int cores = 0;
64-
char buffer[256];
65-
FILE *stream = NULL;
66-
const char *cpufile = "/proc/cpuinfo";
67-
68-
if(cores) {
69-
return cores;
70-
}
71-
stream = fopen(cpufile, "r");
72-
if(stream == NULL) {
73-
int rc = errno;
74-
crm_warn("Couldn't read %s, assuming a single processor: %s (%d)", cpufile, pcmk_strerror(rc), rc);
75-
return 1;
76-
}
77-
78-
while (fgets(buffer, sizeof(buffer), stream)) {
79-
if(strstr(buffer, "processor") == buffer) {
80-
cores++;
81-
}
82-
}
83-
84-
fclose(stream);
85-
86-
if(cores == 0) {
87-
crm_warn("No processors found in %s, assuming 1", cpufile);
88-
return 1;
89-
}
90-
91-
return cores;
92-
}
93-
9460
/*!
9561
* \internal
9662
* \brief Return name of /proc file containing the CIB deamon's load statistics
@@ -259,7 +225,6 @@ throttle_load_avg(float *load)
259225
*load = strtof(buffer, NULL);
260226
if(nl) { nl[0] = 0; }
261227

262-
crm_debug("Current load is %f (full: %s)", *load, buffer);
263228
fclose(stream);
264229
return TRUE;
265230
}
@@ -327,7 +292,7 @@ throttle_handle_load(float load, const char *desc, int cores)
327292
static enum throttle_state_e
328293
throttle_mode(void)
329294
{
330-
int cores;
295+
unsigned int cores;
331296
float load;
332297
float thresholds[4];
333298
enum throttle_state_e mode = throttle_none;
@@ -336,7 +301,7 @@ throttle_mode(void)
336301
return throttle_none;
337302
#endif
338303

339-
cores = throttle_num_cores();
304+
cores = crm_procfs_num_cores();
340305
if(throttle_cib_load(&load)) {
341306
float cib_max_cpu = 0.95;
342307

@@ -373,6 +338,7 @@ throttle_mode(void)
373338
}
374339

375340
if(throttle_load_avg(&load)) {
341+
crm_debug("Current load is %f across %u core(s)", load, cores);
376342
mode |= throttle_handle_load(load, "CPU load", cores);
377343
}
378344

@@ -449,7 +415,7 @@ throttle_update_job_max(const char *preference)
449415
{
450416
int max = 0;
451417

452-
throttle_job_max = 2 * throttle_num_cores();
418+
throttle_job_max = 2 * crm_procfs_num_cores();
453419

454420
if(preference) {
455421
/* Global preference from the CIB */

0 commit comments

Comments
 (0)