From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69AEAC433F5 for ; Mon, 11 Oct 2021 22:45:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B4C460F11 for ; Mon, 11 Oct 2021 22:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235523AbhJKWru (ORCPT ); Mon, 11 Oct 2021 18:47:50 -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-Google-Smtp-Source: ABdhPJzVVPdR4DP73VKGuQiecj7yDMIBF8hL25OwiQSohQYG9orfm3O7WMGfKA4wsIle29LnHWO67wZyVf9Gek2YfOY= 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...