Skip to content

Commit 789d60b

Browse files
committed
Merge: AMD Preferred Core Notification
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6637 JIRA: https://issues.redhat.com/browse/RHEL-53784 Omitted-fix: e120829 - this is typically brought in by perf updates Signed-off-by: David Arcari <[email protected]> Approved-by: Steve Best <[email protected]> Approved-by: Tony Camuso <[email protected]> Approved-by: CKI KWF Bot <[email protected]> Merged-by: Augusto Caringi <[email protected]>
2 parents ff54373 + bac7270 commit 789d60b

File tree

3 files changed

+37
-67
lines changed

3 files changed

+37
-67
lines changed

arch/x86/include/asm/topology.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ extern bool x86_topology_update;
245245
#include <asm/percpu.h>
246246

247247
DECLARE_PER_CPU_READ_MOSTLY(int, sched_core_priority);
248-
extern unsigned int __read_mostly sysctl_sched_itmt_enabled;
248+
extern bool __read_mostly sysctl_sched_itmt_enabled;
249249

250250
/* Interface to set priority of a cpu */
251251
void sched_set_itmt_core_prio(int prio, int core_cpu);
@@ -258,7 +258,7 @@ void sched_clear_itmt_support(void);
258258

259259
#else /* CONFIG_SCHED_MC_PRIO */
260260

261-
#define sysctl_sched_itmt_enabled 0
261+
#define sysctl_sched_itmt_enabled false
262262
static inline void sched_set_itmt_core_prio(int prio, int core_cpu)
263263
{
264264
}

arch/x86/kernel/itmt.c

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/sched.h>
2020
#include <linux/cpumask.h>
2121
#include <linux/cpuset.h>
22+
#include <linux/debugfs.h>
2223
#include <linux/mutex.h>
2324
#include <linux/sysctl.h>
2425
#include <linux/nodemask.h>
@@ -34,50 +35,38 @@ static bool __read_mostly sched_itmt_capable;
3435
* of higher turbo frequency for cpus supporting Intel Turbo Boost Max
3536
* Technology 3.0.
3637
*
37-
* It can be set via /proc/sys/kernel/sched_itmt_enabled
38+
* It can be set via /sys/kernel/debug/x86/sched_itmt_enabled
3839
*/
39-
unsigned int __read_mostly sysctl_sched_itmt_enabled;
40+
bool __read_mostly sysctl_sched_itmt_enabled;
4041

41-
static int sched_itmt_update_handler(struct ctl_table *table, int write,
42-
void *buffer, size_t *lenp, loff_t *ppos)
42+
static ssize_t sched_itmt_enabled_write(struct file *filp,
43+
const char __user *ubuf,
44+
size_t cnt, loff_t *ppos)
4345
{
44-
unsigned int old_sysctl;
45-
int ret;
46+
ssize_t result;
47+
bool orig;
4648

47-
mutex_lock(&itmt_update_mutex);
49+
guard(mutex)(&itmt_update_mutex);
4850

49-
if (!sched_itmt_capable) {
50-
mutex_unlock(&itmt_update_mutex);
51-
return -EINVAL;
52-
}
53-
54-
old_sysctl = sysctl_sched_itmt_enabled;
55-
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
51+
orig = sysctl_sched_itmt_enabled;
52+
result = debugfs_write_file_bool(filp, ubuf, cnt, ppos);
5653

57-
if (!ret && write && old_sysctl != sysctl_sched_itmt_enabled) {
54+
if (sysctl_sched_itmt_enabled != orig) {
5855
x86_topology_update = true;
5956
rebuild_sched_domains();
6057
}
6158

62-
mutex_unlock(&itmt_update_mutex);
63-
64-
return ret;
59+
return result;
6560
}
6661

67-
static struct ctl_table itmt_kern_table[] = {
68-
{
69-
.procname = "sched_itmt_enabled",
70-
.data = &sysctl_sched_itmt_enabled,
71-
.maxlen = sizeof(unsigned int),
72-
.mode = 0644,
73-
.proc_handler = sched_itmt_update_handler,
74-
.extra1 = SYSCTL_ZERO,
75-
.extra2 = SYSCTL_ONE,
76-
},
77-
{}
62+
static const struct file_operations dfs_sched_itmt_fops = {
63+
.read = debugfs_read_file_bool,
64+
.write = sched_itmt_enabled_write,
65+
.open = simple_open,
66+
.llseek = default_llseek,
7867
};
7968

80-
static struct ctl_table_header *itmt_sysctl_header;
69+
static struct dentry *dfs_sched_itmt;
8170

8271
/**
8372
* sched_set_itmt_support() - Indicate platform supports ITMT
@@ -98,16 +87,18 @@ static struct ctl_table_header *itmt_sysctl_header;
9887
*/
9988
int sched_set_itmt_support(void)
10089
{
101-
mutex_lock(&itmt_update_mutex);
90+
guard(mutex)(&itmt_update_mutex);
10291

103-
if (sched_itmt_capable) {
104-
mutex_unlock(&itmt_update_mutex);
92+
if (sched_itmt_capable)
10593
return 0;
106-
}
10794

108-
itmt_sysctl_header = register_sysctl("kernel", itmt_kern_table);
109-
if (!itmt_sysctl_header) {
110-
mutex_unlock(&itmt_update_mutex);
95+
dfs_sched_itmt = debugfs_create_file_unsafe("sched_itmt_enabled",
96+
0644,
97+
arch_debugfs_dir,
98+
&sysctl_sched_itmt_enabled,
99+
&dfs_sched_itmt_fops);
100+
if (IS_ERR_OR_NULL(dfs_sched_itmt)) {
101+
dfs_sched_itmt = NULL;
111102
return -ENOMEM;
112103
}
113104

@@ -118,8 +109,6 @@ int sched_set_itmt_support(void)
118109
x86_topology_update = true;
119110
rebuild_sched_domains();
120111

121-
mutex_unlock(&itmt_update_mutex);
122-
123112
return 0;
124113
}
125114

@@ -135,27 +124,22 @@ int sched_set_itmt_support(void)
135124
*/
136125
void sched_clear_itmt_support(void)
137126
{
138-
mutex_lock(&itmt_update_mutex);
127+
guard(mutex)(&itmt_update_mutex);
139128

140-
if (!sched_itmt_capable) {
141-
mutex_unlock(&itmt_update_mutex);
129+
if (!sched_itmt_capable)
142130
return;
143-
}
131+
144132
sched_itmt_capable = false;
145133

146-
if (itmt_sysctl_header) {
147-
unregister_sysctl_table(itmt_sysctl_header);
148-
itmt_sysctl_header = NULL;
149-
}
134+
debugfs_remove(dfs_sched_itmt);
135+
dfs_sched_itmt = NULL;
150136

151137
if (sysctl_sched_itmt_enabled) {
152138
/* disable sched_itmt if we are no longer ITMT capable */
153139
sysctl_sched_itmt_enabled = 0;
154140
x86_topology_update = true;
155141
rebuild_sched_domains();
156142
}
157-
158-
mutex_unlock(&itmt_update_mutex);
159143
}
160144

161145
int arch_asym_cpu_priority(int cpu)

arch/x86/kernel/smpboot.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -490,27 +490,13 @@ static int x86_core_flags(void)
490490
return cpu_core_flags() | x86_sched_itmt_flags();
491491
}
492492
#endif
493-
#ifdef CONFIG_SCHED_SMT
494-
static int x86_smt_flags(void)
495-
{
496-
return cpu_smt_flags();
497-
}
498-
#endif
499493
#ifdef CONFIG_SCHED_CLUSTER
500494
static int x86_cluster_flags(void)
501495
{
502496
return cpu_cluster_flags() | x86_sched_itmt_flags();
503497
}
504498
#endif
505499

506-
static int x86_die_flags(void)
507-
{
508-
if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
509-
return x86_sched_itmt_flags();
510-
511-
return 0;
512-
}
513-
514500
/*
515501
* Set if a package/die has multiple NUMA nodes inside.
516502
* AMD Magny-Cours, Intel Cluster-on-Die, and Intel
@@ -526,7 +512,7 @@ static void __init build_sched_topology(void)
526512

527513
#ifdef CONFIG_SCHED_SMT
528514
x86_topology[i++] = (struct sched_domain_topology_level){
529-
cpu_smt_mask, x86_smt_flags, SD_INIT_NAME(SMT)
515+
cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT)
530516
};
531517
#endif
532518
#ifdef CONFIG_SCHED_CLUSTER
@@ -546,7 +532,7 @@ static void __init build_sched_topology(void)
546532
*/
547533
if (!x86_has_numa_in_package) {
548534
x86_topology[i++] = (struct sched_domain_topology_level){
549-
cpu_cpu_mask, x86_die_flags, SD_INIT_NAME(PKG)
535+
cpu_cpu_mask, x86_sched_itmt_flags, SD_INIT_NAME(PKG)
550536
};
551537
}
552538

0 commit comments

Comments
 (0)