lib, stackdepot: Add helper to print stack entries into buffer.
Subsystems (6)
v2 cover lib, stackdepot: Add helper to print stack entries into buffer.
Changes in v2:
- Addressed review comment.
- Added Acked from Vlastimil.
- Fixed one mistake, due to which stack_trace_snprint was always getting invoked with 0 as space value.
Changed it to make use of space argument, because users that are printing stack entries into buffer, may intend to specify indentation as well.
I also observed build error reported at [4]. This is happening due to failure in cherry-picking this patch and this happens because the earlier patches (mentioned in original cover lette), are not there in the tree.
Please let me know, if it would be better if I send earlier patches with this change as well. I can resend those patches keeping the Acked-by and Reviewed-by tags, obtained in those patches.
Original cover letter
----------------------
This change is in response to discussion at [1].
The patch has been created on top of my earlier changes [2] and [3]. If needed I can resend all of these patches together, though my earlier patches have been Acked.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
Imran Khan (1):
lib, stackdepot: Add helper to print stack entries into buffer.
drivers/gpu/drm/drm_dp_mst_topology.c | 5 +---- drivers/gpu/drm/drm_mm.c | 5 +---- drivers/gpu/drm/i915/i915_vma.c | 5 +---- drivers/gpu/drm/i915/intel_runtime_pm.c | 20 +++++--------------- include/linux/stackdepot.h | 3 +++ lib/stackdepot.c | 24 ++++++++++++++++++++++++ mm/page_owner.c | 5 +---- 7 files changed, 36 insertions(+), 31 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/1 lib, stackdepot: Add helper to print stack entries into buffer.
To print stack entries into a buffer, users of stackdepot, first get a list of stack entries using stack_depot_fetch and then print this list into a buffer using stack_trace_snprint. Provide a helper in stackdepot for this purpose.
Also change above mentioned users to use this helper.
--- drivers/gpu/drm/drm_dp_mst_topology.c | 5 +---- drivers/gpu/drm/drm_mm.c | 5 +---- drivers/gpu/drm/i915/i915_vma.c | 5 +---- drivers/gpu/drm/i915/intel_runtime_pm.c | 20 +++++--------------- include/linux/stackdepot.h | 3 +++ lib/stackdepot.c | 24 ++++++++++++++++++++++++ mm/page_owner.c | 5 +---- 7 files changed, 36 insertions(+), 31 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +1 -4
@@ -1668,13 +1668,10 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,for (i =0 ; i < history->len; i++) {const struct drm_dp_mst_topology_ref_entry *entry = &history->entries[i]; -ulong *entries; -uint nr_entries;u64 ts_nsec = entry->ts_nsec;u32 rem_nsec =do_div (ts_nsec,1000000000 ); - nr_entries =stack_depot_fetch (entry->backtrace, &entries); -stack_trace_snprint (buf,PAGE_SIZE , entries, nr_entries,4 ); +stack_depot_snprint (entry->backtrace, buf,PAGE_SIZE ,4 ); drm_printf(&p, " %d %ss (last at %5llu.%06u):\n%s", entry->count,
drivers/gpu/drm/drm_mm.c +1 -4
@@ -118,8 +118,6 @@ static noinline void save_stack(struct drm_mm_node *node)static void show_leaks (struct drm_mm *mm) {struct drm_mm_node *node; -unsigned long *entries; -unsigned int nr_entries;char *buf; buf =kmalloc (BUFSZ ,GFP_KERNEL );
@@ -133,8 +131,7 @@ static void show_leaks(struct drm_mm *mm)continue ; } - nr_entries =stack_depot_fetch (node->stack, &entries); -stack_trace_snprint (buf,BUFSZ , entries, nr_entries,0 ); +stack_depot_snprint (node->stack, buf,BUFSZ );DRM_ERROR ("node [%08llx + %08llx]: inserted at\n%s" , node->start, node->size, buf); }
drivers/gpu/drm/i915/i915_vma.c +1 -4
@@ -56,8 +56,6 @@ void i915_vma_free(struct i915_vma *vma)static void vma_print_allocator (struct i915_vma *vma,const char *reason) { -unsigned long *entries; -unsigned int nr_entries;char buf[512 ];if (!vma->node.stack) {
@@ -66,8 +64,7 @@ static void vma_print_allocator(struct i915_vma *vma, const char *reason)return ; } - nr_entries =stack_depot_fetch (vma->node.stack, &entries); -stack_trace_snprint (buf,sizeof (buf), entries, nr_entries,0 ); +stack_depot_snprint (vma->node.stack, buf,sizeof (buf),0 );DRM_DEBUG_DRIVER ("vma.node [%08llx + %08llx] %s: inserted at %s\n" , vma->node.start, vma->node.size, reason, buf); }
drivers/gpu/drm/i915/intel_runtime_pm.c +5 -15
@@ -65,16 +65,6 @@ static noinline depot_stack_handle_t __save_depot_stack(void)return stack_depot_save (entries, n,GFP_NOWAIT | __GFP_NOWARN); } -static void __print_depot_stack (depot_stack_handle_t stack, -char *buf,int sz,int indent) -{ -unsigned long *entries; -unsigned int nr_entries; - - nr_entries =stack_depot_fetch (stack, &entries); -stack_trace_snprint (buf, sz, entries, nr_entries, indent); -} -static void init_intel_runtime_pm_wakeref (struct intel_runtime_pm *rpm) {spin_lock_init (&rpm->debug.lock);
@@ -146,12 +136,12 @@ static void untrack_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm,if (!buf)return ; -__print_depot_stack (stack, buf,PAGE_SIZE ,2 ); +stack_depot_snprint (stack, buf,PAGE_SIZE ,2 );DRM_DEBUG_DRIVER ("wakeref %x from\n%s" , stack, buf); stack =READ_ONCE (rpm->debug.last_release);if (stack) { -__print_depot_stack (stack, buf,PAGE_SIZE ,2 ); +stack_depot_snprint (stack, buf,PAGE_SIZE ,2 );DRM_DEBUG_DRIVER ("wakeref last released at\n%s" , buf); }
@@ -183,12 +173,12 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p,return ;if (dbg->last_acquire) { -__print_depot_stack (dbg->last_acquire, buf,PAGE_SIZE ,2 ); +stack_depot_snprint (dbg->last_acquire, buf,PAGE_SIZE ,2 );drm_printf (p,"Wakeref last acquired:\n%s" , buf); }if (dbg->last_release) { -__print_depot_stack (dbg->last_release, buf,PAGE_SIZE ,2 ); +stack_depot_snprint (dbg->last_release, buf,PAGE_SIZE ,2 );drm_printf (p,"Wakeref last released:\n%s" , buf); }
@@ -203,7 +193,7 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p, rep =1 ;while (i +1 < dbg->count && dbg->owners[i +1 ] == stack) rep++, i++; -__print_depot_stack (stack, buf,PAGE_SIZE ,2 ); +stack_depot_print (stack, buf,PAGE_SIZE ,2 );drm_printf (p,"Wakeref x%lu taken at:\n%s" , rep, buf); }
include/linux/stackdepot.h +3 -0
@@ -19,6 +19,9 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,unsigned int stack_depot_fetch (depot_stack_handle_t handle,unsigned long **entries); +int stack_depot_snprint (depot_stack_handle_t handle,char *buf,size_t size, +int spaces); +void stack_depot_print (depot_stack_handle_t stack);unsigned int filter_irq_stacks (unsigned long *entries,unsigned int nr_entries);
lib/stackdepot.c +24 -0
@@ -214,6 +214,30 @@ static inline struct stack_record *find_stack(struct stack_record *bucket,return NULL ; } +/** +* stack_depot_snprint - print stack entries from a depot into a buffer +* +* @handle: Stack depot handle which was returned from +* stack_depot_save(). +* @buf: Pointer to the print buffer +* +* @size: Size of the print buffer +* +* @spaces: Number of leading spaces to print +* +* Return: Number of bytes printed. +*/ +int stack_depot_snprint (depot_stack_handle_t handle,char *buf,size_t size, +int spaces) +{ +unsigned long *entries; +unsigned int nr_entries; + + nr_entries =stack_depot_fetch (handle, &entries); +return nr_entries ?stack_trace_snprint (buf, size, entries, nr_entries, + spaces) :0 ; +} +/** * stack_depot_print - print stack entries from a depot *
mm/page_owner.c +1 -4
@@ -329,8 +329,6 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, depot_stack_handle_t handle) {int ret, pageblock_mt, page_mt; -unsigned long *entries; -unsigned int nr_entries;char *kbuf; count =min_t (size_t, count,PAGE_SIZE );
@@ -361,8 +359,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,if (ret >= count) goto err; - nr_entries =stack_depot_fetch (handle, &entries); - ret +=stack_trace_snprint (kbuf + ret, count - ret, entries, nr_entries,0 ); + ret +=stack_depot_snprint (handle, kbuf + ret, count - ret,0 );if (ret >= count) goto err;
Signature · 1 line
2.30.2
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for lib, stackdepot: Add helper to print stack entries into buffer.
In reply to Imran Khan== Series Details ==
== Series Details ==
Series: lib, stackdepot: Add helper to print stack entries into buffer.
URL : https://patchwork.freedesktop.org/series/94655/
State : failure
== Summary ==
Applying: lib, stackdepot: Add helper to print stack entries into buffer.
error: sha1 information is lacking or useless (include/linux/stackdepot.h).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 lib, stackdepot: Add helper to print stack entries into buffer. When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".