Why kernel code/thread executing in interrupt context cannot sleep?

前端 未结 11 1754
余生分开走
余生分开走 2020-11-30 17:20

I am reading following article by Robert Love

http://www.linuxjournal.com/article/6916

that says

\"...Let\'s discuss the fact that work queues run i

11条回答
  •  执念已碎
    2020-11-30 18:01

    By nature, the question is whether in interrupt handler you can get a valid "current" (address to the current process task_structure), if yes, it's possible to modify the content there accordingly to make it into "sleep" state, which can be back by scheduler later if the state get changed somehow. The answer may be hardware-dependent.

    But in ARM, it's impossible since 'current' is irrelevant to process under interrupt mode. See the code below:

    #linux/arch/arm/include/asm/thread_info.h 
    94 static inline struct thread_info *current_thread_info(void)
    95 {
    96  register unsigned long sp asm ("sp");
    97  return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
    98 }
    

    sp in USER mode and SVC mode are the "same" ("same" here not mean they're equal, instead, user mode's sp point to user space stack, while svc mode's sp r13_svc point to the kernel stack, where the user process's task_structure was updated at previous task switch, When a system call occurs, the process enter kernel space again, when the sp (sp_svc) is still not changed, these 2 sp are associated with each other, in this sense, they're 'same'), So under SVC mode, kernel code can get the valid 'current'. But under other privileged modes, say interrupt mode, sp is 'different', point to dedicated address defined in cpu_init(). The 'current' calculated under these mode will be irrelevant to the interrupted process, accessing it will result in unexpected behaviors. That's why it's always said that system call can sleep but interrupt handler can't, system call works on process context but interrupt not.

提交回复
热议问题