Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932088AbaLAN6j (ORCPT ); Mon, 1 Dec 2014 08:58:39 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:40590 "EHLO e06smtp17.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753538AbaLAN6i (ORCPT ); Mon, 1 Dec 2014 08:58:38 -0500 Date: Mon, 1 Dec 2014 14:58:30 +0100 From: Martin Schwidefsky To: Heiko Carstens Cc: Frederic Weisbecker , LKML , Tony Luck , Peter Zijlstra , Benjamin Herrenschmidt , Thomas Gleixner , Oleg Nesterov , Paul Mackerras , Wu Fengguang , Ingo Molnar , Rik van Riel Subject: Re: [RFC PATCH 06/30] s390: Introduce cputime64_to_nsecs() Message-ID: <20141201145830.24d3e43e@mschwide> In-Reply-To: <20141201122452.GE4074@osiris> References: <1417199040-21044-1-git-send-email-fweisbec@gmail.com> <1417199040-21044-7-git-send-email-fweisbec@gmail.com> <20141201122452.GE4074@osiris> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14120113-0029-0000-0000-000001F5B70C Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 1 Dec 2014 13:24:52 +0100 Heiko Carstens wrote: > On Fri, Nov 28, 2014 at 07:23:36PM +0100, Frederic Weisbecker wrote: > > This will be needed for the conversion of kernel stat to nsecs. > > > > Cc: Benjamin Herrenschmidt > > Cc: Heiko Carstens > > Cc: Ingo Molnar > > Cc: Martin Schwidefsky > > Cc: Oleg Nesterov > > Cc: Paul Mackerras > > Cc: Peter Zijlstra > > Cc: Rik van Riel > > Cc: Thomas Gleixner > > Cc: Tony Luck > > Cc: Wu Fengguang > > Signed-off-by: Frederic Weisbecker > > --- > > arch/s390/include/asm/cputime.h | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h > > index 820b38a..75ba96f 100644 > > --- a/arch/s390/include/asm/cputime.h > > +++ b/arch/s390/include/asm/cputime.h > > @@ -59,6 +59,11 @@ static inline cputime64_t jiffies64_to_cputime64(const u64 jif) > > return (__force cputime64_t)(jif * (CPUTIME_PER_SEC / HZ)); > > } > > > > +static inline u64 cputime64_to_nsecs(cputime64_t cputime) > > +{ > > + return (__force u64)cputime * CPUTIME_PER_USEC * NSEC_PER_USEC; > > +} > > + > > This is incorrect. You probably wanted to write something like > > return (__force u64)cputime / CPUTIME_PER_USEC * NSEC_PER_USEC; ? > > However we would still lose a lot of precision. > The correct algorithm to convert from cputime to nanoseconds can be found in > tod_to_ns() - see arch/s390/include/asm/timex.h > > And if you see that rather complex algorithm, I doubt we want to have the > changes you propose. We need to have that calculation three times for each > irq (user, system and steal time) and would still have worse precision than > we have right now. Not talking about the additional wasted cpu cycles... > > But I guess Martin wanted to comment on your patches anyway ;) The function that gets called most often is the accounting code for irq_enter and irq_exit. Both are mapped to vtime_account_irq_enter, with the correct implementation for the cputime_to_nsec the function gets 15 instructions longer. The relevant code sequence Upstream code: 10592e: e3 10 02 e8 00 04 lg %r1,744 105934: b2 09 f0 a0 stpt 160(%r15) 105938: e3 30 f0 a0 00 04 lg %r3,160(%r15) 10593e: e3 10 02 d8 00 08 ag %r1,728 105944: e3 30 02 e8 00 24 stg %r3,744 10594a: b9 09 00 13 sgr %r1,%r3 10594e: e3 10 02 d8 00 24 stg %r1,728 105954: b9 04 00 41 lgr %r4,%r1 105958: e3 40 c0 68 00 09 sg %r4,104(%r12) 10595e: e3 30 02 e0 00 04 lg %r3,736 105964: b9 09 00 34 sgr %r3,%r4 105968: b9 04 00 54 lgr %r5,%r4 10596c: e3 30 02 e0 00 24 stg %r3,736 105972: a7 39 00 00 lghi %r3,0 105976: e3 10 c0 68 00 24 stg %r1,104(%r12) 10597c: b9 04 00 b4 lgr %r11,%r4 105980: c0 e5 00 03 78 4c brasl %r14,174a18