* [PATCH] sched/clock: cleanup, remove wrap_{max|min}().
@ 2014-05-07 11:48 Dongsheng Yang
2014-05-07 12:55 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Dongsheng Yang @ 2014-05-07 11:48 UTC (permalink / raw)
To: mingo, peterz; +Cc: linux-kernel, Dongsheng Yang
I am not sure why we need the wrap_{max|min}() in kernel/sched/clock.c.
But I checked the implementation of max() and min() in linux/kernel.h, I think
we can reuse them here rather than introduce a new function named
wrap_{max|min}().
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
---
kernel/sched/clock.c | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index 3ef6451..36c03a8 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -173,20 +173,6 @@ void sched_clock_init(void)
}
/*
- * min, max except they take wrapping into account
- */
-
-static inline u64 wrap_min(u64 x, u64 y)
-{
- return (s64)(x - y) < 0 ? x : y;
-}
-
-static inline u64 wrap_max(u64 x, u64 y)
-{
- return (s64)(x - y) > 0 ? x : y;
-}
-
-/*
* update the percpu scd from the raw @now value
*
* - filter out backward motion
@@ -212,11 +198,11 @@ again:
*/
clock = scd->tick_gtod + delta;
- min_clock = wrap_max(scd->tick_gtod, old_clock);
- max_clock = wrap_max(old_clock, scd->tick_gtod + TICK_NSEC);
+ min_clock = max(scd->tick_gtod, old_clock);
+ max_clock = max(old_clock, scd->tick_gtod + TICK_NSEC);
- clock = wrap_max(clock, min_clock);
- clock = wrap_min(clock, max_clock);
+ clock = max(clock, min_clock);
+ clock = min(clock, max_clock);
if (cmpxchg64(&scd->clock, old_clock, clock) != old_clock)
goto again;
--
1.8.2.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sched/clock: cleanup, remove wrap_{max|min}().
2014-05-07 12:55 ` Peter Zijlstra
@ 2014-05-07 12:04 ` Dongsheng Yang
2014-05-07 13:38 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Dongsheng Yang @ 2014-05-07 12:04 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: mingo, linux-kernel
On 05/07/2014 09:55 PM, Peter Zijlstra wrote:
> On Wed, May 07, 2014 at 08:48:58PM +0900, Dongsheng Yang wrote:
>> I am not sure why we need the wrap_{max|min}() in kernel/sched/clock.c.
>> But I checked the implementation of max() and min() in linux/kernel.h, I think
>> we can reuse them here rather than introduce a new function named
>> wrap_{max|min}().
> wrap is a good hint there.. they're supposed to deal with the clock
> wrapping. Of course 2^64 ns is a rather long time (~584 years in fact),
> but that doesn't mean we shouldn't care.
>
> And no, min/max don't do the right thing.
IMMO, max() in kernel.h is checking and returning the u64 with typeof() if
we are passing a u64 parameter to max(). And I checked current callers
of wrap_max(),
they are all passing parameters of u64 type. So I think max/min works
well at
the place of wrap_max/min().
Maybe I am missing something here, please correct me if I understand it
incorrectly.
Thanx
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched/clock: cleanup, remove wrap_{max|min}().
2014-05-07 11:48 [PATCH] sched/clock: cleanup, remove wrap_{max|min}() Dongsheng Yang
@ 2014-05-07 12:55 ` Peter Zijlstra
2014-05-07 12:04 ` Dongsheng Yang
0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2014-05-07 12:55 UTC (permalink / raw)
To: Dongsheng Yang; +Cc: mingo, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 532 bytes --]
On Wed, May 07, 2014 at 08:48:58PM +0900, Dongsheng Yang wrote:
> I am not sure why we need the wrap_{max|min}() in kernel/sched/clock.c.
> But I checked the implementation of max() and min() in linux/kernel.h, I think
> we can reuse them here rather than introduce a new function named
> wrap_{max|min}().
wrap is a good hint there.. they're supposed to deal with the clock
wrapping. Of course 2^64 ns is a rather long time (~584 years in fact),
but that doesn't mean we shouldn't care.
And no, min/max don't do the right thing.
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched/clock: cleanup, remove wrap_{max|min}().
2014-05-07 12:04 ` Dongsheng Yang
@ 2014-05-07 13:38 ` Peter Zijlstra
0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2014-05-07 13:38 UTC (permalink / raw)
To: Dongsheng Yang; +Cc: mingo, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2233 bytes --]
On Wed, May 07, 2014 at 09:04:19PM +0900, Dongsheng Yang wrote:
> On 05/07/2014 09:55 PM, Peter Zijlstra wrote:
> >On Wed, May 07, 2014 at 08:48:58PM +0900, Dongsheng Yang wrote:
> >>I am not sure why we need the wrap_{max|min}() in kernel/sched/clock.c.
> >>But I checked the implementation of max() and min() in linux/kernel.h, I think
> >>we can reuse them here rather than introduce a new function named
> >>wrap_{max|min}().
> >wrap is a good hint there.. they're supposed to deal with the clock
> >wrapping. Of course 2^64 ns is a rather long time (~584 years in fact),
> >but that doesn't mean we shouldn't care.
> >
> >And no, min/max don't do the right thing.
>
> IMMO, max() in kernel.h is checking and returning the u64 with typeof() if
> we are passing a u64 parameter to max(). And I checked current callers of
> wrap_max(),
> they are all passing parameters of u64 type. So I think max/min works well
> at
> the place of wrap_max/min().
>
> Maybe I am missing something here, please correct me if I understand it
> incorrectly.
Trivial test prog; you really should do these things yourself.
$ ./wrap
wrap_min: 18446744073709551615 wrap_max: 0
min: 0 max: 18446744073709551615
---
#include <stdint.h>
#include <stdio.h>
typedef uint64_t u64;
typedef int64_t s64;
static inline u64 wrap_min(u64 x, u64 y)
{
return (s64)(x - y) < 0 ? x : y;
}
static inline u64 wrap_max(u64 x, u64 y)
{
return (s64)(x - y) > 0 ? x : y;
}
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
void main (void)
{
u64 a = UINT64_MAX, b = a + 1;
printf("wrap_min: %lu wrap_max: %lu\n", wrap_min(a, b), wrap_max(a,b));
printf("min: %lu max: %lu\n", min(a, b), max(a,b));
}
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-07 13:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-07 11:48 [PATCH] sched/clock: cleanup, remove wrap_{max|min}() Dongsheng Yang
2014-05-07 12:55 ` Peter Zijlstra
2014-05-07 12:04 ` Dongsheng Yang
2014-05-07 13:38 ` Peter Zijlstra
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.