Re: [PATCH v14 04/14] task_isolation: add initial support

From: Chris Metcalf
Date: Tue Aug 30 2016 - 14:52:46 EST


On 8/30/2016 1:36 PM, Chris Metcalf wrote:
See the other thread with Peter Z for the longer discussion of this.
At this point I'm leaning towards replacing the set_tsk_need_resched() with

set_current_state(TASK_INTERRUPTIBLE);
schedule();
__set_current_state(TASK_RUNNING);
I don't see how that helps. What will wake the thread up except a signal?

The answer is that the scheduler will keep bringing us back to this
point (either after running another runnable task if there is one,
or else just returning to this point immediately without doing a
context switch), and we will then go around the "prepare exit to
userspace" loop and perhaps discover that enough time has gone
by that the last dyntick interrupt has triggered and the kernel has
quiesced the dynticks. At that point we stop calling schedule()
over and over and can return normally to userspace.

Oops, you're right that if I set TASK_INTERRUPTIBLE, then if I call
schedule(), I never get control back. So I don't want to do that.

I suppose I could do a schedule_timeout() here instead and try
to figure out how long to wait for the next dyntick. But since we
don't expect anything else running on the core anyway, it seems
like we are probably working too hard at this point. I don't think
it's worth it just to go into the idle task and (possibly) save some
power for a few microseconds.

The more I think about this, the more I think I am micro-optimizing
by trying to poke the scheduler prior to some external thing setting
need_resched, so I think the thing to do here is in fact, nothing.
I won't worry about rescheduling but will just continue going around
the prepare-exit-to-userspace loop until the last dyn tick fires.

--
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com