Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1777811pxv; Fri, 16 Jul 2021 18:02:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVbxDe8UfsiIrfQRuSJcOfHTBa3dgDVtQ+tM03710ivwgHpUoOGVGT9TGvkaUcLpH6JsaM X-Received: by 2002:a05:6402:216:: with SMTP id t22mr18038334edv.70.1626483728489; Fri, 16 Jul 2021 18:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626483728; cv=none; d=google.com; s=arc-20160816; b=XAd9gJQpeOQ3uXV+1V+ZAOM7OCBDqQ7wZN+oAsBGDiTLdJH5ixAihoBgwLbDcvzPeg 1U4vNVwBVfpMXYPNB39xbYhn/plLAMz0MDcm2cLNJpEPfaGVaM/6YKfc2rehIBZ2W+wp ad5HklG3gvlco4p30V/DH1VCEph2q0dPd8lynX4oFYSNPcROFGuWKr3mEEXSFdjUa3zk 3up8g1JuodcZ5rElYw3wKfwmA+bp3aQoF7iSHmU5FB7nJHaiRS3SEAhhLt7gRimhiTIW Fa6aDYdQzchfM3tthpHsKTGpmCXEFrA016d+TcZdT/CFgw5CWNVvVoGoajcB8mWbSZ79 V2gQ== 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=WdGiDBrteAb4nj01yiCy7O6Jofv7lyu1LQa/vqz2+sk=; b=PHfapfcDecRLbK48LCZn06lPv6eZUSItEqVIzDMoyVYbFM3MU2vXTH4DYGXj1kZA27 XznCx2HJnsbOZuB5ez62A84O4cN3So9/+VbBv+Jm8UndcMVKvjIhQpvB4fFI1khNPFe/ Bma1fF/lmwsPTX2/p1OX9CbFBHMRVhIQvU/jRzItEHvTNgPPrZZP6zlsulj+8o2M4GPZ D7m4WeEGTYRuuj84ema3pCwv6f7T70z+rYo2IF8lW52OfcNDY7/nG51NA7c8Yl7xWjQR trUX7UXSsTWYFyH0CV+rCW1y8h2pHUWTk7XdTg5XKHIVCi2cpQFTsgM/pO6yWrB0bBix 8xbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@uwaterloo.ca header.s=default header.b=jSo41eg2; 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 nc38si13217322ejc.36.2021.07.16.18.01.44; Fri, 16 Jul 2021 18:02:08 -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=jSo41eg2; 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 S232769AbhGQBBb (ORCPT + 99 others); Fri, 16 Jul 2021 21:01:31 -0400 Received: from esa.hc503-62.ca.iphmx.com ([216.71.131.47]:33565 "EHLO esa.hc503-62.ca.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbhGQBBa (ORCPT ); Fri, 16 Jul 2021 21:01:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uwaterloo.ca; i=@uwaterloo.ca; q=dns/txt; s=default; t=1626483515; x=1658019515; h=to:cc:references:subject:in-reply-to:from:message-id: date:mime-version:content-transfer-encoding; bh=7Msst6GRlO4ej0lfburnS3KYsBzgPojoLxzW+XLxWlQ=; b=jSo41eg2AXP8gs98G/UiyuaTm2bbs4kR+xo3/29BGmVxF3/jGYiZoPzG 5UMc+bPuq4jt9VDAguCB1tiI+k16s6Fxa3nla7e3qH0HjtJSokkzbD+ht 9h4D7mUp568+sD7D/IB5BxwJL4xnfvC+y9QhwSN6GW6hoTCLuOT6hEMGG A=; 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; 16 Jul 2021 20:58:11 -0400 Received: from [10.42.0.123] (10.32.139.159) 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; Fri, 16 Jul 2021 20:58:10 -0400 To: CC: , , , , , , , , , , , , Peter Buhr , Martin Karsten References: <20210716184719.269033-4-posk@google.com> Subject: Re: [RFC PATCH 3/4 v0.3] sched/umcg: RFC: add userspace sll helpers In-Reply-To: <20210716184719.269033-4-posk@google.com> From: Thierry Delisle Message-ID: Date: Fri, 16 Jul 2021 20:58:09 -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: 8bit Content-Language: en-US X-Originating-IP: [10.32.139.159] X-ClientProxiedBy: connhm04.connect.uwaterloo.ca (172.16.137.68) To connhm04.connect.uwaterloo.ca (172.16.137.68) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > The helpers below can work with userspace single-linked lists concurrently > without indefinitely spinning in the kernel. Specifically: > > push (add to the head of the list): > >   step = 0 >   while (++step < N) >      old = *head >      *next = old >      cmp_xchng(head, &old, next) > > pop (remove the first element from the list): >     mark the node as deleted by flipping its lowest bit without >     actually removing the node from the list: > >   curr = *head >   step = 0 > >   while (curr && ++step < N) > >     next = *curr >     if (next & 1) >         curr = next & ~1 >         continue > >     if (cmp_xchng(curr, next, next | 1)) >         return curr >     else >         curr = next & ~1 > > It is the userspace's responsibility to actually remove the > nodes marked as deleted from the list. I believe the subsystem called Nemesis introduced a MCS-based queue that could be useful here. The original paper is https://doi.org/10.1109/CCGRID.2006.31 You can also look at this repo for an implementation of the queue. https://git.uwaterloo.ca/mkarsten/libfibre/-/blob/master/src/runtime/LockFreeQueues.h While it uses 2 pointers, I believe it would fit well for idle_workers_ptr since the push operation is wait-free, which avoids problems for the kernel. The pop operation requires a lock in userspace *if* multiple servers can consume from the same queue, but I don't believe it's a requirement in general.