Received: by 10.223.176.5 with SMTP id f5csp3920420wra; Mon, 29 Jan 2018 22:38:39 -0800 (PST) X-Google-Smtp-Source: AH8x225u2muVAxkfW82VHlZlHPFv99HJgi6/jyQ3HYqqn1OZYKpyKHJpGooVXMAeRRhsvgz3nKBd X-Received: by 2002:a17:902:ab93:: with SMTP id f19-v6mr24711148plr.10.1517294319484; Mon, 29 Jan 2018 22:38:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517294319; cv=none; d=google.com; s=arc-20160816; b=nMHyu/y2GgX1UOV1zWeWek6rVrqhjhW834Mtyjr7BZhPPY62165z3auOeQ1GPG2b25 6K2T2mo7iEQH0NudqYJxaZ5C6fe48oGbx1zAaD2phRmfowTHg373bB0JMiYFvDlj6DZx 8TEvDGk6HMYMknGvive3U6vYBQ6rouu92V3qZVpv9NX2CaN1vFk0ywQeUTspWH9SO8Cn suo7dMP2jmF1Ci0cL3cRUpqXw06gPam99EZdOPf1blN17jWzSeqvhmvq6rAkhlCJzYBt Y9BW8s4x72G91lF4NEJLdpdA8mMUsOWeI++vs86iCQjWgGfr+THCxi0+c4O6sIg7tqe4 WWaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ovvp/mUBu2awkR6lpHIXWjMWlRNt+CHXQemiRPstzn8=; b=OF9Cbe9VRTM4v/CyQ1w70um5f0ajXvkzqukpBQzyDwGHoQ7jpDqi73Ge81fW7HIt00 C7rmanQoX+jzawN3Caoz73nesRr1J1LANNLRhi5qDp0RMyipZmkW8glRHDwE+TQhs//d tRRAUzNjFR8BJL58ClmFJdibfrDQ9tLAQqGiUQlR70mFYgHJgE4rsRJm/u9xXGPM5QU/ QIQys+S12BJGvuIV1mLchcocgWaxCOgNaPR3jm2fUSf3AB4f4Rv3xohKj7U7K1r5TCTS uRPOVdSdKZj2nRWI/iBRk3HTtg8v7dCQGeoxviAFE2mjD3s+UqN13Q3atlMYZJFXRzc/ I2Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PfADxPOs; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t190si1081004pgb.190.2018.01.29.22.38.23; Mon, 29 Jan 2018 22:38:39 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PfADxPOs; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751573AbeA3GiB (ORCPT + 99 others); Tue, 30 Jan 2018 01:38:01 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54702 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751360AbeA3Gh7 (ORCPT ); Tue, 30 Jan 2018 01:37:59 -0500 Received: by mail-wm0-f66.google.com with SMTP id i186so18785806wmi.4 for ; Mon, 29 Jan 2018 22:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ovvp/mUBu2awkR6lpHIXWjMWlRNt+CHXQemiRPstzn8=; b=PfADxPOso9VffAAKr6t4Qb2xO+Aqkg9yTi5B7rI9c5JhCYIWXQMmzSL5FRS9NnZvts pKhMxwmnaKIaAztwuUaqPfkT41V6CYmm/47gJvnr+yuBjlt4xIdIw+8h7OJe+HUAUzrE f3hTh6Ab0YZq8QSiTXjvStkW+/XwLOSfTeTDBm5ZBstg8GX8cGF8p+QIr10Xxfz5r+kE 9AqnqaE3mL5z+j+EiFPtbDleN8lU3L/uwN8bFxhZ85P+IFcSODTz1QHbUTBZJxMTOnp0 oL1tPaeyuEZDOyTMf78PKBTq6zVs/DB+Xfqcr/D5tOccLT8/IEiJcvbadwK33bB7fMQW jxlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ovvp/mUBu2awkR6lpHIXWjMWlRNt+CHXQemiRPstzn8=; b=I0NZiL0XJ3/SXpXKfupKjbW60bocJx1m/nuDpPbyehqGXItZcwfngXiFbfEoZk+duz dauCQsp21ofJHK3WwUPXW8jWsIWQWUjVwpYPHFYqth+JC7zkxmrZPfz3mbXC4SDNsP37 tAF4QcuzcSinA6NEMoCUN7IEn5bFhu6Vi3TcZQqS+6It+vl7ifmggzuiF6eaDLaHrIlo yTBKlouzRwBoJrbqAGUgPmKYMjpSKasgDpzUAiFJC1EqIMAFBT/I6Jqe7/5XfomEoxUr /KSJkrk1WSzPFVtfSAdIbkcAtBnEtLkuMY/SpyD93KtH65qWHd+zaKl8bwFqiSbXhWL1 lHQg== X-Gm-Message-State: AKwxytfEmc/7X3gM/hqSjRauVBbqh27IyM8d1GydAj/rh8OWUtRLzNDb OjzgOGt5Mw0WsTgBwA3O2Mg= X-Received: by 10.80.152.68 with SMTP id h4mr50003978edb.23.1517294278314; Mon, 29 Jan 2018 22:37:58 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id e13sm168503eda.24.2018.01.29.22.37.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2018 22:37:57 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 1AEF2211CB; Tue, 30 Jan 2018 01:37:55 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Tue, 30 Jan 2018 01:37:55 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 959D57E4FC; Tue, 30 Jan 2018 01:37:52 -0500 (EST) Date: Tue, 30 Jan 2018 14:40:57 +0800 From: Boqun Feng To: "zhangheng (AC)" Cc: "Paul E. McKenney" , "lianglihao@huawei.com" , "Guohanjun (Hanjun Guo)" , "Chenhaibo (Haibo, OS Lab)" , "lihao.liang@gmail.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH RFC 01/16] prcu: Add PRCU implementation Message-ID: <20180130064057.bzswn6qkz2wlv776@tardis> References: <1516694381-20333-1-git-send-email-lianglihao@huawei.com> <1516694381-20333-2-git-send-email-lianglihao@huawei.com> <20180125061618.GU3741@linux.vnet.ibm.com> <20180125073033.4rl7bun62newplb3@tardis> <3FF961283AE1E144A2F945F1AD5573FD014DF00C@dggeml508-mbx.china.huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jnryumahsnq5dvay" Content-Disposition: inline In-Reply-To: <3FF961283AE1E144A2F945F1AD5573FD014DF00C@dggeml508-mbx.china.huawei.com> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --jnryumahsnq5dvay Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 30, 2018 at 05:34:03AM +0000, zhangheng (AC) wrote: [...] > >> > +static void prcu_handler(void *info) { > >> > + struct prcu_local_struct *local; > >> > + > >> > + local =3D this_cpu_ptr(&prcu_local); > >> > + if (!local->locked) > > > >And I think a smp_mb() is needed here, because in the following case: > > > > CPU 0 CPU 1 > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > {X is initially 0} > > > > WRITE_ONCE(X, 1); > > > > prcu_read_unlock(void): > > if (locked) { > > synchronize_prcu(void): > > ... > > > > local->locked--; > > # switch to IPI > > WRITE_ONCE(local->version,....) > > > > > > > > r1 =3D READ_ONCE(X); > > > >r1 could be 0, which breaks RCU guarantees. > > >=20 > Thank you. > As I know, > it guarantees that the interrupt to be handled after all write instructio= ns issued before have complete in x86 arch. > So the smp_mb is meaningless in x86 arch. Sure. x86 is TSO, and we are talking about reordering of two stores here, and that can not happen on TSO. > But I am not sure whether other archs guarantee this feature. If not, we = do need a smp_mb here. >=20 I think most of the weak memory model don't have this gaurantee, so you need a smp_mb() or use smp_store_release(). > >> > + WRITE_ONCE(local->version, atomic64_read(&prcu->global_version)); > >> > +} > >> > + > >> > +void synchronize_prcu(void) > >> > +{ > >> > + int cpu; > >> > + cpumask_t cpus; > >> > + unsigned long long version; > >> > + struct prcu_local_struct *local; > >> > + > >> > + version =3D atomic64_add_return(1, &prcu->global_version); > >> > + mutex_lock(&prcu->mtx); > >> > + > >> > + local =3D get_cpu_ptr(&prcu_local); > >> > + local->version =3D version; > >> > + put_cpu_ptr(&prcu_local); > >> > + > >> > + cpumask_clear(&cpus); > >> > + for_each_possible_cpu(cpu) { > >> > + local =3D per_cpu_ptr(&prcu_local, cpu); > >> > + if (!READ_ONCE(local->online)) > >> > + continue; > >> > + if (READ_ONCE(local->version) < version) { > >>=20 > >> On 32-bit systems, given that ->version is long long, you might see=20 > >> load tearing. And on some 32-bit systems, the cmpxchg() in=20 > >> prcu_hander() might not build. > >>=20 > > > >/me curious about why an atomic64_t is used here for global version. I t= hink maybe 32bit global version still suffices. > > > >Regards, > >Boqun >=20 > Because the synchronization latency is low, it can have higher gp frequen= cy. > It seems that 32bit can only correctly work for several years if there ar= e 20+ gps per second. >=20 Because PRCU doesn't handle gp number overflow? May I ask why this is difficult? Currently RCU could tolerate counter wrap for grace period: https://lwn.net/Articles/652677/ (Details in "Parallelism facts of life") Is there any subtle difference I'm missing? Regards, Boqun > > > >> Or is the idea that only prcu_handler() updates ->version? But in=20 > >> that case, you wouldn't need the READ_ONCE() above. What am I missing= here? > >>=20 > >> > + smp_call_function_single(cpu, prcu_handler, NULL, 0); > >> > + cpumask_set_cpu(cpu, &cpus); > >> > + } > >> > + } > >> > + > >> > + for_each_cpu(cpu, &cpus) { > >> > + local =3D per_cpu_ptr(&prcu_local, cpu); > >> > + while (READ_ONCE(local->version) < version) > >>=20 > >> This ->version read can also tear on some 32-bit systems, and this one= =20 > >> most definitely can race with the prcu_handler() above. Does the=20 > >> algorithm operate correctly in that case? (It doesn't look that way= =20 > >> to me, but I might be missing something.) Or are 32-bit systems exclud= ed? > >>=20 > >> > + cpu_relax(); > >> > + } > >>=20 > >> I might be missing something, but I believe we need a memory barrier= =20 > >> here on non-TSO systems. Without that, couldn't we miss a preemption? > >>=20 > >> > + > >> > + if (atomic_read(&prcu->active_ctr)) > >> > + wait_event(prcu->wait_q, !atomic_read(&prcu->active_ctr)); > >> > + > >> > + mutex_unlock(&prcu->mtx); > >> > +} > >> > +EXPORT_SYMBOL(synchronize_prcu); > >> > + > >> > +void prcu_note_context_switch(void) { > >> > + struct prcu_local_struct *local; > >> > + > >> > + local =3D get_cpu_ptr(&prcu_local); > >> > + if (local->locked) { > >> > + atomic_add(local->locked, &prcu->active_ctr); > >> > + local->locked =3D 0; > >> > + } > >> > + local->online =3D 0; > >> > + prcu_report(local); > >> > + put_cpu_ptr(&prcu_local); > >> > +} > >> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c index=20 > >> > 326d4f88..a308581b 100644 > >> > --- a/kernel/sched/core.c > >> > +++ b/kernel/sched/core.c > >> > @@ -15,6 +15,7 @@ > >> > #include > >> > #include #include=20 > >> > > >> > +#include > >> >=20 > >> > #include > >> > #include > >> > @@ -3383,6 +3384,7 @@ static void __sched notrace __schedule(bool=20 > >> > preempt) > >> >=20 > >> > local_irq_disable(); > >> > rcu_note_context_switch(preempt); > >> > + prcu_note_context_switch(); > >> >=20 > >> > /* > >> > * Make sure that signal_pending_state()->signal_pending() below > >> > -- > >> > 2.14.1.729.g59c0ea183 > >> >=20 > >>=20 > > --jnryumahsnq5dvay Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlpwE3UACgkQSXnow7UH +rgmcgf/dzKriuS+fPJvSeNfsrZmNzWLS4r816k0lEvUweRDO7bp9PLfQWS4i0IZ tKdyO9Rubv1RVcWDlqbrGJ6bzgWMqe7GVEhZod6NJRbDg7gDynzmg2MsgzP9uxfA CRH+MjlrGBA7tliU/CRe0nO5AcCFKGxZVmje8vIAmO8b0YSxgMEc3stpJzi5hR1Y WMrwSQmh3BRRmndz8uNcXdzKRIrVwXaONgbWWp0F9TBRsL5+EOsBPqKxo0q2olBy mRDXV3imok2644wQvSy/6NqYsk/rHYxJLkOnv+lXGqzK6mNN+q7uT0JoSGjtQ2Tq 4UAkae88YA97TcKLTPrFR675o/doJw== =2X81 -----END PGP SIGNATURE----- --jnryumahsnq5dvay--