Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1577833imm; Wed, 26 Sep 2018 22:08:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ry8JhtzKFZshsjPicCOYj6RPnhJ8L+UG8zGLFrZpzojewV80Pl6Sz0ufI96+MQkH0a+ui X-Received: by 2002:a17:902:a413:: with SMTP id p19-v6mr8992621plq.220.1538024916298; Wed, 26 Sep 2018 22:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538024916; cv=none; d=google.com; s=arc-20160816; b=iF1By/8Y7l/sMYmaO4w7WVvd7LqC5a08DNO18LmBOdxiGHPjrEgEuMe9TSWYZUG0Uq wszBRvMBk079fxis19d3timq5+rWhcQRU9goSFWH7M6IUlawbMDuoHstHwY7DZ3nQpf+ Rs+FKbrA/qnW9Myq24R8d1cpyLo6fFJmXT0ctDHiuYdI7WDhPHEz1Q7sChWs9N1OpNmn A+rb68fryeU2w9Bc87zpJKWD5MFYmiVA5uY+728oFQEbY5JLx50nzpB6/SASFRlc7t4G G/6DchsTlv6q6O3Lr3++ORc7cYDogrn5BhUx1PrEMLVxhFwG8WWXbW6jn02wSINLkK5/ zR+w== 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; bh=4Ms8QWkhZlOpHqQR6HuvzTeDy3WCJntzDlhJ1gayKt0=; b=KWQY2TEq0cOg/MeegCrvuSjBjK5dHjhO115zXmv6sFLjc1UVXjyjyTPDxIEYYdyk5H LL8T1pA5Xyqqvhb4ciSkjNWVpMckRhah51ntn0uo5gvyJ26NW+Mo3H4/gae/QFMwNdoM Ue/xmNOaqIXJKQVzUPE01FjsV76wn0baO2BCRuvzZjtpG8NQKiiQYA0SxkJjgxToZvJP i92dmdPT2UCZX/WXGQ+4mu88R6iEjthJHI23ITABIFIQmjR3z6LpCJJ3A6cGIdBeVmwn fcYZw5n6npx4bTmYGIIDFt50sz89hru9205Sukct7NyIL4KBtpPG3X5HFUC14D5uxFg3 wMlA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si1128341plv.241.2018.09.26.22.08.20; Wed, 26 Sep 2018 22:08:36 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726820AbeI0LYU (ORCPT + 99 others); Thu, 27 Sep 2018 07:24:20 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:49181 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbeI0LYU (ORCPT ); Thu, 27 Sep 2018 07:24:20 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07437524|-1;CH=green;FP=0|0|0|0|0|-1|-1|-1;HT=e01l07408;MF=ren_guo@c-sky.com;NM=1;PH=DS;RN=19;RT=19;SR=0;TI=SMTPD_---.CwOqUFU_1538024862; Received: from localhost(mailfrom:ren_guo@c-sky.com fp:SMTPD_---.CwOqUFU_1538024862) by smtp.aliyun-inc.com(10.147.40.44); Thu, 27 Sep 2018 13:07:42 +0800 Date: Thu, 27 Sep 2018 13:07:42 +0800 From: Guo Ren To: Peter Zijlstra Cc: Andrea Parri , akpm@linux-foundation.org, arnd@arndb.de, daniel.lezcano@linaro.org, davem@davemloft.net, gregkh@linuxfoundation.org, jason@lakedaemon.net, marc.zyngier@arm.com, mark.rutland@arm.com, mchehab+samsung@kernel.org, robh@kernel.org, robh+dt@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, devicetree@vger.kernel.org, green.hu@gmail.com, palmer@sifive.com Subject: Re: [PATCH V5 17/30] csky: Misc headers Message-ID: <20180927050739.GA27703@guoren> References: <5ae1990e1863fe2293bba1e5ec0408892a9a7f0c.1537789737.git.ren_guo@c-sky.com> <20180925100803.GA6891@andrea> <20180925104541.GA27311@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180925104541.GA27311@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 25, 2018 at 12:45:41PM +0200, Peter Zijlstra wrote: > On Tue, Sep 25, 2018 at 12:08:03PM +0200, Andrea Parri wrote: > > Hi Guo, > > > > > +/* > > > + * set_bit - Atomically set a bit in memory > > > + * @nr: the bit to set > > > + * @addr: the address to start counting from > > > + * > > > + * This function is atomic and may not be reordered. See __set_bit() > > > + * if you do not require the atomic guarantees. > > > + * > > > + * Note: there are no guarantees that this function will not be reordered > > > + * on non x86 architectures, so if you are writing portable code, > > > + * make sure not to rely on its reordering guarantees. > > > + * > > > + * Note that @nr may be almost arbitrarily large; this function is not > > > + * restricted to acting on a single-word quantity. > > > + */ > > > +static inline void set_bit(int nr, volatile unsigned long *addr) > > > +{ > > > + unsigned long mask = BIT_MASK(nr); > > > + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); > > > + unsigned long tmp; > > > + > > > + /* *p |= mask; */ > > > + smp_mb(); > > > + asm volatile ( > > > + "1: ldex.w %0, (%2) \n" > > > + " or32 %0, %0, %1 \n" > > > + " stex.w %0, (%2) \n" > > > + " bez %0, 1b \n" > > > + : "=&r"(tmp) > > > + : "r"(mask), "r"(p) > > > + : "memory"); > > > + smp_mb(); > > > +} > > > + > > > +/** > > > + * clear_bit - Clears a bit in memory > > > + * @nr: Bit to clear > > > + * @addr: Address to start counting from > > > + * > > > + * clear_bit() is atomic and may not be reordered. However, it does > > > + * not contain a memory barrier, so if it is used for locking purposes, > > > + * you should call smp_mb__before_atomic() and/or smp_mb__after_atomic() > > > + * in order to ensure changes are visible on other processors. > > > + */ > > > +static inline void clear_bit(int nr, volatile unsigned long *addr) > > > +{ > > > + unsigned long mask = BIT_MASK(nr); > > > + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); > > > + unsigned long tmp; > > > + > > > + /* *p &= ~mask; */ > > > + mask = ~mask; > > > + smp_mb(); > > > + asm volatile ( > > > + "1: ldex.w %0, (%2) \n" > > > + " and32 %0, %0, %1 \n" > > > + " stex.w %0, (%2) \n" > > > + " bez %0, 1b \n" > > > + : "=&r"(tmp) > > > + : "r"(mask), "r"(p) > > > + : "memory"); > > > + smp_mb(); > > > +} > > > + > > > +/** > > > + * change_bit - Toggle a bit in memory > > > + * @nr: Bit to change > > > + * @addr: Address to start counting from > > > + * > > > + * change_bit() is atomic and may not be reordered. It may be > > > + * reordered on other architectures than x86. > > > + * Note that @nr may be almost arbitrarily large; this function is not > > > + * restricted to acting on a single-word quantity. > > > + */ > > > +static inline void change_bit(int nr, volatile unsigned long *addr) > > > +{ > > > + unsigned long mask = BIT_MASK(nr); > > > + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); > > > + unsigned long tmp; > > > + > > > + /* *p ^= mask; */ > > > + smp_mb(); > > > + asm volatile ( > > > + "1: ldex.w %0, (%2) \n" > > > + " xor32 %0, %0, %1 \n" > > > + " stex.w %0, (%2) \n" > > > + " bez %0, 1b \n" > > > + : "=&r"(tmp) > > > + : "r"(mask), "r"(p) > > > + : "memory"); > > > + smp_mb(); > > > +} > > > > The {set,clear,change}_bit() operations don't have to be ordered: you > > might want to remove the above smp_mb()s (and adjust the comments). I confused it with cmpxchg, seems cmpxchg need smp_mb() before&after. See: https://lkml.org/lkml/2018/7/6/383 > Better yet, you can entirely delete all that and use > asm-generic/bitops/atomic.h instead. Yes, approve. Seems I only need care about asm/atomic.h, it's good for me. Best Regards Guo Ren