From: Christoph Hellwig Date: Wed, 2 Sep 2009 17:55:39 +0000 (+0000) Subject: repair: clean up prefetch tracing X-Git-Tag: v3.0.5~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d081a36;p=thirdparty%2Fxfsprogs-dev.git repair: clean up prefetch tracing Define a dummy pftrace macro for the non-tracing case to reduce the ifdef hell, clean up a few trace calls and add proper init/exit handlers for the tracing setup and teardown. Signed-off-by: Barry Naujok Signed-off-by: Christoph Hellwig Reviewed-by: Alex Elder Signed-off-by: Alex Elder --- diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 4ccf804ed..244d58445 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -629,10 +629,9 @@ process_inode_chunk( cluster_count * sizeof(xfs_buf_t*)); for (bp_index = 0; bp_index < cluster_count; bp_index++) { -#ifdef XR_PF_TRACE pftrace("about to read off %llu in AG %d", (long long)XFS_AGB_TO_DADDR(mp, agno, agbno), agno); -#endif + bplist[bp_index] = libxfs_readbuf(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno, agbno), XFS_FSB_TO_BB(mp, blks_per_cluster), 0); @@ -650,11 +649,9 @@ process_inode_chunk( } agbno += blks_per_cluster; -#ifdef XR_PF_TRACE pftrace("readbuf %p (%llu, %d) in AG %d", bplist[bp_index], (long long)XFS_BUF_ADDR(bplist[bp_index]), XFS_BUF_COUNT(bplist[bp_index]), agno); -#endif } agbno = XFS_AGINO_TO_AGBNO(mp, first_irec->ino_startnum); @@ -906,10 +903,10 @@ process_inode_chunk( * done! - finished up irec and block simultaneously */ for (bp_index = 0; bp_index < cluster_count; bp_index++) { -#ifdef XR_PF_TRACE - pftrace("put/writebuf %p (%llu) in AG %d", bplist[bp_index], - (long long)XFS_BUF_ADDR(bplist[bp_index]), agno); -#endif + pftrace("put/writebuf %p (%llu) in AG %d", + bplist[bp_index], (long long) + XFS_BUF_ADDR(bplist[bp_index]), agno); + if (dirty && !no_modify) libxfs_writebuf(bplist[bp_index], 0); else diff --git a/repair/dir2.c b/repair/dir2.c index 2723e3b92..d0739fd40 100644 --- a/repair/dir2.c +++ b/repair/dir2.c @@ -103,21 +103,19 @@ da_read_buf( bplist = bparray; } for (i = 0; i < nex; i++) { -#ifdef XR_PF_TRACE pftrace("about to read off %llu (len = %d)", (long long)XFS_FSB_TO_DADDR(mp, bmp[i].startblock), XFS_FSB_TO_BB(mp, bmp[i].blockcount)); -#endif + bplist[i] = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bmp[i].startblock), XFS_FSB_TO_BB(mp, bmp[i].blockcount), 0); if (!bplist[i]) goto failed; -#ifdef XR_PF_TRACE + pftrace("readbuf %p (%llu, %d)", bplist[i], (long long)XFS_BUF_ADDR(bplist[i]), XFS_BUF_COUNT(bplist[i])); -#endif } dabuf = malloc(XFS_DA_BUF_SIZE(nex)); if (dabuf == NULL) { @@ -248,10 +246,8 @@ da_brelse( } da_buf_done(dabuf); for (i = 0; i < nbuf; i++) { -#ifdef XR_PF_TRACE pftrace("putbuf %p (%llu)", bplist[i], (long long)XFS_BUF_ADDR(bplist[i])); -#endif libxfs_putbuf(bplist[i]); } if (bplist != &bp) @@ -538,7 +534,7 @@ verify_final_dir2_path(xfs_mount_t *mp, /* * bail out if this is the root block (top of tree) */ - if (this_level >= cursor->active) + if (this_level >= cursor->active) return(0); /* * set hashvalue to correctl reflect the now-validated @@ -1425,7 +1421,7 @@ process_dir2_data( * numbers. Do NOT touch the name until after we've computed * the hashvalue and done a namecheck() on the name. * - * Conditions must either set clearino to zero or set + * Conditions must either set clearino to zero or set * clearreason why it's being cleared. */ if (!ino_discovery && ent_ino == BADFSINO) { @@ -1456,7 +1452,7 @@ process_dir2_data( if (ino_discovery) { add_inode_uncertain(mp, ent_ino, 0); clearino = 0; - } else + } else clearreason = _("non-existent"); } else { /* diff --git a/repair/globals.h b/repair/globals.h index 9a78caee5..fb97c7dec 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -199,10 +199,6 @@ EXTERN pthread_mutex_t *ag_locks; EXTERN int report_interval; EXTERN __uint64_t *prog_rpt_done; -#ifdef XR_PF_TRACE -EXTERN FILE *pf_trace_file; -#endif - EXTERN int ag_stride; EXTERN int thread_count; diff --git a/repair/init.c b/repair/init.c index 2d463d69e..1a1226f98 100644 --- a/repair/init.c +++ b/repair/init.c @@ -150,4 +150,5 @@ xfs_init(libxfs_init_t *args) ts_create(); ts_init(); increase_rlimit(); + pftrace_init(); } diff --git a/repair/prefetch.c b/repair/prefetch.c index 7354c4d8b..aaa56d181 100644 --- a/repair/prefetch.c +++ b/repair/prefetch.c @@ -83,9 +83,8 @@ pf_start_processing( prefetch_args_t *args) { if (!args->can_start_processing) { -#ifdef XR_PF_TRACE pftrace("signalling processing for AG %d", args->agno); -#endif + args->can_start_processing = 1; pthread_cond_signal(&args->start_processing); } @@ -96,9 +95,8 @@ pf_start_io_workers( prefetch_args_t *args) { if (!args->can_start_reading) { -#ifdef XR_PF_TRACE pftrace("signalling reading for AG %d", args->agno); -#endif + args->can_start_reading = 1; pthread_cond_broadcast(&args->start_reading); } @@ -136,25 +134,16 @@ pf_queue_io( if (args->inode_bufs_queued == IO_THRESHOLD) pf_start_io_workers(args); } -#ifdef XR_PF_TRACE - pftrace("getbuf %c %p (%llu) in AG %d (fsbno = %lu) added to " - "primary queue (inode_bufs_queued = %d, last_bno = %lu)", - B_IS_INODE(flag) ? 'I' : 'M', bp, - (long long)XFS_BUF_ADDR(bp), args->agno, fsbno, - args->inode_bufs_queued, args->last_bno_read); -#endif } else { -#ifdef XR_PF_TRACE - pftrace("getbuf %c %p (%llu) in AG %d (fsbno = %lu) added to " - "secondary queue (last_bno = %lu)", - B_IS_INODE(flag) ? 'I' : 'M', bp, - (long long)XFS_BUF_ADDR(bp), args->agno, fsbno, - args->last_bno_read); -#endif ASSERT(!B_IS_INODE(flag)); XFS_BUF_SET_PRIORITY(bp, B_DIR_META_2); } + pftrace("getbuf %c %p (%llu) in AG %d (fsbno = %lu) added to queue" + "(inode_bufs_queued = %d, last_bno = %lu)", B_IS_INODE(flag) ? + 'I' : 'M', bp, (long long)XFS_BUF_ADDR(bp), args->agno, fsbno, + args->inode_bufs_queued, args->last_bno_read); + pf_start_processing(args); pthread_mutex_unlock(&args->lock); @@ -192,9 +181,9 @@ pf_read_bmbt_reclist( while (irec.br_blockcount) { unsigned int len; -#ifdef XR_PF_TRACE + pftrace("queuing dir extent in AG %d", args->agno); -#endif + len = (irec.br_blockcount > mp->m_dirblkfsbs) ? mp->m_dirblkfsbs : irec.br_blockcount; pf_queue_io(args, irec.br_startblock, len, B_DIR_META); @@ -520,20 +509,16 @@ pf_batch_read( } } for (i = 0; i < num; i++) { -#ifdef XR_PF_TRACE pftrace("putbuf %c %p (%llu) in AG %d", B_IS_INODE(XFS_BUF_PRIORITY(bplist[i])) ? 'I' : 'M', bplist[i], (long long)XFS_BUF_ADDR(bplist[i]), args->agno); -#endif libxfs_putbuf(bplist[i]); } pthread_mutex_lock(&args->lock); if (which != PF_SECONDARY) { -#ifdef XR_PF_TRACE pftrace("inode_bufs_queued for AG %d = %d", args->agno, args->inode_bufs_queued); -#endif /* * if primary inode queue running low, process metadata * in boths queues to avoid I/O starvation as the @@ -542,15 +527,14 @@ pf_batch_read( */ if (which == PF_PRIMARY && !args->queuing_done && args->inode_bufs_queued < IO_THRESHOLD) { -#ifdef XR_PF_TRACE pftrace("reading metadata bufs from primary queue for AG %d", args->agno); -#endif + pf_batch_read(args, PF_META_ONLY, buf); -#ifdef XR_PF_TRACE + pftrace("reading bufs from secondary queue for AG %d", args->agno); -#endif + pf_batch_read(args, PF_SECONDARY, buf); } } @@ -571,20 +555,18 @@ pf_io_worker( pthread_mutex_lock(&args->lock); while (!args->queuing_done || btree_find(args->io_queue, 0, NULL)) { -#ifdef XR_PF_TRACE pftrace("waiting to start prefetch I/O for AG %d", args->agno); -#endif + while (!args->can_start_reading && !args->queuing_done) pthread_cond_wait(&args->start_reading, &args->lock); -#ifdef XR_PF_TRACE + pftrace("starting prefetch I/O for AG %d", args->agno); -#endif + pf_batch_read(args, PF_PRIMARY, buf); pf_batch_read(args, PF_SECONDARY, buf); -#ifdef XR_PF_TRACE pftrace("ran out of bufs to prefetch for AG %d", args->agno); -#endif + if (!args->queuing_done) args->can_start_reading = 0; } @@ -592,9 +574,8 @@ pf_io_worker( free(buf); -#ifdef XR_PF_TRACE pftrace("finished prefetch I/O for AG %d", args->agno); -#endif + return NULL; } @@ -636,10 +617,7 @@ pf_queuing_worker( break; } } - -#ifdef XR_PF_TRACE pftrace("starting prefetch for AG %d", args->agno); -#endif for (irec = findfirst_inode_rec(args->agno); irec != NULL; irec = next_ino_rec(irec)) { @@ -676,10 +654,9 @@ pf_queuing_worker( pthread_mutex_lock(&args->lock); -#ifdef XR_PF_TRACE pftrace("finished queuing inodes for AG %d (inode_bufs_queued = %d)", args->agno, args->inode_bufs_queued); -#endif + args->queuing_done = 1; pf_start_io_workers(args); pf_start_processing(args); @@ -690,9 +667,8 @@ pf_queuing_worker( if (args->io_threads[i]) pthread_join(args->io_threads[i], NULL); -#ifdef XR_PF_TRACE pftrace("prefetch for AG %d finished", args->agno); -#endif + pthread_mutex_lock(&args->lock); ASSERT(btree_find(args->io_queue, 0, NULL) == NULL); @@ -712,9 +688,8 @@ pf_create_prefetch_thread( { int err; -#ifdef XR_PF_TRACE pftrace("creating queue thread for AG %d", args->agno); -#endif + err = pthread_create(&args->queuing_thread, NULL, pf_queuing_worker, args); if (err != 0) { @@ -801,14 +776,12 @@ wait_for_inode_prefetch( pthread_mutex_lock(&args->lock); while (!args->can_start_processing) { -#ifdef XR_PF_TRACE pftrace("waiting to start processing AG %d", args->agno); -#endif + pthread_cond_wait(&args->start_processing, &args->lock); } -#ifdef XR_PF_TRACE pftrace("can start processing AG %d", args->agno); -#endif + pthread_mutex_unlock(&args->lock); } @@ -819,15 +792,13 @@ cleanup_inode_prefetch( if (args == NULL) return; -#ifdef XR_PF_TRACE pftrace("waiting AG %d prefetch to finish", args->agno); -#endif + if (args->queuing_thread) pthread_join(args->queuing_thread, NULL); -#ifdef XR_PF_TRACE pftrace("AG %d prefetch done", args->agno); -#endif + pthread_mutex_destroy(&args->lock); pthread_cond_destroy(&args->start_reading); pthread_cond_destroy(&args->start_processing); @@ -839,6 +810,21 @@ cleanup_inode_prefetch( #ifdef XR_PF_TRACE +static FILE *pf_trace_file; + +void +pftrace_init(void) +{ + pf_trace_file = fopen("/tmp/xfs_repair_prefetch.trace", "w"); + setvbuf(pf_trace_file, NULL, _IOLBF, 1024); +} + +void +pftrace_done(void) +{ + fclose(pf_trace_file); +} + void _pftrace(const char *func, const char *msg, ...) { @@ -853,7 +839,8 @@ _pftrace(const char *func, const char *msg, ...) buf[sizeof(buf)-1] = '\0'; va_end(args); - fprintf(pf_trace_file, "%lu.%06lu %s: %s\n", tv.tv_sec, tv.tv_usec, func, buf); + fprintf(pf_trace_file, "%lu.%06lu %s: %s\n", tv.tv_sec, tv.tv_usec, + func, buf); } #endif diff --git a/repair/prefetch.h b/repair/prefetch.h index 17ef46b06..44a406c01 100644 --- a/repair/prefetch.h +++ b/repair/prefetch.h @@ -50,8 +50,15 @@ cleanup_inode_prefetch( #ifdef XR_PF_TRACE +void pftrace_init(void); +void pftrace_done(void); + #define pftrace(msg...) _pftrace(__FUNCTION__, ## msg) void _pftrace(const char *, const char *, ...); +#else +static inline void pftrace_init(void) { }; +static inline void pftrace_done(void) { }; +static inline void pftrace(const char *msg, ...) { }; #endif #endif /* _XFS_REPAIR_PREFETCH_H */ diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 8bf20bbfd..9e5dffa0b 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -536,11 +536,6 @@ main(int argc, char **argv) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); -#ifdef XR_PF_TRACE - pf_trace_file = fopen("/tmp/xfs_repair_prefetch.trace", "w"); - setvbuf(pf_trace_file, NULL, _IOLBF, 1024); -#endif - temp_mp = &xfs_m; setbuf(stdout, NULL); @@ -844,8 +839,7 @@ _("Note - stripe unit (%d) and width (%d) fields have been reset.\n" if (verbose) summary_report(); do_log(_("done\n")); -#ifdef XR_PF_TRACE - fclose(pf_trace_file); -#endif + pftrace_done(); + return (0); }