mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf/x86/intel: Use guard() instead of mutex_lock() to simplify code
@ 2025-09-01 13:17 Liao Yuanhong
  2025-09-02 16:20 ` Liang, Kan
  2025-09-02 16:54 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Liao Yuanhong @ 2025-09-01 13:17 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, Thomas Gleixner,
	Borislav Petkov, Dave Hansen,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:PERFORMANCE EVENTS SUBSYSTEM,
	open list:PERFORMANCE EVENTS SUBSYSTEM
  Cc: Liao Yuanhong

Using guard(mutex) instead of mutex_lock/mutex_unlock pair. Simplifies the
error handling to just return in case of error. No need for the 'done'
label anymore so remove it.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 arch/x86/events/intel/core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 28f5468a6ea3..ac88d9535e85 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -6107,18 +6107,16 @@ static ssize_t freeze_on_smi_store(struct device *cdev,
 	if (val > 1)
 		return -EINVAL;
 
-	mutex_lock(&freeze_on_smi_mutex);
+	guard(mutex)(&freeze_on_smi_mutex);
 
 	if (x86_pmu.attr_freeze_on_smi == val)
-		goto done;
+		return count;
 
 	x86_pmu.attr_freeze_on_smi = val;
 
 	cpus_read_lock();
 	on_each_cpu(flip_smm_bit, &val, 1);
 	cpus_read_unlock();
-done:
-	mutex_unlock(&freeze_on_smi_mutex);
 
 	return count;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf/x86/intel: Use guard() instead of mutex_lock() to simplify code
  2025-09-01 13:17 [PATCH] perf/x86/intel: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong
@ 2025-09-02 16:20 ` Liang, Kan
  2025-09-02 16:54 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Liang, Kan @ 2025-09-02 16:20 UTC (permalink / raw)
  To: Liao Yuanhong, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	Thomas Gleixner, Borislav Petkov, Dave Hansen,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:PERFORMANCE EVENTS SUBSYSTEM,
	open list:PERFORMANCE EVENTS SUBSYSTEM



On 2025-09-01 6:17 a.m., Liao Yuanhong wrote:
> Using guard(mutex) instead of mutex_lock/mutex_unlock pair. Simplifies the
> error handling to just return in case of error. No need for the 'done'
> label anymore so remove it.
> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>

Thanks,
Kan

> ---
>  arch/x86/events/intel/core.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 28f5468a6ea3..ac88d9535e85 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -6107,18 +6107,16 @@ static ssize_t freeze_on_smi_store(struct device *cdev,
>  	if (val > 1)
>  		return -EINVAL;
>  
> -	mutex_lock(&freeze_on_smi_mutex);
> +	guard(mutex)(&freeze_on_smi_mutex);
>  
>  	if (x86_pmu.attr_freeze_on_smi == val)
> -		goto done;
> +		return count;
>  
>  	x86_pmu.attr_freeze_on_smi = val;
>  
>  	cpus_read_lock();
>  	on_each_cpu(flip_smm_bit, &val, 1);
>  	cpus_read_unlock();
> -done:
> -	mutex_unlock(&freeze_on_smi_mutex);
>  
>  	return count;
>  }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf/x86/intel: Use guard() instead of mutex_lock() to simplify code
  2025-09-01 13:17 [PATCH] perf/x86/intel: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong
  2025-09-02 16:20 ` Liang, Kan
@ 2025-09-02 16:54 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-09-02 16:54 UTC (permalink / raw)
  To: Liao Yuanhong, linux-perf-users, x86
  Cc: LKML, Adrian Hunter, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Borislav Petkov, Dave Hansen,
	H. Peter Anvin, Ian Rogers, Ingo Molnar, Jiri Olsa, Kan Liang,
	Mark Rutland, Namhyung Kim, Peter Zijlstra, Thomas Gleixner

> Using guard(mutex) instead of mutex_lock/mutex_unlock pair. Simplifies the
…
  Use?                          Parentheses behind identifiers?


…
> +++ b/arch/x86/events/intel/core.c
> @@ -6107,18 +6107,16 @@ static ssize_t freeze_on_smi_store(struct device *cdev,
>  	cpus_read_lock();
>  	on_each_cpu(flip_smm_bit, &val, 1);
>  	cpus_read_unlock();
> -done:
> -	mutex_unlock(&freeze_on_smi_mutex);
…

How do you think about to apply another lock guard by a subsequent update step?
https://elixir.bootlin.com/linux/v6.17-rc4/source/include/linux/cpuhplock.h#L47

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-02 16:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-01 13:17 [PATCH] perf/x86/intel: Use guard() instead of mutex_lock() to simplify code Liao Yuanhong
2025-09-02 16:20 ` Liang, Kan
2025-09-02 16:54 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®