Skip to content

Commit 41253c1

Browse files
committed
x86/itmt: Use guard() for itmt_update_mutex
JIRA: https://issues.redhat.com/browse/RHEL-53784 commit fc1055d Author: K Prateek Nayak <[email protected]> Date: Mon Dec 23 04:34:01 2024 +0000 x86/itmt: Use guard() for itmt_update_mutex Use guard() for itmt_update_mutex which avoids the extra mutex_unlock() in the bailout and return paths. Signed-off-by: K Prateek Nayak <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Tim Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: David Arcari <[email protected]>
1 parent 794a865 commit 41253c1

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

arch/x86/kernel/itmt.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ static int sched_itmt_update_handler(struct ctl_table *table, int write,
4444
unsigned int old_sysctl;
4545
int ret;
4646

47-
mutex_lock(&itmt_update_mutex);
47+
guard(mutex)(&itmt_update_mutex);
4848

49-
if (!sched_itmt_capable) {
50-
mutex_unlock(&itmt_update_mutex);
49+
if (!sched_itmt_capable)
5150
return -EINVAL;
52-
}
5351

5452
old_sysctl = sysctl_sched_itmt_enabled;
5553
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
@@ -59,8 +57,6 @@ static int sched_itmt_update_handler(struct ctl_table *table, int write,
5957
rebuild_sched_domains();
6058
}
6159

62-
mutex_unlock(&itmt_update_mutex);
63-
6460
return ret;
6561
}
6662

@@ -98,18 +94,14 @@ static struct ctl_table_header *itmt_sysctl_header;
9894
*/
9995
int sched_set_itmt_support(void)
10096
{
101-
mutex_lock(&itmt_update_mutex);
97+
guard(mutex)(&itmt_update_mutex);
10298

103-
if (sched_itmt_capable) {
104-
mutex_unlock(&itmt_update_mutex);
99+
if (sched_itmt_capable)
105100
return 0;
106-
}
107101

108102
itmt_sysctl_header = register_sysctl("kernel", itmt_kern_table);
109-
if (!itmt_sysctl_header) {
110-
mutex_unlock(&itmt_update_mutex);
103+
if (!itmt_sysctl_header)
111104
return -ENOMEM;
112-
}
113105

114106
sched_itmt_capable = true;
115107

@@ -118,8 +110,6 @@ int sched_set_itmt_support(void)
118110
x86_topology_update = true;
119111
rebuild_sched_domains();
120112

121-
mutex_unlock(&itmt_update_mutex);
122-
123113
return 0;
124114
}
125115

@@ -135,12 +125,11 @@ int sched_set_itmt_support(void)
135125
*/
136126
void sched_clear_itmt_support(void)
137127
{
138-
mutex_lock(&itmt_update_mutex);
128+
guard(mutex)(&itmt_update_mutex);
139129

140-
if (!sched_itmt_capable) {
141-
mutex_unlock(&itmt_update_mutex);
130+
if (!sched_itmt_capable)
142131
return;
143-
}
132+
144133
sched_itmt_capable = false;
145134

146135
if (itmt_sysctl_header) {
@@ -154,8 +143,6 @@ void sched_clear_itmt_support(void)
154143
x86_topology_update = true;
155144
rebuild_sched_domains();
156145
}
157-
158-
mutex_unlock(&itmt_update_mutex);
159146
}
160147

161148
int arch_asym_cpu_priority(int cpu)

0 commit comments

Comments
 (0)