Experiments with a different timerhook
I have already done many experiments with pysimCoder generated NuttX code on the SaMoCon platform. The small delays using clock_nanosleep were supposed to be fixed by the Tickless configuration, which has proved to be quite bad (rigorous measurements must be made, speaking only from my experience).
I did some experiments using the systemtick hook, which works well, as I am now capable of achieving at least 4 kHz. Despite the good performance, the hook is tied to the systemtick, introducing a lot of potential switching overhead.
What I propose is a different kind of timerhook. as shown in my local NuttX commit. It uses a local timer device which, when it overflows, generates and interrupt with a sem_post call. The overhead is only in the timer interrupt handling. The timer can be started and its timeout can be set via ioctl calls.
With this, I am also planning to introduce new Makefile and a new nuttx main.c file. If this timerhook proves to be good performing in my experiments, I'd like to create a PR.
Hi,
this is interesting. I did some tests with F7 and H7 STM boards, using the timerhook, but we few improvements... You approach seem to be more interesting.
Can you send an example "main.c" to handle this? What do we have to change in our configuration/files to use it?
Ciao,
I'm ready to propose a new type of NuttX main.c file. You can have a look at it here. Do not confuse this file with the previous nuttx_main_timehook.c, which I renamed to nuttx_main_systemtickhook.c (as it, in my opinion, makes for sense, due to the define in Kconfig).
In the same sense, I would like to introduce a new nuttx_timerhook.tmf file (and nuttx_systemtickhook.tmf, renamed). Basically, this new main.c utilizes a device timer, which can be polled by the poll function. The poll returns if the timer expires. While it's not as elegant like the POSIX functions, it performs very well (up to 10 kHz with simpler models on SAMV7).
In my experiments, the now called systemtickhook performed well as well. The downside of such solution is the high OS switching rate, potentially introducing a lot of overhead.
Yes, it'd be ideal if there was only one Makefile and one nuttx main.c file, but for now I'm keeping these things separated. Also, what I need, is a way to define the device timer to be used for model sampling. I've solved this by introducing a field in the dialog box, called Additional C Defines. If the macro is not defined, the compilation results in an error, prompting the user to do the defines. Also discussed here.