1 #include <lunaix/kpreempt.h>
2 #include <lunaix/process.h>
3 #include <lunaix/switch.h>
4 #include <lunaix/syslog.h>
5 #include <lunaix/trace.h>
9 #ifdef CONFIG_CHECK_STALL
11 preempt_check_stalled(struct thread* th)
13 // we can't access the hart state here
14 // as th might be in other address space
16 if (thread_flags_test(th, TH_STALLED))
18 // alrady stalled, no need to concern
22 struct thread_stats* stats;
25 if (!stats->kpreempt_count) {
33 #if defined(CONFIG_STALL_MAX_PREEMPTS) && CONFIG_STALL_MAX_PREEMPTS
34 if (stats->kpreempt_count > CONFIG_STALL_MAX_PREEMPTS) {
39 ticks_t total_elapsed;
40 total_elapsed = thread_stats_kernel_elapse(th);
42 return total_elapsed > ticks_seconds(CONFIG_STALL_TIMEOUT);
47 preempt_check_stalled(struct thread* th)
55 preempt_handle_stalled(struct signpost_result* result)
57 if (!thread_flags_test(current_thread, TH_STALLED))
59 continue_switch(result);
64 kprintf(" stalling detected (pid: %d, tid: %d)",
65 __current->pid, current_thread->tid);
66 kprintf(" (preempted: %d, elapsed: %dms)",
67 current_thread->stats.kpreempt_count,
68 thread_stats_kernel_elapse(current_thread));
69 kprintf(" are you keeping Luna too busy?");
72 kprintf("last known state:");
73 trace_dump_state(current_thread->hstate);
75 kprintf("trace from the point of stalling:");
76 trace_printstack_isr(current_thread->hstate);
78 kprintf("thread is blocked");
80 block_current_thread();
81 giveup_switch(result);