public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* nanosleep with small value
@ 2005-11-17 16:30 Dag Nygren
  2005-11-17 16:55 ` linux-os (Dick Johnson)
  2005-11-17 17:12 ` Nish Aravamudan
  0 siblings, 2 replies; 11+ messages in thread
From: Dag Nygren @ 2005-11-17 16:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: dag


Hi,

seeing a strange thing happening here:
using nanosleep() with a smallish value gives me a very long sleeptime?

Is this because of a context switch being forced?
Shouldn't the scheduler change affect that?

The test program:
===================================
#include <time.h>
#include <sched.h>
#include <stdio.h>

void delay_ns(unsigned long dly)
{
        static struct timespec time;
        int err;
        {
                time.tv_sec = 0;
                time.tv_nsec = dly;
                err = nanosleep(&time, NULL);
                if (err) {
                        perror( "nanosleep failed" );
                }
        }
}


main()
{
        int i;

        struct sched_param mysched;
        int err;

        if ( sched_getparam( 0, &mysched ) != 0 )
                perror( "" );
        else {
                mysched.sched_priority = sched_get_priority_max(SCHED_FIFO);
                err = sched_setscheduler(0, SCHED_FIFO, &mysched);
                if( err != 0 ) {
                        fprintf (stderr,"sched_setscheduler returned: %d\n", 
err );
                        perror( "" );
                }
        }

        for (i=0; i < 1000; i++)
                delay_ns(1000UL);
}
==================================
The result running this is:
% time ./tst

real    0m8.000s
user    0m0.000s
sys     0m0.000s

I would have expected about 1000 * 1 us + overhead,
but 8 seconds ????

Noticed this when trying to debug a PIC-programming
software where the delay_ns() routine is used.

Increasing the nanosleep() argument to something more than HZ
will give me the expected sleep times.

Best

-- 
Dag Nygren                               email: dag@newtech.fi
Oy Espoon NewTech Ab                     phone: +358 9 8024910
Träsktorpet 3                              fax: +358 9 8024916
02360 ESBO                              Mobile: +358 400 426312
FINLAND



^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <29495f1d0511171051q6088099drfe094817a01668e4@mail.gmail.com>]
* Re: nanosleep with small value
@ 2005-11-17 20:25 Dag Nygren
  0 siblings, 0 replies; 11+ messages in thread
From: Dag Nygren @ 2005-11-17 20:25 UTC (permalink / raw)
  To: linux-kernel


OK,

thanks to all that sorted this out for me. What mislead me
big time was my old manpage for nanosleep() which claimed
to busywait for short nanosleeps().

2.6 doesn't seem to do that.

I will look into the suggested patches. Just hate not being able
to just grab the latest kernel from kernel.org and throw it in there.
Already have to recompile a Matrox display module. Now this would
be an additional problem nuisance.

But once again thanks to all
Dag


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-11-21  7:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-17 16:30 nanosleep with small value Dag Nygren
2005-11-17 16:55 ` linux-os (Dick Johnson)
2005-11-17 17:32   ` Eric Piel
2005-11-17 17:12 ` Nish Aravamudan
2005-11-17 18:47   ` Dag Nygren
     [not found] <29495f1d0511171051q6088099drfe094817a01668e4@mail.gmail.com>
2005-11-17 19:11 ` Dag Nygren
2005-11-17 19:15   ` Randy.Dunlap
2005-11-17 19:17   ` Nish Aravamudan
2005-11-17 19:47   ` Frank Sorenson
2005-11-21  7:12     ` Dag Nygren
  -- strict thread matches above, loose matches on Subject: below --
2005-11-17 20:25 Dag Nygren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox