Subj : Re: Solaris real-time thread capabilities To : comp.unix.solaris,comp.programming.threads From : Greg Menke Date : Tue Sep 06 2005 10:15 pm Should be handling rollover of your delta; if( t2 > t1 ) diff = t2 - t1; else diff = t1 - t2; and your endTime calculation is overflowing the int type, make numberOfSecondsForTest of type hrtime_t. Then the test will run for the specified time. Modifed your app to use bins, configured off the top of my head. Code is attached. Runs follow first- only 2 runs, but RT scheduling shows fine as expected. Ambient scheduling load varies from idle to heavy use (scrolling heavy bitmap pdf docs, running OpenOffice, web browsing, etc). System is 2x450 Ultra 60, 512megs, Solaris 9. Overflows where the diff time exceeds 10ms are flagged as "Overflow!"- considered bad. default priority [gregm@athena ~]$ ./sch 300 Running for 300 seconds... Overflow! Overflow! Overflow! Overflow! Overflow! Overflow! results; bin 0 0- 199999 304137052 bin 1 200000- 399999 1147 bin 2 400000- 599999 582 bin 3 600000- 799999 259 bin 4 800000- 999999 60 bin 5 1000000- 1199999 33 bin 6 1200000- 1399999 23 bin 7 1400000- 1599999 8 bin 8 1600000- 1799999 10 bin 9 1800000- 1999999 6 bin 10 2000000- 2199999 3 bin 11 2200000- 2399999 3 bin 12 2400000- 2599999 1 bin 13 2600000- 2799999 5 bin 14 2800000- 2999999 2 bin 15 3000000- 3199999 1 bin 16 3200000- 3399999 0 bin 17 3400000- 3599999 0 bin 18 3600000- 3799999 0 bin 19 3800000- 3999999 0 bin 20 4000000- 4199999 1 bin 21 4200000- 4399999 0 bin 22 4400000- 4599999 0 bin 23 4600000- 4799999 2 bin 24 4800000- 4999999 0 bin 25 5000000- 5199999 1 bin 26 5200000- 5399999 1 bin 27 5400000- 5599999 0 bin 28 5600000- 5799999 0 bin 29 5800000- 5999999 2 bin 30 6000000- 6199999 0 bin 31 6200000- 6399999 0 bin 32 6400000- 6599999 1 bin 33 6600000- 6799999 1 bin 34 6800000- 6999999 0 bin 35 7000000- 7199999 2 bin 36 7200000- 7399999 1 bin 37 7400000- 7599999 0 bin 38 7600000- 7799999 0 bin 39 7800000- 7999999 1 bin 40 8000000- 8199999 0 bin 41 8200000- 8399999 2 bin 42 8400000- 8599999 1 bin 43 8600000- 8799999 1 bin 44 8800000- 8999999 1 bin 45 9000000- 9199999 1 bin 46 9200000- 9399999 0 bin 47 9400000- 9599999 0 bin 48 9600000- 9799999 1 bin 49 9800000- 9999999 0 RT task, identical executable [root@athena /export/home/gregm]$ priocntl -e -c RT -p 5 ./sch 500 Running for 500 seconds... results; bin 0 0- 199999 520037346 bin 1 200000- 399999 0 bin 2 400000- 599999 0 bin 3 600000- 799999 0 bin 4 800000- 999999 0 bin 5 1000000- 1199999 0 bin 6 1200000- 1399999 0 bin 7 1400000- 1599999 0 bin 8 1600000- 1799999 0 bin 9 1800000- 1999999 0 bin 10 2000000- 2199999 0 bin 11 2200000- 2399999 0 bin 12 2400000- 2599999 0 bin 13 2600000- 2799999 0 bin 14 2800000- 2999999 0 bin 15 3000000- 3199999 0 bin 16 3200000- 3399999 0 bin 17 3400000- 3599999 0 bin 18 3600000- 3799999 0 bin 19 3800000- 3999999 0 bin 20 4000000- 4199999 0 bin 21 4200000- 4399999 0 bin 22 4400000- 4599999 0 bin 23 4600000- 4799999 0 bin 24 4800000- 4999999 0 bin 25 5000000- 5199999 0 bin 26 5200000- 5399999 0 bin 27 5400000- 5599999 0 bin 28 5600000- 5799999 0 bin 29 5800000- 5999999 0 bin 30 6000000- 6199999 0 bin 31 6200000- 6399999 0 bin 32 6400000- 6599999 0 bin 33 6600000- 6799999 0 bin 34 6800000- 6999999 0 bin 35 7000000- 7199999 0 bin 36 7200000- 7399999 0 bin 37 7400000- 7599999 0 bin 38 7600000- 7799999 0 bin 39 7800000- 7999999 0 bin 40 8000000- 8199999 0 bin 41 8200000- 8399999 0 bin 42 8400000- 8599999 0 bin 43 8600000- 8799999 0 bin 44 8800000- 8999999 0 bin 45 9000000- 9199999 0 bin 46 9200000- 9399999 0 bin 47 9400000- 9599999 0 bin 48 9600000- 9799999 0 bin 49 9800000- 9999999 0 Source below; I wonder if your printf (cout- whatever) might have been messing things up. c++ vs c doesn't seem to make much difference. #include #include #define NUM_BINS 50 #define BIN_MAX 10000000 /* 10 ms */ #define BIN_SPAN (BIN_MAX / NUM_BINS) int main(int argc, char* argv[]) { const int ARG_SECONDS = 1; const int ARG_NUMBER = 2; struct timebin { int numSamples; } diffbins[ NUM_BINS ]; if(argc != ARG_NUMBER) { exit(1); } long CONVERT_SECONDS_TO_NS = 1000000000; unsigned int numSeconds = atoi(argv[ARG_SECONDS]); hrtime_t numberOfSecondsForTest = (hrtime_t)numSeconds; hrtime_t startTime = gethrtime(); hrtime_t endTime = startTime + numberOfSecondsForTest * CONVERT_SECONDS_TO_NS; hrtime_t t1 = 0; hrtime_t t2 = 0; hrtime_t diff = 0; hrtime_t cummulativeDiff = 0; hrtime_t averageDiff = 0; hrtime_t maxDiff = 0; long numCyclesInsideSpinLoop = 0; hrtime_t currentTime; memset( diffbins, 0, sizeof(struct timebin) * NUM_BINS); printf("Running for %d seconds...\n", numSeconds ); while( (currentTime = gethrtime()) < endTime) { numCyclesInsideSpinLoop += 1; t1 = gethrtime(); t2 = gethrtime(); if( t2 > t1 ) diff = t2 - t1; else diff = t1 - t2; if( diff < BIN_MAX ) { diffbins[ (unsigned int)(diff / BIN_SPAN) ].numSamples++; } else { printf("Overflow!\n"); } } printf("results;\n"); { int i; for(i=0; i< NUM_BINS; i++) { printf(" bin %2d %10d-%10d %10d\n", i, (BIN_SPAN * i), (BIN_SPAN * (i+1))-1, diffbins[i].numSamples ); } } } /* eof */ .