cpu/SMT: recover global num_threads after disable smt switch fail
PATCH 1/1 cpu/SMT: recover global num_threads after disable smt switch fail
When attempting to disable SMT with the following command:
echo off > /sys/devices/system/cpu/smt/control
if cpuhp_smt_disable fails due to a "resource busy" error, the global variable cpu_smt_num_threads is incorrectly updated to the target value despite the failure.
This state inconsistency leads to subsequent attempts to disable SMT being
ineffective since cpu_smt_num_threads equals orig_threads, preventing cpuhp_smt_disable from being invoked. To recover functionality, users
must manually execute echo on > /sys/devices/system/cpu/smt/control,
which is undesirable.
This commit removes the orig_threads variable and update the global cpu_smt_num_threads only after successfully switching the SMT state. This ensures proper state management and prevents the system from entering
an inconsistent state.
--- kernel/cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/cpu.c +6 -6
@@ -2902,7 +2902,7 @@ static ssize_t __store_smt_control(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ctrlval, ret, num_threads, orig_threads; + int ctrlval, ret, num_threads;bool force_off;if (cpu_smt_control ==CPU_SMT_FORCE_DISABLED )
@@ -2935,16 +2935,16 @@ __store_smt_control(struct device *dev, struct device_attribute *attr,if (ret)return ret; - orig_threads = cpu_smt_num_threads; - cpu_smt_num_threads = num_threads; - force_off = ctrlval != cpu_smt_control && ctrlval ==CPU_SMT_FORCE_DISABLED ; -if (num_threads > orig_threads) +if (num_threads > cpu_smt_num_threads) ret =cpuhp_smt_enable (); -else if (num_threads < orig_threads || force_off) +else if (num_threads < cpu_smt_num_threads || force_off) ret =cpuhp_smt_disable (ctrlval); +if (!ret) + cpu_smt_num_threads = num_threads; +unlock_device_hotplug ();return ret ? ret : count; }
Signature · 1 line
2.34.1
Gentle ping on this patch.