Fix ipipe_tsc2ns for ARM
PATCH 1/1 Fix ipipe_tsc2ns for ARM
Hi,
the current implementation of ipipe_tsc2ns for ARM does not compile (undefined reference to `__udivdi3'). The attached patch fixes that.
--
Sebastian
v2.6/common/include/asm-arm/ipipe.h +6 -1
@@ -124,7 +124,12 @@ extern void __ipipe_mach_demux_irq(unsig#define __ipipe_read_timebase () __ipipe_mach_get_tsc()#define ipipe_cpu_freq () (HZ * __ipipe_mach_ticks_per_jiffy) -#define ipipe_tsc2ns (t) (((t) * 1000) / (ipipe_cpu_freq() / 1000000)) +#define ipipe_tsc2ns (t) \ +({ \ + unsigned long long delta = (t)*1000; \ + do_div(delta, ipipe_cpu_freq() / 1000000 + 1); \ + (unsigned long)delta; \ +})/* Private interface -- Internal use only */
Quoted 4 lines · Sebastian Smolorz
Hi,
the current implementation of
ipipe_tsc2nsfor ARM does not compile (undefined reference to `__udivdi3'). The attached patch fixes that.
the point of using ((t) * 1000) / (freq / 1000000) is to avoid using the 64 bits division. I would rather think a simple cast to unsigned is missing. What value is a 64 bits when it fails, __ipipe_mach_ticks_per_jiffy or t ?
Signature · 1 line
Gilles Chanteperdrix
Quoted 9 lines · Gilles Chanteperdrix
Quoted 4 lines · Sebastian Smolorz
Hi,
the current implementation of
ipipe_tsc2nsfor ARM does not compile (undefined reference to `__udivdi3'). The attached patch fixes that.the point of using ((t) * 1000) / (freq / 1000000) is to avoid using the 64 bits division. I would rather think a simple cast to unsigned is missing.
Ok, see my attached patch. But can we assume in all cases that ipipe_tsc2ns is used with a value smaller than a long long variable? The only usage of this macro so far is in __ipipe_print_delay() which calls it with a substraction of two unsigned long long variables.
Quoted 2 lines
What value is a 64 bits when it fails,
__ipipe_mach_ticks_per_jiffyor t ?
Sorry, I'm not really sure what you mean here.
--
Sebastian
v2.6/common/include/asm-arm/ipipe.h +1 -1
@@ -124,7 +124,7 @@ extern void __ipipe_mach_demux_irq(unsig#define __ipipe_read_timebase () __ipipe_mach_get_tsc()#define ipipe_cpu_freq () (HZ * __ipipe_mach_ticks_per_jiffy) -#define ipipe_tsc2ns (t) (((t) * 1000) / (ipipe_cpu_freq() / 1000000)) +#define ipipe_tsc2ns (t) (((unsigned long)(t) * 1000) / (ipipe_cpu_freq() / 1000000))/* Private interface -- Internal use only */
Quoted 4 lines · Sebastian Smolorz
Ok, see my attached patch. But can we assume in all cases that
ipipe_tsc2nsis used with a value smaller than a long long variable? The only usage of this macro so far is in__ipipe_print_delay()which calls it with a substraction of two unsigned long long variables.
The patch using do_div also assumes that t * 1000 will never overflow 64 bits. But I agree, it is less restrictive.
Quoted 5 lines
Quoted 2 lines
What value is a 64 bits when it fails,
__ipipe_mach_ticks_per_jiffyor t ?Sorry, I'm not really sure what you mean here.
Forget it, I got the answer, it is t that is a 64 bits value.
Signature · 1 line
Gilles Chanteperdrix
Quoted 9 lines · Gilles Chanteperdrix
Quoted 4 lines · Sebastian Smolorz
Ok, see my attached patch. But can we assume in all cases that
ipipe_tsc2nsis used with a value smaller than a long long variable? The only usage of this macro so far is in__ipipe_print_delay()which calls it with a substraction of two unsigned long long variables.The patch using
do_divalso assumes that t * 1000 will never overflow 64 bits. But I agree, it is less restrictive.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
What value is a 64 bits when it fails,
__ipipe_mach_ticks_per_jiffyor t ?Sorry, I'm not really sure what you mean here.
Forget it, I got the answer, it is t that is a 64 bits value.
So which patch are you going to check in?
--
Sebastian
Quoted 16 lines · Sebastian Smolorz
Quoted 14 lines · Gilles Chanteperdrix
Quoted 4 lines · Sebastian Smolorz
Ok, see my attached patch. But can we assume in all cases that
ipipe_tsc2nsis used with a value smaller than a long long variable? The only usage of this macro so far is in__ipipe_print_delay()which calls it with a substraction of two unsigned long long variables.The patch using
do_divalso assumes that t * 1000 will never overflow 64 bits. But I agree, it is less restrictive.Quoted 3 lines
Quoted 2 lines
What value is a 64 bits when it fails,
__ipipe_mach_ticks_per_jiffyor t ?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Sorry, I'm not really sure what you mean here.
Forget it, I got the answer, it is t that is a 64 bits value.
So which patch are you going to check in?
I have no preference, maybe Philippe has one ?
Signature · 1 line
Gilles Chanteperdrix
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Sebastian Smolorz
Quoted 14 lines · Gilles Chanteperdrix
Quoted 4 lines · Sebastian Smolorz
Ok, see my attached patch. But can we assume in all cases that
ipipe_tsc2nsis used with a value smaller than a long long variable? The only usage of this macro so far is in__ipipe_print_delay()which calls it with a substraction of two unsigned long long variables.The patch using
do_divalso assumes that t * 1000 will never overflow 64 bits. But I agree, it is less restrictive.Quoted 3 lines
Quoted 2 lines
What value is a 64 bits when it fails,
__ipipe_mach_ticks_per_jiffyor t ?
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Sorry, I'm not really sure what you mean here.
Forget it, I got the answer, it is t that is a 64 bits value.
So which patch are you going to check in?
I have no preference, maybe Philippe has one ?
It's a detail, but ipipe_tsc2ns() was once designed as a helper for implementing the now defunct I-pipe stats support, which has been replaced by the tracer. The values (time delta between -normally- short events) were guaranteed to be small enough to fit in 32bits, so other ports just cast the input data within the macro. No other I-pipe code should rely on better precision.
This said, in this case, my preferred option is the one of the Adeos maintainer for ARM, who is... oh, yeah! you are. So, I hereby agree with the choice you are going to make next.
Signature · 1 line
Philippe.
Quoted 10 lines · Philippe Gerum
It's a detail, but
ipipe_tsc2ns()was once designed as a helper for implementing the now defunct I-pipe stats support, which has been replaced by the tracer. The values (time delta between -normally- short events) were guaranteed to be small enough to fit in 32bits, so other ports just cast the input data within the macro. No other I-pipe code should rely on better precision.This said, in this case, my preferred option is the one of the Adeos maintainer for ARM, who is... oh, yeah! you are. So, I hereby agree with the choice you are going to make next.
Ok, let us go for what other ports do then, let us cast the argument to a 32 bits value.
Signature · 1 line
Gilles Chanteperdrix