Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp621186ybe; Wed, 4 Sep 2019 05:21:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIyumC4n4NlEK2++bXiut1iYTQOEH882CSCDX4Bo9H8M0bPXboQLdb3CUFi6HC7GnPsuDF X-Received: by 2002:aa7:9117:: with SMTP id 23mr22656048pfh.94.1567599687982; Wed, 04 Sep 2019 05:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567599687; cv=none; d=google.com; s=arc-20160816; b=miHtmjZAL1LUsBLRaa/t3uI0nCFPxKXSGppjo2FCzLiATln8C0dssAo4iW0waVXmhP B5cGAgUvRtU5qRNgmWRsYDeg5cPOcLH8yuh1mTIV6I+Gmjsd5ZK3uVaRoIWi/ZM8JqGg TLqjEJuHheMJdE15qA5G05ICa8n5Nj22IZ5eBK907m9IvCPBO6sUSefT0Ipo9i+rDx6b Qnim3CPsziKiuZfvCJ4dUJVc4OzxJh5sd8hp/ASThPTEF+Qq6o/0E7JWsgs42Mes2wIK tVU2jqmQbdRFcvEHLBRxzEZC+BRCeNB4nJcidDlWY6QvibZeQc88yUVzgvbMOu7pFG5Y iPhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Awvpdgkqn6/w+tezauopO9pT/rkCwfPb/ThYPnLC8xo=; b=LZber0cs2BJ/1ku0VWiWZVwduY6IqN8XMRq7SvF/xbFXjSTSgxeo7IgJ7gT4e0pkgi cj74RDf155y0P9pWLyz5/RA2fNbJP4C/BgDELeOeOA/zzhv6NNU2CgBb1GjKfHKbzYcX eEPqYlXhnuwpIz0qiDq3R8O9j8mtWVkE6Xk5xqWoR5suiesva90WY5H01C+9hDAHPoOf 8CEDu4TIzIJMJcRqyMvKjtXYwPM3W2ZoV+jCUJ2QL4ews1iTPoZ7DnH+JAA+AFWg3MtA bXAe14A/pRJq9VLCdyZ11ASHffrcCVgS3qx4QdDMYqSTE6iOJs6NXMK9ippFbbq6+VRB ku1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=S22mIGBD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v27si17630624pgn.14.2019.09.04.05.21.11; Wed, 04 Sep 2019 05:21:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=S22mIGBD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729913AbfIDMUR (ORCPT + 99 others); Wed, 4 Sep 2019 08:20:17 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42176 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727929AbfIDMUQ (ORCPT ); Wed, 4 Sep 2019 08:20:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Awvpdgkqn6/w+tezauopO9pT/rkCwfPb/ThYPnLC8xo=; b=S22mIGBDa3bIDmaOJah99xsFD /c7IULtxrQCz9AmzLPMibuTKx1dhSVAEaa8hVdn2c5xYy1TMv/KQpCVGApDA9ay043sxNlo+ZwlH4 2UD4R/xW5ypUAhsJFI92Iu5uKj7NNmte0VHT1ijvIvIamRVshOmawFJykKiK8M84mlaeVfnwxALWa wkLFq0jmhjSk8hIzLtgM7M8AlKLiny42Kq0RJ9YzY4jzIUn7Bm+7ALkbABGEFsKO43qgsyyfhgWJV WlUWnaaQm2anLlACQIeN3YVISvlpuqijNJ8wT0lD1QPg1LOXHVW52GFlg7UBpWWrtrUJS9pmU/Lce HofrjIoPw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i5UGK-0004fb-Er; Wed, 04 Sep 2019 12:19:48 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id DD860306029; Wed, 4 Sep 2019 14:19:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6BA2329D94A62; Wed, 4 Sep 2019 14:19:46 +0200 (CEST) Date: Wed, 4 Sep 2019 14:19:46 +0200 From: Peter Zijlstra To: Petr Mladek Cc: John Ogness , linux-kernel@vger.kernel.org, Andrea Parri , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Brendan Higgins , Thomas Gleixner , Linus Torvalds , Greg Kroah-Hartman Subject: Re: numlist_pop(): Re: [RFC PATCH v4 1/9] printk-rb: add a new printk ringbuffer implementation Message-ID: <20190904121946.GZ2369@hirez.programming.kicks-ass.net> References: <20190807222634.1723-1-john.ogness@linutronix.de> <20190807222634.1723-2-john.ogness@linutronix.de> <20190820081518.3r3cagzggtifsvhz@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190820081518.3r3cagzggtifsvhz@pathway.suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 20, 2019 at 10:15:18AM +0200, Petr Mladek wrote: > do { > tail_id = atomic_long_read(&nl->tail_id); > > /* > * Read might fail when the tail node has been removed > * and reused in parallel. > */ > if (!numlist_read(nl, tail_id, NULL, &next_id)) > continue; > > /* Make sure the node is not the only node on the list. */ > if (next_id == tail_id) > return NULL; > > /* cC: Make sure the node is not busy. */ > if (nl->busy(tail_id, nl->busy_arg)) > return NULL; > > while (atomic_long_cmpxchg_relaxed(&nl->tail_id, tail_id, next_id) != > tail_id); Both you and John should have a look at atomic*_try_cmpxchg*(); with that you can write the above as: tail_id = atomic_long_read(&nl->tai_id); do { ... } while (!atomic_long_try_cmpxchg_relaxed(&nl->tail_id, &tail_id, next_id)); And get better code-gen to boot.