Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 317183 Details for
Bug 462853
Time fails to pass on nanosleep()
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
nanosleep() test program
nanotest.c (text/plain), 3.35 KB, created by
Martin Poole
on 2008-09-19 11:45:45 UTC
(
hide
)
Description:
nanosleep() test program
Filename:
MIME Type:
Creator:
Martin Poole
Created:
2008-09-19 11:45:45 UTC
Size:
3.35 KB
patch
obsolete
> > >#include <stdlib.h> >#include <stdio.h> >#include <errno.h> >#include <string.h> >#include <time.h> >#include <sys/time.h> >#include <sys/resource.h> > >/* minimum would be the 20ms of the sleep plus the 10ms jigger as documented */ >#define SLEEP_US 20000 >#define JIGGER_US 10000 >#define LONG_NAP_US (SLEEP_US+JIGGER_US) >#define SLEEP_NS (SLEEP_US*1000) > >static void >show_error( char *fname, int myrv, int myerr ) >{ > printf( "Function %s returned %d with %d - %s\n", > fname, myrv, myerr, strerror( myerr ) ); > return; >} > >static void >timer_diff( struct timeval *lowv, struct timeval *highv, struct timeval *diffv ) >{ > diffv->tv_sec = highv->tv_sec - lowv->tv_sec; > diffv->tv_usec = highv->tv_usec - lowv->tv_usec; > if ( diffv->tv_usec < 0 ) > { > --diffv->tv_sec; > diffv->tv_usec += 1000000; > } > return; >} > >int >main( int argc, char *argv[] ) >{ > int nsrv, todrv1, todrv2, loop, fail; > int short_sleep=0, long_sleep=0, backwards=0, no_time=0; > struct timeval tod1, tod2, tdiff; > struct timespec sleep_for, remains; > struct rusage consumed; > time_t started,finished; > > started = time(NULL); > > for( loop=0; loop < 10000; loop++ ) > { > /* always preset these values for sanity */ > sleep_for.tv_sec = 0; > sleep_for.tv_nsec = SLEEP_NS; > remains.tv_sec = 0; > remains.tv_nsec = 0; > fail = 0; > > /* now we emulate the sequence in rpm/yum */ > if ( ( todrv1 = gettimeofday( &tod1, NULL ) ) ) > { > /* failed to gettimeofday, should not happen ? */ > show_error( "gettimeofday(1)", todrv1, errno ); > fail++; > } > if ( ( nsrv = nanosleep( &sleep_for, &remains ) ) ) > { > /* failed nanosleep, interrupted maybe ? */ > show_error( "nanosleep", nsrv, errno ); > printf( "Remaining time is %d.%d seconds\n", > (int)remains.tv_sec, (int)remains.tv_nsec ); > fail++; > } > if ( ( todrv2 = gettimeofday( &tod2, NULL ) ) ) > { > /* failed to gettimeofday, should not happen ? */ > show_error( "gettimeofday(2)", todrv2, errno ); > fail++; > } > > if ( fail == 0 ) > { > /* now examine the data for oddities */ > if ( ( tod1.tv_sec > tod2.tv_sec ) > || ( ( tod1.tv_sec == tod2.tv_sec ) && ( tod1.tv_usec > tod2.tv_usec ) ) > ) > { > /* backwards ? */ > timer_diff( &tod2, &tod1, &tdiff ); > printf( "Time went backwards by %d.%d seconds\n", > (int)tdiff.tv_sec, (int)tdiff.tv_usec ); > backwards++; > } > else if ( ( tod1.tv_sec == tod2.tv_sec ) && ( tod1.tv_usec == tod2.tv_usec ) ) > { > /* strangely no time passed */ > no_time++; > }else > { > /* report if difference is less then the sleep */ > timer_diff( &tod1, &tod2, &tdiff ); > if ( ( tdiff.tv_sec == 0 ) && ( tdiff.tv_usec < SLEEP_US ) ) > { > printf( "Short sleep 0.%d seconds\n", (int)tdiff.tv_usec ); > short_sleep++; > }else if ( ( tdiff.tv_sec > 0 ) || ( tdiff.tv_usec > LONG_NAP_US ) ) > { > printf( "Long sleep %d.%d seconds\n", > (int)tdiff.tv_sec, (int)tdiff.tv_usec ); > long_sleep++; > } > } > } > } > > (void) getrusage( RUSAGE_SELF, &consumed ); > > finished = time(NULL); > > printf( "backwards = %d\nno_time = %d\nshort_sleep = %d\nlong_sleep = %d\n", > backwards, no_time, short_sleep, long_sleep ); > > printf( "Elapsed: %d\nSystem: %d.%d\nUser: %d.%d\n", > (int)(finished - started), > (int)consumed.ru_stime.tv_sec, (int)consumed.ru_stime.tv_usec, > (int)consumed.ru_utime.tv_sec, (int)consumed.ru_utime.tv_usec ); > > return(0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 462853
: 317183 |
317208