Skip to content

Commit 46cfe1f

Browse files
hbathinik-hagio
authored andcommitted
task.c: avoid unnecessary cpu cycles in stkptr_to_task()
While stkptr_to_task does the job of trying to match a stack pointer to a task, it runs through each task's stack to find whether the given SP falls into its range. This can be a very expensive operation, if the vmcore is from a system running too many tasks. It can get even worse when the total number of CPUs on the system is in the order of thousands. Given the expensive nature of the operation, it must be optimized as much as possible. Possible options to optimize: 1) Get min & max of the stack range in first pass and use these values against the given SP to decide whether or not to proceed with stack lookup. 2) Use multithreading to parallely update irq_tasks. 3) Skip stkptr_to_task() when SP is 0 Though option 3 is a low hanging fruit, it significantly improved the time taken between starting crash utility & reaching crash prompt. Implement option 3 to optimize while listing the other two options as TODO items for follow-up. Signed-off-by: Hari Bathini <[email protected]>
1 parent ea46a88 commit 46cfe1f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

task.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ irqstacks_init(void)
713713
} else
714714
error(WARNING, "cannot determine hardirq_ctx addresses\n");
715715

716+
/* TODO: Use multithreading to parallely update irq_tasks. */
716717
for (i = 0; i < NR_CPUS; i++) {
717718
if (!(tt->hardirq_ctx[i]))
718719
continue;
@@ -5005,6 +5006,10 @@ pid_exists(ulong pid)
50055006
/*
50065007
* Translate a stack pointer to a task, dealing with possible split.
50075008
* If that doesn't work, check the hardirq_stack and softirq_stack.
5009+
*
5010+
* TODO: This function can be optimized by getting min & max of the
5011+
* stack range in first pass and use these values against the
5012+
* given SP to decide whether or not to proceed with stack lookup.
50085013
*/
50095014
ulong
50105015
stkptr_to_task(ulong sp)
@@ -5013,6 +5018,9 @@ stkptr_to_task(ulong sp)
50135018
struct task_context *tc;
50145019
struct bt_info bt_info, *bt;
50155020

5021+
if (!sp)
5022+
return NO_TASK;
5023+
50165024
bt = &bt_info;
50175025
tc = FIRST_CONTEXT();
50185026
for (i = 0; i < RUNNING_TASKS(); i++, tc++) {

0 commit comments

Comments
 (0)