Messages in this thread | | | From | David Howells <> | Subject | Re: [PATCH net 7/9] rxrpc: Fix I/O thread stop | Date | Fri, 16 Dec 2022 06:46:01 +0000 |
| |
Hillf Danton <hdanton@sina.com> wrote:
> > @@ -478,13 +479,14 @@ int rxrpc_io_thread(void *data) > > } > > > > set_current_state(TASK_INTERRUPTIBLE); > > + should_stop = kthread_should_stop(); > > if (!skb_queue_empty(&local->rx_queue) || > > !list_empty(&local->call_attend_q)) { > > __set_current_state(TASK_RUNNING); > > continue; > > } > > > > - if (kthread_should_stop()) > > + if (should_stop) > > break; > > schedule(); > > } > > At the second glance still fail to see the difference this change can > make.
There is a window here:
if (!skb_queue_empty(&local->rx_queue) ...) continue; ---> if (kthread_should_stop()) break;
in which an event can happen that should be attended to. For instance the AF_RXRPC socket being closed, aborting all its calls and stopping the kthread by doing the final unuse on its rxrpc_local struct - in that order. The window can be expanded by an interrupt or softirq handler running.
So once we've observed that we've been asked to stop, we need to check if there's more work to be done and, if so, do that work first.
So by doing:
should_stop = kthread_should_stop(); if (!skb_queue_empty(&local->rx_queue) ...) continue; if (should_stop) break;
we do all outstanding cleanup work before exiting the loop to stop the thread.
David
| |