On 2/14/20 8:47 AM, Jens Axboe wrote: >> I suspect you meant to put that in finish_task_switch() which is the >> tail end of every schedule(), schedule_tail() is the tail end of >> clone(). >> >> Or maybe you meant to put it in (and rename) sched_update_worker() which >> is after every schedule() but in a preemptible context -- much saner >> since you don't want to go add an unbounded amount of work in a >> non-preemptible context. >> >> At which point you already have your callback: io_wq_worker_running(), >> or is this for any random task? > > Let me try and clarify - this isn't for the worker tasks, this is for > any task that is using io_uring. In fact, it's particularly not for the > worker threads, just the task itself. > > I basically want the handler to be called when: > > 1) The task is scheduled in. The poll will complete and stuff some items > on that task list, and I want to task to process them as it wakes up. > > 2) The task is going to sleep, don't want to leave entries around while > the task is sleeping. > > 3) I need it to be called from "normal" context, with ints enabled, > preempt enabled, etc. > > sched_update_worker() (with a rename) looks ideal for #1, and the > context is sane for me. Just need a good spot to put the hook call for > schedule out. I think this: > > if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER)) { > preempt_disable(); > if (tsk->flags & PF_WQ_WORKER) > wq_worker_sleeping(tsk); > else > io_wq_worker_sleeping(tsk); > preempt_enable_no_resched(); > } > > just needs to go into another helper, and then I can call it there > outside of the preempt. > > I'm sure there are daemons lurking here, but I'll test and see how it > goes... Here's a stab at cleaning it up: https://git.kernel.dk/cgit/linux-block/log/?h=io_uring-task-poll top two patches. First one simply cleans up the sched_update_worker(), so we now have sched_in_update() and sched_out_update(). No changes in this patch, just moves the worker sched-out handling into a helper. 2nd patch then utilizes this to flush the per-task requests that may have been queued up. -- Jens Axboe