SAMA5D27 - High Resolution Timer support

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

KevinWysocki
Posts: 9
Joined: Wed Aug 22, 2018 5:20 pm

SAMA5D27 - High Resolution Timer support

Wed Aug 29, 2018 3:30 pm

Hi everybody,

I use SAMA5D2 Xplained demo board with Linux4SAM v5.8 (Linux Kernel v4.9.87), got "Preemptible Kernel" and "High Resolution Timer Support" checked.

I am writing a Kernel module which need to trigger a timer with a period between 1us and 200us so high res timer would be useful.

During Kernel starting :

Code: Select all

sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 21474836475000000ns
And a cat /proc/timer_list command returns :

Code: Select all

Timer List Version: v0.8
HRTIMER_MAX_CLOCK_BASES: 4
now at 133585208076 nsecs

cpu: 0
 clock 0:
  .base:       c080e540
  .index:      0
  .resolution: 10000000 nsecs
  .get_time:   <c0161418>
  .offset:     0 nsecs
active timers:
 #0: <c08456d8>, <c0169f84>, S:01
 # expires at 21474836475000000-21474836475000000 nsecs [in 21474702889791924 to 21474702889791924 nsecs]
 clock 1:
  .base:       c080e560
  .index:      1
  .resolution: 10000000 nsecs
  .get_time:   <c015b98c>
  .offset:     1325567565159780627 nsecs
active timers:
 clock 2:
  .base:       c080e580
  .index:      2
  .resolution: 10000000 nsecs
  .get_time:   <c015b9a4>
  .offset:     0 nsecs
active timers:
 clock 3:
  .base:       c080e5a0
  .index:      3
  .resolution: 10000000 nsecs
  .get_time:   <c015b9bc>
  .offset:     1325567565159780627 nsecs
active timers:
  .expires_next   : 9223372036854775807 nsecs
  .hres_active    : 0
  .nr_events      : 0
  .nr_retries     : 0
  .nr_hangs       : 0
  .max_hang_time  : 0
  .nohz_mode      : 0
  .last_tick      : 0 nsecs
  .tick_stopped   : 0
  .idle_jiffies   : 0
  .idle_calls     : 0
  .idle_sleeps    : 0
  .idle_entrytime : 133574060509 nsecs
  .idle_waketime  : 0 nsecs
  .idle_exittime  : 0 nsecs
  .idle_sleeptime : 129169628324 nsecs
  .iowait_sleeptime: 729213876 nsecs
  .last_jiffies   : 0
  .next_timer     : 0
  .idle_expires   : 0 nsecs
jiffies: 4294950651

Tick Device: mode:     0
Per CPU device: 0
Clock Event Device: pit
 max_delta_ns:   0
 min_delta_ns:   0
 mult:           22280142
 shift:          32
 mode:           2
 next_event:     9223372036854775807 nsecs
 set_next_event: <00000000>
 shutdown: <c049970c>
 periodic: <c0499728>
 event_handler:  <c0169940>
 retries:        0
Does SAMA5D27 support high resolution timers ? Anyway to get a resolution of 1ns ?

Regards,

Kevin
blue_z
Location: USA
Posts: 1952
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D27 - High Resolution Timer support

Fri Aug 31, 2018 1:31 am

KevinWysocki wrote: Does SAMA5D27 support high resolution timers ?
Yes.
KevinWysocki wrote: Anyway to get a resolution of 1ns ?
All you have to do is use the kernel configuration "sama5_defconfig", which will automatically configure both halves of this feature.
CONFIG_HIGH_RES_TIMERS only enables the upper-half of the framework. The bottom half is a driver for the timer hardware.

# uname -r
4.9.87-linux4sam_5.8
# cat /proc/timer_list
Timer List Version: v0.8
HRTIMER_MAX_CLOCK_BASES: 4
now at 58037114882 nsecs

cpu: 0
clock 0:
.base: c0d0e0c0
.index: 0
.resolution: 1 nsecs
.get_time: <c01534fc>
.offset: 0 nsecs
...

Regards
KevinWysocki
Posts: 9
Joined: Wed Aug 22, 2018 5:20 pm

Re: SAMA5D27 - High Resolution Timer support

Fri Aug 31, 2018 11:48 am

blue_z wrote:
Fri Aug 31, 2018 1:31 am
All you have to do is use the kernel configuration "sama5_defconfig", which will automatically configure both halves of this feature.
CONFIG_HIGH_RES_TIMERS only enables the upper-half of the framework. The bottom half is a driver for the timer hardware.
I didn't specify it but yes, my kernel is configured with "sama5_defconfig" (sama5d2_xplained_mmc_defconfig to be specific).

Here is an extract of my .config file :
#
# Timers subsystem
#
CONFIG_TICK_ONESHOT=y
CONFIG_NO_HZ_COMMON=y
# CONFIG_HZ_PERIODIC is not set
CONFIG_NO_HZ_IDLE=y
# CONFIG_NO_HZ is not set
CONFIG_HIGH_RES_TIMERS=y
blue_z wrote:
Fri Aug 31, 2018 1:31 am
# uname -r
4.9.87-linux4sam_5.8
# cat /proc/timer_list
Timer List Version: v0.8
HRTIMER_MAX_CLOCK_BASES: 4
now at 58037114882 nsecs

cpu: 0
clock 0:
.base: c0d0e0c0
.index: 0
.resolution: 1 nsecs
.get_time: <c01534fc>
.offset: 0 nsecs
...
On my board :
# uname -r
4.9.87-linux4sam_5.8
# cat /proc/timer_list
Timer List Version: v0.8
HRTIMER_MAX_CLOCK_BASES: 4
now at 25116337923 nsecs

cpu: 0
clock 0:
.base: c080e540
.index: 0
.resolution: 10000000 nsecs
.get_time: <c0161418>
.offset: 0 nsecs
active timers:
#0: <c08456d8>, <c0169f84>, S:01
# expires at 21474836475000000-21474836475000000 nsecs [in 21474811358662077 to 21474811358662077 nsecs]
clock 1:
.base: c080e560
.index: 1
.resolution: 10000000 nsecs
.get_time: <c015b98c>
.offset: 1325715972159718169 nsecs
active timers:
clock 2:
.base: c080e580
.index: 2
.resolution: 10000000 nsecs
.get_time: <c015b9a4>
.offset: 0 nsecs
active timers:
clock 3:
.base: c080e5a0
.index: 3
.resolution: 10000000 nsecs
.get_time: <c015b9bc>
.offset: 1325715972159718169 nsecs
active timers:
.expires_next : 9223372036854775807 nsecs
.hres_active : 0
.nr_events : 0
.nr_retries : 0
.nr_hangs : 0
.max_hang_time : 0
.nohz_mode : 0
.last_tick : 0 nsecs
.tick_stopped : 0
.idle_jiffies : 0
.idle_calls : 0
.idle_sleeps : 0
.idle_entrytime : 25105522309 nsecs
.idle_waketime : 0 nsecs
.idle_exittime : 0 nsecs
.idle_sleeptime : 20852948791 nsecs
.iowait_sleeptime: 738272787 nsecs
.last_jiffies : 0
.next_timer : 0
.idle_expires : 0 nsecs
jiffies: 4294939804

Tick Device: mode: 0
Per CPU device: 0
Clock Event Device: pit
max_delta_ns: 0
min_delta_ns: 0
mult: 22280142
shift: 32
mode: 2
next_event: 9223372036854775807 nsecs
set_next_event: <00000000>
shutdown: <c049970c>
periodic: <c0499728>
event_handler: <c0169940>
retries: 0
I also tried to modify the Kernel tick to 1kHz (just to give a try) and it has not been modified (still at 100Hz).
KevinWysocki
Posts: 9
Joined: Wed Aug 22, 2018 5:20 pm

Re: SAMA5D27 - High Resolution Timer support

Tue May 07, 2019 1:59 pm

I would like to reopen that subject. I am still not able to get a 1nsec resolution while HIGH_RES_TIMERS is set in my linux defconfig file.

Context : Linux kernel 4.14.73 (compiled by buildroot-at91, revision linux4sam_6.0) with custom DTS and defconfig files (that match my custom board hardware), based on at91-sama5d2_xplained.dts and sama5_defconfig in-tree files. I can post my files content if needed.

As far as I know, PIT and TC Block can be used as scheduler clock source. In my case, I use PIT timer, as shown below :

Code: Select all

# cat /proc/timer_list
Timer List Version: v0.8
HRTIMER_MAX_CLOCK_BASES: 4
now at 220780767600 nsecs

cpu: 0
 clock 0:
  .base:       c0911580
  .index:      0
  .resolution: 10000000 nsecs
  .get_time:   <c0162174>
  .offset:     0 nsecs
active timers:
 #0: <c09522f8>, <c016e9bc>, S:01
 # expires at 21474836475000000-21474836475000000 nsecs [in 21474615694232400 to 21474615694232400 nsecs]
 clock 1:
  .base:       c09115a0
  .index:      1
  .resolution: 10000000 nsecs
  .get_time:   <c01608c0>
  .offset:     1325376000249781200 nsecs
active timers:
 clock 2:
  .base:       c09115c0
  .index:      2
  .resolution: 10000000 nsecs
  .get_time:   <c01608c8>
  .offset:     0 nsecs
active timers:
 clock 3:
  .base:       c09115e0
  .index:      3
  .resolution: 10000000 nsecs
  .get_time:   <c01608d0>
  .offset:     1325376000249781200 nsecs
active timers:
  .expires_next   : 9223372036854775807 nsecs
  .hres_active    : 0
  .nr_events      : 0
  .nr_retries     : 0
  .nr_hangs       : 0
  .max_hang_time  : 0
  .nohz_mode      : 0
  .last_tick      : 0 nsecs
  .tick_stopped   : 0
  .idle_jiffies   : 0
  .idle_calls     : 0
  .idle_sleeps    : 0
  .idle_entrytime : 220771473400 nsecs
  .idle_waketime  : 0 nsecs
  .idle_exittime  : 0 nsecs
  .idle_sleeptime : 218358076600 nsecs
  .iowait_sleeptime: 189638400 nsecs
  .last_jiffies   : 0
  .next_timer     : 0
  .idle_expires   : 0 nsecs
jiffies: 4294959374

Tick Device: mode:     0
Per CPU device: 0
Clock Event Device: pit
 max_delta_ns:   0
 min_delta_ns:   0
 mult:           21474836
 shift:          32
 mode:           2
 next_event:     9223372036854775807 nsecs
 set_next_event: <00000000>
 shutdown: <c04c739c>
 periodic: <c04c73b8>
 event_handler:  <c016e348>
 retries:        0

I tried to get TC Block as clock source without any success ( "TC Block Clocksource" enabled in menuconfig, CONFIG_ATMEL_TCB_CLKSRC=y and CONFIG_ATMEL_TCB_CLKSRC_BLOCK=0 automatically added to .config file). The clock event device is still the PIT timer.

I have got two questions :
- Can PIT timer driver achieve resolution lower than 10000000 nsecs ? (So in that case, something should be wrong in my configuration files, device tree, ...)
- How to get TC Block as clock source to try if that makes any difference on timer resolution ?
blue_z
Location: USA
Posts: 1952
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D27 - High Resolution Timer support

Thu May 09, 2019 1:15 am

KevinWysocki wrote: I am still not able to get a 1nsec resolution while HIGH_RES_TIMERS is set in my linux defconfig file.
Seems like you are not using the information already provided.

One more time: CONFIG_HIGH_RES_TIMERS only enables the upper-half of the framework. By itself this is not sufficient to obtain better resolutions.
The bottom half is a driver for the (faster) timer hardware.

One more time: All you have to do is use the kernel configuration sama5_defconfig, and you will automatically have 1ns high resolution timers.

You repeatedly mention a "defconfig file". Is this a a new file in arch/arm/ that is named after your board?
Or are you referring to a modified/customized .config file with incorrect nomenclature?

You previously claimed that your kernel "is configured with "sama5_defconfig"", but then also report that it has a "custom DTS and defconfig files".
That's contradictory; you can only initiate a Linux kernel build with just one defconfig file.
Your current kernel configuration that you are now testing with has broken the original defconfig that properly enabled the high resolution timer framework. Obviously you have disabled/removed one-too-many features/drivers.

You could simply perform a sanity check by either
(a) performing a comparison of the .config produced by the original sama5_defconfig with your current .config (`sdiff` works for me), or
(b) start a fresh kernel build with sama5_defconfig, and use `make menuconfig` to only enable/add features/drivers (that you need/want) and not disable/remove any features/drivers.

Regards
KevinWysocki
Posts: 9
Joined: Wed Aug 22, 2018 5:20 pm

Re: SAMA5D27 - High Resolution Timer support

Thu May 09, 2019 2:54 pm

blue_z wrote:
Thu May 09, 2019 1:15 am
Seems like you are not using the information already provided.

One more time: CONFIG_HIGH_RES_TIMERS only enables the upper-half of the framework. By itself this is not sufficient to obtain better resolutions.
The bottom half is a driver for the (faster) timer hardware.
And that's why I asked if it could be a limitation of the PIT timer driver used as scheduler clock source.

blue_z wrote:
Thu May 09, 2019 1:15 am
One more time: All you have to do is use the kernel configuration sama5_defconfig, and you will automatically have 1ns high resolution timers.
We were using that defconfig file last year when we were evaluating the SAMA5D27 with a SAMA5D2 Xplained evaluation board.

blue_z wrote:
Thu May 09, 2019 1:15 am
You repeatedly mention a "defconfig file". Is this a a new file in arch/arm/ that is named after your board?
Or are you simply referring to a modified/customized .config file?

You previously claimed that your kernel "is configured with "sama5_defconfig"", but then also report that it has a "custom DTS and defconfig [sic] files".
That's contradictory.
To make it short, we now have our custom designed board, based on a SAMA5D26. So yes, we have our own xxxxx_defconfig in arch/arm/configs folder. It is based on sama5_defconfig, we just made some changes to add/suppress drivers we need (or not) as described below:

Defconfig file creation procedure :

Code: Select all

# make sama5_defconfig
# make menuconfig
.... do some modifications ...
# make savedefconfig
# mv defconfig arch/arm/configs/my_custom_defconfig

We never modify .config files, always modify our defconfig, then use make commands to update / save it.

blue_z wrote:
Thu May 09, 2019 1:15 am
Your current kernel configuration that you are now testing with has broken the original defconfig that properly enables the high resolution timer framework. Obviously you have disabled/removed one-too-many features/drivers.

You could simply perform a sanity check by either
(a) performing a comparison of the .config produced by the original sama5_defconfig with your current .config (`sdiff` works for me), or
(b) start a fresh kernel build with sama5_defconfig, and use `make menuconfig` to only enable/add features/drivers and not disable/remove any features/drivers.

(a) has already been done by performing a comparisaon of sama5_defconfig and ou defconfig file. The only difference I have seen is that we use PIT timer and not TC Block as clock source ("TC Block clocksource" unchecked in Device drivers/Misc devices/Atmel AT32/AT91 Timer/Counter Library).

(b) That's the procedure I just explained above. That's exactly how we have created our defconfig file.


FYI, I just tried to build and install a fresh kernel image, built with sama5_defconfig, without any modification. Here is the result :

Code: Select all

# cat /proc/timer_list
Timer List Version: v0.8
HRTIMER_MAX_CLOCK_BASES: 4
now at 15569564720 nsecs

cpu: 0
 clock 0:
  .base:       c0a10fc0
  .index:      0
  .resolution: 1 nsecs
  .get_time:   <c0152538>
  .offset:     0 nsecs
active timers:
 #0: <c0a11680>, <c015e308>, S:01
 # expires at 15570000000-15570000000 nsecs [in 435280 to 435280 nsecs]
 #1: <c0a53bb8>, <c015de48>, S:01
 # expires at 21474836475000000-21474836475000000 nsecs [in 21474820905435280 to 21474820905435280 nsecs]
 clock 1:
  .base:       c0a10fe0
  .index:      1
  .resolution: 1 nsecs
  .get_time:   <c0150f78>
  .offset:     1325376099828239326 nsecs
active timers:
 clock 2:
  .base:       c0a11000
  .index:      2
  .resolution: 1 nsecs
  .get_time:   <c0150f80>
  .offset:     0 nsecs
active timers:
 clock 3:
  .base:       c0a11020
  .index:      3
  .resolution: 1 nsecs
  .get_time:   <c0150f88>
  .offset:     1325376099828239326 nsecs
active timers:
  .expires_next   : 15570000000 nsecs
  .hres_active    : 1
  .nr_events      : 311
  .nr_retries     : 6
  .nr_hangs       : 0
  .max_hang_time  : 0
  .nohz_mode      : 2
  .last_tick      : 15270000000 nsecs
  .tick_stopped   : 0
  .idle_jiffies   : 4294938822
  .idle_calls     : 329
  .idle_sleeps    : 294
  .idle_entrytime : 15557439997 nsecs
  .idle_waketime  : 15557439997 nsecs
  .idle_exittime  : 15557543033 nsecs
  .idle_sleeptime : 13161479313 nsecs
  .iowait_sleeptime: 386266120 nsecs
  .last_jiffies   : 4294938822
  .next_timer     : 16080000000
  .idle_expires   : 16080000000 nsecs
jiffies: 4294938852

Tick Device: mode:     1
Per CPU device: 0
Clock Event Device: tc_clkevt
 max_delta_ns:   1999976423
 min_delta_ns:   30518
 mult:           140737
 shift:          32
 mode:           3
 next_event:     15570000000 nsecs
 set_next_event: <c04f8b14>
 shutdown: <c04f8c50>
 periodic: <c04f8cf8>
 oneshot:  <c04f8c98>
 event_handler:  <c0151ac4>
 retries:        1
Resolution is, actually, 1 nsec but the clock event device is "tc_clkevent" so, TC Block timer is used as scheduler clock. So, my last post's question is still relevant :
- Can PIT timer driver achieve resolution lower than 10000000 nsecs ? (So in that case, something should be wrong in my configuration files, device tree, ...)
In fact, we can't use TC Block timer as scheduler clock source, we already use all channels to generate PWM signals.

Regards
blue_z
Location: USA
Posts: 1952
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D27 - High Resolution Timer support

Fri May 10, 2019 10:33 pm

KevinWysocki wrote: (a) has already been done by performing a comparisaon of sama5_defconfig and ou defconfig file.
No, that is not the procedure that I described for (a).
You're conflating the defconfig files with .config files.

KevinWysocki wrote: The only difference I have seen is that we use PIT timer and not TC Block as clock source ("TC Block clocksource" unchecked in Device drivers/Misc devices/Atmel AT32/AT91 Timer/Counter Library).
Have you bothered at all to consider the significance of this difference?

KevinWysocki wrote: (b) That's the procedure I just explained above. That's exactly how we have created our defconfig file.
Exactly as (b)??!!
No, again you fail to grasp what is written because by "add/suppress[ing] drivers we need (or not) ", you clearly did not follow that procedure of "not disable/remove any features/drivers".
You have not performed step (b), but instead confirmed that you have disabled/removed one-too-many features/drivers necessary for hrtimers with 1 ns resolution.

KevinWysocki wrote:
- Can PIT timer driver achieve resolution lower than 10000000 nsecs ?
Yes, but it's the inferior choice that has negative consequences.
The kernel timer frequency (aka HZ or tick) can be 100 (default), 200, 250, 300, 500, or 1000 Hz.

KevinWysocki wrote: In fact, we can't use TC Block timer as scheduler clock source, we already use all channels to generate PWM signals.
Then why did you write that you "tried to get TC Block as clock source without any success" and just asked about "how to get TC Block as clock source"?

Why are you asking for solutions that you are not going to use?

If you are not going to permit the kernel to manage one TC peripheral as its clocksource, then you have broken the AT91 implementation of high resolution timers.
You have to revert to the legacy scheme of a common tick and timer resolution. The maximum tick rate of 1000 Hz means a timer resolution of 1 millisecond.

Regards
KevinWysocki
Posts: 9
Joined: Wed Aug 22, 2018 5:20 pm

Re: SAMA5D27 - High Resolution Timer support

Mon May 13, 2019 9:39 am

blue_z wrote:
Fri May 10, 2019 10:33 pm
You're conflating the defconfig files with .config files.

No, I'm not. I clearly make the difference with defconfig files (which are "input" files) and .config which are generated.

blue_z wrote:
Fri May 10, 2019 10:33 pm
Have you bothered at all to consider the significance of this difference?


Different peripheral, different driver. That's why I am asking if PIT timer driver can achieve resolutions lower than the default resolution of 10msec (ideally, even lower than 1msec, we have got some control loops scheduled every 500usecs).

blue_z wrote:
Fri May 10, 2019 10:33 pm
No, again you fail to grasp what is written because by "add/suppress[ing] drivers we need (or not) ", you clearly did not follow that procedure of "not disable/remove any features/drivers".
You have not performed step (b), but instead confirmed that you have disabled/removed one-too-many features/drivers necessary for hrtimers with 1 ns resolution.

Then why did you write that you "tried to get TC Block as clock source without any success" and just asked about "how to get TC Block as clock source"?

Why are you asking for solutions that you are not going to use?

My goal is to get HR timers working so, I tried different solutions to understand why some worked and some did't, even I knew full well some solutions couldn't apply with our hardware. That's my choice, to get a full understanding of the situation.

blue_z wrote:
Fri May 10, 2019 10:33 pm
If you are not going to permit the kernel to manage one TC peripheral as its clocksource, then you have broken the AT91 implementation of high resolution timers.
You have to revert to the legacy scheme of a common tick and timer resolution. The maximum tick rate of 1000 Hz means a timer resolution of 1 millisecond.


If I correctly read between the lines, you're suggesting that HR timers couldn't work if TC peripheral isn't selected as clocksource. So, my only option is to stay with the PIT timer as clocksource and modify tick rate (HZ) to 1000Hz to get a timer resolution of 1msec.

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 1 guest