Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1897829pxb; Mon, 11 Oct 2021 15:53:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3n5lxsWtLmgvPpTjZeFGcstukXtUuDcMh1yLxwRqsyGfAFm7k5LgZuEtuUS8leRoeQciw X-Received: by 2002:a50:da0a:: with SMTP id z10mr45390772edj.95.1633992791072; Mon, 11 Oct 2021 15:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633992791; cv=none; d=google.com; s=arc-20160816; b=TupVJxooyu2g58ddL5qjjin9rKLDfopCSQT/XKhPQl3lfkxSaHtnJLKE5Tm4JWjU2i sk7ibZYh+UJWe6tnBoGaHVesQ3Em8/4kaMVWHxJp2VeS6DgPoEhc2sLcqwDk8kahB56o IfRdi86NfdAJ9GoZxYXvWMm8CfR8aDnXKEzLSyK11nl21/tUsmzoLaVPrIGYIgVpOJM2 QhC8A9n6C3iReLzf/TLB+g0Dw0PhxyM9QrsQSu8E2kOS7sYQlTZNH4WY6xF4zLwmBp2r Wkgs8iWDnESlrmT+B4Ml7b1d3+cpWZfZwCiDYCR51ERms3mYqY5dO2Z+oDjI2Ft91yNv jXeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+F7mbCRUVIAd5+FarZoaSUIAm/NRPRaqoitjHUAk/CY=; b=x/M8gApaAOpOx0mS4gjdlACa47QeE5W20DU/Eyn//U0UUEyYLgy872X3lGuYy40RLF fW8XAsYCuZLU9Bl8wSgwAHKvHNz1TbFWLWSjU4Aq0cUHmTe4MnHepBiiKJvD9K0HGXnR bzePkHHDm8xNIIbvwJ+6NovFnWK2uM/xpd3NUJE4hlLbXKi10DHWfe7KasdItFY77dC2 eP0IIz8qMIvfy084VCTzWb2hxVirRLDJmvsA1hutpE8/d1CAVM91UHskgJYZ/H3FXfCr nKzUnBisnPLcI2BTKG3uzc7ord/kqlj8NWefZkrQ+WTzdYlVzc/xLZTbWxJrp41XPTwP RxHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=LdRWzX87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 14si12514303edx.336.2021.10.11.15.52.40; Mon, 11 Oct 2021 15:53:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=LdRWzX87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229590AbhJKWrt (ORCPT + 99 others); Mon, 11 Oct 2021 18:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231307AbhJKWrt (ORCPT ); Mon, 11 Oct 2021 18:47:49 -0400 Received: from mail-ua1-x934.google.com (mail-ua1-x934.google.com [IPv6:2607:f8b0:4864:20::934]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCF2C06161C for ; Mon, 11 Oct 2021 15:45:48 -0700 (PDT) Received: by mail-ua1-x934.google.com with SMTP id j8so7222995uak.9 for ; Mon, 11 Oct 2021 15:45:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+F7mbCRUVIAd5+FarZoaSUIAm/NRPRaqoitjHUAk/CY=; b=LdRWzX87yafLKh5rG+nJLozEgMBzBfZOwRq0iZYO7pBUujGAfc+4up+udWikXfY6KZ hZLapqKfV+4JeGhaBwsQAcJSNckPuWK5xG/vr8S7xCGXFoBNzLBmKhU5p0Khz9D28Ste mxW6bDcLg6QlS8Tv9dDjEcZxh3TFEM69BTUp+9cqoUg+/VprmXiNAR/v7Zt/AwlRvvJn tMD84x4JYHWids3F7LCalEml1oK3Bxel+lZvYVCEoG6e5sEz805yZacx7BuQRkpatC3e w/gKEzaBtA61cMuFlSdQsNGNvn1RnjQEEbOvEBdrS9Zk6ITrb3nbun+2se0iJalRqpO4 0Fzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+F7mbCRUVIAd5+FarZoaSUIAm/NRPRaqoitjHUAk/CY=; b=t0cIJpP59R4yiyYGtN6hkYJVWNGCGUQIE/PRMYN5apJh6DihrpqIqZu/FlcpzhTteM 8gzxj1oRgXH2v0bontUi/usMH9cncDiBsiX395J9Yn+Njftk4oPjd96b0Ja1dIM5tLjq aGWFNlM0u9k/GdD+PjPAS3KQwuC9sW606YfXFEiLIjAfOBi1MKiHaY68SwmdbwNJ67fG QTku8v6ciakiQXLSRKBMsHOhxTsh1Fp8pSOqU//ek2hLz8b+mMJa6g8VbKbS57lHAjYl YPpbBLshkroBkjQAto/xf/uO/KPeESDuFaGhKfR42ldGrO67Tn8vRoW/OHovNuQABTnz IDMA== X-Gm-Message-State: AOAM532titvmjovp3tmSEazh0wMpBCHOJO30x3+hV1dOC/8aEEJFE+hc Fw7zX9sg9rSV8ssjEB7R63TEkek5tJ5+O1Xg2mdk5w== X-Received: by 2002:ab0:1623:: with SMTP id k32mr18245214uae.71.1633992347458; Mon, 11 Oct 2021 15:45:47 -0700 (PDT) MIME-Version: 1.0 References: <20210917180323.278250-1-posk@google.com> <20210917180323.278250-6-posk@google.com> <12eb2300-4a78-9e93-30a3-8e2ddba4693f@uwaterloo.ca> In-Reply-To: <12eb2300-4a78-9e93-30a3-8e2ddba4693f@uwaterloo.ca> From: Peter Oskolkov Date: Mon, 11 Oct 2021 15:45:36 -0700 Message-ID: Subject: Re: [PATCH 5/5 v0.6] sched/umcg: add Documentation/userspace-api/umcg.txt To: Thierry Delisle Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Linux Kernel Mailing List , linux-api@vger.kernel.org, Paul Turner , Ben Segall , Peter Oskolkov , Andrei Vagin , Jann Horn Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thierry, sorry for the delayed reply - I'm finally going through the documentation patches in preparation for the upcoming next version patchset mail-out. On Wed, Sep 22, 2021 at 11:39 AM Thierry Delisle wrote: > > On 2021-09-17 2:03 p.m., Peter Oskolkov wrote: > > [...] > > +SYS_UMCG_WAIT() > > + > > +int sys_umcg_wait(uint32_t flags, uint64_t abs_timeout) operates on > > +registered UMCG servers and workers: struct umcg_task *self provided to > > +sys_umcg_ctl() when registering the current task is consulted in > addition > > +to flags and abs_timeout parameters. > > + > > +The function can be used to perform one of the three operations: > > + > > +* wait: if self->next_tid is zero, sys_umcg_wait() puts the current > > + server or worker to sleep; > > I believe this description is misleading but I might be wrong. > From the example > * worker to server context switch (worker "yields"): > S:IDLE+W:RUNNING => +S:RUNNING+W:IDLE > > It seems to me that when a worker goes from running to idle, it should > *not* set the next_tid to 0, it should preserve the next_tid as-is, > which is expected to point to its current server. This is consistent > with my understanding of the umcg_wait implementation. This operation > is effectively a direct context-switch to the server. The documentation here outlines what sys_umcg_wait does, and it does put the current task to sleep without context switching if next_tid is zero. The question of whether this behavior is or is not appropriate for a worker wishing to yield/park itself is at a "policy" level, if you wish, and this "policy" level is described in "state transitions" section later in the document. sys_umcg_wait() does not enforce this "policy" directly, in order to make it simpler and easier to describe and reason about. > > With that said, I'm a little confused by the usage of "yields" in that > example. I would expect workers yielding to behave like kernel threads > calling sched_yield(), i.e., context switch to the server but also be > immediately added to the idle_workers_ptr. > > From my understanding of the umcg_wait call, "worker to server context > switch" does not have analogous behaviour to sched_yield. Am I correct? > If so, I suggest using "park" instead of "yield" in the description > of that example. I believe the naming of wait/wake as park/unpark is > consistent with Java[1] and Rust[2], but I don't know if that naming > is used in contexts closer to the linux kernel. > > [1] > https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/LockSupport.html > [2] https://doc.rust-lang.org/std/thread/fn.park.html I'm not a fan of arguing about how to name things. If the maintainers ask me to rename wait/wake to park/unpark, I'll do that. But it seems they are OK with this terminology, I believe because wait/wake is a relatively well understood pair of verbs in the kernel context; futexes, for example, have wait/wake operations. A higher level library in the userspace may later expose park/unpark functions that at the lower level call sys_umcg_wait...