From: Roman Mamedov <rm@romanrm.net>
To: Kuan-Wei Chiu <visitorckw@gmail.com>
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()
Date: Sun, 3 Sep 2023 18:30:58 +0500 [thread overview]
Message-ID: <20230903183058.1301b149@nvm> (raw)
In-Reply-To: <20230903095059.2683850-1-visitorckw@gmail.com>
On Sun, 3 Sep 2023 17:50:59 +0800
Kuan-Wei Chiu <visitorckw@gmail.com> 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 <visitorckw@gmail.com>
> ---
> 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
next prev parent reply other threads:[~2023-09-03 13:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-03 9:50 [PATCH] md/raid5: eliminate if-statements in cmp_stripe() Kuan-Wei Chiu
2023-09-03 13:30 ` Roman Mamedov [this message]
2023-09-03 20:10 ` Kuan-Wei Chiu
2023-09-05 20:49 ` Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230903183058.1301b149@nvm \
--to=rm@romanrm.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=visitorckw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox