Skip to content

Commit

Permalink
ppc64_cpu: Clean up sysfs smt/control error handling
Browse files Browse the repository at this point in the history
When the kernel does not support the sysfs interface do not report an
error, fall back to the old method silently.

Suggested-by: Nathan Lynch<[email protected]>
Signed-off-by: Michal Suchanek <[email protected]>
Signed-off-by: Tyrel Datwyler <[email protected]>
  • Loading branch information
hramrach authored and tyreld committed Nov 1, 2024
1 parent b0816b4 commit 15cdce1
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/ppc64_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,30 @@ static int is_dscr_capable(void)

/*
* Depends on kernel's CONFIG_HOTPLUG_CPU
* Return -1 for fatal error, -2 to retry.
*/
static int set_smt_control(int smt_state)
{
if (set_attribute(SYS_SMT_CONTROL, "%d", smt_state)) {
/* Silently ignore kernel not supporting this feature */
if (errno != ENODEV)
perror(SYS_SMT_CONTROL);
return -1;
switch (errno) {
case ENOENT:
/*
* The kernel does not have the interface.
* Try the old method.
*/
return -2;
case ENODEV:
/*
* Setting SMT state not supported by this interface.
* On older kernels (before Linux 6.6) the generic interface
* may exist but is not hooked on powerpc resulting in ENODEV
* on kernels that can set SMT using the old interface.
*/
return -2;
default:
perror(SYS_SMT_CONTROL);
return -1;
}
}
return 0;
}
Expand Down Expand Up @@ -405,7 +421,7 @@ static int do_smt(char *state, bool numeric)
}

/* Try using smt/control if failing, fall back to the legacy way */
if (set_smt_control(smt_state))
if ((rc = set_smt_control(smt_state)) == -2)
rc = set_smt_state(smt_state);
}

Expand Down

0 comments on commit 15cdce1

Please sign in to comment.