History

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. [imran.f.khan@oracle.com: fix build error] Link: https://lkml.kernel.org/r/20210915175321.3472770-4-imran.f.khan@oracle.com [imran.f.khan@oracle.com: export stack_depot_snprint() to modules] Link: https://lkml.kernel.org/r/20210916133535.3592491-4-imran.f.khan@oracle.com

Imran Khan committed 5 years ago

Commit 0f68d451 parent 505be487 files · +37 −31Browse files

Unified · Split

7 files
  1. drivers/gpu/drm/drm_dp_mst_topology.c +1 −4
  2. drivers/gpu/drm/drm_mm.c +1 −4
  3. drivers/gpu/drm/i915/i915_vma.c +1 −4
  4. drivers/gpu/drm/i915/intel_runtime_pm.c +5 −15
  5. include/linux/stackdepot.h +3 −0
  6. lib/stackdepot.c +25 −0
  7. mm/page_owner.c +1 −4
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, · 1667 unmodified lines
16681668 for (i = 0; i < history->len; i++) {
16691669 const struct drm_dp_mst_topology_ref_entry *entry =
16701670 &history->entries[i];
1671− ulong *entries;
1672− uint nr_entries;
16731671 u64 ts_nsec = entry->ts_nsec;
16741672 u32 rem_nsec = do_div(ts_nsec, 1000000000);
16751673
1676− nr_entries = stack_depot_fetch(entry->backtrace, &entries);
1677− stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
1674+ stack_depot_snprint(entry->backtrace, buf, PAGE_SIZE, 4);
16781675
16791676 drm_printf(&p, " %d %ss (last at %5llu.%06u):\n%s",
16801677 entry->count,
drivers/gpu/drm/drm_mm.c+1−4
@@ -118,8 +118,6 @@ static noinline void save_stack(struct drm_mm_node *node) · 117 unmodified lines
118118 static void show_leaks(struct drm_mm *mm)
119119 {
120120 struct drm_mm_node *node;
121− unsigned long *entries;
122− unsigned int nr_entries;
123121 char *buf;
124122
125123 buf = kmalloc(BUFSZ, GFP_KERNEL);
@@ -133,8 +131,7 @@ static void show_leaks(struct drm_mm *mm) · 7 unmodified lines
133131 continue;
134132 }
135133
136− nr_entries = stack_depot_fetch(node->stack, &entries);
137− stack_trace_snprint(buf, BUFSZ, entries, nr_entries, 0);
134+ stack_depot_snprint(node->stack, buf, BUFSZ, 0);
138135 DRM_ERROR("node [%08llx + %08llx]: inserted at\n%s",
139136 node->start, node->size, buf);
140137 }
drivers/gpu/drm/i915/i915_vma.c+1−4
@@ -56,8 +56,6 @@ void i915_vma_free(struct i915_vma *vma) · 55 unmodified lines
5656
5757 static void vma_print_allocator(struct i915_vma *vma, const char *reason)
5858 {
59− unsigned long *entries;
60− unsigned int nr_entries;
6159 char buf[512];
6260
6361 if (!vma->node.stack) {
@@ -66,8 +64,7 @@ static void vma_print_allocator(struct i915_vma *vma, const char *reason) · 2 unmodified lines
6664 return;
6765 }
6866
69− nr_entries = stack_depot_fetch(vma->node.stack, &entries);
70− stack_trace_snprint(buf, sizeof(buf), entries, nr_entries, 0);
67+ stack_depot_snprint(vma->node.stack, buf, sizeof(buf), 0);
7168 DRM_DEBUG_DRIVER("vma.node [%08llx + %08llx] %s: inserted at %s\n",
7269 vma->node.start, vma->node.size, reason, buf);
7370 }
drivers/gpu/drm/i915/intel_runtime_pm.c+5−15
@@ -65,16 +65,6 @@ static noinline depot_stack_handle_t __save_depot_stack(void) · 64 unmodified lines
6565 return stack_depot_save(entries, n, GFP_NOWAIT | __GFP_NOWARN);
6666 }
6767
68−static void __print_depot_stack(depot_stack_handle_t stack,
69− char *buf, int sz, int indent)
70−{
71− unsigned long *entries;
72− unsigned int nr_entries;
73−
74− nr_entries = stack_depot_fetch(stack, &entries);
75− stack_trace_snprint(buf, sz, entries, nr_entries, indent);
76−}
77−
7868 static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm)
7969 {
8070 spin_lock_init(&rpm->debug.lock);
@@ -146,12 +136,12 @@ static void untrack_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm, · 65 unmodified lines
146136 if (!buf)
147137 return;
148138
149− __print_depot_stack(stack, buf, PAGE_SIZE, 2);
139+ stack_depot_snprint(stack, buf, PAGE_SIZE, 2);
150140 DRM_DEBUG_DRIVER("wakeref %x from\n%s", stack, buf);
151141
152142 stack = READ_ONCE(rpm->debug.last_release);
153143 if (stack) {
154− __print_depot_stack(stack, buf, PAGE_SIZE, 2);
144+ stack_depot_snprint(stack, buf, PAGE_SIZE, 2);
155145 DRM_DEBUG_DRIVER("wakeref last released at\n%s", buf);
156146 }
157147
@@ -183,12 +173,12 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p, · 25 unmodified lines
183173 return;
184174
185175 if (dbg->last_acquire) {
186− __print_depot_stack(dbg->last_acquire, buf, PAGE_SIZE, 2);
176+ stack_depot_snprint(dbg->last_acquire, buf, PAGE_SIZE, 2);
187177 drm_printf(p, "Wakeref last acquired:\n%s", buf);
188178 }
189179
190180 if (dbg->last_release) {
191− __print_depot_stack(dbg->last_release, buf, PAGE_SIZE, 2);
181+ stack_depot_snprint(dbg->last_release, buf, PAGE_SIZE, 2);
192182 drm_printf(p, "Wakeref last released:\n%s", buf);
193183 }
194184
@@ -203,7 +193,7 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p, · 8 unmodified lines
203193 rep = 1;
204194 while (i + 1 < dbg->count && dbg->owners[i + 1] == stack)
205195 rep++, i++;
206− __print_depot_stack(stack, buf, PAGE_SIZE, 2);
196+ stack_depot_snprint(stack, buf, PAGE_SIZE, 2);
207197 drm_printf(p, "Wakeref x%lu taken at:\n%s", rep, buf);
208198 }
209199
include/linux/stackdepot.h+3−0
@@ -25,6 +25,9 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, · 24 unmodified lines
2525 unsigned int stack_depot_fetch(depot_stack_handle_t handle,
2626 unsigned long **entries);
2727
28+int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
29+ int spaces);
30+
2831 void stack_depot_print(depot_stack_handle_t stack);
2932
3033 #ifdef CONFIG_STACKDEPOT
lib/stackdepot.c+25−0
@@ -213,6 +213,31 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, · 212 unmodified lines
213213 return NULL;
214214 }
215215
216+/**
217+ * stack_depot_snprint - print stack entries from a depot into a buffer
218+ *
219+ * @handle: Stack depot handle which was returned from
220+ * stack_depot_save().
221+ * @buf: Pointer to the print buffer
222+ *
223+ * @size: Size of the print buffer
224+ *
225+ * @spaces: Number of leading spaces to print
226+ *
227+ * Return: Number of bytes printed.
228+ */
229+int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
230+ int spaces)
231+{
232+ unsigned long *entries;
233+ unsigned int nr_entries;
234+
235+ nr_entries = stack_depot_fetch(handle, &entries);
236+ return nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries,
237+ spaces) : 0;
238+}
239+EXPORT_SYMBOL_GPL(stack_depot_snprint);
240+
216241 /**
217242 * stack_depot_print - print stack entries from a depot
218243 *
mm/page_owner.c+1−4
@@ -329,8 +329,6 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, · 328 unmodified lines
329329 depot_stack_handle_t handle)
330330 {
331331 int ret, pageblock_mt, page_mt;
332− unsigned long *entries;
333− unsigned int nr_entries;
334332 char *kbuf;
335333
336334 count = min_t(size_t, count, PAGE_SIZE);
@@ -361,8 +359,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, · 24 unmodified lines
361359 if (ret >= count)
362360 goto err;
363361
364− nr_entries = stack_depot_fetch(handle, &entries);
365− ret += stack_trace_snprint(kbuf + ret, count - ret, entries, nr_entries, 0);
362+ ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0);
366363 if (ret >= count)
367364 goto err;
368365

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t