All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xie XiuQi <xiexiuqi@huawei.com>
To: Tony Luck <tony.luck@intel.com>
Cc: <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	Mauro Chehab <m.chehab@samsung.com>
Subject: Re: [PATCH] time: Provide full featured jiffies_to_nsecs() function
Date: Mon, 19 May 2014 09:28:27 +0800	[thread overview]
Message-ID: <53795E3B.9000004@huawei.com> (raw)
In-Reply-To: <0286550@agluck-desk.sc.intel.com>

On 2014/4/9 1:32, Tony Luck wrote:
> The "uptime" tracer added in:
>     commit 8aacf017b065a805d27467843490c976835eb4a5
>     tracing: Add "uptime" trace clock that uses jiffies
> has wraparound problems when the system has been up more
> than 1 hour 11 minutes and 34 seconds. It converts jiffies
> to nanoseconds using:
> 	(u64)jiffies_to_usecs(jiffy) * 1000ULL
> but since jiffies_to_usecs() only returns a 32-bit value, it
> truncates at 2^32 microseconds.  An additional problem on 32-bit
> systems is that the argument is "unsigned long", so fixing the
> return value only helps until 2^32 jiffies (49.7 days on a HZ=1000
> system).
> 
> So we provide a full featured jiffies_to_nsec() function that
> takes a "u64" argument and provides a "u64" result.  To avoid
> cries of rage from the other user of this: scheduler_tick_max_deferment()
> we check whether the argument is small enough that we can do
> the calculations in 32-bit operations.
> 
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
>  include/linux/jiffies.h    |  6 +-----
>  kernel/time.c              | 24 ++++++++++++++++++++++++
>  kernel/timeconst.bc        | 12 ++++++++++++
>  kernel/trace/trace_clock.c |  2 +-
>  4 files changed, 38 insertions(+), 6 deletions(-)
> 

[...]

> diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
> index 26dc348332b7..52470fba1d26 100644
> --- a/kernel/trace/trace_clock.c
> +++ b/kernel/trace/trace_clock.c
> @@ -65,7 +65,7 @@ u64 notrace trace_clock_jiffies(void)
>  	u64 jiffy = jiffies - INITIAL_JIFFIES;

Hi Tony and Steven,
Another problem, maybe we should use get_jiffies_64() instead of jiffies
directly here OR we'll meet wraparound problems on 32bit system. But a
same problem is that the jiffies_lock is not safe in NMI context...

>  
>  	/* Return nsecs */
> -	return (u64)jiffies_to_usecs(jiffy) * 1000ULL;
> +	return jiffies_to_nsecs(jiffy);
>  }
>  
>  /*
> 



  parent reply	other threads:[~2014-05-19  1:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-07 22:25 [RFC PATCH] time: Fix truncation in jiffies_to_usecs() Tony Luck
2014-04-08  5:34 ` Tony Luck
2014-04-08 15:27   ` Steven Rostedt
2014-04-08 17:49   ` Frederic Weisbecker
2014-04-08 18:15     ` Steven Rostedt
2014-04-08 18:56       ` Frederic Weisbecker
2014-04-08 19:34         ` Steven Rostedt
2014-04-08 17:32           ` [PATCH] time: Provide full featured jiffies_to_nsecs() function Tony Luck
2014-04-09 16:53             ` Tony Luck
2014-05-09 21:46               ` Luck, Tony
2014-05-16 14:24             ` Shy Shuky
2014-05-16 17:17               ` Luck, Tony
2014-05-16 19:02                 ` Steven Rostedt
2014-05-19  1:28             ` Xie XiuQi [this message]
2014-05-19 22:35               ` Luck, Tony
2014-06-28 11:56                 ` Xie XiuQi

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=53795E3B.9000004@huawei.com \
    --to=xiexiuqi@huawei.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.