Results 1 to 1 of 1
I'm inspecting the timing capabilities in Linux. I made a program that sends pulse-per-second to parallel port. I measured the frequency of the pulses and noticed some surprising effects caused ...
- 08-31-2007 #1Just Joined!
- Join Date
- Aug 2007
- Location
- Finland
- Posts
- 1
nanosleep() -system call does some confusing things
I'm inspecting the timing capabilities in Linux. I made a program that sends pulse-per-second to parallel port. I measured the frequency of the pulses and noticed some surprising effects caused by involving a nanosleep() system call to my program. Here is my program:
In my code, the function of the first nanosleep() is to change the phase of pulses relative to system clock second ticks. So it should not affect to the frequency of the pulses. Nevertheless, the frequency of pulses without nanosleep() is ~1.000001 Hz, but with nanosleep the frequency is ~1.0001 Hz. I tried to change the amount of nanosleeping, but it doesnt make effect if it was 1 ns or 1 ms. So my conclusion from that is that involving a nanosleep to my loop raises the frequency of pulse-per-second. Does anyone know any explanations to this? The latter nanosleep() is there just to keep outputlevel up for a while to create short pulse. The problem is in the first nanosleep(). My frequency analyzator detects rising edges of pulses. I programmed a kernel module that is operating identically, but the same problem exists there too (in kernel nanosleep() is replaced by nsleep() of course).Code:while(1) { // Wait for system clock second change while(second1 == second2) { time(&aclock); test_time = localtime(&aclock); second2 = test_time->tm_sec; } time(&aclock); test_time = localtime(&aclock); second1 = test_time->tm_sec; second2 = test_time->tm_sec; // Wait a bit more. This should not make effect, but makes. ts.tv_nsec = 1e8 nanosleep(&ts, NULL); outb(0xff, 0x378); ts.tv_nsec = 1e4 nanosleep(&ts, NULL); outb(0x00, 0x378); }
Best Regards,
Jussi


Reply With Quote