Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp213107imm; Wed, 4 Jul 2018 22:04:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc+vrb9xZjQo3aaWi0BZbObLnfwJtVSreBD3ZJHq/2a0hDMXbzR1R0FimH3TQoxFC8o2Q5n X-Received: by 2002:a63:a5c:: with SMTP id z28-v6mr4140592pgk.209.1530767056204; Wed, 04 Jul 2018 22:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530767056; cv=none; d=google.com; s=arc-20160816; b=kG2WmEQbVfw7zTIU2pRoMmgEyAwINDHmQpc8/aZJuU86dDhoH4vuk6N7OeBJAVyFHE Rfy/Ba3+ZNmqgT60iynm35XZI6JdeNcuxQnNXP7OHPG1BkJ1UPBr746dHO6lgDgo7DdH QQDQ0R1HS7fl2pevgSnqLjoBiEtUliaQvdkFJvPRjOIT2hJKczJrU6rsyTj70gh1JBtD HoSt/sFAvOtzJVrLaGfjMimbl//S7p1iSKDJ9WooxvzEntFfGbyoWnNMANc+5Q4iud6Z WuI1uSwDX4fVB3+kAyW5ZhGdMqJEZyAMjEKNrAmTKSJ0j+eW9UUHFzKalzLwszRf92X8 yoyg== 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:arc-authentication-results; bh=prLMKByhzn3YNNq0iRzWyl218UJuTSF420FsXAmZIHA=; b=NT5lDunLggYz859NM6rVRrG9zlwXJ3n4uvjH7+Vr0xyPUR7sIVOEhRjnfNeZ3p6r78 YWdfhyWC+9jsu8GJjCbK1C8BNoWpNv9K31naFvSW9aVwhssoZo28pG7rnzJrbPaUTxQf eiz3X0H5ooJgh7tj9nUGeDWacQo61DCGWoqztRMx/PqI+yN4SCVix9gJFJrl8OtX4Xbw z2KOttPYf/l7v1986EbdSjizeQVANoe14NjJlCev1uU2+DFebsvCxKCZdp7/w+UqkGUe bT8FofY/TEoebmK9glG9qziawwOJO1o9q3OzE58Jh2Cm1+XyWNIQDCjrMZ6oN0Fv25dA DjMQ== 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 u35-v6si3989163pgl.237.2018.07.04.22.04.01; Wed, 04 Jul 2018 22:04:16 -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 S1752696AbeGEFDZ (ORCPT + 99 others); Thu, 5 Jul 2018 01:03:25 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:53597 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750854AbeGEFDY (ORCPT ); Thu, 5 Jul 2018 01:03:24 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07753187|-1;CH=green;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03296;MF=ren_guo@c-sky.com;NM=1;PH=DS;RN=11;RT=11;SR=0;TI=SMTPD_---.CMUNGGG_1530766992; Received: from localhost(mailfrom:ren_guo@c-sky.com fp:SMTPD_---.CMUNGGG_1530766992) by smtp.aliyun-inc.com(10.147.42.16); Thu, 05 Jul 2018 13:03:12 +0800 Date: Thu, 5 Jul 2018 13:03:12 +0800 From: Guo Ren To: Thomas Gleixner Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, jason@lakedaemon.net, arnd@arndb.de, c-sky_gcc_upstream@c-sky.com, gnu-csky@mentor.com, thomas.petazzoni@bootlin.com, wbx@uclibc-ng.org, green.hu@gmail.com Subject: Re: [PATCH V2 18/19] clocksource: add C-SKY clocksource drivers Message-ID: <20180705050311.GA20088@guoren> References: <20180704104957.GB23536@guoren> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Jul 04, 2018 at 04:35:43PM +0200, Thomas Gleixner wrote: > On Wed, 4 Jul 2018, Guo Ren wrote: > > On Tue, Jul 03, 2018 at 11:39:05AM +0200, Thomas Gleixner wrote: > > > > +static inline u64 get_ccvr(void) > > > > +{ > > > > + u32 lo, hi, t; > > > > + > > > > + do { > > > > + hi = mfcr(PTIM_CCVR_HI); > > > > + lo = mfcr(PTIM_CCVR_LO); > > > > + t = mfcr(PTIM_CCVR_HI); > > > > + } while(t != hi); > > > > > > No idea which frequency this timer ticks at, but if the 32 bit wrap does > > > not come too fast, then you really should avoid that loop. That function is > > > called very frequently. > > > > 0000006c : > > hi = mfcr(PTIM_CCVR_HI); > > 6c: c1c26023 mfcr r3, cr<2, 14> > > lo = mfcr(PTIM_CCVR_LO); > > 70: c1c36021 mfcr r1, cr<3, 14> > > t = mfcr(PTIM_CCVR_HI); > > 74: c1c26022 mfcr r2, cr<2, 14> > > } while(t != hi); > > 78: 648e cmpne r3, r2 > > 7a: 0bf9 bt 0x6c // 6c > > > > When two read cr<2, 14> is not equal, we'll retry. So only when > > CCVR_LO is at 0xffffffff between the two read of CCVR_HI. That's very > > very small probability event for "bt 0x6c". > > > > Don't worry about the "do {...} whie(t != hi)", it's no performance issue. > > But _three_ mfcr plus a conditional jump which _cannot_ be predicted are a > performance issue. When you can replace that with a single mfcr, then you > win a lot, really. The time keeping and the sched clock code can handle > that nicely unless you really have fast wrap arounds on the LO word. Timer's frequency is about 50Mhz-100Mhz and LO word wrap arounds timer is about 42s ~ 84s. Our Branch prediction buffer will let the CPU speculative execute continually. So the "bt" won't be the performance issue. And I could modify it like this: static inline u64 get_ccvr(void) { u32 lo, hi, t; t = mfcr(PTIM_CCVR_LO); hi = mfcr(PTIM_CCVR_HI); lo = mfcr(PTIM_CCVR_LO); if (lo < t) hi++; return ((u64)hi << 32) | lo; } t = mfcr(PTIM_CCVR_LO); 50: c1c36023 mfcr r3, cr<3, 14> hi = mfcr(PTIM_CCVR_HI); 54: c1c26021 mfcr r1, cr<2, 14> lo = mfcr(PTIM_CCVR_LO); 58: c1c3602c mfcr r12, cr<3, 14> if (lo < t) hi++; 5c: 64f0 cmphs r12, r3 5e: c4210c21 incf r1, r1, 1 return ((u64)hi << 32) | lo; 62: 3200 movi r2, 0 Hmm? (No jump at all) Guo Ren