Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1781529ybg; Sat, 19 Oct 2019 02:22:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7W4bYrOtczQwyRxEHZ6pnqBj97lqaOYn+AlisUN7lb+Z/iaT9qZhE8E6xHj4E2///QNkR X-Received: by 2002:a17:906:7e50:: with SMTP id z16mr1182310ejr.130.1571476962626; Sat, 19 Oct 2019 02:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571476962; cv=none; d=google.com; s=arc-20160816; b=CbEeuXKmBYEP+tW2UnQ2my63Jrxyg2sBiLIyArC3uvfVoddpRaUiTEQ4QwZneiaR9V RUz2avX45wzhcS44H/gfcekJeHMp31d32OJ52F4sWDadlhjQjWL7xFSp0lzD+l8PinIg 7x2qyEN6YoHlZ855bIFW86ErEhZjbMF8OHzwgMt+TJlGd7YHA0xaVjClK3l+0Py+LJB6 q7CT8b2YdSXmYWfxjb15jRWymbjrsuMjXkWklHvfPl7gd1H8sOrPEjbUwH9Aaj0uu6TS xoXfwVdGHbBm0J2xZEI1IdeSRcq/rTGMeDX072SipZWZZdKByFXVR1A5Kj14+cb1uePW hBbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=5W1zd7nq65vk8CdakBav75MumlQjhdBLEL0qVBi/lR0=; b=V70g/5v9/4qm9jGtTA9jLTzEwBuNm6p326IJYN7w9wysJFaIjMDNf87rLZJ0q2GvCI 2HX/xAZ7QUL4ruvqgDIUYDyrQ5j4mtt0jHFmWB1c1IrDlQiptxfdihXVJGDAxpwqBNmz 9SJST9js60dsGrKDMDSsx8vJnBAHhS9M1alNgPJyyTfI27fsbGy1OjGexELtFuA+GyPr MB4E5eYCq680XMBu6JA58ssvsHOS9wdBz717fnSKwgSa2vlW0FJbWmDZz5uRt+HiGOiE vuLwVmdnC0rhco4lWE2uDIa2KsUstPUYhyWM+6mLFzbGgXby+RmBo3t3lpmueUZWZvhq G1fA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26si5141461ejb.6.2019.10.19.02.22.19; Sat, 19 Oct 2019 02:22:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440529AbfJRVzF (ORCPT + 99 others); Fri, 18 Oct 2019 17:55:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40610 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394243AbfJRVzF (ORCPT ); Fri, 18 Oct 2019 17:55:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B51D307C65B; Fri, 18 Oct 2019 21:55:04 +0000 (UTC) Received: from llong.remote.csb (ovpn-120-190.rdu2.redhat.com [10.10.120.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5E5A5D713; Fri, 18 Oct 2019 21:55:01 +0000 (UTC) Subject: Re: [PATCH v5 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock To: Alex Kogan Cc: linux@armlinux.org.uk, Peter Zijlstra , Ingo Molnar , Will Deacon , Arnd Bergmann , linux-arch@vger.kernel.org, linux-arm-kernel , linux-kernel@vger.kernel.org, Thomas Gleixner , Borislav Petkov , hpa@zytor.com, x86@kernel.org, Hanjun Guo , Jan Glauber , Steven Sistare , Daniel Jordan , dave.dice@oracle.com, Rahul Yadav References: <20191016042903.61081-1-alex.kogan@oracle.com> <20191016042903.61081-4-alex.kogan@oracle.com> <6ce50aeb-6b87-5d1c-9011-4329e8dadfec@redhat.com> <1B59E517-D418-46DF-BC58-174BAFC5EC23@oracle.com> From: Waiman Long Organization: Red Hat Message-ID: <3b8afb53-18e8-bd1d-9def-e1e7bdc73087@redhat.com> Date: Fri, 18 Oct 2019 17:55:01 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1B59E517-D418-46DF-BC58-174BAFC5EC23@oracle.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 18 Oct 2019 21:55:04 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/18/19 5:37 PM, Alex Kogan wrote: >> On Oct 18, 2019, at 12:03 PM, Waiman Long 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