linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] lib, stackdepot: Add helper to print stack entries into buffer.
@ 2021-09-10 14:10 Imran Khan
  2021-09-10 14:10 ` [PATCH 1/1] " Imran Khan
  2021-09-14  9:03 ` [PATCH 0/1] " Vlastimil Babka
  0 siblings, 2 replies; 7+ messages in thread
From: Imran Khan @ 2021-09-10 14:10 UTC (permalink / raw)
  To: vbabka, geert, akpm, ryabinin.a.a, glider, andreyknvl, dvyukov,
	maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm

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/e6f6fb85-1d83-425b-9e36-b5784cc9e69a@suse.cz/
[2] https://lore.kernel.org/lkml/fe94ffd8-d235-87d8-9c3d-80f7f73e0c4e@suse.cz/
[3] https://lore.kernel.org/lkml/85f4f073-0b5a-9052-0ba9-74d450608656@suse.cz/

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                        | 23 +++++++++++++++++++++++
 mm/page_owner.c                         |  5 +----
 7 files changed, 35 insertions(+), 31 deletions(-)

-- 
2.30.2


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

* [PATCH 1/1] lib, stackdepot: Add helper to print stack entries into buffer.
  2021-09-10 14:10 [PATCH 0/1] lib, stackdepot: Add helper to print stack entries into buffer Imran Khan
@ 2021-09-10 14:10 ` Imran Khan
  2021-09-13  8:51   ` Vlastimil Babka
  2021-09-15 10:06   ` Jani Nikula
  2021-09-14  9:03 ` [PATCH 0/1] " Vlastimil Babka
  1 sibling, 2 replies; 7+ messages in thread
From: Imran Khan @ 2021-09-10 14:10 UTC (permalink / raw)
  To: vbabka, geert, akpm, ryabinin.a.a, glider, andreyknvl, dvyukov,
	maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm

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.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
---
 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                        | 23 +++++++++++++++++++++++
 mm/page_owner.c                         |  5 +----
 7 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
index 86d13d6bc463..2d1adab9e360 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -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,
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 93d48a6f04ab..ca04d7f6f7b5 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -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);
 	}
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 4b7fc4647e46..f2d9ed375109 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -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);
 }
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index eaf7688f517d..cc312f0a05eb 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -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);
 	}
 
diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
index d77a30543dd4..88b0b4cc9906 100644
--- a/include/linux/stackdepot.h
+++ b/include/linux/stackdepot.h
@@ -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);
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index 873aeb152f52..e1c1d7683f6b 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -214,6 +214,29 @@ 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 stack_trace_snprint(buf, size, entries, nr_entries, 0);
+}
+
 /**
  * stack_depot_print - print stack entries from a depot
  *
diff --git a/mm/page_owner.c b/mm/page_owner.c
index 7918770c2b2b..a83f546c06b5 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -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;
 
-- 
2.30.2


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

* Re: [PATCH 1/1] lib, stackdepot: Add helper to print stack entries into buffer.
  2021-09-10 14:10 ` [PATCH 1/1] " Imran Khan
@ 2021-09-13  8:51   ` Vlastimil Babka
  2021-09-14  4:26     ` imran.f.khan
  2021-09-15 10:06   ` Jani Nikula
  1 sibling, 1 reply; 7+ messages in thread
From: Vlastimil Babka @ 2021-09-13  8:51 UTC (permalink / raw)
  To: Imran Khan, geert, akpm, ryabinin.a.a, glider, andreyknvl,
	dvyukov, maarten.lankhorst, mripard, tzimmermann, airlied,
	daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm

On 9/10/21 16:10, Imran Khan wrote:
> 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.
> 
> Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

A comment below:

> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -214,6 +214,29 @@ 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 stack_trace_snprint(buf, size, entries, nr_entries, 0);

stack_trace_snprint() has a WARN_ON(!entries).
So maybe we should not call it if nr_entries is 0 (because e.g. handle was
0) as the warnings are not useful in that case.

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

* Re: [PATCH 1/1] lib, stackdepot: Add helper to print stack entries into buffer.
  2021-09-13  8:51   ` Vlastimil Babka
@ 2021-09-14  4:26     ` imran.f.khan
  0 siblings, 0 replies; 7+ messages in thread
From: imran.f.khan @ 2021-09-14  4:26 UTC (permalink / raw)
  To: Vlastimil Babka, geert, akpm, ryabinin.a.a, glider, andreyknvl,
	dvyukov, maarten.lankhorst, mripard, tzimmermann, airlied,
	daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm



On 13/9/21 6:51 pm, Vlastimil Babka wrote:
> On 9/10/21 16:10, Imran Khan wrote:
>> 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.
>>
>> Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
>> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> 
Thanks for the review.

A comment below:
> 
>> --- a/lib/stackdepot.c
>> +++ b/lib/stackdepot.c
>> @@ -214,6 +214,29 @@ static inline struct stack_record *find_stack(struct stack_record *bucket,
>>   	return NULL;
>>   }

[...]

>> + */
>> +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 stack_trace_snprint(buf, size, entries, nr_entries, 0);
> 
> stack_trace_snprint() has a WARN_ON(!entries).
> So maybe we should not call it if nr_entries is 0 (because e.g. handle was
> 0) as the warnings are not useful in that case.
> 
Agree. I have addressed this feedback in v2 of patch.


Thanks
-- Imran

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

* Re: [PATCH 0/1] lib, stackdepot: Add helper to print stack entries into buffer.
  2021-09-10 14:10 [PATCH 0/1] lib, stackdepot: Add helper to print stack entries into buffer Imran Khan
  2021-09-10 14:10 ` [PATCH 1/1] " Imran Khan
@ 2021-09-14  9:03 ` Vlastimil Babka
  2021-09-15  3:33   ` imran.f.khan
  1 sibling, 1 reply; 7+ messages in thread
From: Vlastimil Babka @ 2021-09-14  9:03 UTC (permalink / raw)
  To: Imran Khan, geert, akpm, ryabinin.a.a, glider, andreyknvl,
	dvyukov, maarten.lankhorst, mripard, tzimmermann, airlied,
	daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm

On 9/10/21 16:10, Imran Khan wrote:
> 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.

I think you sent those at the beginning of merge window, so it would be best
to gather everything in a self-contained series now and resend. I suggested
another change for one of those anyway.

You can of course resend including the Acks you already got, as you did
already with "[PATCH v2 1/1] lib, stackdepot: Add helper to print stack
entries into buffer."

> [1] https://lore.kernel.org/lkml/e6f6fb85-1d83-425b-9e36-b5784cc9e69a@suse.cz/
> [2] https://lore.kernel.org/lkml/fe94ffd8-d235-87d8-9c3d-80f7f73e0c4e@suse.cz/
> [3] https://lore.kernel.org/lkml/85f4f073-0b5a-9052-0ba9-74d450608656@suse.cz/
> 
> 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                        | 23 +++++++++++++++++++++++
>  mm/page_owner.c                         |  5 +----
>  7 files changed, 35 insertions(+), 31 deletions(-)
> 


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

* Re: [PATCH 0/1] lib, stackdepot: Add helper to print stack entries into buffer.
  2021-09-14  9:03 ` [PATCH 0/1] " Vlastimil Babka
@ 2021-09-15  3:33   ` imran.f.khan
  0 siblings, 0 replies; 7+ messages in thread
From: imran.f.khan @ 2021-09-15  3:33 UTC (permalink / raw)
  To: Vlastimil Babka, geert, akpm, ryabinin.a.a, glider, andreyknvl,
	dvyukov, maarten.lankhorst, mripard, tzimmermann, airlied,
	daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm

Hi Vlastimil,

On 14/9/21 7:03 pm, Vlastimil Babka wrote:
> On 9/10/21 16:10, Imran Khan wrote:
>> 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.
> 
> I think you sent those at the beginning of merge window, so it would be best
> to gather everything in a self-contained series now and resend. I suggested
> another change for one of those anyway.
> 
> You can of course resend including the Acks you already got, as you did
> already with "[PATCH v2 1/1] lib, stackdepot: Add helper to print stack
> entries into buffer."
> 

Thanks for clarifying this. I have resend consolidated patch as per your 
suggestion. This self-contained change set can be seen at [1].

[1] 
https://lore.kernel.org/lkml/20210915014806.3206938-1-imran.f.khan@oracle.com/

>> [1] https://urldefense.com/v3/__https://lore.kernel.org/lkml/e6f6fb85-1d83-425b-9e36-b5784cc9e69a@suse.cz/__;!!ACWV5N9M2RV99hQ!aF3HSKJ9eit2OvdDk5j_DTKT8rL2SkG6cYL1lLVvegHz5_YTJhN7dSkHgBKeJjupkw$
>> [2] https://urldefense.com/v3/__https://lore.kernel.org/lkml/fe94ffd8-d235-87d8-9c3d-80f7f73e0c4e@suse.cz/__;!!ACWV5N9M2RV99hQ!aF3HSKJ9eit2OvdDk5j_DTKT8rL2SkG6cYL1lLVvegHz5_YTJhN7dSkHgBITooNU1w$
>> [3] https://urldefense.com/v3/__https://lore.kernel.org/lkml/85f4f073-0b5a-9052-0ba9-74d450608656@suse.cz/__;!!ACWV5N9M2RV99hQ!aF3HSKJ9eit2OvdDk5j_DTKT8rL2SkG6cYL1lLVvegHz5_YTJhN7dSkHgBJcGhmlHA$
>>
>> 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                        | 23 +++++++++++++++++++++++
>>   mm/page_owner.c                         |  5 +----
>>   7 files changed, 35 insertions(+), 31 deletions(-)
>>
> 

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

* Re: [PATCH 1/1] lib, stackdepot: Add helper to print stack entries into buffer.
  2021-09-10 14:10 ` [PATCH 1/1] " Imran Khan
  2021-09-13  8:51   ` Vlastimil Babka
@ 2021-09-15 10:06   ` Jani Nikula
  1 sibling, 0 replies; 7+ messages in thread
From: Jani Nikula @ 2021-09-15 10:06 UTC (permalink / raw)
  To: Imran Khan, vbabka, geert, akpm, ryabinin.a.a, glider,
	andreyknvl, dvyukov, maarten.lankhorst, mripard, tzimmermann,
	airlied, daniel
  Cc: dri-devel, linux-kernel, intel-gfx, linux-mm

On Sat, 11 Sep 2021, Imran Khan <imran.f.khan@oracle.com> wrote:
> 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.
>
> Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>  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 +++++---------------

For the i915 parts,

Acked-by: Jani Nikula <jani.nikula@intel.com>

for merging via whichever tree suits you best.

>  include/linux/stackdepot.h              |  3 +++
>  lib/stackdepot.c                        | 23 +++++++++++++++++++++++
>  mm/page_owner.c                         |  5 +----
>  7 files changed, 35 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
> index 86d13d6bc463..2d1adab9e360 100644
> --- a/drivers/gpu/drm/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/drm_dp_mst_topology.c
> @@ -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,
> diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
> index 93d48a6f04ab..ca04d7f6f7b5 100644
> --- a/drivers/gpu/drm/drm_mm.c
> +++ b/drivers/gpu/drm/drm_mm.c
> @@ -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);
>  	}
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index 4b7fc4647e46..f2d9ed375109 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -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);
>  }
> diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
> index eaf7688f517d..cc312f0a05eb 100644
> --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
> +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
> @@ -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);
>  	}
>  
> diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
> index d77a30543dd4..88b0b4cc9906 100644
> --- a/include/linux/stackdepot.h
> +++ b/include/linux/stackdepot.h
> @@ -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);
> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> index 873aeb152f52..e1c1d7683f6b 100644
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -214,6 +214,29 @@ 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 stack_trace_snprint(buf, size, entries, nr_entries, 0);
> +}
> +
>  /**
>   * stack_depot_print - print stack entries from a depot
>   *
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index 7918770c2b2b..a83f546c06b5 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -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;

-- 
Jani Nikula, Intel Open Source Graphics Center

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

end of thread, other threads:[~2021-09-15 10:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10 14:10 [PATCH 0/1] lib, stackdepot: Add helper to print stack entries into buffer Imran Khan
2021-09-10 14:10 ` [PATCH 1/1] " Imran Khan
2021-09-13  8:51   ` Vlastimil Babka
2021-09-14  4:26     ` imran.f.khan
2021-09-15 10:06   ` Jani Nikula
2021-09-14  9:03 ` [PATCH 0/1] " Vlastimil Babka
2021-09-15  3:33   ` imran.f.khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).