public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Yield to specific thread?
@ 2021-05-20 10:42 Alexandre Bique
  2021-05-20 11:02 ` Florian Weimer
  2021-05-20 12:27 ` Godmar Back
  0 siblings, 2 replies; 9+ messages in thread
From: Alexandre Bique @ 2021-05-20 10:42 UTC (permalink / raw)
  To: libc-help

Hi,

I'm working on a soft real-time problem, for audio processing.

We have 2 processes A and B.
A produces a request, B processes it and produces a response, A consumes it.

The whole thing is synchronous so it looks like
   result = process(request);
except that we execute the process function in another process for
isolation purposes.

Right now, we put everything into SHM, and A writes a lightweight request
into a pipe which B is blocking on using read(); and another pipe to notify
A about the result.

On the papers this approach works but in practice we are facing scheduling
issues.
I read some of the Linux kernel and if I understood correctly the kernel
does not schedule right away the threads waiting on I/O but put them in a
wake up queue, and they will be woken up by the scheduler on the next
scheduler_tick() which depends on the scheduler tick frequency. On a low
latency kernel the frequency is about 1000Hz which is not too bad, but on
most desktops it is lower than that, and it produces jitter.

I found that locking a mutex may schedule the mutex owner immediately.

Ideally I'd like to do:
A produces a request
A sched_yield_to(B)
B processes the request
B sched_yield_to(A)

In a way the execution of A and B is exclusive, we achieve it by waiting on
pipe read.
I did not find a good design to do it using mutexes and I am looking for
help.

I tried a design with two mutexes but it will race and deadlock. I can
share the sequence diagram if you want.

Thank you very much,
Alexandre Bique

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

end of thread, other threads:[~2021-05-26 14:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 10:42 Yield to specific thread? Alexandre Bique
2021-05-20 11:02 ` Florian Weimer
2021-05-20 11:09   ` Alexandre Bique
2021-05-20 11:20     ` Konstantin Kharlamov
2021-05-20 11:54       ` Alexandre Bique
2021-05-25 18:21         ` Adhemerval Zanella
2021-05-26  9:36           ` Tadeus Prastowo
2021-05-26 14:09           ` Alexandre Bique
2021-05-20 12:27 ` Godmar Back

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).