From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by sourceware.org (Postfix) with ESMTPS id 60FCC3848023 for ; Thu, 20 May 2021 10:42:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 60FCC3848023 Received: by mail-vs1-xe2f.google.com with SMTP id u188so8287423vsu.8 for ; Thu, 20 May 2021 03:42:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Vp9LbR1CObqMrIY+VFsF1LVvjwJ+Nm1vgN/OOA7WPVg=; b=IMHhKb/yjLN2oypAZV0cPx3fxRKg5zZG10+9jhTjbS2nRlBwwWsb3iIdg3vell+vOR aq2WmLHO1j4MMkscr8XDhxOl9ciM5esN6K2gw2GeNPhN1iKluk/N77cWvcJRvvgpswnd /ubua0/obh8V3Icw/Upxqg+01M8gLkLTlcD5rdYDrljlZyyLrM0se9P0H7Cxpi6oxpUR twY8c/Zym38YUoKt6h2I1vLCVRDjL7ny18pQ9/Ml0rbZKEssherVf5jAxzVIIL3XWPGF 6EzXhSJPK/IHBM39UpISMNUvi8ykpbbl4NoGc5voz5LiRu5v2NsPKmWz/ANZiYeOPp8H RdTg== X-Gm-Message-State: AOAM533cbb2ju8whZbIreBmH3iEcI2q6dggOX5pRkbt11yAHpQa6TYRi jlip8LrIbZ3MEom3RbqADhK5HN52MPFip/TdkvJlVSyjJeg= X-Google-Smtp-Source: ABdhPJw0hOFgsgjdY7gHtKGIV+15b8BU90eCFzehvtkL0hYuf2RiaiSiFg9eoq1fi5dKqrOaPoBtHv23YhXnxejLsuc= X-Received: by 2002:a05:6102:b0e:: with SMTP id b14mr2917223vst.30.1621507356761; Thu, 20 May 2021 03:42:36 -0700 (PDT) MIME-Version: 1.0 From: Alexandre Bique Date: Thu, 20 May 2021 12:42:20 +0200 Message-ID: Subject: Yield to specific thread? To: libc-help@sourceware.org X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 10:42:38 -0000 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