Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4009631imw; Mon, 11 Jul 2022 22:50:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vsYL4h1iMeoitG32fP9QJ2JkjMwUa8apb2FlVy9U/VEs8fK4W0UCWCexacQ5RzJzhzown5 X-Received: by 2002:a05:6a00:b92:b0:52a:e60d:dfbb with SMTP id g18-20020a056a000b9200b0052ae60ddfbbmr2214126pfj.72.1657605033784; Mon, 11 Jul 2022 22:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657605033; cv=none; d=google.com; s=arc-20160816; b=Y/fVPeXk3odd4z9dSh+e7asNXGfEaur+AidL2CIlR1Y09P4Af50aODDxWnK/vMvk79 MNaU9ORvW6aXkYjeoWnize7ZTbMe0HAQriTxujfoEGwahWZHfSTMSOmsygLL0RFrLz1y BIr5xC46T7rj6OG0ZF71P3r1VdfioAopXtSNrgoIec4p0sHJb+LpukcWEO8MSYNWDheK 1XD8V33JLkM9d8pz/+1p5eNEgDtdkwcpcKx01vtpBEO4pMynQZQXRxT71U/wW2GZ1iAU qIjXRE+RkUD1zPC5yz5ApOFtyJmwEaOg2x43ZFfyOWU98vkzmp2WyK53QSqSXmjJhVHC TvmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ega+Z9B/4Yexu++aBsELz0a6/2VIgxnLFmauVgfSpZU=; b=f7J2zaC+QCHPSXYGI9EHCUdkxVCF7dVilejm3V6TtUa1BAAnyaPCA0uXnNmIouDuyc 2Ble3AXQZI90JfrsUdtxfjoKFpdYva64NHBy+r6z/T7x4CBw8+FwtA8EyZropvx0appm 8c+BLj8vfjAIMVoZrPkBRqDm4jhflE1B9gET5v+dhxMUjZH+V6qEAhHN8rGysUJSGMSc hA5Fv0g/QULn2MT82Nm5wQAVADMWa0oxx/WtIYqQNzASLV+AMDM6vR+2CM+eH0F9G2dy wM2jh09BFU4+qeFKCwfoQ6X9G1S4HSrESfHvjO23j5dMmyCeRUZkveJXWuRYwJHGhR8V MVZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wxVoxPxw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r30-20020a635d1e000000b00407e25d4528si12603355pgb.5.2022.07.11.22.50.22; Mon, 11 Jul 2022 22:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wxVoxPxw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbiGLFNV (ORCPT + 99 others); Tue, 12 Jul 2022 01:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbiGLFNU (ORCPT ); Tue, 12 Jul 2022 01:13:20 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D4731226; Mon, 11 Jul 2022 22:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=ega+Z9B/4Yexu++aBsELz0a6/2VIgxnLFmauVgfSpZU=; b=wxVoxPxw3IyK+C8HHBMt2jepI4 TSBxQB+MTtSoxQDrUn24D94dNsXzN6zLMu8dlxphvBFdxicbMCDD7y7ZflkcrON9bvhjU++Vjby5X kN1IOFbMpX50qJ8ONftqHyoT5LIsYW/rHUhxDHbf39gg7gWJ4bfg5MYEaxTx+fyvklOxTedIWs/aG sC0vtIT0WcLbTIpQiIiHaaKMvEMhMwBrzHIYP3ciufq+vArc99ai1HMi/CvMl9tETI2RQgoOxwTcS Q1GIitEq/PrgMdEm7BS3KVEfpi1ElDAtSQ/FkZdHv1CiK7RipSLjfi54m89AlLy9v6W3OBCc0rJ6m nQKjLX0Q==; Received: from hch by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oB8D1-007iTg-H9; Tue, 12 Jul 2022 05:13:19 +0000 Date: Mon, 11 Jul 2022 22:13:19 -0700 From: Christoph Hellwig To: Uros Bizjak Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Jens Axboe Subject: Re: [PATCH] block: Use try_cmpxchg some more Message-ID: References: <20220711153301.2388-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220711153301.2388-1-ubizjak@gmail.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 11, 2022 at 05:33:01PM +0200, Uros Bizjak wrote: > Use try_cmpxchg family of functions instead of cmpxchg (*ptr, old, new) == old. > x86 CMPXCHG instruction returns success in ZF flag, so this change saves a > compare after cmpxchg (and related move instruction in front of cmpxchg). > > Also, try_cmpxchg implicitly assigns old *ptr value to "old" when > cmpxchg fails, enabling further code simplifications. > > No functional change intended. You might want to split this into a patch per caller as it might attact different reviewers. > + do { > + } while (old && !atomic_try_cmpxchg(&blkg->use_delay, &old, old - 1)); It might just be me, but for loops with an empty body this do { } while construct looks odd. Why not: while (old && !atomic_try_cmpxchg(&blkg->use_delay, &old, old - 1)) ; ? The the use of the atomic on ->use_delay looks really whacky to start with. To me it sounds like it really wants to use a proper lock instead of all this magic. > else > return; > > - old = atomic_cmpxchg(&iolat->scale_cookie, our_cookie, cur_cookie); > - > - /* Somebody beat us to the punch, just bail. */ > - if (old != our_cookie) > + if (!atomic_try_cmpxchg(&iolat->scale_cookie, &our_cookie, cur_cookie)) { > + /* Somebody beat us to the punch, just bail. */ > return; > + } /* If somebody beat us to the punch, just bail. */ if (!atomic_try_cmpxchg(&iolat->scale_cookie, &our_cookie, cur_cookie)) return;