[PATCH v5 3/3] task_stack: uninline stack_not_used

Pasha Tatashin posted 3 patches 1 year, 4 months ago
There is a newer version of this series
[PATCH v5 3/3] task_stack: uninline stack_not_used
Posted by Pasha Tatashin 1 year, 4 months ago
Given that stack_not_used() is not performance critical function
uninline it.

Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 include/linux/sched/task_stack.h | 18 +++---------------
 kernel/exit.c                    | 19 +++++++++++++++++++
 kernel/sched/core.c              |  4 +---
 3 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h
index ccd72b978e1f..bf10bdb487dd 100644
--- a/include/linux/sched/task_stack.h
+++ b/include/linux/sched/task_stack.h
@@ -95,23 +95,11 @@ static inline int object_is_on_stack(const void *obj)
 extern void thread_stack_cache_init(void);
 
 #ifdef CONFIG_DEBUG_STACK_USAGE
+unsigned long stack_not_used(struct task_struct *p);
+#else
 static inline unsigned long stack_not_used(struct task_struct *p)
 {
-	unsigned long *n = end_of_stack(p);
-
-	do { 	/* Skip over canary */
-# ifdef CONFIG_STACK_GROWSUP
-		n--;
-# else
-		n++;
-# endif
-	} while (!*n);
-
-# ifdef CONFIG_STACK_GROWSUP
-	return (unsigned long)end_of_stack(p) - (unsigned long)n;
-# else
-	return (unsigned long)n - (unsigned long)end_of_stack(p);
-# endif
+	return 0;
 }
 #endif
 extern void set_task_stack_end_magic(struct task_struct *tsk);
diff --git a/kernel/exit.c b/kernel/exit.c
index 64bfc2bae55b..45085a0e7c16 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -778,6 +778,25 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 }
 
 #ifdef CONFIG_DEBUG_STACK_USAGE
+unsigned long stack_not_used(struct task_struct *p)
+{
+	unsigned long *n = end_of_stack(p);
+
+	do {	/* Skip over canary */
+# ifdef CONFIG_STACK_GROWSUP
+		n--;
+# else
+		n++;
+# endif
+	} while (!*n);
+
+# ifdef CONFIG_STACK_GROWSUP
+	return (unsigned long)end_of_stack(p) - (unsigned long)n;
+# else
+	return (unsigned long)n - (unsigned long)end_of_stack(p);
+# endif
+}
+
 /* Count the maximum pages reached in kernel stacks */
 static inline void kstack_histogram(unsigned long used_stack)
 {
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ae5ef3013a55..f5861f64e960 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7405,7 +7405,7 @@ EXPORT_SYMBOL(io_schedule);
 
 void sched_show_task(struct task_struct *p)
 {
-	unsigned long free = 0;
+	unsigned long free;
 	int ppid;
 
 	if (!try_get_task_stack(p))
@@ -7415,9 +7415,7 @@ void sched_show_task(struct task_struct *p)
 
 	if (task_is_running(p))
 		pr_cont("  running task    ");
-#ifdef CONFIG_DEBUG_STACK_USAGE
 	free = stack_not_used(p);
-#endif
 	ppid = 0;
 	rcu_read_lock();
 	if (pid_alive(p))
-- 
2.45.2.1089.g2a221341d9-goog
Re: [PATCH v5 3/3] task_stack: uninline stack_not_used
Posted by Shakeel Butt 1 year, 4 months ago
On Wed, Jul 24, 2024 at 08:33:22PM GMT, Pasha Tatashin wrote:
> Given that stack_not_used() is not performance critical function
> uninline it.
> 
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Re: [PATCH v5 3/3] task_stack: uninline stack_not_used
Posted by Pasha Tatashin 1 year, 4 months ago
> > Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
>
> Acked-by: Shakeel Butt <shakeel.butt@linux.dev>

Andrew,

You took the other two patches, but not this one. Should I drop it in
the next version?

Pasha
Re: [PATCH v5 3/3] task_stack: uninline stack_not_used
Posted by Shakeel Butt 1 year, 4 months ago
On Thu, Jul 25, 2024 at 10:30:15AM GMT, Pasha Tatashin wrote:
> > > Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> >
> > Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
> 
> Andrew,
> 
> You took the other two patches, but not this one. Should I drop it in
> the next version?
> 

Please keep it as we do want this patch. Most probably this was missed
by misttake and if you see the commit message of first patch, it says
"This patch (of 3):".