I need to have precise timing on a multicore machine (Allwinner A20 processor) for home automation applications
- using bit banging lirc (infrared remote simulation) to control some hifi and tv equipment
- using RF-OOK to control some RF controlled plugs or TV/Projector screens, maybe more in the future
The problem:
- The available kernel is only legacy (3.4.1xx or so), which uses BogoMIPS to control udelay()
- The machine has two processors. "cat /proc/cpuinfo" shows 1914.96 BogoMIPS on the first processor and 1664.12 BogoMIPS on the second one
- The timing and configuration files for LIRC always seemed to be extremely fiddly and IR receivers did not work well. After revisiting, I noticed (years later) that udelay seems to be using the 1664.12 BogoMIPS as a base programmatically, but it actually uses the 1914.94 BogoMIPS in reality. The timing is always around 15% faster than expected. I am pretty sure that this is because of the different timings of processors.
- If I try using usleep or usleep_range, I need to get out of atomic context and timing is not working at all, in this case. I would actually like this, as e.g. listening to music experiences some scrambling whenever the lirc bit banging or the OOK is used.
Interestingly, I find in the dmesg: "Calibrating delay loop... 1914.96 BogoMIPS (lpj=3188736)"... So there may be something fishy with the kernel, but I do not know where to look for...
Knowing the problem, of course it can be taken into consideration when specifying the delays, but this seems like a terrible hack...
I have two questions actually
- Is it possible to use usleep to get precise timing for a kernel module (precise meaning usec precision for immediately repeated delays of around 20 usecs), thus, not having atomic context
- How can the udelay made more "deterministic" in terms of on which processor it should run while using the correct BogoMIPS constant for that processor
If it helps, kernel modules are here: https://github.com/matzrh/sunxi-lirc and https://github.com/matzrh/rfm12b-linux (the sun7i-spi patch)