You can use the processor's cycle counter to measure the number of cycles between two moments, and then convert them to seconds. To ensure that the processor operates at its rated frequency, switch its zoom control to βperformanceβ mode (there are many applications on the Play Store for this, but root access is required for this). You also need to cool the device well to make sure that the CPU is not throttling (this is especially important for phones). Finally, you must bind your code to one kernel (preferably kernel 0, because other kernels can be disabled by the system on the system).
There are two ways to access the cycle counter in ARM: using the perf_event subsystem on Linux or directly reading the cycle counter from the CP15 coprocessor. The perf_event method will only work if the Linux kernel is compiled with support for this subsystem (the file / proc / sys / kernel / perf_event_paranoid exists) and reading event counters is unlimited (the file / proc / sys / kernel / perf_event_paranoid contains 0 or - 1, with root access, you can overwrite the value in this file). The CP15 method will work only if the user access to performance counters mode is enabled (by default it is always disabled and you will either have to fix the kernel or use the kernel driver to enable it). Yeppp! the library (I am the author) is able to use any method whenever it is available, and includes a kernel-mode driver that allows the user access to performance counters in user mode. You may find this example helpful.
Marat dukhan
source share