latencytest0.42/ 40755 764 764 0 6766470000 12306 5ustar bennobennolatencytest0.42/Makefile100644 764 764 1635 6766467112 14062 0ustar bennobenno# on Intel systems use PENTIM_TIMER (uses the RDTSC instruction) # on other systems (ALPHA,SPARC,PPC) use GENERIC_TIMER (uses gettimeofday() ) #TIMER_OPTIONS=-DUSE_GENERIC_TIMER TIMER_OPTIONS=-DUSE_PENTIUM_TIMER CC=gcc #CCOPTS=-Wall -O -D_REENTRANT CCOPTS=-Wall -O2 $(TIMER_OPTIONS) all: latencytest rtc_latencytest # cpu_latency latencytest: latencytest.o gfx.o $(CC) -o latencytest latencytest.o gfx.o -lm -lgd rtc_latencytest: rtc_latencytest.o gfx.o $(CC) -o rtc_latencytest rtc_latencytest.o gfx.o -lm -lgd #cpu_latency: cpu_latency.o gfx.o # $(CC) -o cpu_latency cpu_latency.o gfx.o -lm -lgd latencytest.o: latencytest.c $(CC) $(CCOPTS) -c latencytest.c rtc_latencytest.o: rtc_latencytest.c $(CC) $(CCOPTS) -c rtc_latencytest.c gfx.o: gfx.c $(CC) $(CCOPTS) -c gfx.c #cpu_latency.o: cpu_latency.c # $(CC) $(CCOPTS) -c cpu_latency.c clean: rm -f *.o latencytest rtc_latencytest cpu_latency core latencytest0.42/README100664 764 764 21717 6766467642 13337 0ustar bennobenno The main purpose of the program is to measure scheduling latencies under high system load, of programs which must do things in realtime. Actually there are 5 operating system stressing classes: - heavy graphics output , using x11perf to simulate large BitBlts - heavy access to the /proc filesystem using "top" with an update frequency of 0.01 sec - disk write stress ( write a large file to disk) - disk copy stress (copy a large file to an other) - disk read stress ( read a large file from disk) I wrote the benchmark to test the realtime audio (PCM I/O) capatibilities of Linux. In future I will extend the program to test other subsystems, like MIDI I/O , serial I/O and using usleep()s The playing is done strictly from RAM. the player thread gets RT priorty through sched_setscheduler() is is scheduled with FIFO policy at maximum priority the player sits in a loop which does basically the following while(1) { time1=my_gettime(); waste 80% of the CPU of the duration of one audio fragment time2=my_gettime(); write(audio_fd,playbuffer,fragmentsize); time3=my_gettime(); } time3-time1 = duration of one loop ( CPU wasting + audio output) If this time gets bigger then the audio buffer ( n fragments) then you will hear an audio dropout. time2-time1 = duration of the CPU wasting loop should be constant at 80% of the fragment timelen , but can vary if if there is some device on the bus (or kernel I/O routine) which steals cycles to the CPU. On some graphics cards, heavy graphic output, blocks the bus for too much time, and therefore the process gets blocked too long, and the deadline (in this case the audio buffer timelen) will be missed. So high scheduling latencies have two causes - hardware related ( operating system can't cure these problems, therefore the only solution is to buy non-problematic hardware) examples: DMA/PCI transfers which move around large amounts of data and block bus access to the CPU, like some graphics cards which blocks the bus during large BitBlits , or some older mainboards (Socket 7) which freeze the bus during harddisk DMA transfers. - software related: the operating system holds some global spinlocks during disk I/O so that other syscalls can't access to needed data structures for long time, and therefore there are scheduling deadline misses. My machine is a PII400 , Mainboard ASUS P2B (BX) 256MB RAM Harddisk IBM Deskstar 16GB EIDE UDMA The performed tests show clearly that modern hardware ( PII + UDMA Harddrives) is capable of low scheduling latencies during high system load. Unfortunately Linux has some problems, and sometimes blocks other system calls for too much time ( up to 100-130ms ) and therefore stable low-latency ( < 10-20ms) realtime audio becomes almost impossible. *UPDATE*: Ingo Molnar found the problems ( certain parts of the kernel do not reschedule for several msecs leading to long scheduling latencies for user processes) With his patch, I get excellent results (about 2ms-3ms audio latency). get the latest news from my audio page: http://www.gardena.net/benno/linux/audio HOW TO USE THE BENCHMARK: IMPORTANT: Before running the benchmark if you have EIDE drives, tune *ALL* your disks, because a not tuned EIDE drive can produce very bad benchmark results. You can tune the disk with the my script "tunedisk" wich calls hdparm and turns on all disk-tuning options. for example if you have 2 drives hda and hdc runs run ./tunedisk /dev/hda ./tunedisk /dev/hdc Turn off the screensaver too, because it could cause some distortion in the testresults. NOTE: to compile the program you need the gd GIF library, which is installed on Redhat by default. to compile the program on NON-INTEL architectures (like ALPHA, SPARC , PPC) comment TIMER_OPTIONS=-DUSE_PENTIUM_TIMER and remove the comment from TIMER_OPTIONS=-DUSE_GENERIC_TIMER ( USE_GENERIC_TIMER uses the gettimeofday() syscall) If you know that your non-intel architecture,has some cycle counter, please let me know , so I will add these timer methods, to the benchmark. compile the benchmark with make the executable is named "latencytest" to run the tests you should use "do_tests" this is a script which calls latencytest, but in background starts several system stressing scripts. stress_x11 : graphics card stress using x11perf stress_proc : /proc file system stress using top stress_diskwrite : disk write stress stress_diskcopy : disk copy stress stress_diskread : disk read stress example: ./do_tests none 3 256 0 350000000 none means produce a static sound, (you can pass a .WAV file as argument instead) 3 = number of audio fragments to use 256 = fragmentsize in bytes 0 = background syncing frequency ( a thread which calls sync() every n msec (0 disables the sync thread, I left this option only for experimenting, syncing 1-2 times per sec. may give you a bit better results, but it's not the definitive solution, so it's better to disable) 350000000 = filesize of the disk stress tests use a filesize at least 1.5times of your RAM size, to avoid caching. Note that the diskcopy test needs at least 2 times the filesize you gave as argument, so make sure you have enough space left on disk. (in the above example you need at least 700MB free on your disk) There is another script which runs several tests in sequence: "runalltests" which takes as parameter the filesize example: ./runalltests 350000000 the scripts performs the tests with 3x256 , 3x512 , 3x1024 (num.fragments x fragmentsize) do_tests (or runalltests) outputs the result in the subdirectory "html" the file is called for example "3x256.html" which contains the tests performed for an audio buffer of 3 fragments of 256 bytes. The html page shows 5 diagrams for each system stress type, The green line is the time spent in the CPU wasting loop which is calibrated at 80% of the frament time, If this time goes up, the cause can be bus contention through other devices (like gfx-card, harddisk etc.) NOTE: if you want to change the cpu load, change the value of the variable cpu_load ( default 0.80 = 80% ) in latencytest.c and rtc_latencytest.c My tests shows that this time remains pretty constant on my machine even under high disk I/O. but if I turn off DMA with hdparm , then things get extremely bad, and even the RT scheduled CPU loop is slowed down *EXTREMELY* due to the non-DMA EIDE transfer. The white line is the actual measured scheduling latency of the entire loop, if it goes beyond the red line (audio buffer len in ms), then you will hear a sound drop-out. The yellow line is the fragment timelen, the white line should not exceed this line too much. "cpu latency" is the nominal time of the CPU loop "fragment latency" is the fragent latency. (the value enclosed in the braces is the max measured cpu latency, this value should ideally differ only a fraction of ms from the nominal value, you can notice this on the thickness of the green line too) "max latency" is the max measured scheduling latency of the entire loop ( CPU + audio play) "overruns" are the number of audio buffer overruns, which occurs everytime the white line goes beyond the red line. the white "between +/-1ms" tell how much % of time the total scheduling latency (CPU + audio play) stays in the range fragment latency +/-1ms idem for "between +/-2ms" the green "between +/-0.2ms" tell how much % of time the CPU loop latency stays in the range ( CPU loop latency +/-0.2ms) idem for "between +/-0.1ms" The CPU loop latency is pretty constant on my machine during DMA Disk I/O, and stays in the the +/-0.2ms range 99.98% of time with peaks of +0.5ms , this makes me think that we could use <5ms audio buffers for realtime audio software and having no problems during heavy disk I/O. NEW FEATURES in latencytest 0.42: Realtime clock (RTC) benchmarking: added rtc_latency_test which performs benchmarking of the realtime clock (RTC) device, using async notification ( by installing a SIGIO hander) To perform this test you must first apply the included rtc-async.patch because the standard RTC device doesn't support async signal handling. rtc_latencytest is similar to latencytest but takes only one argument which is the RTC frequency (ie 256 for a 3.9ms interval) "do_rtc_tests" is a script similar to "do_tests" and takes 2 arguments: the RTC frequency and the filesize for the disk stress tests for example ./do_rtc_tests 2048 350000000 sets the RTC frequency to 2048HZ (0.48ms period), and uses a filesize of 350MB for the disk I/O tests) The benchmark measures the time-differences between two calls to the SIGIO signal handler (triggered by the RTC device). The red deadline is set to an immaginary 3*RTC-period. Again , with Ingo's patches the resuls excellent (+/-500usecs jitter). NOTE FOR SMP SYSTEMS: the cpu wasting loop is not multithreaded yet, therefore, it's not a real simulation of a highly stressed SMP system. For updated info and latest news check out: http://www.gardena.net/benno/linux/audio comments, suggestions feedback welcome. regards, Benno. sbenno@gardena.net latencytest0.42/diskstress100644 764 764 755 6725607746 14531 0ustar bennobennoecho "creating tmpfile" head -c 60000000 /dev/zero >tmpfile echo "tmpfile creation done" echo "starting 4 find processes" find /usr >/dev/null 2>/dev/null & sleep 2 find /home >/dev/null 2>/dev/null & sleep 2 find /usr >/dev/null 2>/dev/null & sleep 2 find /home >/dev/null 2>/dev/null & sleep 2 echo "find processes started" echo "copying tmpfile to tmpfile2" cp tmpfile tmpfile2 echo "copying tmpfile and tmpfile2 to /dev/null" cat tmpfile tmpfile2 >/dev/null echo "copy done" killall find latencytest0.42/do_tests100755 764 764 2171 6751426172 14163 0ustar bennobenno./genhtml $2 $3 #echo "x11 stress ......................." ./latencytest $1 $2 $3 $4 >latency.out & ./stress_x11 killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$2x$3-x11.gif sync sleep 4 #echo "proc filesystem stress (using top) ......................." ./latencytest $1 $2 $3 $4 >latency.out & ./stress_procfile killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$2x$3-proc.gif sync sleep 4 #echo "disk write stress ......................" ./latencytest $1 $2 $3 $4 >latency.out & ./stress_diskwrite $5 killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$2x$3-diskwrite.gif ls -la tmpfile* sync sleep 4 #echo "disk copy stress ......................." ./latencytest $1 $2 $3 $4 >latency.out & ./stress_diskcopy killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$2x$3-diskcopy.gif ls -la tmpfile* sync sleep 4 #echo "disk read stress ......................." ./latencytest $1 $2 $3 $4 >latency.out & ./stress_diskread killall latencytest 2>/dev/null sleep 1 cat latency.out ls -la tmpfile* mv out.gif html/$2x$3-diskread.gif rm -f tmpfile tmpfile2 latencytest0.42/latencytest.c100755 764 764 27543 6766467514 15164 0ustar bennobenno#include #include #include #include #include #include #include #include #include #include #include #include #include #include "gfx.h" #define DEBUG 0 #define MAX_TIME_SAMPLES 250000 double cpu_load=0.80; #ifdef USE_PENTIUM_TIMER __inline__ unsigned long long int rdtsc() { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } #endif #ifdef USE_PENTIUM_TIMER #define mygettime() (rdtsc() / cpu_hz) #endif #ifdef USE_GENERIC_TIMER double mygettime(void) { static struct timeval mytv; gettimeofday(&mytv,NULL); return(mytv.tv_sec+mytv.tv_usec/1000000.0); } #endif int calibrate_loop(void); int init_audio(void); int set_realtime_priority(void); void *my_exithandler(void); void mydelay(int loops); int audio_fd; int aubuf_size; int abuf_wptr; caddr_t abuf; struct audio_buf_info abinfo; struct count_info cinfo; int u,k,t1; int counter=0; int fc=0; int delta; int maxdelta=0; int min_sound_delta=100000000; double media; double num_medie=0; double sum_sound_delta=0; int sound_delta; int wb=0; int sb=0; double loops_per_sec; int loops_per_grain; double grain_len; double cpu_hz=0.0; double fragment_latency=0.0; double fragment_latency_minus_1ms,fragment_latency_plus_1ms; double fragment_latency_minus_2ms,fragment_latency_plus_2ms; double cpu_latency=0.0; double cpu_latency_minus_02ms,cpu_latency_plus_02ms; double cpu_latency_minus_01ms,cpu_latency_plus_01ms; int SYNC_USECS=0; int c; int MYSIZE=0; float time_arr[MAX_TIME_SAMPLES+1]; float latency_arr[MAX_TIME_SAMPLES+1]; float latency2_arr[MAX_TIME_SAMPLES+1]; short sample_buffer[65536]; #define MYSONGSIZE 25000000 char *buf0; char *bufstart; char *bufend; int myerrs=0; double buffer_latency; int mynumfragments; int myfragmentsize; int overruns=0; double max_timediff=0.0; double max_timediff2=0.0; pid_t pid=-1; int num_time_samples=0; int num_times_within_1ms=0; int num_times_within_2ms=0; int cpu_num_times_within_02ms=0; int cpu_num_times_within_01ms=0; double mytime_start; double mytime_end; double mytime_x; int main(int argc,char **argv) { double mytimediff; double mytimediff2; double mytime1; double mytime2; double mytime3; int loops_per_run; int res; int i3; int fragsize; int bufsize; int myvalue=0; int mystep=80; int mydirection=1; int use_tone; int j; double over_time=0.0; int infd; mynumfragments=3; signal(SIGTERM,my_exithandler); signal(SIGINT,my_exithandler); if(argc >2) { mynumfragments=atoi(argv[2]); if(mynumfragments <2 || mynumfragments >16) { fprintf(stderr,"num fragments out of range: valid values 2-16\n"); exit(1); } } myfragmentsize=12; if(argc >3) { fragsize=atoi(argv[3]); if(fragsize < 128 || fragsize >32768) { fprintf(stderr,"fragment size out of range: valid values 128 , 256 , 512, 1024, ... , 32768\n"); exit(1); } myfragmentsize=(int)floor((log(fragsize)/log(2.0))+0.5); if(myfragmentsize<4 || myfragmentsize >15) { fprintf(stderr,"fragment size out of range (%d): valid values 256 , 512, 1024, ... , 32768\n",myfragmentsize); exit(1); } } if(argc >4) { SYNC_USECS=atoi(argv[4])*1000; } MYSIZE=(1 << myfragmentsize)/2; bufsize=MYSIZE*2; if(DEBUG) fprintf(stderr,"calling mlockall() to prevent pagefaults ....\n"); if(mlockall(MCL_CURRENT|MCL_FUTURE)) { perror("mlockall() failed, exiting. mlock"); exit(1); } res=set_realtime_priority(); if(res == -1) { fprintf(stderr,"can't get realtime priority, run the program as root.\n"); exit(1); } if(res==0) if(DEBUG) fprintf(stderr,"got realtime scheduling\n"); loops_per_sec=calibrate_loop(); if(DEBUG) printf("fragment size=%d\n",bufsize); grain_len=bufsize/176400.0; loops_per_grain=loops_per_sec*grain_len; if(DEBUG) printf("loops per grain = %d\n",loops_per_grain); if(DEBUG) printf("GRAIN_LEN=%f ms \n",grain_len*1000.0); loops_per_run=loops_per_grain*cpu_load; if(DEBUG) printf("cpu_load=%f loops per run = %d\n",cpu_load,loops_per_run); i3=0; use_tone=0; if(strcmp(argv[1],"none")) { infd=open(argv[1],O_RDONLY); if(infd<0) { perror("error in opening file. open"); exit(0); } buf0=malloc(MYSONGSIZE); read(infd,buf0,MYSONGSIZE); close(infd); } else { use_tone=1; } bufstart=buf0; bufend=buf0+MYSONGSIZE; init_audio(); fragment_latency=bufsize/176400.0; fragment_latency_minus_1ms=fragment_latency-0.001; fragment_latency_plus_1ms=fragment_latency+0.001; fragment_latency_minus_2ms=fragment_latency-0.002; fragment_latency_plus_2ms=fragment_latency+0.002; cpu_latency=grain_len*cpu_load; cpu_latency_minus_02ms=cpu_latency-0.0002; cpu_latency_plus_02ms=cpu_latency+0.0002; cpu_latency_minus_01ms=cpu_latency-0.0001; cpu_latency_plus_01ms=cpu_latency+0.0001; printf("fragment latency = %f ms\n",fragment_latency*1000.0); printf("cpu latency = %f ms\n",cpu_latency*1000.0); if(DEBUG) printf("buffer latency=%f\n",buffer_latency); if(SYNC_USECS > 0) { if(DEBUG) fprintf(stderr,"starting background sync() process with %d ms frequency ...\n",SYNC_USECS/1000); pid=fork(); if(pid==0) { if(DEBUG) fprintf(stderr,"background sync() process started\n"); nice(-20); for(;;) { usleep(SYNC_USECS); sync(); } } } mytime_start=mygettime(); for(;;) { if(use_tone) { for(j=0;j300) mydirection=-mydirection; } else { memcpy(sample_buffer,buf0,bufsize); buf0 += bufsize; wb+=bufsize; if((buf0+bufsize)>bufend) { //printf("MEMORY FINISH !!!!\n"); buf0=bufstart; } } mytime1=mygettime(); mydelay(loops_per_run); mytime2=mygettime(); write(audio_fd,sample_buffer,bufsize); mytime3=mygettime(); //printf("before write =%f\n",mytime2); //printf("after write =%f\n",mytime3); //printf("timediff write =%f\n",(mytime3-mytime2)*1000.0); mytimediff=mytime3-mytime1; mytimediff2=mytime2-mytime1; mytime_x=mytime1-mytime_start; time_arr[num_time_samples]=mytime_x; latency_arr[num_time_samples]=mytimediff; latency2_arr[num_time_samples]=mytimediff2; num_time_samples++; if(num_time_samples >= MAX_TIME_SAMPLES) my_exithandler(); if(mytimediff >= (fragment_latency_minus_1ms) && mytimediff <= (fragment_latency_plus_1ms)) num_times_within_1ms++; if(mytimediff >= (fragment_latency_minus_2ms) && mytimediff <= (fragment_latency_plus_2ms)) num_times_within_2ms++; if(mytimediff2 >= (cpu_latency_minus_02ms) && mytimediff2 <= (cpu_latency_plus_02ms)) cpu_num_times_within_02ms++; if(mytimediff2 >= (cpu_latency_minus_01ms) && mytimediff2 <= (cpu_latency_plus_01ms)) cpu_num_times_within_01ms++; if(mytimediff2 > max_timediff2) max_timediff2=mytimediff2; if(mytimediff > max_timediff) max_timediff=mytimediff; //printf("DIFF=%f\n",mytimediff*1000.0); // over_time+=(mytimediff-fragment_latency); // // if(over_time > 0.002) //printf("over_time=%f\n",over_time); // if(fabs(over_time) < 0.0001) over_time=0.0; if(mytimediff >= buffer_latency ) { overruns++; if(DEBUG) { printf("OVERRUN nr=%d :",overruns); printf("time diff=%f buffer_latency=%f factor=%.1f %%\n",mytimediff,buffer_latency,(mytimediff/buffer_latency)*100.0); } } // res=ioctl(audio_fd,SNDCTL_DSP_GETOSPACE,&abinfo); // if(res == -1) // { // perror("ERROR: ioctl: SNDCTL_DSP_GETOSPACE"); //exit(0); // // return(-1); // } } return(0); } int init_audio(void) { int res; int apar=0; audio_fd=open("/dev/dsp",O_WRONLY,0); if(audio_fd<0) { perror("ERROR: open /dev/dsp"); exit(0); return(-1); } res=ioctl(audio_fd,SNDCTL_DSP_RESET,&apar); apar=AFMT_S16_LE; res=ioctl(audio_fd,SNDCTL_DSP_SETFMT,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_SETFMT"); return(-1); } if( apar != AFMT_S16_LE) { fprintf(stderr,"ERROR: 16 bit format not supported\n"); return(-1); } apar=1; res=ioctl(audio_fd,SNDCTL_DSP_STEREO,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_STEREO"); return(-1); } if( apar != 1) { fprintf(stderr,"ERROR: stereo not supported\n"); return(-1); } apar=44100; res=ioctl(audio_fd,SNDCTL_DSP_SPEED,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_SPEED"); return(-1); } if(DEBUG) printf("SAMPLINGRATE=%d\n",apar); //apar=0x0004000b; // apar=0x0003000d; // apar=0x0002000c; //printf("mynumfragments=%d myfragmentsize=%d\n",mynumfragments,myfragmentsize); apar=((mynumfragments-1) << 16) | myfragmentsize; if(DEBUG) printf("fragment parameter = %x\n",apar); res=ioctl(audio_fd,SNDCTL_DSP_SETFRAGMENT,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_SETFRAGMENT"); exit(1); return(-1); } res=ioctl(audio_fd,SNDCTL_DSP_GETOSPACE,&abinfo); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_GETOSPACE"); return(-1); } aubuf_size=abinfo.fragstotal * abinfo.fragsize; buffer_latency=(aubuf_size/176400.0); if(DEBUG) printf("OSS BUFFERS: fragments=%d fragment size=%d total buffer size=%d\n buffer latency=%f ms\n",\ abinfo.fragstotal,abinfo.fragsize,aubuf_size,buffer_latency*1000.0); return(0); } int set_realtime_priority(void) { struct sched_param schp; /* * set the process to realtime privs */ memset(&schp, 0, sizeof(schp)); schp.sched_priority = sched_get_priority_max(SCHED_FIFO); if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { perror("sched_setscheduler"); return -1; } return 0; } void *my_exithandler(void) { int overruns2=overruns; if(pid == 0) { exit(0); // child (sync() process) exits quietly. } mytime_end=mygettime(); close(audio_fd); if (overruns2>999) overruns2=999; if(DEBUG) printf("\nNUMBER of OVERRUNS = %d , max latency=%.1f ms factor=%.1f %% of buffer\n",overruns2,max_timediff*1000.0,(max_timediff/buffer_latency)*100.0); //printf("% 5.1fms (% 3d)%5.1f%%|",max_timediff*1000.0,overruns2,(max_timediff/buffer_latency)*100.0); printf("%5.1fms (%3d)|",max_timediff*1000.0,overruns2); printf("\n1MS num_time_samples=%d num_times_within_1ms=%d factor=%f\n",num_time_samples,num_times_within_1ms,num_times_within_1ms*100.0/num_time_samples); printf("2MS num_time_samples=%d num_times_within_2ms=%d factor=%f\n",num_time_samples,num_times_within_2ms,num_times_within_2ms*100.0/num_time_samples); draw_chart(time_arr,latency_arr,latency2_arr,num_time_samples,buffer_latency,fragment_latency,cpu_latency,overruns,max_timediff,max_timediff2,num_times_within_1ms,num_times_within_2ms,cpu_num_times_within_02ms,cpu_num_times_within_01ms); if(DEBUG) fprintf(stderr,"\nexiting.\n"); exit(0); } #define NUM_TESTS 1400 int calibrate_loop(void) { FILE *f; char *res; char s1[100]; double tmp_loops_per_sec; double mytime1,mytime2; f=fopen("/proc/cpuinfo","r"); if(f==NULL) { perror("can't open /proc/cpuinfo, exiting. open"); exit(1); } for(;;) { res=fgets(s1,100,f); if(res==NULL) break; if(!memcmp(s1,"cpu MHz",7)) { cpu_hz=atof(&s1[10])*1000000.0; break; } } fclose(f); if(cpu_hz < 1.0) { fprintf(stderr,"can't determine CPU clock frequency, exiting.\n"); } if(DEBUG) printf("calibrating loop ....\n"); #define CALIB_LOOPS 200000000 mytime1=mygettime(); mydelay(CALIB_LOOPS); mytime2=mygettime(); if(DEBUG) printf("time diff= %f \n",mytime2-mytime1); if(DEBUG) printf("loops/sec = %f\n",CALIB_LOOPS/(mytime2-mytime1)); tmp_loops_per_sec=CALIB_LOOPS/(mytime2-mytime1); return(tmp_loops_per_sec); } void mydelay(int loops) { int k=0; int u; for(u=0;u/dev/null latencytest0.42/stress_diskwrite100755 764 764 37 6726467562 15720 0ustar bennobennohead -c $1 /dev/zero >tmpfile latencytest0.42/stress_procfile100755 764 764 55 6726250206 15477 0ustar bennobennoxterm -e top -d 0.01 & sleep 30 killall top latencytest0.42/tunedisk100755 764 764 44 6726245072 14122 0ustar bennobenno/sbin/hdparm -m 8 -d 1 -u 1 -c 1 $1 latencytest0.42/runseq100664 0 0 221 6755646400 13231 0ustar rootrootfor x in t1 t2 t3 t4 t5 t6 ; do echo running test $x ./do_tests none 3 256 0 350000000 mkdir html/$x mv -v html/*.gif html/*.html html/$x done; latencytest0.42/latency.out100664 0 0 355 6766465747 14210 0ustar rootrootfragment latency = 0.725624 ms cpu latency = 0.072562 ms 1.4ms ( 0)| 1MS num_time_samples=124363 num_times_within_1ms=124363 factor=100.000000 2MS num_time_samples=124363 num_times_within_2ms=124363 factor=100.000000 PIXEL_PER_MS=206 latencytest0.42/runalltests100755 764 764 1131 6731032213 14675 0ustar bennobennomyfilesize=$1 echo "running tests with filesize=$myfilesize" echo echo "--------------+-------------+-------------+-------------+-------------+" echo "buffer size |proc (top) | disk write | disk copy | disk read |" echo "--------------+-------------+-------------+-------------+-------------+" echo -n "2x1024(11.6ms)|" ./do_tests none 2 1024 0 $myfilesize echo echo -n "3x1024(17.4ms)|" ./do_tests none 3 1024 0 $myfilesize echo echo -n "2x2048(23.2ms)|" ./do_tests none 2 2048 0 $myfilesize echo echo "--------------+-------------+-------------+-------------+-------------+" echo latencytest0.42/cpu_latency.c100664 764 764 15120 6735425264 15106 0ustar bennobenno__inline__ unsigned long long int rdtsc() { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } #include #include #include #include #include #include #include #include #include #include #include #include #include "gfx.h" #define DEBUG 0 #define MAX_TIME_SAMPLES 250000 #define mygettime() (rdtsc() / cpu_hz) int set_realtime_priority(void); void *my_exithandler(void); void mydelay(int loops); int overruns; int i_test; int num_time_samples=0; int NUM_TESTS; double mytimediff; double max_timediff=0.0; double buffer_latency=0.032; double mean_sum=0.0; float time_arr[MAX_TIME_SAMPLES+1]; float latency_arr[MAX_TIME_SAMPLES+1]; main(int argc,char **argv) { double cpu_hz=0.0; double mytime1,mytime2; double loops_per_sec; int loops_per_grain; int usleep_len; double sleep_len; double grain_len; int i,u; int res2; int run_nr; FILE *f; char *res; char s1[100]; grain_len=10.0; if(argc>1) { grain_len=atof(argv[1]); } grain_len=grain_len/1000.0; printf("grain_len=%f\n",grain_len); sleep_len=5.0; if(argc>2) { sleep_len=atof(argv[2]); } usleep_len=sleep_len*1000; printf("usleep_len=%d\n",usleep_len); signal(SIGTERM,my_exithandler); signal(SIGINT,my_exithandler); overruns=0; f=fopen("/proc/cpuinfo","r"); if(f==NULL) { perror("can't open /proc/cpuinfo, exiting. open"); exit(1); } for(;;) { res=fgets(s1,100,f); if(res==NULL) break; if(!memcmp(s1,"cpu MHz",7)) { cpu_hz=atof(&s1[10])*1000000.0; break; } } fclose(f); if(cpu_hz < 1.0) { fprintf(stderr,"can't determine CPU clock frequency, exiting.\n"); } res2=set_realtime_priority(); if(res2 == -1) { fprintf(stderr,"can't get realtime priority, run the program as root.\n"); exit(1); } printf("calibrating loop ....\n"); #define CALIB_LOOPS 100000000 mytime1=mygettime(); mydelay(CALIB_LOOPS); mytime2=mygettime(); printf("time diff= %f \n",mytime2-mytime1); printf("loops/sec = %f\n",CALIB_LOOPS/(mytime2-mytime1)); loops_per_sec=CALIB_LOOPS/(mytime2-mytime1); loops_per_grain=loops_per_sec*grain_len; printf("loops per grain = %d\n",loops_per_grain); printf("GRAIN_LEN=%f ms \n",grain_len*1000.0); NUM_TESTS=10.0/grain_len; printf("running loops ....\n"); sleep(1); mean_sum=0.0; run_nr=-1; for(i_test=0;i_testmax_timediff) { max_timediff=mytimediff; run_nr=i_test; } if(mytimediff >= buffer_latency ) { overruns++; } mean_sum+=mytimediff; } exit(0); for(;;) { //printf("rdtsc=%lld \n",cycles); //printf("cpu hz=%f\n",cpu_hz); for(u=0;u<100000;u++); if(mytimediff > max_timediff) max_timediff=mytimediff; } } void mydelay(int loops) { int k=0; int u; for(u=0;u999) overruns=999; if(DEBUG) printf("\nNUMBER of OVERRUNS = %d , max latency=%.1f ms factor=%.1f %% of buffer\n",overruns,max_timediff*1000.0,(max_timediff/buffer_latency)*100.0); //printf("% 5.1fms (% 3d)%5.1f%%|",max_timediff*1000.0,overruns,(max_timediff/buffer_latency)*100.0); printf("%5.1fms (%3d)|",max_timediff*1000.0,overruns); //printf("time diff= %f \n",mytime2-mytime1); printf("MAX time diff= %f \n",max_timediff); printf("MEAN time diff= %f \n",mean_sum/NUM_TESTS); printf("overruns = %d\n",overruns); //printf("run nr = %d\n",run_nr); draw_chart(time_arr,latency_arr,num_time_samples,buffer_latency,overruns,max_timediff,0,0); if(DEBUG) fprintf(stderr,"\nexiting.\n"); exit(0); } /* --------------------------- if(mytimediff >= (buffer_latency*0.99) ) { overruns++; if(DEBUG) { printf("OVERRUN nr=%d :",overruns); printf("time diff=%.1f buffer_latency=%.1f factor=%.1f %%\n",mytimediff,buffer_latency,(mytimediff/buffer_latency)*100.0); } } // res=ioctl(audio_fd,SNDCTL_DSP_GETOSPACE,&abinfo); // if(res == -1) // { // perror("ERROR: ioctl: SNDCTL_DSP_GETOSPACE"); //exit(0); // // return(-1); // } } return(0); } int init_audio(void) { int res; int apar=0; audio_fd=open("/dev/dsp",O_WRONLY,0); if(audio_fd<0) { perror("ERROR: open /dev/dsp"); exit(0); return(-1); } res=ioctl(audio_fd,SNDCTL_DSP_RESET,&apar); apar=AFMT_S16_LE; res=ioctl(audio_fd,SNDCTL_DSP_SETFMT,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_SETFMT"); return(-1); } if( apar != AFMT_S16_LE) { fprintf(stderr,"ERROR: 16 bit format not supported\n"); return(-1); } apar=1; res=ioctl(audio_fd,SNDCTL_DSP_STEREO,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_STEREO"); return(-1); } if( apar != 1) { fprintf(stderr,"ERROR: stereo not supported\n"); return(-1); } apar=44100; res=ioctl(audio_fd,SNDCTL_DSP_SPEED,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_SPEED"); return(-1); } if(DEBUG) printf("SAMPLINGRATE=%d\n",apar); //apar=0x0004000b; // apar=0x0003000d; // apar=0x0002000c; //printf("mynumfragments=%d myfragmentsize=%d\n",mynumfragments,myfragmentsize); apar=((mynumfragments-1) << 16) | myfragmentsize; if(DEBUG) printf("fragment parameter = %x\n",apar); res=ioctl(audio_fd,SNDCTL_DSP_SETFRAGMENT,&apar); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_SETFRAGMENT"); exit(1); return(-1); } res=ioctl(audio_fd,SNDCTL_DSP_GETOSPACE,&abinfo); if(res == -1) { perror("ERROR: ioctl: SNDCTL_DSP_GETOSPACE"); return(-1); } aubuf_size=abinfo.fragstotal * abinfo.fragsize; buffer_latency=(aubuf_size/176400.0)*1000000.0; if(DEBUG) printf("OSS BUFFERS: fragments=%d fragment size=%d total buffer size=%d\n buffer latency=%f ms\n",\ abinfo.fragstotal,abinfo.fragsize,aubuf_size,buffer_latency/1000.0); return(0); } close(audio_fd); */ latencytest0.42/runcputests100755 0 0 770 6737451302 14320 0ustar rootroot# DON'T USE THIS SCRIPT, IT'S NOT STABLE YET !! exit myfilesize=$1 echo "running cpu tests with filesize=$myfilesize" echo echo "--------------+-------------+-------------+-------------+-------------+" echo "latency |proc (top) | disk write | disk copy | disk read |" echo "--------------+-------------+-------------+-------------+-------------+" echo -n "|" ./do_cpu_tests 5 3 $myfilesize echo echo "--------------+-------------+-------------+-------------+-------------+" echo latencytest0.42/gfx.c100664 764 764 13514 6766444623 13375 0ustar bennobenno #include /* Bring in gd library functions */ #include "gd.h" #include "gdfonts.h" /* Bring in standard I/O so we can output the GIF to a file */ #include #define CHART_X1 50 #define CHART_X2 840 #define CHART_Y1 20 #define CHART_Y2 599 //#define PIXEL_PER_MS 90 #define GRID_MS 5 int PIXEL_PER_MS; void draw_chart(float *time_arr,float *latency_arr,float *latency2_arr,int num_samples,float deadline,float fragment_latency,float cpu_latency,int overruns,double max_timediff,double max_timediff2,double time_1ms,double time_2ms,double cpu_time_02ms,double cpu_time_01ms) { /* Declare the image */ gdImagePtr im; /* Declare an output file */ FILE *out; /* Declare color indexes */ int black; int red; int gray; int gray2; int yellow; int green; int white; int white2; int oldx,oldy; int x,y; int index,i; double i2; double time_division; double total_time; int tmp_ms; int over_flag=0; int old_x1; char str1[80]; PIXEL_PER_MS=450/(deadline*1000.0); printf("PIXEL_PER_MS=%d\n",PIXEL_PER_MS); /* Allocate the image: 64 pixels across by 64 pixels tall */ im = gdImageCreate(CHART_X2+20,680 ); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im,0 , 0, 0); gray = gdImageColorAllocate(im,64 , 64, 64); gray2 = gdImageColorAllocate(im,110 , 110, 110); white2 = gdImageColorAllocate(im,200 , 200, 200); yellow = gdImageColorAllocate(im,230 , 230, 0); red = gdImageColorAllocate(im,255 , 0, 0); green = gdImageColorAllocate(im,0 , 255, 0); /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); oldx=CHART_X1+1; oldy=CHART_Y2-latency_arr[0]*1000*PIXEL_PER_MS; old_x1=CHART_X1; for(i=CHART_Y2;i>=CHART_Y1;i-=PIXEL_PER_MS) { gdImageLine(im, CHART_X1,i, CHART_X2, i, gray); } tmp_ms=0; for(i=CHART_Y2;i>=CHART_Y1;i-=PIXEL_PER_MS*GRID_MS) { gdImageLine(im, CHART_X1,i, CHART_X2, i, gray2); sprintf(str1,"%3.1d ms",tmp_ms); tmp_ms+=GRID_MS; gdImageString(im, gdFontSmall,7, i-8, str1, white); } gdImageLine(im, CHART_X1,CHART_Y2, CHART_X2, CHART_Y2, white2); gdImageLine(im, CHART_X1,CHART_Y2, CHART_X1, CHART_Y1, white2); total_time=time_arr[num_samples-1]-time_arr[0]; time_division=1.0; if(total_time>200.0) time_division=10.0; for(i2=0;i230) { sprintf(str1,"%.1fms",(latency_arr[index]*1000.0)); gdImageString(im, gdFontSmall,x+2,y-4+10*over_flag, str1, white); over_flag=1-over_flag; old_x1=x; } } gdImageLine(im, oldx,oldy, x, y, white); oldx=x; oldy=y; } oldx=CHART_X1+1; oldy=CHART_Y2-latency2_arr[0]*1000*PIXEL_PER_MS; for(index=0;indexlatency.out & ./stress_procfile killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1+$2-proc.gif sync sleep 4 #echo "disk write stress ......................" ./cpu_latency $1 $2 >latency.out & ./stress_diskwrite $3 killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1+$2-diskwrite.gif sync sleep 4 #echo "disk copy stress ......................." ./cpu_latency $1 $2 >latency.out & ./stress_diskcopy killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1+$2-diskcopy.gif sync sleep 4 #echo "disk read stress ......................." ./cpu_latency $1 $2 >latency.out & ./stress_diskcopy killall latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1+$2-diskread.gif rm -f tmpfile tmpfile2 latencytest0.42/COPYING100664 764 764 43127 6737151227 13474 0ustar bennobenno GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. latencytest0.42/template.html100664 0 0 4047 6740412456 14520 0ustar rootroot

Audio-latency test results _label1_



- the red reference line is the global audio buffer size , if this deadline is missed you will hear a sond drop-out.
- the white line is the actual scheduling latency, the ideal would be the time it takes to play 1 audio fragment. (fragment latency)
- the green line is the time the CPU takes to execute an empty loop (which is calibrated at 80% of the fragment time)
   this is used to simulate heavy CPU computations during the audio play, a typical example could be a synthesizer which computes the waveform to play in realtime.
  since the thread runs with SCHED_FIFO priority, if this time goes up, then the cause could be the DMA / PCI / ISA contention on the system bus, or busy kernel I/O routines
- the yellow reference line is the len of one audio fragment (ideally the white line should stay close to yellow line)
- the white between +/-1ms is the % of time the total latency stays in the range between +/-1ms of the optimal latency.
- the white between +/-2ms is the % of time the total latency stays in the range between +/-2ms of the optimal latency.
- the green between +/-0.2ms is the % of time the CPU loop latency stays in the range between +/-0.2ms of the nominal CPU loop latency.
- the green between +/-0.1ms is the % of time the CPU loop latency stays in the range between +/-0.1ms of the nominal CPU loop latency.

X11 stress



/proc filesystem stress



disk write stress



disk copy stress



disk read stress




latencytest0.42/genhtml100775 0 0 226 6737444271 13364 0ustar rootrootlabel1="(audio buffer $1 x $2 bytes)" filelabel="$1x$2" sed -e "s/_label1_/$label1/;s/_filelabel_/$filelabel/" html/$filelabel.html latencytest0.42/rtc_latencytest.c100755 0 0 22343 6766467521 15425 0ustar rootroot#include #include #include #include #include #include #include #include #include #include #include #include #include #include "gfx.h" #define DEBUG 1 #define MAX_TIME_SAMPLES 250000 double cpu_load=0.80; #ifdef USE_PENTIUM_TIMER __inline__ unsigned long long int rdtsc() { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } #endif #ifdef USE_PENTIUM_TIMER #define mygettime() (rdtsc() / cpu_hz) #endif #ifdef USE_GENERIC_TIMER double mygettime(void) { static struct timeval mytv; gettimeofday(&mytv,NULL); return(mytv.tv_sec+mytv.tv_usec/1000000.0); } #endif int calibrate_loop(void); int set_realtime_priority(void); void *my_exithandler(void); void mydelay(int loops); void sigio_handler (int sig); static int rtc_fd; int u,k,t1; int counter=0; int fc=0; int delta; int maxdelta=0; int min_sound_delta=100000000; double media; double num_medie=0; double sum_sound_delta=0; int sound_delta; int wb=0; int sb=0; double loops_per_sec; int loops_per_grain; int loops_per_run; double grain_len; double cpu_hz=0.0; double mytimediff; double mytimediff2; double mytime1; double mytime2; double mytime3; double old_mytime3; double fragment_latency=0.0; double fragment_latency_minus_1ms,fragment_latency_plus_1ms; double fragment_latency_minus_2ms,fragment_latency_plus_2ms; double cpu_latency=0.0; double cpu_latency_minus_02ms,cpu_latency_plus_02ms; double cpu_latency_minus_01ms,cpu_latency_plus_01ms; int SYNC_USECS=0; int c; int MYSIZE=0; float time_arr[MAX_TIME_SAMPLES+1]; float latency_arr[MAX_TIME_SAMPLES+1]; float latency2_arr[MAX_TIME_SAMPLES+1]; short sample_buffer[65536]; #define MYSONGSIZE 25000000 int myerrs=0; double buffer_latency; int mynumfragments; int myfragmentsize; int overruns=0; double max_timediff=0.0; double max_timediff2=0.0; pid_t pid=-1; int num_time_samples=0; int num_times_within_1ms=0; int num_times_within_2ms=0; int cpu_num_times_within_02ms=0; int cpu_num_times_within_01ms=0; double mytime_start; double mytime_end; double mytime_x; int main(int argc,char **argv) { int res; int rtc_interval; int oflags; mynumfragments=3; signal(SIGTERM,my_exithandler); signal(SIGINT,my_exithandler); old_mytime3=-1.0; if(argc != 2) { fprintf(stderr,"wrong number of arguments, exiting.\n"); exit(1); } rtc_interval=atoi(argv[1]); if(mynumfragments <2 || mynumfragments >16) { fprintf(stderr,"num fragments out of range: valid values 2-16\n"); exit(1); } printf("rtc_interval=%d\n",rtc_interval); if(DEBUG) fprintf(stderr,"calling mlockall() to prevent pagefaults ....\n"); if(mlockall(MCL_CURRENT|MCL_FUTURE)) { perror("mlockall() failed, exiting. mlock"); exit(1); } res=set_realtime_priority(); if(res == -1) { fprintf(stderr,"can't get realtime priority, run the program as root.\n"); exit(1); } if(res==0) if(DEBUG) fprintf(stderr,"got realtime scheduling\n"); loops_per_sec=calibrate_loop(); grain_len=1.0/((double)rtc_interval); loops_per_grain=loops_per_sec*grain_len; buffer_latency=3.0*grain_len; if(DEBUG) printf("loops per grain = %d\n",loops_per_grain); if(DEBUG) printf("GRAIN_LEN=%f ms \n",grain_len*1000.0); loops_per_run=loops_per_grain*cpu_load; if(DEBUG) printf("cpu_load=%f loops per run = %d\n",cpu_load,loops_per_run); fragment_latency=grain_len; fragment_latency_minus_1ms=fragment_latency-0.001; fragment_latency_plus_1ms=fragment_latency+0.001; fragment_latency_minus_2ms=fragment_latency-0.002; fragment_latency_plus_2ms=fragment_latency+0.002; cpu_latency=grain_len*cpu_load; cpu_latency_minus_02ms=cpu_latency-0.0002; cpu_latency_plus_02ms=cpu_latency+0.0002; cpu_latency_minus_01ms=cpu_latency-0.0001; cpu_latency_plus_01ms=cpu_latency+0.0001; printf("grain latency = %f ms\n",fragment_latency*1000.0); printf("cpu latency = %f ms\n",cpu_latency*1000.0); if ((rtc_fd = open ("/dev/rtc", O_RDONLY)) < 0) { perror ("open: "); return -1; } signal (SIGIO, sigio_handler); if (fcntl (rtc_fd, F_SETOWN, getpid()) < 0) { perror ("fcntl setown: "); return -1; } if ((oflags = fcntl (rtc_fd, F_GETFL)) < 0) { perror ("fcntl getfl: "); return -1; } if (fcntl (rtc_fd, F_SETFL, oflags | FASYNC) < 0) { perror ("fcntl setfl: "); return -1; } if (ioctl(rtc_fd, RTC_IRQP_SET, rtc_interval) < 0) { perror ("rtc irq set: "); return -1; } if (ioctl (rtc_fd, RTC_PIE_ON, 0) < 0) { perror ("rtc pie on: "); return -1; } printf("entering main sleep loop ....\n"); while (1) { sleep (999999999); } mytime_start=mygettime(); return(0); } int set_realtime_priority(void) { struct sched_param schp; /* * set the process to realtime privs */ memset(&schp, 0, sizeof(schp)); schp.sched_priority = sched_get_priority_max(SCHED_FIFO); if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { perror("sched_setscheduler"); return -1; } return 0; } void *my_exithandler(void) { int overruns2=overruns; if(pid == 0) { exit(0); // child (sync() process) exits quietly. } mytime_end=mygettime(); close (rtc_fd); if (overruns2>999) overruns2=999; if(DEBUG) printf("\nNUMBER of OVERRUNS = %d , max latency=%.1f ms factor=%.1f %% of buffer\n",overruns2,max_timediff*1000.0,(max_timediff/buffer_latency)*100.0); //printf("% 5.1fms (% 3d)%5.1f%%|",max_timediff*1000.0,overruns2,(max_timediff/buffer_latency)*100.0); printf("%5.1fms (%3d)|",max_timediff*1000.0,overruns2); printf("\n1MS num_time_samples=%d num_times_within_1ms=%d factor=%f\n",num_time_samples,num_times_within_1ms,num_times_within_1ms*100.0/num_time_samples); printf("2MS num_time_samples=%d num_times_within_2ms=%d factor=%f\n",num_time_samples,num_times_within_2ms,num_times_within_2ms*100.0/num_time_samples); draw_chart(time_arr,latency_arr,latency2_arr,num_time_samples,buffer_latency,fragment_latency,cpu_latency,overruns,max_timediff,max_timediff2,num_times_within_1ms,num_times_within_2ms,cpu_num_times_within_02ms,cpu_num_times_within_01ms); if(DEBUG) fprintf(stderr,"\nexiting.\n"); exit(0); } #define NUM_TESTS 1400 int calibrate_loop(void) { FILE *f; char *res; char s1[100]; double tmp_loops_per_sec; double mytime1,mytime2; f=fopen("/proc/cpuinfo","r"); if(f==NULL) { perror("can't open /proc/cpuinfo, exiting. open"); exit(1); } for(;;) { res=fgets(s1,100,f); if(res==NULL) break; if(!memcmp(s1,"cpu MHz",7)) { cpu_hz=atof(&s1[10])*1000000.0; break; } } fclose(f); if(cpu_hz < 1.0) { fprintf(stderr,"can't determine CPU clock frequency, exiting.\n"); } if(DEBUG) printf("calibrating loop ....\n"); #define CALIB_LOOPS 200000000 mytime1=mygettime(); mydelay(CALIB_LOOPS); mytime2=mygettime(); if(DEBUG) printf("time diff= %f \n",mytime2-mytime1); if(DEBUG) printf("loops/sec = %f\n",CALIB_LOOPS/(mytime2-mytime1)); tmp_loops_per_sec=CALIB_LOOPS/(mytime2-mytime1); return(tmp_loops_per_sec); } void mydelay(int loops) { int k=0; int u; for(u=0;u> 8); // fprintf (stdout, "%ld\n", interrupts); // fflush (stdout); mytime1=mygettime(); mydelay(loops_per_run); mytime2=mygettime(); mytime3=mytime2; //printf("before write =%f\n",mytime2); //printf("after write =%f\n",mytime3); mytimediff=mytime3-old_mytime3; if(old_mytime3 < 0.0) mytimediff=0.0; //printf("HANDLER: mytimediff =%f\n",mytimediff); mytimediff2=mytime2-mytime1; old_mytime3=mytime3; mytime_x=mytime1-mytime_start; time_arr[num_time_samples]=mytime_x; latency_arr[num_time_samples]=mytimediff; latency2_arr[num_time_samples]=mytimediff2; num_time_samples++; if(num_time_samples >= MAX_TIME_SAMPLES) my_exithandler(); if(mytimediff >= (fragment_latency_minus_1ms) && mytimediff <= (fragment_latency_plus_1ms)) num_times_within_1ms++; if(mytimediff >= (fragment_latency_minus_2ms) && mytimediff <= (fragment_latency_plus_2ms)) num_times_within_2ms++; if(mytimediff2 >= (cpu_latency_minus_02ms) && mytimediff2 <= (cpu_latency_plus_02ms)) cpu_num_times_within_02ms++; if(mytimediff2 >= (cpu_latency_minus_01ms) && mytimediff2 <= (cpu_latency_plus_01ms)) cpu_num_times_within_01ms++; if(mytimediff2 > max_timediff2) max_timediff2=mytimediff2; if(mytimediff > max_timediff) max_timediff=mytimediff; //printf("DIFF=%f\n",mytimediff*1000.0); if(mytimediff >= buffer_latency ) { overruns++; if(DEBUG) { printf("OVERRUN nr=%d :",overruns); printf("time diff=%f buffer_latency=%f factor=%.1f %%\n",mytimediff,buffer_latency,(mytimediff/buffer_latency)*100.0); } } } latencytest0.42/do_rtc_tests100755 0 0 2150 6766437746 14451 0ustar rootroot./genhtml2 $1 #echo "x11 stress ......................." ./rtc_latencytest $1 >latency.out & ./stress_x11 killall rtc_latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1-x11.gif sync sleep 4 #echo "proc filesystem stress (using top) ......................." ./rtc_latencytest $1 >latency.out & ./stress_procfile killall rtc_latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1-proc.gif sync sleep 4 #echo "disk write stress ......................" ./rtc_latencytest $1 >latency.out & ./stress_diskwrite $2 killall rtc_latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1-diskwrite.gif ls -la tmpfile* sync sleep 4 #echo "disk copy stress ......................." ./rtc_latencytest $1 >latency.out & ./stress_diskcopy killall rtc_latencytest 2>/dev/null sleep 1 cat latency.out mv out.gif html/$1-diskcopy.gif ls -la tmpfile* sync sleep 4 #echo "disk read stress ......................." ./rtc_latencytest $1 >latency.out & ./stress_diskread killall rtc_latencytest 2>/dev/null sleep 1 cat latency.out ls -la tmpfile* mv out.gif html/$1-diskread.gif rm -f tmpfile tmpfile2 latencytest0.42/genhtml2100775 0 0 215 6766436516 13451 0ustar rootrootlabel1="(RTC FREQUENCY $1 HZ)" filelabel="$1" sed -e "s/_label1_/$label1/;s/_filelabel_/$filelabel/" html/$filelabel.html latencytest0.42/template2.html100664 0 0 3773 6766441435 14616 0ustar rootroot

RTC-latency test results _label1_



- the red reference line is an immaginary deadline, the number of "overruns" are the number of deadline misses
  actually this is set to 3*fragment latency (for examp   for example if RTC-HZ=512 (1.9ms period), then the deadline is set to 5.85ms)
- the white line is the actual scheduling latency, the ideal would be 1/RTCfrequency . (fragment latency)
- the green line is the time the CPU takes to execute an empty loop (which is calibrated at 80% of the fragment time)

  since the thread runs with SCHED_FIFO priority, if this time goes up, then the cause could be the DMA / PCI / ISA contention on the system bus, or busy kernel I/O routines
- the yellow reference line is the period of the RTC frequency (ideally the white line should stay close to yellow line)
- the white between +/-1ms is the % of time the total latency stays in the range between +/-1ms of the optimal latency.
- the white between +/-2ms is the % of time the total latency stays in the range between +/-2ms of the optimal latency.
- the green between +/-0.2ms is the % of time the CPU loop latency stays in the range between +/-0.2ms of the nominal CPU loop latency.
- the green between +/-0.1ms is the % of time the CPU loop latency stays in the range between +/-0.1ms of the nominal CPU loop latency.

X11 stress



/proc filesystem stress



disk write stress



disk copy stress



disk read stress




latencytest0.42/rtc-async.patch100664 0 0 2361 6766443132 14743 0ustar rootroot--- linux/drivers/char/rtc.c.orig Sat Sep 11 00:50:25 1999 +++ linux/drivers/char/rtc.c Sat Sep 11 00:50:41 1999 @@ -69,6 +69,8 @@ * ioctls. */ +static struct fasync_struct *rtc_async_queue; + static struct wait_queue *rtc_wait; static struct timer_list rtc_irq_timer; @@ -134,6 +136,9 @@ rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); wake_up_interruptible(&rtc_wait); + if (rtc_async_queue) + kill_fasync (rtc_async_queue, SIGIO); + if (rtc_status & RTC_TIMER_ON) mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100); } @@ -455,6 +460,12 @@ return 0; } +static int rtc_fasync (int fd, struct file *filp, int on) + +{ + return fasync_helper (fd, filp, on, &rtc_async_queue); +} + static int rtc_release(struct inode *inode, struct file *file) { /* @@ -480,6 +491,10 @@ del_timer(&rtc_irq_timer); } + if (file->f_flags & FASYNC) { + rtc_fasync (-1, file, 0); + } + rtc_irq_data = 0; rtc_status &= ~RTC_IS_OPEN; return 0; @@ -493,6 +508,7 @@ return 0; } + /* * The various file operations we support. */ @@ -507,7 +523,9 @@ NULL, /* No mmap */ rtc_open, NULL, /* flush */ - rtc_release + rtc_release, + NULL, /* fsync */ + rtc_fasync }; static struct miscdevice rtc_dev=