Skip to content

Commit fc1055d

Browse files
kudureranganathPeter Zijlstra
authored andcommitted
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]
1 parent 2f6f726 commit fc1055d

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(const 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(const struct ctl_table *table, int write,
5957
rebuild_sched_domains();
6058
}
6159

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

@@ -97,18 +93,14 @@ static struct ctl_table_header *itmt_sysctl_header;
9793
*/
9894
int sched_set_itmt_support(void)
9995
{
100-
mutex_lock(&itmt_update_mutex);
96+
guard(mutex)(&itmt_update_mutex);
10197

102-
if (sched_itmt_capable) {
103-
mutex_unlock(&itmt_update_mutex);
98+
if (sched_itmt_capable)
10499
return 0;
105-
}
106100

107101
itmt_sysctl_header = register_sysctl("kernel", itmt_kern_table);
108-
if (!itmt_sysctl_header) {
109-
mutex_unlock(&itmt_update_mutex);
102+
if (!itmt_sysctl_header)
110103
return -ENOMEM;
111-
}
112104

113105
sched_itmt_capable = true;
114106

@@ -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,12 +124,11 @@ 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

145134
if (itmt_sysctl_header) {
@@ -153,8 +142,6 @@ void sched_clear_itmt_support(void)
153142
x86_topology_update = true;
154143
rebuild_sched_domains();
155144
}
156-
157-
mutex_unlock(&itmt_update_mutex);
158145
}
159146

160147
int arch_asym_cpu_priority(int cpu)

0 commit comments

Comments
 (0)