Precision periodic timer using virtual timers

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: Precision periodic timer using virtual timers

Postby electronic_eel » Wed Apr 28, 2021 8:28 pm

Giovanni wrote:Callback changes will require going through the whole code base and find all places where to adjust code.

Wouldn't the compiler give you errors for all these places when you change the callback function parameter from void* to a pointer to a virtual timer struct pointer?

If the compiler doesn't give an error, this change would be a dangerous one, as users migrating their code might overlook one function in a seldom used code path.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Precision periodic timer using virtual timers

Postby Giovanni » Thu Apr 29, 2021 4:50 am

It does give warnings so it is pretty clear where to adjust.

Giovanni

electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: Precision periodic timer using virtual timers

Postby electronic_eel » Thu Apr 29, 2021 9:57 pm

I now had time to look through the patches you implemented.

You now implemented it with fully automatic reload where you don't have to call chVTReload in the callback to make it periodic, correct? What made you change your mind? You had to add last and reload to virtual_timer_t.

This part of the documentation for chVTSetContinuous and chVTSetContinuousI does not look correct to me:

Code: Select all

+ * @param[in] vtfunc    the timer callback function. After invoking the
+ *                      callback the timer is disabled and the structure can
+ *                      be disposed or reused.


Will chVTGetRemainingIntervalX() work for one-shot timers? I think it won't because you calculate based on the reload value. I think this should at least be documented. It would be better if it would work for both kinds of timers though ;)

Oh, and one small request from me: please sync changes like these to github too. I know you prefer SVN over git, but I find extracting patches using svn or the OSDN webinterface much slower and more cumbersome than using git where they are all synced to your local system and are easily accessible.

faisal
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

Re: Precision periodic timer using virtual timers

Postby faisal » Thu Apr 29, 2021 10:39 pm

electronic_eel wrote:Oh, and one small request from me: please sync changes like these to github too. I know you prefer SVN over git, but I find extracting patches using svn or the OSDN webinterface much slower and more cumbersome than using git where they are all synced to your local system and are easily accessible.


We need to get off Giovanni's case about git. He likes his inferior VCS :). Why don't you just use SVN to checkout the official repo? SVN has pretty much the same functionality - svn diff and svn patch. How is that any different from git?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Precision periodic timer using virtual timers

Postby Giovanni » Fri Apr 30, 2021 6:19 am

electronic_eel wrote:Will chVTGetRemainingIntervalX() work for one-shot timers? I think it won't because you calculate based on the reload value. I think this should at least be documented. It would be better if it would work for both kinds of timers though ;)

Oh, and one small request from me: please sync changes like these to github too. I know you prefer SVN over git, but I find extracting patches using svn or the OSDN webinterface much slower and more cumbersome than using git where they are all synced to your local system and are easily accessible.


Implementing it for one-shot timers would mean scanning the list before removing the timer adding all deltas or add a 3rd field to the structure, not sure about both solutions. We are working on a problem on the new implementation that is shown by the updated "VT Storm" test application, please do not assume that the current code can be used safely.

About SVN, I don't see how it is different from what you are saying, it is clear you never used it. There are features I use in SVN that I could not replicate using git, especially administrative ones.

Anyway, updating the git repository is not up to me, it is community-maintained.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Precision periodic timer using virtual timers

Postby Giovanni » Fri May 07, 2021 8:58 pm

Hi,

Changes to timers have been committed, Bob is helping with stress tests. Now it is possible to start one-shot or continuous timers and change the period from the callback if required.

Callbacks now have 2 parameters, the timer itself and the usual user parameter, look for warnings and adjust.

Another thing we tried is to return from the callback the next reload value or zero, this saved the extra field from the timer structure but code become a bit larger in each callback so it was reverted.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Precision periodic timer using virtual timers

Postby Giovanni » Fri Jun 04, 2021 9:10 am

Just an update on this.

Recent work (thanks Bob) has improved VTs performance, in general now it is possible to run with much lower CH_CFG_ST_TIMEDELTA values and use very very high resolutions for system time. I used frequencies like 50 MHz without problems.

1 MHz could become the new "standard" for platforms with 32 bits ST timers.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 22 guests