All of lore.kernel.org
 help / color / mirror / Atom feed
* wait queues
@ 2015-04-20  1:23 Ruben Safir
  2015-04-20  1:48 ` Ruben Safir
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Ruben Safir @ 2015-04-20  1:23 UTC (permalink / raw)
  To: kernelnewbies

I'm not pouring over Love's book in detail and the section in Chapter 4
on the wit queue is implemented  in the text completely surprised me.

He is recommending that you have to right your own wait queue entry
routine for every process?  Isn't that reckless?

He is suggesting

DEFINE_WAIT(wait) //what IS wait

add_wait_queue(q, &wait); // in the current kernel this invovled
                         //  flag   checking and a linked list

while(!condition){ /* an event we are weighting for
  prepare_to_wait(&q, &wait, TASK_INTERRUPTIBLE);
  if(signal_pending(current))
        /* SIGNAl HANDLE */
  schedule();
}

finish_wait(&q, &wait);

He also write how this proceeds to function and one part confuses me

5.  When the taks awakens, it again checks whether the condition is
true.  If it is, it exists the loop.  Otherwise it again calls schedule.


This is not the order that it seems to follow according to the code.

To me it looks like it should
1 - creat2 the wait queue
2 - adds &wait onto queue q
3 checks if condition is true, if so, if not, enter a while loop
4 prepare_to_wait which changes the status of our &wait to
TASK_INTERUPPABLE
5 check for signals ... notice the process is still moving.  Does it
stop and wait now?
6  schedule itself on the runtime rbtree... which make NO sense unless
there was a stopage I didn't know about.
7 check the condition again and repeat while look
	7a. if the loop ends fishish_waiting... take it off the queue.



Isn't this reckless to leave this to users to write the code.  Your
begging for a race condition.

Ruben

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 16+ messages in thread
* wait queues
@ 2015-04-19 10:20 Ruben Safir
  0 siblings, 0 replies; 16+ messages in thread
From: Ruben Safir @ 2015-04-19 10:20 UTC (permalink / raw)
  To: kernelnewbies

I'm not pouring over Love's book in detail and the section in Chapter 4
on the wit queue is implemented  in the text completely surprised me.

He is recommending that you have to right your own wait queue entry
routine for every process?  Isn't that reckless?

He is suggesting

DEFINE_WAIT(wait) //what IS wait

add_wait_queue(q, &wait); // in the current kernel this invovled
                         //  flag   checking and a linked list

while(!condition){ /* an event we are weighting for
  prepare_to_wait(&q, &wait, TASK_INTERRUPTIBLE);
  if(signal_pending(current))
        /* SIGNAl HANDLE */
  schedule();
}

finish_wait(&q, &wait);

He also write how this proceeds to function and one part confuses me

5.  When the taks awakens, it again checks whether the condition is
true.  If it is, it exists the loop.  Otherwise it again calls schedule.


This is not the order that it seems to follow according to the code.

To me it looks like it should
1 - creat2 the wait queue
2 - adds &wait onto queue q
3 checks if condition is true, if so, if not, enter a while loop
4 prepare_to_wait which changes the status of our &wait to
TASK_INTERUPPABLE
5 check for signals ... notice the process is still moving.  Does it
stop and wait now?
6  schedule itself on the runtime rbtree... which make NO sense unless
there was a stopage I didn't know about.
7 check the condition again and repeat while look
	7a. if the loop ends fishish_waiting... take it off the queue.



Isn't this reckless to leave this to users to write the code.  Your
begging for a race condition.

Ruben

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Wait Queues
@ 2012-11-07 20:54 Andres Lagar-Cavilla
  2012-11-08  3:22 ` Andres Lagar-Cavilla
  0 siblings, 1 reply; 16+ messages in thread
From: Andres Lagar-Cavilla @ 2012-11-07 20:54 UTC (permalink / raw)
  To: Tim Deegan, Keir (Xen.org), Jan Beulich, xen-devel

Hi all,
we currently have a problem in the (x86) mm layer. Callers may request the p2m to perform a translation of a gfn to an mfn. Such translation may need to wait for a third party to service it. This happens when:

- a page needs to be paged in
- a CoW breaking of a shared page fails due to lack of memory

Note that paging in may also fail due to lack of memory. In both ENOMEM cases, all the plumbing for a toolstack to be notified and take some corrective action to release some memory and retry is in place. We also have plumbing for pagers in place.

Ideally we want the internals to be self-contained, so that callers need not be concerned with any of this. A request for a p2m translation may or may not sleep, but on exit from the p2m the caller either has an mfn with a page ref, or an error code due to some other condition.

Wait queue support in (x86) Xen prevents sleeping on a wait queue if any locks are held, including RCU read-side locks (i.e. BUG_ON(!in_atomic()).

For this reason, we have not yet implemented sleeping on the p2m. Callers may get errors telling them to retry. A lot of (imho) ugly code is peppered around the hypervisor to deal with the consequences of this. More fundamentally, in some cases there is no possible elegant handling, and guests are crashed (for example, if a page table page is paged out and the hypervisor needs to translate a guest virtual address to a gfn). This limits the applicability of memory paging and sharing.

One way to solve this would be to ensure no code path liable to sleep in a wait queue is holding any locks at wait queue sleep time. I believe this is doomed. Not just because this is a herculean task. It also makes writing hypervisor code *very* difficult. Anyone trying to throw a p2m translation into a code path needs to think of all possible upstream call sequences. Not even RCU read locks are allowed.

I'd like to propose an approach that ensures that as long some properties are met, arbitrary wait queue sleep is allowed. Here are the properties:
1. Third parties servicing a wait queue sleep are indeed third parties. In other words, dom0 does not do paging.
2. Vcpus of a wait queue servicing domain may never go to sleep on a wait queue during a foreign map.
3. A guest vcpu may go to sleep on a wait queue holding any kinds of locks as long as it does not hold the p2m lock.
4. "Kick" routines in the hypervisor by which service domains effectively wake up a vcpu may only take the p2m lock to do a fix up of the p2m.
5. Wait queues can be awakened on a special domain destroy condition.

Property 1. is hopefully self-evident, and although not enforced in the code it is reasonably simple to do so.

Property 2. is also self-evident and enforced in the code today.

Property 3. simplifies reasoning about p2m translations and wait queue sleeping. Provides a clean model for reasoning about what might or might not happen. It will require us to restructure some code paths (i.e. XENMEM_add_to_physmap) that require multiple p2m translations in a single critical region to perform all translations up front.

Property 4. is already enforced in the code as is right now.

Property 5. needs adding some logic to the top of domain destruction: set a flag, wake up all vcpus in wait queues. Extra logic on the wait queue side will exit the wait if the destroy flag is set, with an error. Most if not all callers can deal right now with a p2m translation error (other than paging), and unwind and release all their locks.

I confess my understanding of RCU is not 100% there and I am not sure what will happen to force_quiescent_state. I also understand there is a impedance mismatch wrt to "saving" and "restoring" the physical CPU preempt count.

Thanks,
Andres

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Wait Queues
@ 2000-12-11 15:43 Carlo Pagano
  0 siblings, 0 replies; 16+ messages in thread
From: Carlo Pagano @ 2000-12-11 15:43 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2019 bytes --]

I am trying to modify a driver that worked great on 2.2.16 to 2.4.0-x..
 
My old code was:
 
static struct wait_queue *roundrobin_wait; 
static struct wait_queue *task_stop_wait; 
 
static struct tq_struct roundrobin_task; 
static struct timer_list timeout_timer; 
 
...
 
init_timer(&timeout_timer);              
timeout_timer.function = Timer; 
timeout_timer.data = (unsigned long)&timer_data; 
timeout_timer.expires = jiffies + 3*HZ;
 
void Timer(unsigned long ptr) 
{ 
    struct clientdata *pTimerData = (struct clientdata *) ptr;
 
if (pTimerData->one_shot_queue_task){
        // start the main round robin
        queue_task(&roundrobin_task, &tq_scheduler); 
        pTimerData->one_shot_queue_task = FALSE;
    }
 
    /* wake-up the task responsible for the Timeout callbacks round-robin */
    wake_up_interruptible(&roundrobin_wait); 
 
    /* re-schedule this Timer function */
    init_timer(&timeout_timer);              
    timeout_timer.function = Timer; 
    timeout_timer.data = (unsigned long)&timer_data; 
    timeout_timer.expires = jiffies + HZ/100; 
    add_timer(&timeout_timer); 
} 
 
void RoundRobin(void *ptr) 
{ 
    struct clientdata *data = (struct clientdata *) ptr;
 
    interruptible_sleep_on(&roundrobin_wait); 
 
    if (data->queue)    // data->queue set to NULL in Stop()
    {
        /* do whatever you want to do here ... */ 
        OSALTimeoutCallback *pCallback = data->callback; 
 
        pCallback->RoundRobinCallbacks(); 
    }
 
    /* re-register itself, if needed */ 
    roundrobin_task.routine = RoundRobin; //main_round_robin; 
    roundrobin_task.data = (void *) &roundrobin_data; 
    if (data->queue)
    { 
        queue_task(&roundrobin_task, data->queue); 
    } 
    else 
    { 
        wake_up_interruptible(&task_stop_wait); 
 
    } 
} 
 
 
 
 
 
Carlo Pagano
Software Designer
Trisignal Communications, a division of i-data Technology
(514) 832-3603
carlop@trisignal.com
 

[-- Attachment #2: Type: text/html, Size: 4462 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-04-22 16:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-20  1:23 wait queues Ruben Safir
2015-04-20  1:48 ` Ruben Safir
2015-04-20  1:54 ` Fred Chou
2015-04-20  8:57   ` Ruben Safir
2015-04-20 15:23 ` michi1 at michaelblizek.twilightparadox.com
2015-04-20 16:39   ` Ruben Safir
2015-04-21 15:05     ` michi1 at michaelblizek.twilightparadox.com
2015-04-22 11:23       ` wait queues semiphores kernel implementations Ruben Safir
2015-04-22 16:49         ` michi1 at michaelblizek.twilightparadox.com
  -- strict thread matches above, loose matches on Subject: below --
2015-04-19 10:20 wait queues Ruben Safir
2012-11-07 20:54 Wait Queues Andres Lagar-Cavilla
2012-11-08  3:22 ` Andres Lagar-Cavilla
2012-11-08  7:42   ` Keir Fraser
2012-11-08 15:39     ` Andres Lagar-Cavilla
2012-11-08 16:48       ` Keir Fraser
2000-12-11 15:43 Carlo Pagano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.