public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Schwidefsky <schwidefsky@de.ibm.com>
To: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Tony Luck <tony.luck@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Oleg Nesterov <oleg@redhat.com>,
	Paul Mackerras <paulus@samba.org>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Ingo Molnar <mingo@kernel.org>, Rik van Riel <riel@redhat.com>
Subject: Re: [RFC PATCH 06/30] s390: Introduce cputime64_to_nsecs()
Date: Mon, 1 Dec 2014 14:58:30 +0100	[thread overview]
Message-ID: <20141201145830.24d3e43e@mschwide> (raw)
In-Reply-To: <20141201122452.GE4074@osiris>

On Mon, 1 Dec 2014 13:24:52 +0100
Heiko Carstens <heiko.carstens@de.ibm.com> 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 <benh@kernel.crashing.org>
> > Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> > Cc: Ingo Molnar <mingo@kernel.org>
> > Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
> > Cc: Oleg Nesterov <oleg@redhat.com>
> > Cc: Paul Mackerras <paulus@samba.org>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Rik van Riel <riel@redhat.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Tony Luck <tony.luck@intel.com>
> > Cc: Wu Fengguang <fengguang.wu@intel.com>
> > Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> > ---
> >  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 <account_system_time

Patched code:
  105a3e:       e3 50 02 e8 00 04       lg      %r5,744
  105a44:       b2 09 f0 a0             stpt    160(%r15)
  105a48:       b9 04 00 15             lgr     %r1,%r5
  105a4c:       e3 50 f0 a0 00 04       lg      %r5,160(%r15)
  105a52:       e3 50 02 e8 00 24       stg     %r5,744
  105a58:       e3 10 02 d8 00 08       ag      %r1,728
  105a5e:       b9 e9 50 51             sgrk    %r5,%r1,%r5
  105a62:       e3 00 02 e0 00 04       lg      %r0,736
  105a68:       e3 50 02 d8 00 24       stg     %r5,728
  105a6e:       b9 04 00 15             lgr     %r1,%r5
  105a72:       e3 10 a0 68 00 09       sg      %r1,104(%r10)
  105a78:       b9 04 00 e1             lgr     %r14,%r1
  105a7c:       b9 04 00 81             lgr     %r8,%r1
  105a80:       eb 11 00 20 00 0c       srlg    %r1,%r1,32
  105a86:       ec 3e 20 bf 00 55       risbg   %r3,%r14,32,191,0
  105a8c:       eb 91 00 02 00 0d       sllg    %r9,%r1,2
  105a92:       eb c3 00 07 00 0d       sllg    %r12,%r3,7
  105a98:       eb b1 00 07 00 0d       sllg    %r11,%r1,7
  105a9e:       eb 43 00 02 00 0d       sllg    %r4,%r3,2
  105aa4:       b9 09 00 b9             sgr     %r11,%r9
  105aa8:       b9 e9 40 4c             sgrk    %r4,%r12,%r4
  105aac:       b9 08 00 43             agr     %r4,%r3
  105ab0:       b9 08 00 1b             agr     %r1,%r11
  105ab4:       b9 e9 e0 30             sgrk    %r3,%r0,%r14
  105ab8:       eb 11 00 17 00 0d       sllg    %r1,%r1,23
  105abe:       e3 30 02 e0 00 24       stg     %r3,736
  105ac4:       eb 44 00 09 00 0c       srlg    %r4,%r4,9
  105aca:       e3 50 a0 68 00 24       stg     %r5,104(%r10)
  105ad0:       b9 08 00 41             agr     %r4,%r1
  105ad4:       b9 04 00 54             lgr     %r5,%r4
  105ad8:       a7 39 00 00             lghi    %r3,0
  105adc:       c0 e5 00 03 78 02       brasl   %r14,174ae0 <account_system_time

The function is called two times for each interrupt and accounts
the system time only, that makes 2 * 15 instructions more for each
interrupt, while loosing a small amount of precision. Imho not good.

The idea of cputime_t was to allow an architecture to define its preferred
format, for s390 this is a pure CPU timer delta. We do not loose *any*
precision as long as the CPU timer works correctly. From my point of view
this is a change for the worse.

On the positive side, there are some nice improvements in the patch
series. We will definitely pick up some of the patches.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


  reply	other threads:[~2014-12-01 13:58 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-28 18:23 [RFC PATCH 00/30] cputime: Convert task/cpu cputime accounting to nsecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 01/30] jiffies: Remove HZ > USEC_PER_SEC special case Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 02/30] time: Introduce jiffies64_to_nsecs() Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 03/30] cputime: Introduce nsecs_to_cputime64() Frederic Weisbecker
2014-12-01 14:05   ` Martin Schwidefsky
2014-11-28 18:23 ` [RFC PATCH 04/30] s390: Convert open coded idle time seqcount Frederic Weisbecker
2014-12-01 13:46   ` Heiko Carstens
2014-11-28 18:23 ` [RFC PATCH 05/30] s390: Translate cputime magic constants to macros Frederic Weisbecker
2014-12-01 13:47   ` Heiko Carstens
2014-12-01 16:23     ` Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 06/30] s390: Introduce cputime64_to_nsecs() Frederic Weisbecker
2014-12-01 12:24   ` Heiko Carstens
2014-12-01 13:58     ` Martin Schwidefsky [this message]
2014-12-01 16:23     ` Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 07/30] cputime: Convert kcpustat to nsecs Frederic Weisbecker
2014-12-01 14:14   ` Martin Schwidefsky
2014-12-01 16:10     ` Frederic Weisbecker
2014-12-01 16:48       ` Martin Schwidefsky
2014-12-01 17:15         ` Thomas Gleixner
2014-12-01 17:27           ` Martin Schwidefsky
2014-12-01 19:59             ` Frederic Weisbecker
2014-12-01 20:14           ` Christian Borntraeger
2014-12-01 20:21             ` Thomas Gleixner
2014-11-28 18:23 ` [RFC PATCH 08/30] apm32: Fix cputime == jiffies assumption Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 09/30] alpha: Fix jiffies based cputime assumption Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 10/30] cputime: Convert guest time accounting to nsecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 11/30] cputime: Special API to return old-typed cputime Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 12/30] cputime: Convert task/group cputime to nsecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 13/30] alpha: Convert obsolete cputime_t " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 14/30] x86: Convert obsolete cputime type " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 15/30] isdn: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 16/30] binfmt: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 17/30] acct: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 18/30] delaycct: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 19/30] tsacct: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 20/30] signal: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 21/30] cputime: Remove task_cputime_t_scaled Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 22/30] u64_stats_sync: Introduce preempt-unsafe readers Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 23/30] cputime: Convert irq_time_accounting to use u64_stats_sync Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 24/30] cputime: Increment kcpustat directly on irqtime account Frederic Weisbecker
2014-12-01 14:41   ` Martin Schwidefsky
2014-12-01 16:15     ` Frederic Weisbecker
2014-12-01 16:50       ` Martin Schwidefsky
2014-11-28 18:23 ` [RFC PATCH 25/30] cputime: Remove temporary irqtime states Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 26/30] cputime: Push time to account_user_time() in nanosecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 27/30] cputime: Push time to account_steal_time() " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 28/30] cputime: Push time to account_idle_time() " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 29/30] cputime: Push time to account_guest_time() " Frederic Weisbecker
2014-11-28 18:24 ` [RFC PATCH 30/30] cputime: Push time to account_system_time() " Frederic Weisbecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141201145830.24d3e43e@mschwide \
    --to=schwidefsky@de.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=fengguang.wu@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox