[PATCH 08/12] unwind: Simplify unwind_user_faultable()

Peter Zijlstra posted 12 patches 4 months, 2 weeks ago
[PATCH 08/12] unwind: Simplify unwind_user_faultable()
Posted by Peter Zijlstra 4 months, 2 weeks ago

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/unwind/deferred.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

--- a/kernel/unwind/deferred.c
+++ b/kernel/unwind/deferred.c
@@ -128,17 +128,15 @@ int unwind_user_faultable(struct unwind_
 
 	cache = info->cache;
 	trace->entries = cache->entries;
-
-	if (cache->nr_entries) {
+	trace->nr = cache->nr_entries;
+	if (trace->nr) {
 		/*
 		 * The user stack has already been previously unwound in this
 		 * entry context.  Skip the unwind and use the cache.
 		 */
-		trace->nr = cache->nr_entries;
 		return 0;
 	}
 
-	trace->nr = 0;
 	unwind_user(trace, UNWIND_MAX_ENTRIES);
 
 	cache->nr_entries = trace->nr;
Re: [PATCH 08/12] unwind: Simplify unwind_user_faultable()
Posted by Steven Rostedt 4 months, 1 week ago
On Wed, 24 Sep 2025 09:59:56 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>  kernel/unwind/deferred.c |    6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> --- a/kernel/unwind/deferred.c
> +++ b/kernel/unwind/deferred.c
> @@ -128,17 +128,15 @@ int unwind_user_faultable(struct unwind_
>  
>  	cache = info->cache;
>  	trace->entries = cache->entries;
> -
> -	if (cache->nr_entries) {
> +	trace->nr = cache->nr_entries;
> +	if (trace->nr) {
>  		/*
>  		 * The user stack has already been previously unwound in this
>  		 * entry context.  Skip the unwind and use the cache.
>  		 */
> -		trace->nr = cache->nr_entries;
>  		return 0;
>  	}

Could we turn the above into:

	/*
	 * If the user stack has already been previously unwound in this
	 * entry context.  Skip the unwind and use the cache.
	 */
	if (trace->nr)
		return 0;

So we could remove the squiggly brackets?

-- Steve



>  
> -	trace->nr = 0;
>  	unwind_user(trace, UNWIND_MAX_ENTRIES);
>  
>  	cache->nr_entries = trace->nr;
>
Re: [PATCH 08/12] unwind: Simplify unwind_user_faultable()
Posted by Peter Zijlstra 3 months, 3 weeks ago
On Wed, Oct 01, 2025 at 11:40:53AM -0400, Steven Rostedt wrote:
> On Wed, 24 Sep 2025 09:59:56 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> >  kernel/unwind/deferred.c |    6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > --- a/kernel/unwind/deferred.c
> > +++ b/kernel/unwind/deferred.c
> > @@ -128,17 +128,15 @@ int unwind_user_faultable(struct unwind_
> >  
> >  	cache = info->cache;
> >  	trace->entries = cache->entries;
> > -
> > -	if (cache->nr_entries) {
> > +	trace->nr = cache->nr_entries;
> > +	if (trace->nr) {
> >  		/*
> >  		 * The user stack has already been previously unwound in this
> >  		 * entry context.  Skip the unwind and use the cache.
> >  		 */
> > -		trace->nr = cache->nr_entries;
> >  		return 0;
> >  	}
> 
> Could we turn the above into:
> 
> 	/*
> 	 * If the user stack has already been previously unwound in this
> 	 * entry context.  Skip the unwind and use the cache.
> 	 */
> 	if (trace->nr)
> 		return 0;
> 
> So we could remove the squiggly brackets?

This tarriff nonsense must be really bad if you're re-cycling them so
aggressively :-)

Sure, done.
[tip: perf/core] unwind: Simplify unwind_user_faultable()
Posted by tip-bot2 for Peter Zijlstra 3 months, 1 week ago
The following commit has been merged into the perf/core branch of tip:

Commit-ID:     42b9138f81fc22c36128f9524bb21bc9eabfb1b8
Gitweb:        https://git.kernel.org/tip/42b9138f81fc22c36128f9524bb21bc9eabfb1b8
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Mon, 22 Sep 2025 15:49:14 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 29 Oct 2025 10:29:56 +01:00

unwind: Simplify unwind_user_faultable()

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20250924080119.271671514@infradead.org
---
 kernel/unwind/deferred.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c
index 6395192..09617d8 100644
--- a/kernel/unwind/deferred.c
+++ b/kernel/unwind/deferred.c
@@ -128,17 +128,14 @@ int unwind_user_faultable(struct unwind_stacktrace *trace)
 
 	cache = info->cache;
 	trace->entries = cache->entries;
-
-	if (cache->nr_entries) {
-		/*
-		 * The user stack has already been previously unwound in this
-		 * entry context.  Skip the unwind and use the cache.
-		 */
-		trace->nr = cache->nr_entries;
+	trace->nr = cache->nr_entries;
+	/*
+	 * The user stack has already been previously unwound in this
+	 * entry context.  Skip the unwind and use the cache.
+	 */
+	if (trace->nr)
 		return 0;
-	}
 
-	trace->nr = 0;
 	unwind_user(trace, UNWIND_MAX_ENTRIES);
 
 	cache->nr_entries = trace->nr;