Skip to content

Commit

Permalink
x86/itmt: Use guard() for itmt_update_mutex
Browse files Browse the repository at this point in the history
Use guard() for itmt_update_mutex which avoids the extra mutex_unlock()
in the bailout and return paths.

Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Link: https://lore.kernel.org/r/20241223043407.1611-3-kprateek.nayak@amd.com
  • Loading branch information
K Prateek Nayak authored and Peter Zijlstra committed Jan 13, 2025
1 parent 2f6f726 commit fc1055d
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions arch/x86/kernel/itmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ static int sched_itmt_update_handler(const struct ctl_table *table, int write,
unsigned int old_sysctl;
int ret;

mutex_lock(&itmt_update_mutex);
guard(mutex)(&itmt_update_mutex);

if (!sched_itmt_capable) {
mutex_unlock(&itmt_update_mutex);
if (!sched_itmt_capable)
return -EINVAL;
}

old_sysctl = sysctl_sched_itmt_enabled;
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
Expand All @@ -59,8 +57,6 @@ static int sched_itmt_update_handler(const struct ctl_table *table, int write,
rebuild_sched_domains();
}

mutex_unlock(&itmt_update_mutex);

return ret;
}

Expand Down Expand Up @@ -97,18 +93,14 @@ static struct ctl_table_header *itmt_sysctl_header;
*/
int sched_set_itmt_support(void)
{
mutex_lock(&itmt_update_mutex);
guard(mutex)(&itmt_update_mutex);

if (sched_itmt_capable) {
mutex_unlock(&itmt_update_mutex);
if (sched_itmt_capable)
return 0;
}

itmt_sysctl_header = register_sysctl("kernel", itmt_kern_table);
if (!itmt_sysctl_header) {
mutex_unlock(&itmt_update_mutex);
if (!itmt_sysctl_header)
return -ENOMEM;
}

sched_itmt_capable = true;

Expand All @@ -117,8 +109,6 @@ int sched_set_itmt_support(void)
x86_topology_update = true;
rebuild_sched_domains();

mutex_unlock(&itmt_update_mutex);

return 0;
}

Expand All @@ -134,12 +124,11 @@ int sched_set_itmt_support(void)
*/
void sched_clear_itmt_support(void)
{
mutex_lock(&itmt_update_mutex);
guard(mutex)(&itmt_update_mutex);

if (!sched_itmt_capable) {
mutex_unlock(&itmt_update_mutex);
if (!sched_itmt_capable)
return;
}

sched_itmt_capable = false;

if (itmt_sysctl_header) {
Expand All @@ -153,8 +142,6 @@ void sched_clear_itmt_support(void)
x86_topology_update = true;
rebuild_sched_domains();
}

mutex_unlock(&itmt_update_mutex);
}

int arch_asym_cpu_priority(int cpu)
Expand Down

0 comments on commit fc1055d

Please sign in to comment.