From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 61B753851C27 for ; Thu, 20 May 2021 11:54:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 61B753851C27 Received: by mail-lj1-x232.google.com with SMTP id v5so19327689ljg.12 for ; Thu, 20 May 2021 04:54:20 -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:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=rkljBOuXQ1eiDHFhHX7FFKGvwBWxMC633lkI+/x/DeQ=; b=UThtXpFBPtmCYhWFQ0csiXp39gJX/jTeZwqHNc6j9QeY2mSe97b1v2m+X03t7imU5t 0DAUxoWSMbaQ8uVyB1PJeTK00lD3+Ug6zwVpVfVMK39HrtmOIS9XY+AuOirQtvoelu+1 /pk6c2LoQ0bN0YNM2dTNXiwCzY2T1KFrv1NDLoH70neTVvV0VQRsyccPdQQRI9yiKwlC 3efxsyoefn3+X4sluTdXtH1vz7okCfo78SIPBbiQ1VwQBYgqtBIHGa8l/+HX5VDt8gpa tLmDtChWxUE7k4JUlgogzdvWHXHp9QX0Wdx4fuzfIO5sYdonkZP6l5nY68I8zb/IrJJE eWVg== X-Gm-Message-State: AOAM531G9W0ZgzfxfwVVcfvaFESskxQwDcU1aMt47aL/oJushBP+TU2i oOtItT2XzeTR1fsuXRA6aLQAntuTsnbgWOlazvDEIXO/BVI= X-Google-Smtp-Source: ABdhPJwRPAe3CGc/bYgp1ZZiUqhWJa83k5tyferaYu+auC7smXqmzqBAUoTxiZLkSb7NQBl2/OMbnsCKsN/6sTsTJVs= X-Received: by 2002:a2e:a7c9:: with SMTP id x9mr2794841ljp.216.1621511659210; Thu, 20 May 2021 04:54:19 -0700 (PDT) MIME-Version: 1.0 References: <877djtsm5h.fsf@oldenburg.str.redhat.com> <75365b7da217aab24c686e18399bc017aa6c9ac7.camel@yandex.ru> In-Reply-To: <75365b7da217aab24c686e18399bc017aa6c9ac7.camel@yandex.ru> From: Alexandre Bique Date: Thu, 20 May 2021 13:54:02 +0200 Message-ID: Subject: Re: Yield to specific thread? To: Konstantin Kharlamov Cc: Florian Weimer , Alexandre Bique via Libc-help Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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 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 11:54:23 -0000 Oh I think I fixed it using 3 mutexes. Alexandre Bique On Thu, May 20, 2021 at 1:20 PM Konstantin Kharlamov w= rote: > > On Thu, 2021-05-20 at 13:09 +0200, Alexandre Bique via Libc-help wrote: > > On Thu, May 20, 2021 at 1:03 PM Florian Weimer wro= te: > > > > > > * Alexandre Bique via Libc-help: > > > > > > > Ideally I'd like to do: > > > > A produces a request > > > > A sched_yield_to(B) > > > > B processes the request > > > > B sched_yield_to(A) > > > > > > This looks like an application for a condition variable or perhaps a > > > barrier. If there is just a single writer, the kernel should wake up > > > the desired thread. > > > > I don't think conditions or barriers would solve the problem. Because > > they would just put the waiting threads on the wake up queue like the > > read() on the pipe would. > > I assume it should work. I remember Torvalds ranting about people using s= ched_yield() for the wrong reasons=C2=B9, and he mentioned mutex (which app= arently worked for you) as one of possible solutions. Quoting: > > > Good locking simply needs to be more directed than what "sched_yield()"= can ever give you outside of a UP system without caches. It needs to activ= ely tell the system what you're yielding to (and optimally it would also te= ll the system about whether you care about fairness/latency or not - a lot = of loads don't). > > > > But that's not "sched_yield()" - that's something different. It's gener= ally something like std::mutex, pthread_mutex_lock(), or perhaps a tuned th= ing that uses an OS-specific facility like "futex", where you do the nonblo= cking (and non-contended) case in user space using a shared memory location= , but when you get contention you tell the OS what you're waiting for (and = what you're waking up). > > > 1: https://www.realworldtech.com/forum/?threadid=3D189711&curpostid=3D189= 752 >