Skip to content

Commit e1572f1

Browse files
vittyvkbonzini
authored andcommitted
cpu/SMT: create and export cpu_smt_possible()
KVM needs to know if SMT is theoretically possible, this means it is supported and not forcefully disabled ('nosmt=force'). Create and export cpu_smt_possible() answering this question. Signed-off-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a073d7e commit e1572f1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/linux/cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,14 @@ enum cpuhp_smt_control {
201201
extern enum cpuhp_smt_control cpu_smt_control;
202202
extern void cpu_smt_disable(bool force);
203203
extern void cpu_smt_check_topology(void);
204+
extern bool cpu_smt_possible(void);
204205
extern int cpuhp_smt_enable(void);
205206
extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
206207
#else
207208
# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
208209
static inline void cpu_smt_disable(bool force) { }
209210
static inline void cpu_smt_check_topology(void) { }
211+
static inline bool cpu_smt_possible(void) { return false; }
210212
static inline int cpuhp_smt_enable(void) { return 0; }
211213
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
212214
#endif

kernel/cpu.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
392392

393393
void __init cpu_smt_disable(bool force)
394394
{
395-
if (cpu_smt_control == CPU_SMT_FORCE_DISABLED ||
396-
cpu_smt_control == CPU_SMT_NOT_SUPPORTED)
395+
if (!cpu_smt_possible())
397396
return;
398397

399398
if (force) {
@@ -438,6 +437,14 @@ static inline bool cpu_smt_allowed(unsigned int cpu)
438437
*/
439438
return !cpumask_test_cpu(cpu, &cpus_booted_once_mask);
440439
}
440+
441+
/* Returns true if SMT is not supported of forcefully (irreversibly) disabled */
442+
bool cpu_smt_possible(void)
443+
{
444+
return cpu_smt_control != CPU_SMT_FORCE_DISABLED &&
445+
cpu_smt_control != CPU_SMT_NOT_SUPPORTED;
446+
}
447+
EXPORT_SYMBOL_GPL(cpu_smt_possible);
441448
#else
442449
static inline bool cpu_smt_allowed(unsigned int cpu) { return true; }
443450
#endif

0 commit comments

Comments
 (0)