[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] rwlock: remove unneeded subtraction


  • To: Julien Grall <julien@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 15 Feb 2022 14:22:02 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rJBQZ+Ux1WL+WjXUaL0a6qz5XGjP6Fl33toIGOB7zvs=; b=mtuighdwkfAvKA1fdfNw6JBjEgF5f38oeKzUrjZyYM08kM2W/Vo/EEYQSOFIV9CQRupjSmAMvYIHaP/aEEmx9OSSjbISn8HAs+Tt9oOo9ibpHyF+6V4+CVZaBBRCeEH3SVpOY1UGYNdP+XTtbISWBVAZPzEev3cyTno5K8nttl3SP5WzUHnzSlC7Pkt1u6YDZ9NR+JOYgLSn6R3q0mcX/neiFyfAQV4ll7Q4/sWSV00sf2gHY3xKwlpqDBoiYx+S5NbCKL6afg/vZdiT5vI7Egd0ThwcPLmmaWghKiuLBOD8pegH8ZuAray6gwCwb7itQP+c2oSZzyjLbqxcWa9JEQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KaQg8f9J6Kv31SSvoREstDRjZgBp6ETTtyqZOoMOHdpzcCWUkhCM+IpxZ4qBwueh+oPls4gC8yWF7kniCJi+Y8YpRpd3W86s90Fp6vP3U6L4n9/ZKgjRwglrX5MU3U1+hbmEH7Zlmci2tZa6Gkbpt5L5AqRPD/KOR2K7JRzRGDmmZkTwlqCDEXrtMyi4Z2XBveAXaMEXLIHU2z5Qn3ErqJNHAui1T0WyZE9T+7bdUxUfqfCgHxWgQ2b4w2vZb1Dmz+VSIUIQd0u/kwLDWV4hotXSZkPxjzYkKA2NC4ip6jL11+7t6t2JcuGBssslpEbu0sZQEEv/LJTRa87JE9b30w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 15 Feb 2022 13:22:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 15.02.2022 14:13, Julien Grall wrote:
> On 15/02/2022 09:39, Roger Pau Monne wrote:
>> There's no need to subtract _QR_BIAS from the lock value for storing
>> in the local cnts variable in the read lock slow path: the users of
>> the value in cnts only care about the writer-related bits and use a
>> mask to get the value.
>>
>> Note that further setting of cnts in rspin_until_writer_unlock already
>> do not subtract _QR_BIAS.
> 
> The rwlock is a copy of the Linux implementation. So I looked at the 
> history to find out why _QR_BIAS was substracted.
> 
> It looks like this was done to get better assembly on x86:
> 
> commit f9852b74bec0117b888da39d070c323ea1cb7f4c
> Author: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Date:   Mon Apr 18 01:27:03 2016 +0200
> 
>      locking/atomic, arch/qrwlock: Employ atomic_fetch_add_acquire()
> 
>      The only reason for the current code is to make GCC emit only the
>      "LOCK XADD" instruction on x86 (and not do a pointless extra ADD on
>      the result), do so nicer.
> 
>      Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
>      Acked-by: Waiman Long <waiman.long@xxxxxxx>
>      Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>      Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
>      Cc: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
>      Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>      Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>      Cc: linux-arch@xxxxxxxxxxxxxxx
>      Cc: linux-kernel@xxxxxxxxxxxxxxx
>      Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
> 
> diff --git a/kernel/locking/qrwlock.c b/kernel/locking/qrwlock.c
> index fec082338668..19248ddf37ce 100644
> --- a/kernel/locking/qrwlock.c
> +++ b/kernel/locking/qrwlock.c
> @@ -93,7 +93,7 @@ void queued_read_lock_slowpath(struct qrwlock *lock, 
> u32 cnts)
>           * that accesses can't leak upwards out of our subsequent critical
>           * section in the case that the lock is currently held for write.
>           */
> -       cnts = atomic_add_return_acquire(_QR_BIAS, &lock->cnts) - _QR_BIAS;
> +       cnts = atomic_fetch_add_acquire(_QR_BIAS, &lock->cnts);
>          rspin_until_writer_unlock(lock, cnts);
> 
>          /*
> 
> This is a slowpath, so probably not a concern. But I thought I would 
> double check whether the x86 folks are still happy to proceed with that 
> in mind.

Hmm, that's an interesting observation. Roger - did you inspect the
generated code? At the very least the description may want amending.

Jan




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.