lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Fri, 18 Oct 2019 17:55:01 -0400
From:   Waiman Long <longman@...hat.com>
To:     Alex Kogan <alex.kogan@...cle.com>
Cc:     linux@...linux.org.uk, Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Will Deacon <will.deacon@....com>,
        Arnd Bergmann <arnd@...db.de>, linux-arch@...r.kernel.org,
        linux-arm-kernel <linux-arm-kernel@...ts.infradead.org>,
        linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
        Borislav Petkov <bp@...en8.de>, hpa@...or.com, x86@...nel.org,
        Hanjun Guo <guohanjun@...wei.com>,
        Jan Glauber <jglauber@...vell.com>,
        Steven Sistare <steven.sistare@...cle.com>,
        Daniel Jordan <daniel.m.jordan@...cle.com>,
        dave.dice@...cle.com, Rahul Yadav <rahul.x.yadav@...cle.com>
Subject: Re: [PATCH v5 3/5] locking/qspinlock: Introduce CNA into the slow
 path of qspinlock

On 10/18/19 5:37 PM, Alex Kogan wrote:
>> On Oct 18, 2019, at 12:03 PM, Waiman Long <longman@...hat.com> wrote:
>>
>> On 10/16/19 12:29 AM, Alex Kogan wrote:
>>> +static inline void cna_pass_lock(struct mcs_spinlock *node,
>>> +				 struct mcs_spinlock *next)
>>> +{
>>> +	struct cna_node *cn = (struct cna_node *)node;
>>> +	struct mcs_spinlock *next_holder = next, *tail_2nd;
>>> +	u32 val = 1;
>>> +
>>> +	u32 scan = cn->pre_scan_result;
>>> +
>>> +	/*
>>> +	 * check if a successor from the same numa node has not been found in
>>> +	 * pre-scan, and if so, try to find it in post-scan starting from the
>>> +	 * node where pre-scan stopped (stored in @pre_scan_result)
>>> +	 */
>>> +	if (scan > 0)
>>> +		scan = cna_scan_main_queue(node, decode_tail(scan));
>>> +
>>> +	if (!scan) { /* if found a successor from the same numa node */
>>> +		next_holder = node->next;
>>> +		/*
>>> +		 * make sure @val gets 1 if current holder's @locked is 0 as
>>> +		 * we have to store a non-zero value in successor's @locked
>>> +		 * to pass the lock
>>> +		 */
>>> +		val = node->locked + (node->locked == 0);
>> node->locked can be 0 when the cpu enters into an empty MCS queue. We
>> could unconditionally set node->locked to 1 for this case in qspinlock.c
>> or with your above code.
> Right, I was doing that in the first two versions of the series. It adds 
> unnecessary store into @locked for non-CNA variants, and even if it does not
> have any real performance implications, I think Peter did not like that (or, 
> at least, the comment I had to explain why we needed that store).
>
>> Perhaps, a comment about when node->locked will
>> be 0.
> Yeah, I was tinkering with this comment. Here is how it read in v3:
> /*
>  * We unlock a successor by passing a non-zero value,
>  * so set @val to 1 iff @locked is 0, which will happen
>  * if we acquired the MCS lock when its queue was empty
>  */
>
> I can change back to something like that if it is better.
That looks OK.
>> It may be easier to understand if you just do
>>
>>     val = node->locked ? node->locked : 1;
> You’re right, that’s another possibility.
> However, it adds yet another if-statement on the critical path, which I was
> trying to avoid that.

Have you compared the generated assembly code if one is better than the
other? I am OK with whatever one generates a better code, but often time
cmove is used for ?: statements. If the same code is generated, I will
prefer an easier to understand statement.

Cheers,
Longman


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ