Shared Clock between Linux and M4

We are planning on using a M4 to process packets from an external device, with the data being sent via rpmsg to our main process. The time the M4 initially receives these packets is critically important to our application.

Even simply reading the TSTMR from userland would be enough. Is there a shared clock that’s available between the M4 and Linux that can be easily read, and what would be the process to access it from inside a docker container?

-Will

Hi @WilliamW,

i.MX7 / i.MX8 seem having plenty of GPT timers. Obvious would be letting one of them free running at appropriate tick rate and allowing to read timer counter from user space… M4 could read the same timer counter easily. But that seems being not implemented, I mean Linux driver to let GPT free run and read timer counter from user space.

What is your expected timer tick? Another approach could be creating two timer counters with identical tick rate on M4 and A, then synchronizing counters with appropriate precision.

Edward

Oh, if /dev/mem is enabled and present, then you should be able to initialize GPT on M4 (without RDC-restricting GPT usage from M4 only) and access the same GPT counter form user space using mmap() calls.

Edward

I thought about going about it through /dev/mem, have you attempted this from inside a privileged docker container? I get an operation not permitted error, and open() returns -1 when reading that file.

Anyway, for a long term solution I don’t think this would work. The security risks alone are uncomfortable to think about. Writing a driver for the specific address I need to read will work, but there’s got to be another way right?

Greetings @WilliamW!

Can you please share how you ran this container? Did you just run this with the --privileged flag or did you also share the specific device e.g. --device /dev/mem?

Regarding a long term solution, I have nothing on my mind except the two timer counters approach that @Edward has suggested. I don’t think there’s such an example on the NXP-provided SDK, though.

You can program a GPT as a System Clock in the M4 and send the current clock to Linux through RPMSG. This way both programs would use a single clock reference.

As long as the application on Linux can wait for the next RPMSG package, this should suffice.

HI @WilliamW

Did you try the suggestion of Gustavo? Is the issue solved?

Hi, sorry for the late response.

I ended up going with Edward’s suggestion. A privileged container can access /dev/mem, which can be mmapped and read, allowing both the M4 and the main SOC to access the same timer (in my case, the TSTMR). The issue has been solved.

Hi @WilliamW

Perfect that the issue is solved. Thanks for the feedback.

Best regards,
Jaski