On 25.07.2025 20:55, Steven Rostedt wrote:
> From: Josh Poimboeuf <[email protected]>
> 
> Cache the results of the unwind to ensure the unwind is only performed
> once, even when called by multiple tracers.
> 
> The cache nr_entries gets cleared every time the task exits the kernel.
> When a stacktrace is requested, nr_entries gets set to the number of
> entries in the stacktrace. If another stacktrace is requested, if
> nr_entries is not zero, then it contains the same stacktrace that would be
> retrieved so it is not processed again and the entries is given to the
> caller.
> 
> Co-developed-by: Steven Rostedt (Google) <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> Signed-off-by: Steven Rostedt (Google) <[email protected]>

Reviewed-by: Jens Remus <[email protected]>

> diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c

> +     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;
> +             return 0;
> +     }
> +
>       trace->nr = 0;
> -     trace->entries = info->entries;
>       unwind_user(trace, UNWIND_MAX_ENTRIES);
>  
> +     cache->nr_entries = trace->nr;
> +

Would the following alternative to above excerpt be easier to read?

        /* Use the cache, if the user stack has already been previously
         * unwound in this entry context.  If not this will initialize
         * trace->nr to zero to trigger the unwind now.
         */
        cache = info->cache;
        trace->nr = cache->nr_entries;
        trace->entries = cache->entries;

        if (!trace->nr) {
                unwind_user(trace, UNWIND_MAX_ENTRIES);
                cache->nr_entries = trace->nr;
        }

>       return 0;
>  }

Regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
[email protected]

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: 
Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: 
Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/


Reply via email to