From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752584AbcGOG2V (ORCPT ); Fri, 15 Jul 2016 02:28:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53118 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbcGOG2T (ORCPT ); Fri, 15 Jul 2016 02:28:19 -0400 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: xinhui@linux.vnet.ibm.com Subject: Re: [PATCH v3] locking/qrwlock: Let qrwlock has same layout regardless of the endian To: Peter Zijlstra , xinhui References: <1466403652-2931-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> <20160713195423.GD30921@twins.programming.kicks-ass.net> <578742EA.7060108@linux.vnet.ibm.com> <20160714093733.GF30909@twins.programming.kicks-ass.net> Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, mingo@redhat.com, arnd@arndb.de, Waiman.Long@hpe.com From: panxinhui Date: Fri, 15 Jul 2016 14:28:29 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160714093733.GF30909@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16071506-0028-0000-0000-0000052B9A55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16071506-0029-0000-0000-00002D8996F8 Message-Id: <51cf6c4c-3626-c03d-a88a-955e14c6a4e5@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-15_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607150073 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 16/7/14 17:37, Peter Zijlstra 写道: > On Thu, Jul 14, 2016 at 03:44:42PM +0800, xinhui wrote: >>> OK, so I poked at this a bit and I ended up with the below; but now >>> qrwlock and qspinlock are inconsistent; although I suspect qspinlock is >>> similarly busted wrt endian muck. >>> >>> Not sure what to do.. >>> >> Lets talk about the qspinlock. >> >> for x86, We has already assumed that ->locked sit at the low 8 bits, as is >> smp_store_release((u8 *)lock, 0); > > Right, true on x86 though :-) I noticed your PPC patches have a +3 in > there conditional on __BIG_ENDIAN. > >> Then we can do a favor, export ->locked but other fields as reserved. >> say >> >> struct __qspinlock_unlcok_interface {/* what name is better?*/ >> #ifdef __LITTLE_ENDIAN >> u8 locked; >> u8 reserved[3]; /* do not touch it, internally use only */ >> #else >> u8 reserved[3]; >> u8 locked; >> #endif >> }; > > Right, maybe, although something like: > > static inline u8 *__qspinlock_lock_byte(struct qspinlock *lock) > { > return (u8 *)lock + 3 * IS_BUILTIN(__BIG_ENDIAN); > } > > static inline u8 *__qrwlock_write_byte(struct qrwlock *lock) > { > return (u8 *)lock + 3 * IS_BUILTIN(__BIG_ENDIAN); > } > > is shorter? > yes, looks simpler. I will take them into my patch. thanks > >>> /* >>> + * Writer states & reader shift and bias. >>> + * >>> + * | +0 | +1 | +2 | +3 | >>> + * ----+----+----+----+----+ >>> + * LE | 12 | 34 | 56 | 78 | 0x12345678 >>> + * ----+----+----+----+----+ >>> + * BE | 78 | 56 | 34 | 12 | 0x12345678 >>> + * ----+----+----+----+----+ >>> + * | wr | rd | >>> + * +----+----+----+----+ >>> + * >>> */ >> >> very clearly. :) > > I did one for the qspinlock code too.. > hmm, pretty nice, I think I can include them into my patch too while I am at it. thanks xinhui > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index b2caec7315af..9191dc454e96 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -120,6 +120,23 @@ static inline __pure struct mcs_spinlock *decode_tail(u32 tail) > * > * This internal structure is also used by the set_locked function which > * is not restricted to _Q_PENDING_BITS == 8. > + * > + * | +0 | +1 | +2 | +3 | > + * ----+----+----+----+----+ > + * LE | 78 | 56 | 34 | 12 | val = 0x12345678 > + * ----+----+----+----+----+ > + * LE | 34 | 12 | locked_pending = 0x1234 > + * ----+----+----+----+----+ > + * | L | P | tail | > + * +----+----+----+----+ > + * > + * ----+----+----+----+----+ > + * BE | 12 | 34 | 56 | 78 | val = 0x12345678 > + * ----+----+----+----+----+ > + * BE | 12 | 34 | locked_pending = 0x1234 > + * ----+----+----+----+----+ > + * | tail | P | L | > + * +----+----+----+----+ > */ > struct __qspinlock { > union { >