Skip to content

Commit

Permalink
Remove LXC special handling for the CPU count
Browse files Browse the repository at this point in the history
LXC shows the real host CPU ids but can be limited in configuration
as to which cores are used. Still the sysfs files are visible and the
CPUs (stay) marked online. We will need to parse
/sys/devices/system/cpu/online to follow LXC's logic.
Revert for now until we can come up with a better handling of the LXC hacks.

Cf. issue #1195
Essentially reverting 33973f7 and 0d53245 (#993, #995)
  • Loading branch information
Daniel Lange authored and BenBE committed Feb 25, 2023
1 parent c66f99b commit 11318b5
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions linux/LinuxProcessList.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,6 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) {

#endif

static unsigned int scanAvailableCPUsFromCPUinfo(LinuxProcessList* this) {
FILE* file = fopen(PROCCPUINFOFILE, "r");
if (file == NULL)
return this->super.existingCPUs;

unsigned int availableCPUs = 0;

while (!feof(file)) {
char buffer[PROC_LINE_LENGTH];

if (fgets(buffer, PROC_LINE_LENGTH, file) == NULL)
break;

if (String_startsWith(buffer, "processor"))
availableCPUs++;
}

fclose(file);

return availableCPUs ? availableCPUs : 1;
}

static void LinuxProcessList_updateCPUcount(ProcessList* super) {
/* Similar to get_nprocs_conf(3) / _SC_NPROCESSORS_CONF
* https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getsysstats.c;hb=HEAD
Expand Down Expand Up @@ -306,12 +284,6 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
if (existing < 1)
return;

if (Running_containerized) {
/* LXC munges /proc/cpuinfo but not the /sys/devices/system/cpu/ files,
* so limit the visible CPUs to what the guest has been configured to see: */
currExisting = active = scanAvailableCPUsFromCPUinfo(this);
}

#ifdef HAVE_SENSORS_SENSORS_H
/* When started with offline CPUs, libsensors does not monitor those,
* even when they become online. */
Expand All @@ -320,7 +292,7 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
#endif

super->activeCPUs = active;
assert(Running_containerized || (existing == currExisting));
assert(existing == currExisting);
super->existingCPUs = currExisting;
}

Expand Down

0 comments on commit 11318b5

Please sign in to comment.