2016-12-08 20:53:46

by Thomas Gleixner

[permalink] [raw]
Subject: [patch 2/6] timekeeping: Make the conversion call chain consistently unsigned

Propagating a unsigned value through signed variables and functions makes
absolutely no sense and is just prone to (re)introduce subtle signed
vs. unsigned issues as happened recently.

Clean it up.

Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/time/timekeeping.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -311,7 +311,7 @@ static inline u64 timekeeping_delta_to_n
return nsec + arch_gettimeoffset();
}

-static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
+static inline u64 timekeeping_get_ns(struct tk_read_base *tkr)
{
cycle_t delta;

@@ -319,8 +319,8 @@ static inline s64 timekeeping_get_ns(str
return timekeeping_delta_to_ns(tkr, delta);
}

-static inline s64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
- cycle_t cycles)
+static inline u64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
+ cycle_t cycles)
{
cycle_t delta;

@@ -623,7 +623,7 @@ static void timekeeping_forward_now(stru
{
struct clocksource *clock = tk->tkr_mono.clock;
cycle_t cycle_now, delta;
- s64 nsec;
+ u64 nsec;

cycle_now = tk->tkr_mono.read(clock);
delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
@@ -652,7 +652,7 @@ int __getnstimeofday64(struct timespec64
{
struct timekeeper *tk = &tk_core.timekeeper;
unsigned long seq;
- s64 nsecs = 0;
+ u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);
@@ -692,7 +692,7 @@ ktime_t ktime_get(void)
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base;
- s64 nsecs;
+ u64 nsecs;

WARN_ON(timekeeping_suspended);

@@ -735,7 +735,7 @@ ktime_t ktime_get_with_offset(enum tk_of
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base, *offset = offsets[offs];
- s64 nsecs;
+ u64 nsecs;

WARN_ON(timekeeping_suspended);

@@ -779,7 +779,7 @@ ktime_t ktime_get_raw(void)
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base;
- s64 nsecs;
+ u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);
@@ -804,8 +804,8 @@ void ktime_get_ts64(struct timespec64 *t
{
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 tomono;
- s64 nsec;
unsigned int seq;
+ u64 nsec;

WARN_ON(timekeeping_suspended);

@@ -893,8 +893,8 @@ void ktime_get_snapshot(struct system_ti
unsigned long seq;
ktime_t base_raw;
ktime_t base_real;
- s64 nsec_raw;
- s64 nsec_real;
+ u64 nsec_raw;
+ u64 nsec_real;
cycle_t now;

WARN_ON_ONCE(timekeeping_suspended);
@@ -1052,7 +1052,7 @@ int get_device_system_crosststamp(int (*
cycle_t cycles, now, interval_start;
unsigned int clock_was_set_seq = 0;
ktime_t base_real, base_raw;
- s64 nsec_real, nsec_raw;
+ u64 nsec_real, nsec_raw;
u8 cs_was_changed_seq;
unsigned long seq;
bool do_interp;
@@ -1365,7 +1365,7 @@ void getrawmonotonic64(struct timespec64
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 ts64;
unsigned long seq;
- s64 nsecs;
+ u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);



2016-12-08 23:47:47

by David Gibson

[permalink] [raw]
Subject: Re: [patch 2/6] timekeeping: Make the conversion call chain consistently unsigned

On Thu, Dec 08, 2016 at 08:49:34PM -0000, Thomas Gleixner wrote:
> Propagating a unsigned value through signed variables and functions makes
> absolutely no sense and is just prone to (re)introduce subtle signed
> vs. unsigned issues as happened recently.
>
> Clean it up.
>
> Signed-off-by: Thomas Gleixner <[email protected]>

Reviewed-by: David Gibson <[email protected]>

> ---
> kernel/time/timekeeping.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -311,7 +311,7 @@ static inline u64 timekeeping_delta_to_n
> return nsec + arch_gettimeoffset();
> }
>
> -static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
> +static inline u64 timekeeping_get_ns(struct tk_read_base *tkr)
> {
> cycle_t delta;
>
> @@ -319,8 +319,8 @@ static inline s64 timekeeping_get_ns(str
> return timekeeping_delta_to_ns(tkr, delta);
> }
>
> -static inline s64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
> - cycle_t cycles)
> +static inline u64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
> + cycle_t cycles)
> {
> cycle_t delta;
>
> @@ -623,7 +623,7 @@ static void timekeeping_forward_now(stru
> {
> struct clocksource *clock = tk->tkr_mono.clock;
> cycle_t cycle_now, delta;
> - s64 nsec;
> + u64 nsec;
>
> cycle_now = tk->tkr_mono.read(clock);
> delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
> @@ -652,7 +652,7 @@ int __getnstimeofday64(struct timespec64
> {
> struct timekeeper *tk = &tk_core.timekeeper;
> unsigned long seq;
> - s64 nsecs = 0;
> + u64 nsecs;
>
> do {
> seq = read_seqcount_begin(&tk_core.seq);
> @@ -692,7 +692,7 @@ ktime_t ktime_get(void)
> struct timekeeper *tk = &tk_core.timekeeper;
> unsigned int seq;
> ktime_t base;
> - s64 nsecs;
> + u64 nsecs;
>
> WARN_ON(timekeeping_suspended);
>
> @@ -735,7 +735,7 @@ ktime_t ktime_get_with_offset(enum tk_of
> struct timekeeper *tk = &tk_core.timekeeper;
> unsigned int seq;
> ktime_t base, *offset = offsets[offs];
> - s64 nsecs;
> + u64 nsecs;
>
> WARN_ON(timekeeping_suspended);
>
> @@ -779,7 +779,7 @@ ktime_t ktime_get_raw(void)
> struct timekeeper *tk = &tk_core.timekeeper;
> unsigned int seq;
> ktime_t base;
> - s64 nsecs;
> + u64 nsecs;
>
> do {
> seq = read_seqcount_begin(&tk_core.seq);
> @@ -804,8 +804,8 @@ void ktime_get_ts64(struct timespec64 *t
> {
> struct timekeeper *tk = &tk_core.timekeeper;
> struct timespec64 tomono;
> - s64 nsec;
> unsigned int seq;
> + u64 nsec;
>
> WARN_ON(timekeeping_suspended);
>
> @@ -893,8 +893,8 @@ void ktime_get_snapshot(struct system_ti
> unsigned long seq;
> ktime_t base_raw;
> ktime_t base_real;
> - s64 nsec_raw;
> - s64 nsec_real;
> + u64 nsec_raw;
> + u64 nsec_real;
> cycle_t now;
>
> WARN_ON_ONCE(timekeeping_suspended);
> @@ -1052,7 +1052,7 @@ int get_device_system_crosststamp(int (*
> cycle_t cycles, now, interval_start;
> unsigned int clock_was_set_seq = 0;
> ktime_t base_real, base_raw;
> - s64 nsec_real, nsec_raw;
> + u64 nsec_real, nsec_raw;
> u8 cs_was_changed_seq;
> unsigned long seq;
> bool do_interp;
> @@ -1365,7 +1365,7 @@ void getrawmonotonic64(struct timespec64
> struct timekeeper *tk = &tk_core.timekeeper;
> struct timespec64 ts64;
> unsigned long seq;
> - s64 nsecs;
> + u64 nsecs;
>
> do {
> seq = read_seqcount_begin(&tk_core.seq);
>
>

--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


Attachments:
(No filename) (3.61 kB)
signature.asc (819.00 B)
Download all attachments
Subject: [tip:timers/core] timekeeping: Make the conversion call chain consistently unsigned

Commit-ID: acc89612a70e370a5640fd77a83f15b7b94d85e4
Gitweb: http://git.kernel.org/tip/acc89612a70e370a5640fd77a83f15b7b94d85e4
Author: Thomas Gleixner <[email protected]>
AuthorDate: Thu, 8 Dec 2016 20:49:34 +0000
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 9 Dec 2016 12:06:41 +0100

timekeeping: Make the conversion call chain consistently unsigned

Propagating a unsigned value through signed variables and functions makes
absolutely no sense and is just prone to (re)introduce subtle signed
vs. unsigned issues as happened recently.

Clean it up.

Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Parit Bhargava <[email protected]>
Cc: Laurent Vivier <[email protected]>
Cc: "Christopher S. Hall" <[email protected]>
Cc: Chris Metcalf <[email protected]>
Cc: Richard Cochran <[email protected]>
Cc: Liav Rehana <[email protected]>
Cc: John Stultz <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>

---
kernel/time/timekeeping.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index bfe589e..5244821 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -311,7 +311,7 @@ static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
return nsec + arch_gettimeoffset();
}

-static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
+static inline u64 timekeeping_get_ns(struct tk_read_base *tkr)
{
cycle_t delta;

@@ -319,8 +319,8 @@ static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
return timekeeping_delta_to_ns(tkr, delta);
}

-static inline s64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
- cycle_t cycles)
+static inline u64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
+ cycle_t cycles)
{
cycle_t delta;

@@ -652,7 +652,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
{
struct clocksource *clock = tk->tkr_mono.clock;
cycle_t cycle_now, delta;
- s64 nsec;
+ u64 nsec;

cycle_now = tk->tkr_mono.read(clock);
delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
@@ -681,7 +681,7 @@ int __getnstimeofday64(struct timespec64 *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
unsigned long seq;
- s64 nsecs = 0;
+ u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);
@@ -721,7 +721,7 @@ ktime_t ktime_get(void)
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base;
- s64 nsecs;
+ u64 nsecs;

WARN_ON(timekeeping_suspended);

@@ -764,7 +764,7 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs)
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base, *offset = offsets[offs];
- s64 nsecs;
+ u64 nsecs;

WARN_ON(timekeeping_suspended);

@@ -808,7 +808,7 @@ ktime_t ktime_get_raw(void)
struct timekeeper *tk = &tk_core.timekeeper;
unsigned int seq;
ktime_t base;
- s64 nsecs;
+ u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);
@@ -833,8 +833,8 @@ void ktime_get_ts64(struct timespec64 *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 tomono;
- s64 nsec;
unsigned int seq;
+ u64 nsec;

WARN_ON(timekeeping_suspended);

@@ -922,8 +922,8 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot)
unsigned long seq;
ktime_t base_raw;
ktime_t base_real;
- s64 nsec_raw;
- s64 nsec_real;
+ u64 nsec_raw;
+ u64 nsec_real;
cycle_t now;

WARN_ON_ONCE(timekeeping_suspended);
@@ -1081,7 +1081,7 @@ int get_device_system_crosststamp(int (*get_time_fn)
cycle_t cycles, now, interval_start;
unsigned int clock_was_set_seq = 0;
ktime_t base_real, base_raw;
- s64 nsec_real, nsec_raw;
+ u64 nsec_real, nsec_raw;
u8 cs_was_changed_seq;
unsigned long seq;
bool do_interp;
@@ -1394,7 +1394,7 @@ void getrawmonotonic64(struct timespec64 *ts)
struct timekeeper *tk = &tk_core.timekeeper;
struct timespec64 ts64;
unsigned long seq;
- s64 nsecs;
+ u64 nsecs;

do {
seq = read_seqcount_begin(&tk_core.seq);