Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2732888pxt; Mon, 9 Aug 2021 07:40:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBdicbQI2xD6LTHqY+uSStAz6T9hyj2CuE2ByWlNnv6q0hlZw4Fcvf+qBfCkbQEcUmn8JL X-Received: by 2002:a17:906:9bd4:: with SMTP id de20mr2305597ejc.322.1628520056580; Mon, 09 Aug 2021 07:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628520056; cv=none; d=google.com; s=arc-20160816; b=Rj424DQr6BEBb62Ppml1i+WrtjmXT8PdSUVH+fOgK/Ct3SoH3f9wbp8cahXp/8Vy0R J/ZHii06NlECtb6PrRL5J5P93NoGX/Im0M2z1QvwfE/bRpVzH/BcyjrZJ9dVA4REY1Wh 8/o/KQsKt+QtsXPjll7N08UsMkhskfUPRhLksXNhNPoo6GKOPTsdwr0Uh9vmxV+waVRc lzhKCEe5/sE8K11QVVZ3gQZW7yyPxeDaT/Vbf8xgNvsvBf0SQQubnmJ9SGHjHutradZO c2fDaJrpppvVY6ymXt0cnJEFFWvZ9d9nLyooc+CgTZi87BsfMc8KfnsPpsciNb5zhKhh dpSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :mime-version:user-agent:date:message-id:from:in-reply-to:subject :references:cc:to:dkim-signature; bh=4x9sjHeD5a8VARosMaEyBrjLPXQdoIE6Gb2m/Ff3xKs=; b=nkEK/WwaEuyuMO4wCYXs3lvU241ki+O+sRD5JstN7U8tLqtVNF/ukmX9/Nee2dO3S9 hygpJxczuIE7TTA8KaXUwVXbLVllqcGzgy7hh3TDrIiVtMsO2DftdWVhZLg1ajN/P4uZ qpDyiQFPeEEc5V6TM+GvoEE04c8RLmRKivxAlMttNcz9tLnDo2/lFuRBFAk5mgDscvj8 RGe4kEwHMznAGrI0C8yiUgQ0vipdjtU7BRWQpqCIeWciqLv3G395ABp4hZro71fZZowp ee/NBiFLnvWEgVIfGhteRfpdi7EP9oUc3qdgMStNspbCm6+Q0Ay6EsZBDFdctWHwvpa1 Dzdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@uwaterloo.ca header.s=default header.b=pm8lt8eA; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uwaterloo.ca Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq34si1387818ejc.343.2021.08.09.07.40.33; Mon, 09 Aug 2021 07:40:56 -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=fail header.i=@uwaterloo.ca header.s=default header.b=pm8lt8eA; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uwaterloo.ca Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234771AbhHIOQY (ORCPT + 99 others); Mon, 9 Aug 2021 10:16:24 -0400 Received: from esa.hc503-62.ca.iphmx.com ([216.71.135.51]:25938 "EHLO esa.hc503-62.ca.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234707AbhHIOQX (ORCPT ); Mon, 9 Aug 2021 10:16:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uwaterloo.ca; i=@uwaterloo.ca; q=dns/txt; s=default; t=1628518562; x=1660054562; h=to:cc:references:subject:in-reply-to:from:message-id: date:mime-version:content-transfer-encoding; bh=4x9sjHeD5a8VARosMaEyBrjLPXQdoIE6Gb2m/Ff3xKs=; b=pm8lt8eAk1wNnmMKDg6tTD4jh3xzjbBDgGkpfEZQqsHZMEXdnh7uMGJ3 NgB951MUPtAPoy2RX4S8+lmMfW4RTImEb4oL89kgrhN/8grlulDalyVV2 SF5Qtw3U48fjmEqLBdfph719YVNDz+oXXOOjBt31wEEe64kjdok1a7PSM 4=; Received: from connect.uwaterloo.ca (HELO connhm04.connect.uwaterloo.ca) ([129.97.208.43]) by ob1.hc503-62.ca.iphmx.com with ESMTP/TLS/AES256-GCM-SHA384; 09 Aug 2021 10:16:00 -0400 Received: from [10.42.0.123] (10.32.240.218) by connhm04.connect.uwaterloo.ca (172.16.137.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 9 Aug 2021 10:15:59 -0400 To: CC: , , , , , , , , , , , References: Subject: Re: [PATCH 3/4 v0.4] sched/umcg: add Documentation/userspace-api/umcg.rst In-Reply-To: From: Thierry Delisle Message-ID: Date: Mon, 9 Aug 2021 10:15:59 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.32.240.218] X-ClientProxiedBy: connhm01.connect.uwaterloo.ca (172.16.137.65) To connhm04.connect.uwaterloo.ca (172.16.137.68) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > This is a wake, not a context switch, right? I followed the "worker to worker context switch" procedure in the documentation. > I'm not sure why you are concerned with context switching here. And even > if it were a context switch, the kernel manages thread stacks properly, > there's nothing to worry about. The reason I'm interested in this particular operation is because the outcome is decided by an invisible race (between W1 and W2) in the kernel. W2 might context-switch to W1 and it might not. Note I don't mean race in the problematic sense, just that there are two possible outcomes that are decided by relative speed. I'm wondering how many outcomes the users needs to program for and if they may have to back-track anything. For example, if W2 wants to "yield to", it must enqueue itself in the user scheduler before the system call. But if the system call doesn't context-switch and W2 keeps running, it may need to undo the enqueue. I agree the comment about the stack was a tangent and I expected the kernel to handle it. But, I believe, how the kernel handles this case affects the number of outcomes for this scenario. > If both cmpxchg() succeeded, but W1 was never put to sleep, ttwu() > will do nothing and W1 will continue running on its initial CPU, while > W2 will continue running on its own CPU. WF_CURRENT_CPU is an advisory > flag, and in this situation it will not do anything. This does not sound right to me. If ttwu does nothing, W1 and W2 keep running. Who sets W2's state back to RUNNING? Is W2 responsible for doing that? It's not "the party initiating the state transition" in this case. Since there is no way for W2 to tell if it did context-switch to W1, does that mean that W2 should always cmpxchg() its state to RUNNING after a sys_umcg_wait()?