Hi,
I am doing an embedded project. Kernel is 4.9.
A simple app runs when whole system is almost idle (no other apps running)
int main(int argc, char **argv)
{
int i = 0;
system("date");
for(i=0; i<6000; i++)
usleep(400);
system("date");
}
You would expect it can finish in 2.4 seconds with a bit overhead. But this one takes
60 seconds for the loop, I measure each usleep(400) takes around 10ms.
Tried below:
1, patch 4.9 from 4.9.1 to 4.9.214, No improvement.
2, with rt patch (choose "Fully Preemptible Kernel RT") or without rt patch (choose "Preemptible Kernel Low-latency Desktop"). No difference.
3, change this small app's real time priority from 0 to 90, No difference.
4, try replacing usleep with nanosleep/select with timeout, No improvement.
5, Change HZ from 100 to
1000, each usleep(400) takes around 1 ms.
Nothing else is competing for CPU. It seems 4.9 kernel adds extra scheduler delay, and it is related to HZ value (100HZ is around 10ms, 1000HZ is around 1ms, it seems it always consumes a full jiffy before being rescheduled). I have run similar kernel options with
4.1 kernel, it takes <3 seconds to finish, that is correct.
If it is not scheduler issue, it may be timer issue: the app is not waken up at 400us, but 10ms or 1ms later depending on HZ value. The hrtimer is enabled in test.
This issue only happens in 4.9, but not in 4.1.
Any thoughts on this ? very much appreciated !
Regards,
Jack.