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 595158 Details for
Bug 812148
High CPU usage of scheduler when sleeping
[?]
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.
Simpler version of test_sleep program
test_sleep_simple.c (text/x-csrc), 4.65 KB, created by
Dave Johansen
on 2012-06-29 00:32:53 UTC
(
hide
)
Description:
Simpler version of test_sleep program
Filename:
MIME Type:
Creator:
Dave Johansen
Created:
2012-06-29 00:32:53 UTC
Size:
4.65 KB
patch
obsolete
>#include <poll.h> >#include <pthread.h> >#include <stdio.h> >#include <stdlib.h> >#include <unistd.h> >#include <sys/select.h> > > >// The different type of sleep that are supported >enum sleep_type { > SLEEP_TYPE_NONE, > SLEEP_TYPE_YIELD, > SLEEP_TYPE_SELECT, > SLEEP_TYPE_POLL, > SLEEP_TYPE_USLEEP, > SLEEP_TYPE_PTHREAD_COND, > SLEEP_TYPE_NANOSLEEP, >}; > >// Function type for doing work with a sleep >typedef void (*work_func)(const int sleep_time, const int num_iterations, const int work_size); > >// In order to make SLEEP_TYPE a run-time parameter function pointers are used. >// The function pointer could have been to the sleep function being used, but >// then that would mean an extra function call inside of the "work loop" and I >// wanted to keep the measurements as tight as possible and the extra work being >// done to be as small/controlled as possible so instead the work is declared as >// a seriees of macros that are called in all of the sleep functions. The code >// is a bit uglier this way, but I believe it results in a more accurate test. > >// Fill in a buffer with random numbers (taken from latt.c by Jens Axboe <jens.axboe@oracle.com>) >#define DECLARE_FUNC(NAME) void do_work_##NAME(const int sleep_time, const int num_iterations, const int work_size) > >#define DECLARE_WORK() \ > int *buf; \ > int pseed; \ > int inum, bnum; \ > buf = malloc(work_size * sizeof(*buf)); > >#define DO_WORK(SLEEP_FUNC) \ > for (inum=0; inum<num_iterations; ++inum) { \ > SLEEP_FUNC \ > \ > pseed = 1; \ > for (bnum=0; bnum<work_size; ++bnum) { \ > pseed = pseed * 1103515245 + 12345; \ > buf[bnum] = (pseed / 65536) % 32768; \ > } \ > } \ > >#define FINISH_WORK() \ > free(buf); > >DECLARE_FUNC(nosleep) >{ > DECLARE_WORK(); > > // Let the compiler know that sleep_time isn't used in this function > (void)sleep_time; > > DO_WORK(); > > FINISH_WORK(); >} > >DECLARE_FUNC(select) >{ > struct timeval ts; > DECLARE_WORK(); > > DO_WORK( > ts.tv_sec = 0; > ts.tv_usec = sleep_time; > select(0, 0, 0, 0, &ts); > ); > > FINISH_WORK(); >} > >DECLARE_FUNC(poll) >{ > struct pollfd pfd; > const int sleep_time_ms = sleep_time / 1000; > DECLARE_WORK(); > > pfd.fd = 0; > pfd.events = 0; > > DO_WORK( > poll(&pfd, 1, sleep_time_ms); > ); > > FINISH_WORK(); >} > >DECLARE_FUNC(usleep) >{ > DECLARE_WORK(); > > DO_WORK( > usleep(sleep_time); > ); > > FINISH_WORK(); >} > >DECLARE_FUNC(yield) >{ > DECLARE_WORK(); > > // Let the compiler know that sleep_time isn't used in this function > (void)sleep_time; > > DO_WORK( > sched_yield(); > ); > > FINISH_WORK(); >} > >DECLARE_FUNC(pthread_cond) >{ > pthread_cond_t cond = PTHREAD_COND_INITIALIZER; > pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; > struct timespec ts; > const int sleep_time_ns = sleep_time * 1000; > DECLARE_WORK(); > > pthread_mutex_lock(&mutex); > > DO_WORK( > clock_gettime(CLOCK_REALTIME, &ts); > ts.tv_nsec += sleep_time_ns; > if (ts.tv_nsec >= 1000000000) { > ts.tv_sec += 1; > ts.tv_nsec -= 1000000000; > } > pthread_cond_timedwait(&cond, &mutex, &ts); > ); > > pthread_mutex_unlock(&mutex); > > pthread_cond_destroy(&cond); > pthread_mutex_destroy(&mutex); > > FINISH_WORK(); >} > >DECLARE_FUNC(nanosleep) >{ > struct timespec req, rem; > const int sleep_time_ns = sleep_time * 1000; > DECLARE_WORK(); > > DO_WORK( > req.tv_sec = 0; > req.tv_nsec = sleep_time_ns; > nanosleep(&req, &rem); > ); > > FINISH_WORK(); >} > >int main(int argc, char **argv) >{ > if (argc < 5) { > printf("Usage: %s <sleep_time> <num_iterations> <work_size> <sleep_type>\n", argv[0]); > printf(" num_iterations: Number of work/sleep cycles performed (used to improve consistency/observability))\n"); > printf(" work_size: Number of array elements (in kb) that are filled with psuedo-random numbers\n"); > printf(" sleep_type: 0=none 1=select 2=poll 3=usleep 4=yield 5=pthread_cond 6=nanosleep\n"); > return -1; > } > > int sleep_time; > int num_iterations; > int work_size; > int sleep_type; > work_func func; > > // Get the parameters > sleep_time = atoi(argv[1]); > num_iterations = atoi(argv[2]); > work_size = atoi(argv[3]) * 1024; > sleep_type = atoi(argv[4]); > switch (sleep_type) { > case SLEEP_TYPE_NONE: func = &do_work_nosleep; break; > case SLEEP_TYPE_SELECT: func = &do_work_select; break; > case SLEEP_TYPE_POLL: func = &do_work_poll; break; > case SLEEP_TYPE_USLEEP: func = &do_work_usleep; break; > case SLEEP_TYPE_YIELD: func = &do_work_yield; break; > case SLEEP_TYPE_PTHREAD_COND: func = &do_work_pthread_cond; break; > case SLEEP_TYPE_NANOSLEEP: func = &do_work_nanosleep; break; > default: > printf("Invalid sleep type: %d\n", sleep_type); > return -7; > } > > // Do the work > func(sleep_time, num_iterations, work_size); > > 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 812148
:
577173
|
577384
|
577389
|
580227
|
580576
|
581243
|
581244
|
581245
|
581246
|
581247
|
581248
|
581249
|
581250
|
581251
|
582713
|
582723
|
582724
|
582725
|
582726
|
582727
|
582728
|
582729
|
582730
|
582731
|
582732
|
582733
|
582734
|
582735
|
582736
|
582737
|
582738
|
582739
|
582740
|
583676
|
584416
|
584419
|
595158
|
598759
|
734215