Changeset View
Changeset View
Standalone View
Standalone View
sbin/fsck_ffs/fsutil.c
Show First 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | if (debug && bp->b_type != type) | ||||
printf("Buffer type changed from %s to %s\n", | printf("Buffer type changed from %s to %s\n", | ||||
buftype[bp->b_type], buftype[type]); | buftype[bp->b_type], buftype[type]); | ||||
TAILQ_REMOVE(&bufhead, bp, b_list); | TAILQ_REMOVE(&bufhead, bp, b_list); | ||||
TAILQ_INSERT_HEAD(&bufhead, bp, b_list); | TAILQ_INSERT_HEAD(&bufhead, bp, b_list); | ||||
bp->b_flags |= B_INUSE; | bp->b_flags |= B_INUSE; | ||||
return (bp); | return (bp); | ||||
} | } | ||||
/* | |||||
* Timespec operations (from <sys/time.h>). | |||||
*/ | |||||
#define timespecsub(vvp, uvp) \ | |||||
do { \ | |||||
(vvp)->tv_sec -= (uvp)->tv_sec; \ | |||||
(vvp)->tv_nsec -= (uvp)->tv_nsec; \ | |||||
if ((vvp)->tv_nsec < 0) { \ | |||||
(vvp)->tv_sec--; \ | |||||
(vvp)->tv_nsec += 1000000000; \ | |||||
} \ | |||||
} while (0) | |||||
#define timespecadd(vvp, uvp) \ | |||||
do { \ | |||||
(vvp)->tv_sec += (uvp)->tv_sec; \ | |||||
(vvp)->tv_nsec += (uvp)->tv_nsec; \ | |||||
if ((vvp)->tv_nsec >= 1000000000) { \ | |||||
(vvp)->tv_sec++; \ | |||||
(vvp)->tv_nsec -= 1000000000; \ | |||||
} \ | |||||
} while (0) | |||||
void | void | ||||
getblk(struct bufarea *bp, ufs2_daddr_t blk, long size) | getblk(struct bufarea *bp, ufs2_daddr_t blk, long size) | ||||
{ | { | ||||
ufs2_daddr_t dblk; | ufs2_daddr_t dblk; | ||||
struct timespec start, finish; | struct timespec start, finish; | ||||
dblk = fsbtodb(&sblock, blk); | dblk = fsbtodb(&sblock, blk); | ||||
if (bp->b_bno == dblk) { | if (bp->b_bno == dblk) { | ||||
totalreads++; | totalreads++; | ||||
} else { | } else { | ||||
flush(fswritefd, bp); | flush(fswritefd, bp); | ||||
if (debug) { | if (debug) { | ||||
readcnt[bp->b_type]++; | readcnt[bp->b_type]++; | ||||
clock_gettime(CLOCK_REALTIME_PRECISE, &start); | clock_gettime(CLOCK_REALTIME_PRECISE, &start); | ||||
} | } | ||||
bp->b_errs = blread(fsreadfd, bp->b_un.b_buf, dblk, size); | bp->b_errs = blread(fsreadfd, bp->b_un.b_buf, dblk, size); | ||||
if (debug) { | if (debug) { | ||||
clock_gettime(CLOCK_REALTIME_PRECISE, &finish); | clock_gettime(CLOCK_REALTIME_PRECISE, &finish); | ||||
timespecsub(&finish, &start); | timespecsub(&finish, &start, &finish); | ||||
timespecadd(&readtime[bp->b_type], &finish); | timespecadd(&readtime[bp->b_type], &finish, | ||||
&readtime[bp->b_type]); | |||||
} | } | ||||
bp->b_bno = dblk; | bp->b_bno = dblk; | ||||
bp->b_size = size; | bp->b_size = size; | ||||
} | } | ||||
} | } | ||||
void | void | ||||
flush(int fd, struct bufarea *bp) | flush(int fd, struct bufarea *bp) | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | IOstats(char *what) | ||||
} | } | ||||
if (startpass.tv_sec == 0) | if (startpass.tv_sec == 0) | ||||
startpass = startprog; | startpass = startprog; | ||||
printf("%s: I/O statistics\n", what); | printf("%s: I/O statistics\n", what); | ||||
printIOstats(); | printIOstats(); | ||||
totaldiskreads += diskreads; | totaldiskreads += diskreads; | ||||
diskreads = 0; | diskreads = 0; | ||||
for (i = 0; i < BT_NUMBUFTYPES; i++) { | for (i = 0; i < BT_NUMBUFTYPES; i++) { | ||||
timespecadd(&totalreadtime[i], &readtime[i]); | timespecadd(&totalreadtime[i], &readtime[i], &totalreadtime[i]); | ||||
totalreadcnt[i] += readcnt[i]; | totalreadcnt[i] += readcnt[i]; | ||||
readtime[i].tv_sec = readtime[i].tv_nsec = 0; | readtime[i].tv_sec = readtime[i].tv_nsec = 0; | ||||
readcnt[i] = 0; | readcnt[i] = 0; | ||||
} | } | ||||
clock_gettime(CLOCK_REALTIME_PRECISE, &startpass); | clock_gettime(CLOCK_REALTIME_PRECISE, &startpass); | ||||
} | } | ||||
void | void | ||||
finalIOstats(void) | finalIOstats(void) | ||||
{ | { | ||||
int i; | int i; | ||||
if (debug == 0) | if (debug == 0) | ||||
return; | return; | ||||
printf("Final I/O statistics\n"); | printf("Final I/O statistics\n"); | ||||
totaldiskreads += diskreads; | totaldiskreads += diskreads; | ||||
diskreads = totaldiskreads; | diskreads = totaldiskreads; | ||||
startpass = startprog; | startpass = startprog; | ||||
for (i = 0; i < BT_NUMBUFTYPES; i++) { | for (i = 0; i < BT_NUMBUFTYPES; i++) { | ||||
timespecadd(&totalreadtime[i], &readtime[i]); | timespecadd(&totalreadtime[i], &readtime[i], &totalreadtime[i]); | ||||
totalreadcnt[i] += readcnt[i]; | totalreadcnt[i] += readcnt[i]; | ||||
readtime[i] = totalreadtime[i]; | readtime[i] = totalreadtime[i]; | ||||
readcnt[i] = totalreadcnt[i]; | readcnt[i] = totalreadcnt[i]; | ||||
} | } | ||||
printIOstats(); | printIOstats(); | ||||
} | } | ||||
static void printIOstats(void) | static void printIOstats(void) | ||||
{ | { | ||||
long long msec, totalmsec; | long long msec, totalmsec; | ||||
int i; | int i; | ||||
clock_gettime(CLOCK_REALTIME_PRECISE, &finishpass); | clock_gettime(CLOCK_REALTIME_PRECISE, &finishpass); | ||||
timespecsub(&finishpass, &startpass); | timespecsub(&finishpass, &startpass, &finishpass); | ||||
printf("Running time: %jd.%03ld sec\n", | printf("Running time: %jd.%03ld sec\n", | ||||
(intmax_t)finishpass.tv_sec, finishpass.tv_nsec / 1000000); | (intmax_t)finishpass.tv_sec, finishpass.tv_nsec / 1000000); | ||||
printf("buffer reads by type:\n"); | printf("buffer reads by type:\n"); | ||||
for (totalmsec = 0, i = 0; i < BT_NUMBUFTYPES; i++) | for (totalmsec = 0, i = 0; i < BT_NUMBUFTYPES; i++) | ||||
totalmsec += readtime[i].tv_sec * 1000 + | totalmsec += readtime[i].tv_sec * 1000 + | ||||
readtime[i].tv_nsec / 1000000; | readtime[i].tv_nsec / 1000000; | ||||
if (totalmsec == 0) | if (totalmsec == 0) | ||||
totalmsec = 1; | totalmsec = 1; | ||||
▲ Show 20 Lines • Show All 505 Lines • Show Last 20 Lines |