Skip to content

Commit fbe76a6

Browse files
soleenakpm00
authored andcommitted
task_stack: uninline stack_not_used
Given that stack_not_used() is not performance critical function uninline it. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pasha Tatashin <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Domenico Cerasuolo <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Li Zhijian <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Nhat Pham <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c4a6fce commit fbe76a6

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

include/linux/sched/task_stack.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,11 @@ static inline int object_is_on_stack(const void *obj)
9595
extern void thread_stack_cache_init(void);
9696

9797
#ifdef CONFIG_DEBUG_STACK_USAGE
98+
unsigned long stack_not_used(struct task_struct *p);
99+
#else
98100
static inline unsigned long stack_not_used(struct task_struct *p)
99101
{
100-
unsigned long *n = end_of_stack(p);
101-
102-
do { /* Skip over canary */
103-
# ifdef CONFIG_STACK_GROWSUP
104-
n--;
105-
# else
106-
n++;
107-
# endif
108-
} while (!*n);
109-
110-
# ifdef CONFIG_STACK_GROWSUP
111-
return (unsigned long)end_of_stack(p) - (unsigned long)n;
112-
# else
113-
return (unsigned long)n - (unsigned long)end_of_stack(p);
114-
# endif
102+
return 0;
115103
}
116104
#endif
117105
extern void set_task_stack_end_magic(struct task_struct *tsk);

kernel/exit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,25 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
778778
}
779779

780780
#ifdef CONFIG_DEBUG_STACK_USAGE
781+
unsigned long stack_not_used(struct task_struct *p)
782+
{
783+
unsigned long *n = end_of_stack(p);
784+
785+
do { /* Skip over canary */
786+
# ifdef CONFIG_STACK_GROWSUP
787+
n--;
788+
# else
789+
n++;
790+
# endif
791+
} while (!*n);
792+
793+
# ifdef CONFIG_STACK_GROWSUP
794+
return (unsigned long)end_of_stack(p) - (unsigned long)n;
795+
# else
796+
return (unsigned long)n - (unsigned long)end_of_stack(p);
797+
# endif
798+
}
799+
781800
/* Count the maximum pages reached in kernel stacks */
782801
static inline void kstack_histogram(unsigned long used_stack)
783802
{

kernel/sched/core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7405,7 +7405,7 @@ EXPORT_SYMBOL(io_schedule);
74057405

74067406
void sched_show_task(struct task_struct *p)
74077407
{
7408-
unsigned long free = 0;
7408+
unsigned long free;
74097409
int ppid;
74107410

74117411
if (!try_get_task_stack(p))
@@ -7415,9 +7415,7 @@ void sched_show_task(struct task_struct *p)
74157415

74167416
if (task_is_running(p))
74177417
pr_cont(" running task ");
7418-
#ifdef CONFIG_DEBUG_STACK_USAGE
74197418
free = stack_not_used(p);
7420-
#endif
74217419
ppid = 0;
74227420
rcu_read_lock();
74237421
if (pid_alive(p))

0 commit comments

Comments
 (0)