Skip to contentSkip to conversation

clockevent questions

DISCUSSION Francis Moreau 2 participants 9 messages May 12, 2007 – May 16, 2007

lore
Share & tools
lore
#0 lore raw

Hi,

I'm trying to use clocksource and clockevent new subsystem. My platform has a timer that I'd like to use both as a clocksource and a clockevent devices. This timer is continueous in sense that it can run without any interruption so I assume I can flag the clocksource device with "CLOCK_SOURCE_IS_CONTINUOUS". However I noticed that clockevent device can be stopped by using "set_mode()" method. Are these two behaviours compatible ?

Another question is that I have another embedded 16 bits timer that I would like to use. Since the timer is only 16 bits, the maximum interval is tiny, My question if a user ask for a clockevent device using an interval is bigger that 2^16, the clockevent system doesn't return an error. Instead it silently reduce the interval to 2^16. Is this correct ? if so why ?

Thanks for your answers

Signature · 1 line
Francis
#1 lore raw

Francis,

Quoted 3 lines · Francis Moreau

I'm trying to use clocksource and clockevent new subsystem. My platform has a timer that I'd like to use both as a clocksource and a clockevent devices.

See arch/i386/kernel/hpet.c

Quoted 2 lines

This timer is continueous in sense that it can run without any interruption

-ENOPARSE

Has your timer a free running counter and a match register based event mechanism ?

Quoted 4 lines

so I assume I can flag the clocksource device
with "CLOCK_SOURCE_IS_CONTINUOUS". However I noticed that clockevent device can be stopped by using "set_mode()" method. Are these two behaviours compatible ?

the clock event stop only stops the event mechanism, it does not stop the counter.

See arch/i386/kernel/hpet.c

Quoted 6 lines

Another question is that I have another embedded 16 bits timer that I would like to use. Since the timer is only 16 bits, the maximum interval is tiny, My question if a user ask for a clockevent device using an interval is bigger that 2^16, the clockevent system doesn't return an error. Instead it silently reduce the interval to 2^16. Is this correct ? if so why ?

Yes, it is correct. The generic timer code requests an event in the future. It does not care, whether the hardware device can handle that or not. So the clock event code limits the delta to the maximum delta the device can handle. The interrupt fires and the generic timer code reschedules the event with the remaining delta time.

tglx

#2 lore raw

Hi Thomas,

Thanks for answering so quickly !

Quoted 9 lines · Thomas Gleixner

Francis,

Quoted 3 lines · Francis Moreau

I'm trying to use clocksource and clockevent new subsystem. My platform has a timer that I'd like to use both as a clocksource and a clockevent devices.

See arch/i386/kernel/hpet.c

thanks for the pointer

Quoted 8 lines
Quoted 2 lines

This timer is continueous in sense that it can run without any interruption

-ENOPARSE

Has your timer a free running counter and a match register based event mechanism ?

yes

Quoted 10 lines
Quoted 4 lines

so I assume I can flag the clocksource device
with "CLOCK_SOURCE_IS_CONTINUOUS". However I noticed that clockevent device can be stopped by using "set_mode()" method. Are these two behaviours compatible ?

the clock event stop only stops the event mechanism, it does not stop the counter.

See arch/i386/kernel/hpet.c

OK. I got it now, In my initial plan, I was thinking to stop the counter to stop the event. But that's not the right thing to do. It seems that I should disable event interrupt instead.

Quoted 7 lines
Quoted 6 lines

Another question is that I have another embedded 16 bits timer that I would like to use. Since the timer is only 16 bits, the maximum interval is tiny, My question if a user ask for a clockevent device using an interval is bigger that 2^16, the clockevent system doesn't return an error. Instead it silently reduce the interval to 2^16. Is this correct ? if so why ?

Quoted 6 lines

Yes, it is correct. The generic timer code requests an event in the future. It does not care, whether the hardware device can handle that or not. So the clock event code limits the delta to the maximum delta the device can handle. The interrupt fires and the generic timer code reschedules the event with the remaining delta time.

Thanks again for explanations. Could you give me a pointer of this reschedules ?

Signature · 1 line
Francis
#3 lore raw
Quoted 8 lines · Francis Moreau
Quoted 6 lines

Yes, it is correct. The generic timer code requests an event in the future. It does not care, whether the hardware device can handle that or not. So the clock event code limits the delta to the maximum delta the device can handle. The interrupt fires and the generic timer code reschedules the event with the remaining delta time.

Thanks again for explanations. Could you give me a pointer of this reschedules ?

Well, it ends up in hrtimer_interrupt() and the code there finds out, that the next timer is not due right now, so it simply requests the same (absolute) time event again, which is processed by the clock events code and eventually limited to the max delta of the device again.

tglx

#4 lore raw
Quoted 8 lines · Thomas Gleixner
Quoted 7 lines · Francis Moreau
Quoted 6 lines

Yes, it is correct. The generic timer code requests an event in the future. It does not care, whether the hardware device can handle that or not. So the clock event code limits the delta to the maximum delta the device can handle. The interrupt fires and the generic timer code reschedules the event with the remaining delta time.

Quoted 7 lines
Quoted 1 line

Thanks again for explanations. Could you give me a pointer of this reschedules ?

Well, it ends up in hrtimer_interrupt() and the code there finds out, that the next timer is not due right now, so it simply requests the same (absolute) time event again, which is processed by the clock events code and eventually limited to the max delta of the device again.

OK, I'll give it a deeper look soon.

Thanks for your great work !

Signature · 1 line
Francis
#5 lore raw
In reply to Thomas Gleixner

Thomas,

Quoted 5 lines · Thomas Gleixner

Well, it ends up in hrtimer_interrupt() and the code there finds out, that the next timer is not due right now, so it simply requests the same (absolute) time event again, which is processed by the clock events code and eventually limited to the max delta of the device again.

My timer is finally using the clockevent subsystem. Below is the output of '/proc/timer_list':

cat /proc/timer_list
Timer List Version: v0.3
HRTIMER_MAX_CLOCK_BASES: 2
now at 64696544360531 nsecs

cpu: 0
clock 0:
.index: 0
.resolution: 1 nsecs
.get_time: ktime_get_real
.offset: 1179151153000000000 nsecs
active timers:
clock 1:
.index: 1
.resolution: 1 nsecs
.get_time: ktime_get
.offset: 0 nsecs
active timers:
#0: <c03fde10>, tick_sched_timer, S:01

# expires at 64696546875000 nsecs [in 2514469 nsecs]
 .expires_next   : 64696546875000 nsecs
 .hres_active    : 1
 .nr_events      : 16562163
 .nohz_mode      : 0
 .idle_tick      : 0 nsecs
 .tick_stopped   : 0
 .idle_jiffies   : 0
 .idle_calls     : 0
 .idle_sleeps    : 0
 .idle_entrytime : 0 nsecs
 .idle_sleeptime : 0 nsecs
 .last_jiffies   : 0
 .next_jiffies   : 0
 .idle_expires   : 0 nsecs
jiffies: 16485515
Tick Device: mode:     1
Clock Event Device: hrt
max_delta_ns:   2147483647
min_delta_ns:   1000
mult:           206158430
shift:          32
mode:           3
next_event:     64696546875000 nsecs
set_next_event: hrt_next_event
set_mode:       hrt_timer_setup
event_handler:  hrtimer_interrupt

My question is about the clock resolution field which is equal to 1ns. How is this possible since my timer's frequency is only 100Mhz ?

My 2 cents, it looks like some tabs are missing when printing the list of hrtimers of each clock...

Thanks

Signature · 1 line
Francis
#6 lore raw

Francis,

Quoted 2 lines · Francis Moreau

My question is about the clock resolution field which is equal to 1ns. How is this possible since my timer's frequency is only 100Mhz ?

you are right. It is a bit strange. The resolution info is not really reflecting the clock event source capability. I look if there is a sane solution for that.

tglx

#7 lore raw

Hi Thomas,

Quoted 10 lines · Thomas Gleixner

Francis,

Quoted 2 lines · Francis Moreau

My question is about the clock resolution field which is equal to 1ns. How is this possible since my timer's frequency is only 100Mhz ?

you are right. It is a bit strange. The resolution info is not really reflecting the clock event source capability. I look if there is a sane solution for that.

Doesn't that make hrtimer_get_res() and its callers buggy since they return this 1ns value which is not reflecting the correct clock event capability ?

Another question about the output of '/proc/timer_list':

[...]
active timers:
#0: <c03fde10>, tick_sched_timer, S:01

# expires at 64696546875000 nsecs [in 2514469 nsecs]
.expires_next   : 64696546875000 nsecs
[...]

Doesn't the 2 expire time lines give the same information ? If so,
couldn't we merge them into : ".expires_next : 64696546875000 nsecs
[in 2514469 nsecs]" ?

Thanks

Signature · 1 line
Francis
#8 lore raw
Quoted 4 lines · Francis Moreau
Quoted 4 lines · Francis Moreau
Quoted 2 lines

My question is about the clock resolution field which is equal to 1ns. How is this possible since my timer's frequency is only 100Mhz ?

Quoted 8 lines
Quoted 4 lines

you are right. It is a bit strange. The resolution info is not really reflecting the clock event source capability. I look if there is a sane solution for that.

Doesn't that make hrtimer_get_res() and its callers buggy since they return this 1ns value which is not reflecting the correct clock event capability ?

Well, it's not really buggy. It's just not telling the truth.

Quoted 5 lines

Another question about the output of '/proc/timer_list':

[...]
active timers:
#0: <c03fde10>, tick_sched_timer, S:01

Quoted 7 lines
 # expires at 64696546875000 nsecs [in 2514469 nsecs]
 .expires_next   : 64696546875000 nsecs
[...]

Doesn't the 2 expire time lines give the same information ? If so,
couldn't we merge them into : ".expires_next : 64696546875000 nsecs
[in 2514469 nsecs]" ?

No. The timers are taken from the hrtimer queue and the expires_next value is the clock events code internal value of the next timer event. The expiry time of the first timer and the clock events code should match of course, but we definitely want to have them seperate.

tglx