Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1470458rdb; Mon, 4 Sep 2023 15:38:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzrbEfuJt63kI8JmhDdJxt7pOjftXOLO90y2JOV46IcZT1g612wRD0XAx8k0EqxmXBhwdF X-Received: by 2002:a05:6a20:1605:b0:14d:7511:1c2 with SMTP id l5-20020a056a20160500b0014d751101c2mr15172156pzj.55.1693867120077; Mon, 04 Sep 2023 15:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693867120; cv=none; d=google.com; s=arc-20160816; b=w55pV9HUnFU4C97JcTx/mG4gERwzOQUzAC39kUfgdu8b6SAofIU4fZd4qctW2AaZ2g lgMuQT9ugdFjE/vkoCPM2CpEfaUh1gYkE+ZIme9eAsVsTOsr3pjiXGbJVq+2K+1RQEm7 XgI3sOg0oKMcn5XebhpjLUhrq8csoigYNtd6v2PX1dwvKMg1ygqNQg/OXx5ZuQ1uXMPi USfN50EQk/zGbnagWOUFA30G4VCpevDtOf2nGWfhd2AR/3j3jO+j4x+w6GNY+UBDuH7L OmtLtZOFXtabC3R1y++hWHvf+7b/MDZhgG5KI/WrcjuHHDV6tEkKTLYrWRDZInlvTfHN srwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=Gb1WQjTMsE7fzj52awZk47SW0zr4mUp8MOgjsUTII38=; fh=tKPJ/3Eew66U8xoPpPxcL4OHuppx7yvf6lRpZ9A8f3o=; b=b8TTX5BBaVudUPqVp+SuFgiYCvT02wBuaCKMrDYRHccGG1EJrCnYQgzqbnwYGKYcK+ nvHsR6ujKduRtJPwSZZZKQYYR3K4yVaAvIpS89M5n5q7zeE3cJsE6ofqadUnbw+Xa4Oi cGS2KwxlXoAL9wPRzXoOMO+BPK/rqWLoWAkzjSLinz5Xy6ZpRzBQzWN9McMVFMI0QEMe jYmGa03o6JVH8o52gaAOQtxqRq60yU60KhD8qRZ8fr7WPvWW8A+T7lJfXsN1i/nxLbDs dK0XJPYYjAfcfuTw/vZj/MDJkeHLgj9XxGAmfxPEgTdbL5+nqV4ZiLCCQFvZbBgVhNs3 jryA== ARC-Authentication-Results: i=1; mx.google.com; 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 l6-20020a656806000000b00565ed0e5847si8133074pgt.793.2023.09.04.15.38.25; Mon, 04 Sep 2023 15:38:39 -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; 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 S237923AbjICNbU (ORCPT + 99 others); Sun, 3 Sep 2023 09:31:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233650AbjICNbT (ORCPT ); Sun, 3 Sep 2023 09:31:19 -0400 Received: from len.romanrm.net (len.romanrm.net [IPv6:2001:41d0:1:8b3b::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 468ABFA for ; Sun, 3 Sep 2023 06:31:16 -0700 (PDT) Received: from nvm (nvm2.home.romanrm.net [IPv6:fd39::4a:3cff:fe57:d6b5]) by len.romanrm.net (Postfix) with SMTP id 908714006E; Sun, 3 Sep 2023 13:31:08 +0000 (UTC) Date: Sun, 3 Sep 2023 18:30:58 +0500 From: Roman Mamedov To: Kuan-Wei Chiu Cc: song@kernel.org, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] md/raid5: eliminate if-statements in cmp_stripe() Message-ID: <20230903183058.1301b149@nvm> In-Reply-To: <20230903095059.2683850-1-visitorckw@gmail.com> References: <20230903095059.2683850-1-visitorckw@gmail.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Sun, 3 Sep 2023 17:50:59 +0800 Kuan-Wei Chiu wrote: > Replace the conditional statements in the cmp_stripe() function with a > branchless version to improve code readability and potentially enhance > performance. The new code will always do two comparisons and a subtraction (3 instructions in total), whereas the old version could return after just 1 comparison, or after 2 comparisons. So depending on the data values it is 3x to 1.5x as much operations performed than before, there unlikely to be any enhancement of performance. Also IMO the previous version is more easily readable. > The new code calculates the result using a subtraction of > comparison results, making it more concise and avoiding conditional > branches. This change does not alter the functionality of the code. > > Signed-off-by: Kuan-Wei Chiu > --- > drivers/md/raid5.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c > index 4cb9c608ee19..b14d7ba38f0f 100644 > --- a/drivers/md/raid5.c > +++ b/drivers/md/raid5.c > @@ -1035,11 +1035,7 @@ static int cmp_stripe(void *priv, const struct list_head *a, > struct r5pending_data, sibling); > const struct r5pending_data *db = list_entry(b, > struct r5pending_data, sibling); > - if (da->sector > db->sector) > - return 1; > - if (da->sector < db->sector) > - return -1; > - return 0; > + return (da->sector > db->sector) - (da->sector < db->sector); > } > > static void dispatch_defer_bios(struct r5conf *conf, int target, -- With respect, Roman