# 2025q1 Homework3 (KXO) contributed by < `devarajabc` > {%hackmd NrmQUGbRQWemgwPfhzXj6g %} ## Introduction to deferred interrupts (Softirq, Tasklets and Workqueues) ### Softirqs 1. `The bottom half of the processor` -> a common noun referring to all the different ways of organizing deferred processing of an interrupt. >An interrupt handler can do large amount of work that is impermissible as it executes in the context where interrupts are disabled. 為什麼 interrupts are disabled ? 如何做到的? 2. `spawn_ksoftirqd` -> 3. `softirq_vec` -> An array of `softirq_action` which contains an action pointer to the softirq function >The `local_irq_save` saves the state of the IF flag of the eflags register and disables interrupts on the local processor. >The `local_irq_restore` macro does the opposite thing: restores the interrupt flag and enables interrupts. >We disable interrupts here because a softirq interrupt runs in the interrupt context and that one softirq (and no others) will be run. 1. 為何要儲存 [IF flag](https://en.wikipedia.org/wiki/Interrupt_flag) ? 2. 為何要 disable interrupts ? >The `raise_softirq_irqoff` function marks the softirq as deffered by setting the bit corresponding to the given index nr in the softirq bit mask (__softirq_pending) of the local processor. softirq bit mask 是什麼呢?如何運作? >Registration of a softirq with the open_softirq function. Activation of a softirq by marking it as deferred with the raise_softirq function. After this, all marked softirqs will be triggered in the next time the Linux kernel schedules a round of executions of deferrable functions. And execution of the deferred functions that have the same type. `have the same type` 是什麼意思? type 是指 softirq_vec 的 index 嗎。 4. How softirqs run on multiple processors at a time. ### 1. `possible cpus` 是啥 2. `tasklet_trylock` 是啥?單一處理器為何需要 lock ? -> pdates state of the given tasklet 3. `WORK_STRUCT_PENDING_BIT` 是什麼? >The __queue_work function gets the work pool. Yes, the work pool not workqueue. Actually, all works are not placed in the workqueue, but to the work pool that is represented by the worker_pool structure in the Linux kernel. As you can see above, the workqueue_struct structure has the pwqs field which is list of worker_pools 1. `workqueue_struct structure` 是啥 2. `worker_pools` 跟 `workqueue_struct structure` 的關係是? 跟 `pool_workqueue` 以及 `workqueue` 的關係是? :::danger 更新以上 :::