lkml.org 
[lkml]   [2014]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC] [PATCH] Pre-emption control for userspace
Date
"H. Peter Anvin" <hpa@zytor.com> writes:

> I have several issues with this interface:
>
> 1. First, a process needs to know if it *should* have been preempted
> before it calls sched_yield(). So there needs to be a second flag set
> by the scheduler when granting amnesty.
>
> 2. A process which fails to call sched_yield() after being granted
> amnesty must be penalized.
>
> 3. I'm not keen on occupying a full page for this. I'm wondering if
> doing a pointer into user space, futex-style, might make more sense.
> The downside, of course, is what happens if the page being pointed to is
> swapped out.

Is it possible to implement non-sleeping versions of {get,put}_user()?
That is, use the same basic approach (let the MMU do the hard work) but use
different, and simpler, "fixup" code (return -ESOMETHING on a major
fault).

If so, I think an extra pointer (->amnesty) and an extra bit
(->amnesty_granted) in task_struct suffices:

If the scheduler runs and tsk->amnesty_granted is true, penalize the
current task (and possibly clear tsk->amnesty_granted).

Otherwise, the task is granted amnesty provided these conditions are
met:

tsk->amnesty is non-NULL
get_user_nosleep(j, tsk->amnesty) succeeds
j is now 1
put_user_nosleep(YOU_WERE_LUCKY, tsk->amnesty) succeeds

If so, set amnesty_granted and let the thread continue; otherwise reschedule.

The userspace side would be something like

void *thread_func(void*)
{
int Im_busy = 0;
sched_need_amnesty(&Im_busy); /* better name needed */
/* -EPERM if not allowed (new capability?) */

/* go critical */
Im_busy = 1;
LOCK();
do_stuff();
UNLOCK();
if (Im_busy != 1) {
/* better play nice with the others */
sched_yield();
}
Im_busy = 0;

/* If the thread doesn't need the amnesty feature anymore, it can just do
sched_need_amnesty(NULL); */
}


Rasmus


\
 
 \ /
  Last update: 2014-03-06 15:02    [W:0.310 / U:0.340 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site