From 098c52c7848dcb95c6a1f9e30afd00db80f40cae Mon Sep 17 00:00:00 2001 From: xiphmont Date: Tue, 26 Aug 2008 09:55:22 +0000 Subject: [PATCH] refinements/compat fixes to fisrt-stage cache/timing tests CLOCK_MONOTONIC not supported on 2.4 (grrrr) don't rely on roundoff falling right for spinup test base spinup test on amount of time stable, not number of iterations git-svn-id: http://svn.xiph.org/trunk@15202 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- cdparanoia/cachetest.c | 39 +++++++++++++++++++-------------- cdparanoia/interface/cooked_interface.c | 4 ++-- cdparanoia/interface/low_interface.h | 2 ++ cdparanoia/interface/scan_devices.c | 11 ++++++++++ cdparanoia/interface/scsi_interface.c | 8 +++---- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/cdparanoia/cachetest.c b/cdparanoia/cachetest.c index b8600f349..514bdedd9 100644 --- a/cdparanoia/cachetest.c +++ b/cdparanoia/cachetest.c @@ -107,8 +107,9 @@ int analyze_timing_and_cache(cdrom_drive *d){ double sum; double sumsq; int sofar; - double best=0; + int best=0; int bestcount=0; + int iterating=0; offset = lastsector-firstsector-current-1; @@ -118,7 +119,7 @@ int analyze_timing_and_cache(cdrom_drive *d){ int m = offset/4500; int s = (offset-m*4500)/75; int f = offset-m*4500-s*75; - if(bestcount==10){ + if(iterating){ reportC("\n"); }else{ printC("\r"); @@ -167,7 +168,7 @@ int analyze_timing_and_cache(cdrom_drive *d){ { double mean = sum/(float)(current-1); double stddev = sqrt( (sumsq/(float)(current-1) - mean*mean)); - double upper= mean+((isnan(stddev) || stddev<1.)?1.:stddev); + double upper= mean+((isnan(stddev) || stddev*2<1.)?1.:stddev*2); int j; mean=0; @@ -186,17 +187,21 @@ int analyze_timing_and_cache(cdrom_drive *d){ logC("\n\tAverage read latency: %.2fms/sector (raw speed: %.1fx)",mean,1000./75./mean); logC("\n\tRead latency standard deviation: %.2fms/sector",stddev); - if(bestcount<10){ - if(1./mean>best){ - best=1./mean; + sofar=mean*current; + if(!iterating){ + if(-sofarsofar && bestcount>2000) + iterating=1; + } } } next: - if(bestcount==10){ + if(iterating){ offset = (offset-firstsector+44999)/45000*45000+firstsector; offset-=45000; printC(" "); @@ -216,7 +221,7 @@ int analyze_timing_and_cache(cdrom_drive *d){ int hi=15000; int current=0; int under=1; - offset = firstsector+1000; + offset = firstsector; while(current <= hi && under){ int i,j; @@ -262,16 +267,18 @@ int analyze_timing_and_cache(cdrom_drive *d){ logC("seek_read=%d:%d\n",ret2,cdda_milliseconds(d)); if(ret1<=0 || ret2<=0){ - if(j==2){ - reportC("\n\tRead error while performing drive cache checks; aborting test.\n"); + offset+=current+100; + if(j==10 || offset+current>lastsector){ + reportC("\n\tToo many read errors while performing drive cache checks;" + "\n\t aborting test.\n\n"); return(-1); } + reportC("\n\tRead error while performing drive cache checks;" + "\n\t choosing new offset and trying again.\n"); }else{ if(cdda_milliseconds(d)==-1){ - if(j==2){ - reportC("\n\tTiming error while performing drive cache checks; aborting test.\n"); - return(-1); - } + reportC("\n\tTiming error while performing drive cache checks; aborting test.\n"); + return(-1); }else{ if(cdda_milliseconds(d)<9)under=1; break; diff --git a/cdparanoia/interface/cooked_interface.c b/cdparanoia/interface/cooked_interface.c index 61ac5a2db..de290551f 100644 --- a/cdparanoia/interface/cooked_interface.c +++ b/cdparanoia/interface/cooked_interface.c @@ -13,9 +13,9 @@ static int timed_ioctl(cdrom_drive *d, int fd, int command, void *arg){ struct timespec tv1; struct timespec tv2; - int ret1=clock_gettime(CLOCK_MONOTONIC,&tv1); + int ret1=clock_gettime(d->private->clock,&tv1); int ret2=ioctl(fd, command,arg); - int ret3=clock_gettime(CLOCK_MONOTONIC,&tv2); + int ret3=clock_gettime(d->private->clock,&tv2); if(ret1<0 || ret3<0){ d->private->last_milliseconds=-1; }else{ diff --git a/cdparanoia/interface/low_interface.h b/cdparanoia/interface/low_interface.h index a0086dc5c..76981fe7a 100644 --- a/cdparanoia/interface/low_interface.h +++ b/cdparanoia/interface/low_interface.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -99,6 +100,7 @@ typedef struct sg_io_hdr struct cdda_private_data { struct sg_header *sg_hd; unsigned char *sg_buffer; /* points into sg_hd */ + clockid_t clock; int last_milliseconds; int (*cache_clear) (struct cdrom_drive *d, int lba, int sectors); diff --git a/cdparanoia/interface/scan_devices.c b/cdparanoia/interface/scan_devices.c index fa3256fef..fc58110ec 100644 --- a/cdparanoia/interface/scan_devices.c +++ b/cdparanoia/interface/scan_devices.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include "cdda_interface.h" @@ -264,6 +265,11 @@ cdrom_drive *cdda_identify_cooked(const char *dev, int messagedest, d->bigendianp=-1; /* We don't know yet... */ d->nsectors=-1; d->private=calloc(1,sizeof(*d->private)); + { + /* goddamnit */ + struct timespec tv; + d->private->clock=(clock_gettime(CLOCK_MONOTONIC,&tv)<0?CLOCK_REALTIME:CLOCK_MONOTONIC); + } idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description); return(d); } @@ -669,6 +675,11 @@ cdrom_drive *cdda_identify_scsi(const char *generic_device, d->nsectors=-1; d->messagedest = messagedest; d->private=calloc(1,sizeof(*d->private)); + { + /* goddamnit */ + struct timespec tv; + d->private->clock=(clock_gettime(CLOCK_MONOTONIC,&tv)<0?CLOCK_REALTIME:CLOCK_MONOTONIC); + } if(use_sgio){ d->interface=SGIO_SCSI; d->private->sg_buffer=(unsigned char *)(d->private->sg_hd=malloc(MAX_BIG_BUFF_SIZE)); diff --git a/cdparanoia/interface/scsi_interface.c b/cdparanoia/interface/scsi_interface.c index ba728191f..152ba8b8c 100644 --- a/cdparanoia/interface/scsi_interface.c +++ b/cdparanoia/interface/scsi_interface.c @@ -15,9 +15,9 @@ static int timed_ioctl(cdrom_drive *d, int fd, int command, void *arg){ struct timespec tv1; struct timespec tv2; - int ret1=clock_gettime(CLOCK_MONOTONIC,&tv1); + int ret1=clock_gettime(d->private->clock,&tv1); int ret2=ioctl(fd, command,arg); - int ret3=clock_gettime(CLOCK_MONOTONIC,&tv2); + int ret3=clock_gettime(d->private->clock,&tv2); if(ret1<0 || ret3<0){ d->private->last_milliseconds=-1; }else{ @@ -247,7 +247,7 @@ static int sg2_handle_scsi_cmd(cdrom_drive *d, } sigprocmask (SIG_BLOCK, &(d->sigset), NULL ); - tret1=clock_gettime(CLOCK_MONOTONIC,&tv1); + tret1=clock_gettime(d->private->clock,&tv1); errno=0; status = write(d->cdda_fd, sg_hd, writebytes ); @@ -293,7 +293,7 @@ static int sg2_handle_scsi_cmd(cdrom_drive *d, } } - tret2=clock_gettime(CLOCK_MONOTONIC,&tv2); + tret2=clock_gettime(d->private->clock,&tv2); errno=0; status = read(d->cdda_fd, sg_hd, SG_OFF + out_size); sigprocmask ( SIG_UNBLOCK, &(d->sigset), NULL ); -- 2.11.4.GIT