Skip to content

Commit 04cd6aa

Browse files
committed
Merge: AMD Preferred Core Notification
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/639 Description: x86/itmt: updates Omitted-fix: e120829 - this is typically brought in by perf updates JIRA: https://issues.redhat.com/browse/RHEL-53783 Build Info: 67134728 Signed-off-by: Steve Best <sbest@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: David Arcari <darcari@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Julio Faracco <jfaracco@redhat.com>
2 parents ad3ff66 + d5b6126 commit 04cd6aa

File tree

5 files changed

+39
-66
lines changed

5 files changed

+39
-66
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@
477477
#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3) /* BHI_DIS_S HW control enabled */
478478
#define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4) /* Clear branch history at vmexit using SW loop */
479479
#define X86_FEATURE_AMD_FAST_CPPC (21*32 + 5) /* Fast CPPC */
480+
#define X86_FEATURE_AMD_HETEROGENEOUS_CORES (21*32 + 6) /* Heterogeneous Core Topology */
480481

481482
/*
482483
* BUG word(s)

arch/x86/include/asm/topology.h

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

243243
DECLARE_PER_CPU_READ_MOSTLY(int, sched_core_priority);
244-
extern unsigned int __read_mostly sysctl_sched_itmt_enabled;
244+
extern bool __read_mostly sysctl_sched_itmt_enabled;
245245

246246
/* Interface to set priority of a cpu */
247247
void sched_set_itmt_core_prio(int prio, int core_cpu);
@@ -254,7 +254,7 @@ void sched_clear_itmt_support(void);
254254

255255
#else /* CONFIG_SCHED_MC_PRIO */
256256

257-
#define sysctl_sched_itmt_enabled 0
257+
#define sysctl_sched_itmt_enabled false
258258
static inline void sched_set_itmt_core_prio(int prio, int core_cpu)
259259
{
260260
}

arch/x86/kernel/cpu/scattered.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static const struct cpuid_bit cpuid_bits[] = {
5252
{ X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 },
5353
{ X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 },
5454
{ X86_FEATURE_AMD_LBR_PMC_FREEZE, CPUID_EAX, 2, 0x80000022, 0 },
55+
{ X86_FEATURE_AMD_HETEROGENEOUS_CORES, CPUID_EAX, 30, 0x80000026, 0 },
5556
{ 0, 0, 0, 0, 0 }
5657
};
5758

arch/x86/kernel/itmt.c

Lines changed: 33 additions & 48 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,49 +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(const 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-
},
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,
7767
};
7868

79-
static struct ctl_table_header *itmt_sysctl_header;
69+
static struct dentry *dfs_sched_itmt;
8070

8171
/**
8272
* sched_set_itmt_support() - Indicate platform supports ITMT
@@ -97,16 +87,18 @@ static struct ctl_table_header *itmt_sysctl_header;
9787
*/
9888
int sched_set_itmt_support(void)
9989
{
100-
mutex_lock(&itmt_update_mutex);
90+
guard(mutex)(&itmt_update_mutex);
10191

102-
if (sched_itmt_capable) {
103-
mutex_unlock(&itmt_update_mutex);
92+
if (sched_itmt_capable)
10493
return 0;
105-
}
10694

107-
itmt_sysctl_header = register_sysctl("kernel", itmt_kern_table);
108-
if (!itmt_sysctl_header) {
109-
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;
110102
return -ENOMEM;
111103
}
112104

@@ -117,8 +109,6 @@ int sched_set_itmt_support(void)
117109
x86_topology_update = true;
118110
rebuild_sched_domains();
119111

120-
mutex_unlock(&itmt_update_mutex);
121-
122112
return 0;
123113
}
124114

@@ -134,27 +124,22 @@ int sched_set_itmt_support(void)
134124
*/
135125
void sched_clear_itmt_support(void)
136126
{
137-
mutex_lock(&itmt_update_mutex);
127+
guard(mutex)(&itmt_update_mutex);
138128

139-
if (!sched_itmt_capable) {
140-
mutex_unlock(&itmt_update_mutex);
129+
if (!sched_itmt_capable)
141130
return;
142-
}
131+
143132
sched_itmt_capable = false;
144133

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

150137
if (sysctl_sched_itmt_enabled) {
151138
/* disable sched_itmt if we are no longer ITMT capable */
152139
sysctl_sched_itmt_enabled = 0;
153140
x86_topology_update = true;
154141
rebuild_sched_domains();
155142
}
156-
157-
mutex_unlock(&itmt_update_mutex);
158143
}
159144

160145
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
@@ -482,27 +482,13 @@ static int x86_core_flags(void)
482482
return cpu_core_flags() | x86_sched_itmt_flags();
483483
}
484484
#endif
485-
#ifdef CONFIG_SCHED_SMT
486-
static int x86_smt_flags(void)
487-
{
488-
return cpu_smt_flags();
489-
}
490-
#endif
491485
#ifdef CONFIG_SCHED_CLUSTER
492486
static int x86_cluster_flags(void)
493487
{
494488
return cpu_cluster_flags() | x86_sched_itmt_flags();
495489
}
496490
#endif
497491

498-
static int x86_die_flags(void)
499-
{
500-
if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
501-
return x86_sched_itmt_flags();
502-
503-
return 0;
504-
}
505-
506492
/*
507493
* Set if a package/die has multiple NUMA nodes inside.
508494
* AMD Magny-Cours, Intel Cluster-on-Die, and Intel
@@ -518,7 +504,7 @@ static void __init build_sched_topology(void)
518504

519505
#ifdef CONFIG_SCHED_SMT
520506
x86_topology[i++] = (struct sched_domain_topology_level){
521-
cpu_smt_mask, x86_smt_flags, SD_INIT_NAME(SMT)
507+
cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT)
522508
};
523509
#endif
524510
#ifdef CONFIG_SCHED_CLUSTER
@@ -538,7 +524,7 @@ static void __init build_sched_topology(void)
538524
*/
539525
if (!x86_has_numa_in_package) {
540526
x86_topology[i++] = (struct sched_domain_topology_level){
541-
cpu_cpu_mask, x86_die_flags, SD_INIT_NAME(PKG)
527+
cpu_cpu_mask, x86_sched_itmt_flags, SD_INIT_NAME(PKG)
542528
};
543529
}
544530

0 commit comments

Comments
 (0)