mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Uros Bizjak <ubizjak@gmail.com>,
	yongli-oc <yongli-oc@zhaoxin.com>,
	peterz@infradead.org, mingo@redhat.com, will@kernel.org,
	boqun.feng@gmail.com
Cc: linux-kernel@vger.kernel.org, yongli@zhaoxin.com,
	louisqi@zhaoxin.com, cobechen@zhaoxin.com,
	jiangbowang@zhaoxin.com
Subject: Re: [PATCH 3/4] locking/osq_lock: From x_osq_lock/unlock to numa-aware lock/unlock.
Date: Sun, 15 Sep 2024 17:06:10 -0400	[thread overview]
Message-ID: <afddc02d-fa96-4793-bc60-6c81629d8d5b@redhat.com> (raw)
In-Reply-To: <fd0e5627-b89c-d25b-bbf5-edc712642f85@gmail.com>

On 9/15/24 14:44, Uros Bizjak wrote:
>
>
> On 14. 09. 24 10:53, yongli-oc wrote:
>> According to the contention level, switches from x_osq_lock to
>> numa-aware osq_lock.
>> The numa-aware lock is a two level osq_lock.
>> The Makefile for dynamic numa-aware osq lock.
>>
>> Signed-off-by: yongli-oc <yongli-oc@zhaoxin.com>
>> ---
>>   kernel/locking/Makefile      |   1 +
>>   kernel/locking/numa.h        |  98 ++++++++
>>   kernel/locking/numa_osq.h    |  32 +++
>>   kernel/locking/x_osq_lock.c  | 332 +++++++++++++++++++++++++++
>>   kernel/locking/zx_numa_osq.c | 433 +++++++++++++++++++++++++++++++++++
>>   5 files changed, 896 insertions(+)
>>   create mode 100644 kernel/locking/numa.h
>>   create mode 100644 kernel/locking/numa_osq.h
>>   create mode 100644 kernel/locking/x_osq_lock.c
>>   create mode 100644 kernel/locking/zx_numa_osq.c
>
> ...
>
>> +    if (lock->numa_enable == OSQLOCKSTOPPING && old == 
>> OSQ_UNLOCKED_VAL)
>> +        old = OSQ_LOCKED_VAL;
>> +
>> +    for (;;) {
>> +        if (READ_ONCE(lock->tail16) == curr &&
>> +            cmpxchg(&lock->tail16, curr, old) == curr) {
>
> I would like to ask if there is any benefit to read the location two 
> times? cmpxchg() reads the location and skips the update when curr is 
> different from the value at the location by itself. Using 
> try_cmpxchg() can produce even more optimized code, since on x86 arch 
> CMPXCHG also sets ZF flag when operand 2 is equal to the value at 
> location (and update happens), and this flag can be used in a 
> conditional jump.

The major reason is for doing a read first before cmpxchg() is to avoid 
the overhead of an atomic operation in case the current task isn't the 
tail. We usually optimize for the case with a lot of incoming lockers 
where the chance of a match isn't particularly high.

Cheers,
Longman


  reply	other threads:[~2024-09-15 21:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-14  8:53 [PATCH 0/4] locking/osq_lock: Update osq_lock to dynamic yongli-oc
2024-09-14  8:53 ` [PATCH 1/4] locking/osq_lock: The Kconfig for dynamic numa-aware osq lock yongli-oc
2024-09-14  8:53 ` [PATCH 2/4] locking/osq_lock: Turn to dynamic switch function from osq_lock/unlock yongli-oc
2024-09-14 16:06   ` Waiman Long
2024-09-19  9:32     ` yongli-os
2024-09-14  8:53 ` [PATCH 3/4] locking/osq_lock: From x_osq_lock/unlock to numa-aware lock/unlock yongli-oc
2024-09-14 17:11   ` Waiman Long
2024-09-19  9:35     ` yongli-os
2024-09-15 18:44   ` Uros Bizjak
2024-09-15 21:06     ` Waiman Long [this message]
2024-09-14  8:53 ` [PATCH 4/4] locking/osq_lock: The numa-aware lock memory prepare, assign and cleanup yongli-oc
2024-09-14 17:21   ` Waiman Long
2024-09-19  9:41     ` yongli-os
2024-09-19 11:28       ` Waiman Long
2024-09-15 16:43   ` kernel test robot
2024-09-30  7:23 ` [PATCH v2 0/3] locking/osq_lock: Update osq_lock to dynamic yongli-oc
2024-09-30  7:23   ` [PATCH v2 1/3] locking/osq_lock: The Kconfig for dynamic numa-aware osq lock yongli-oc
2024-09-30  7:23   ` [PATCH v2 2/3] locking/osq_lock: Define osq by union to support dynamic numa-aware lock yongli-oc
2024-09-30  7:23   ` [PATCH v2 3/3] locking/osq_lock: Turn from 2-byte osq_lock/unlock to numa lock/unlock yongli-oc

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=afddc02d-fa96-4793-bc60-6c81629d8d5b@redhat.com \
    --to=longman@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=cobechen@zhaoxin.com \
    --cc=jiangbowang@zhaoxin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=louisqi@zhaoxin.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ubizjak@gmail.com \
    --cc=will@kernel.org \
    --cc=yongli-oc@zhaoxin.com \
    --cc=yongli@zhaoxin.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

all inboxes | Powered by JetHome®