gettimeofday() has the lowest overhead due it to using vDSO as cleverca22 mentioned.I am trying to do something as close to "real time" as possible. Using a system call (IMHO) just adds overhead.
The RTC can't be accessed directly as its part of the PMIC which the Pi firmware controls. Even if you could access it, the I2C transaction will be much slower than a syscall.One frequently used system call is gettimeofday(2). This system call is called both directly by user-space applications as well as indirectly by the C library. Think timestamps or timing loops or polling—all of these frequently need to know what time it is right now. This information is also not secret—any application in any privilege mode (root or any unprivileged user) will get the same answer. Thus the kernel arranges for the information required to answer this question to be placed in memory the process can access. Now a call to gettimeofday(2) changes from a system call to a normal function call and a few memory accesses.
The Linux system clock will be more accurate than the RTC anyway. The kernel and NTP if available will correct for drift during operation. The RTC won't have that continual adjustment.
You're making it difficult by trying to directly port across what you'd do on a microcontroller. Bare metal on a microcontroller is very different to a multiuser multitasking OS on a complex processor with a MMU.Why is this so hard ?
Statistics: Posted by trejan — Thu Jul 04, 2024 12:09 pm