Skip to content

Commit

Permalink
tools/power/x86/intel-speed-select: Prevent CPU 0 offline
Browse files Browse the repository at this point in the history
Kernel 6.5 version deprecated CPU 0 hotplug. This will cause all
requests to fail to offline CPU 0. Check version number of kernel
and ignore CPU 0 hotplug request with debug aid to use cgroup
isolation feature for CPU 0.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
  • Loading branch information
spandruvada committed Aug 8, 2023
1 parent e67b6ed commit 01bcb56
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tools/power/x86/intel-speed-select/isst-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <linux/isst_if.h>
#include <sys/utsname.h>

#include "isst.h"

Expand Down Expand Up @@ -473,11 +474,44 @@ static unsigned int is_cpu_online(int cpu)
return online;
}

static int get_kernel_version(int *major, int *minor)
{
struct utsname buf;
int ret;

ret = uname(&buf);
if (ret)
return ret;

ret = sscanf(buf.release, "%d.%d", major, minor);
if (ret != 2)
return ret;

return 0;
}

#define CPU0_HOTPLUG_DEPRECATE_MAJOR_VER 6
#define CPU0_HOTPLUG_DEPRECATE_MINOR_VER 5

void set_cpu_online_offline(int cpu, int state)
{
char buffer[128];
int fd, ret;

if (!cpu) {
int major, minor;

ret = get_kernel_version(&major, &minor);
if (!ret) {
if (major > CPU0_HOTPLUG_DEPRECATE_MAJOR_VER || (major == CPU0_HOTPLUG_DEPRECATE_MAJOR_VER &&
minor >= CPU0_HOTPLUG_DEPRECATE_MINOR_VER)) {
debug_printf("Ignore CPU 0 offline/online for kernel version >= %d.%d\n", major, minor);
debug_printf("Use cgroups to isolate CPU 0\n");
return;
}
}
}

snprintf(buffer, sizeof(buffer),
"/sys/devices/system/cpu/cpu%d/online", cpu);

Expand Down

0 comments on commit 01bcb56

Please sign in to comment.