From 9b924e86b27df0cb7a6f0d4c04ff96f867413485 Mon Sep 17 00:00:00 2001 From: Ben Evans Date: Wed, 12 Dec 2018 15:20:03 -0500 Subject: [PATCH] LU-10171 headers: define pct(a,b) once pct is defined 6 times in different places. Define it in one. Also change it to a static inline to do a better job of enforcing types. Signed-off-by: Ben Evans Change-Id: If61132a1096c351a9bcb7debb868351206267535 Reviewed-on: https://review.whamcloud.com/29852 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Andreas Dilger --- lustre/fld/fld_cache.c | 11 ++--------- lustre/include/lprocfs_status.h | 5 +++++ lustre/llite/lproc_llite.c | 6 ++---- lustre/mdt/mdt_lproc.c | 8 ++------ lustre/obdclass/genops.c | 6 +----- lustre/osc/lproc_osc.c | 15 ++++++--------- lustre/osd-ldiskfs/osd_lproc.c | 6 +----- lustre/osd-zfs/osd_lproc.c | 6 +----- 8 files changed, 20 insertions(+), 43 deletions(-) diff --git a/lustre/fld/fld_cache.c b/lustre/fld/fld_cache.c index 9b46fee..bb3dfe0 100644 --- a/lustre/fld/fld_cache.c +++ b/lustre/fld/fld_cache.c @@ -88,23 +88,16 @@ struct fld_cache *fld_cache_init(const char *name, */ void fld_cache_fini(struct fld_cache *cache) { - __u64 pct; ENTRY; LASSERT(cache != NULL); fld_cache_flush(cache); - if (cache->fci_stat.fst_count > 0) { - pct = cache->fci_stat.fst_cache * 100; - do_div(pct, cache->fci_stat.fst_count); - } else { - pct = 0; - } - CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name); CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count); CDEBUG(D_INFO, " Cache reqs: %llu\n", cache->fci_stat.fst_cache); - CDEBUG(D_INFO, " Cache hits: %llu%%\n", pct); + CDEBUG(D_INFO, " Cache hits: %u%%\n", + pct(cache->fci_stat.fst_cache, cache->fci_stat.fst_count)); OBD_FREE_PTR(cache); diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index d42981d..865553d 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -58,6 +58,11 @@ struct lprocfs_vars { mode_t proc_mode; }; +static inline u32 pct(s64 a, s64 b) +{ + return b ? a * 100 / b : 0; +} + /** * Append a space separated list of current set flags to str. */ diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 24b4010..eeb3ad1 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -1528,8 +1528,6 @@ void ll_debugfs_unregister_super(struct super_block *sb) } #undef MAX_STRING_SIZE -#define pct(a,b) (b ? a * 100 / b : 0) - static void ll_display_extents_info(struct ll_rw_extents_info *io_extents, struct seq_file *seq, int which) { @@ -1554,8 +1552,8 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents, read_cum += r; write_cum += w; end = BIT(i + LL_HIST_START - units); - seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | " - "%14lu %4lu %4lu\n", start, *unitp, end, *unitp, + seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u | " + "%14lu %4u %4u\n", start, *unitp, end, *unitp, (i == LL_HIST_MAX - 1) ? '+' : ' ', r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index da3c529..b64b74a 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -76,8 +76,6 @@ * 16kB: { samples: 12, pct: 3, cum_pct: 81 } **/ -#define pct(a, b) (b ? a * 100 / b : 0) - static void display_rename_stats(struct seq_file *seq, char *name, struct obd_histogram *hist) { @@ -101,8 +99,8 @@ static void display_rename_stats(struct seq_file *seq, char *name, else seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:"); - seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n", - t, pct(t, tot), pct(cum, tot)); + seq_printf(seq, " { sample: %3lu, pct: %3u, cum_pct: %3u }\n", + t, pct(t, tot), pct(cum, tot)); if (cum == tot) break; @@ -128,8 +126,6 @@ static void rename_stats_show(struct seq_file *seq, &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]); } -#undef pct - static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v) { struct mdt_device *mdt = seq->private; diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 6d06336..2bfa781 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -2225,8 +2225,6 @@ int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max) } EXPORT_SYMBOL(obd_set_max_mod_rpcs_in_flight); - -#define pct(a, b) (b ? a * 100 / b : 0) int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq) { @@ -2252,7 +2250,7 @@ int obd_mod_rpc_stats_seq_show(struct client_obd *cli, for (i = 0; i < OBD_HIST_MAX; i++) { unsigned long mod = cli->cl_mod_rpcs_hist.oh_buckets[i]; mod_cum += mod; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu\n", + seq_printf(seq, "%d:\t\t%10lu %3u %3u\n", i, mod, pct(mod, mod_tot), pct(mod_cum, mod_tot)); if (mod_cum == mod_tot) @@ -2264,8 +2262,6 @@ int obd_mod_rpc_stats_seq_show(struct client_obd *cli, return 0; } EXPORT_SYMBOL(obd_mod_rpc_stats_seq_show); -#undef pct - /* The number of modify RPCs sent in parallel is limited * because the server has a finite number of slots per client to diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 2a4dd88..4289266 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -781,8 +781,6 @@ struct lprocfs_vars lprocfs_osc_obd_vars[] = { { NULL } }; -#define pct(a,b) (b ? a * 100 / b : 0) - static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) { struct timespec64 now; @@ -821,7 +819,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) read_cum += r; write_cum += w; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", + seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n", 1 << i, r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), @@ -844,7 +842,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i]; read_cum += r; write_cum += w; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", + seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n", i, r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), @@ -867,10 +865,10 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) unsigned long w = cli->cl_write_offset_hist.oh_buckets[i]; read_cum += r; write_cum += w; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", - (i == 0) ? 0 : 1 << (i - 1), - r, pct(r, read_tot), pct(read_cum, read_tot), - w, pct(w, write_tot), pct(write_cum, write_tot)); + seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n", + (i == 0) ? 0 : 1 << (i - 1), + r, pct(r, read_tot), pct(read_cum, read_tot), + w, pct(w, write_tot), pct(write_cum, write_tot)); if (read_cum == read_tot && write_cum == write_tot) break; } @@ -879,7 +877,6 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v) return 0; } -#undef pct static ssize_t osc_rpc_stats_seq_write(struct file *file, const char __user *buf, diff --git a/lustre/osd-ldiskfs/osd_lproc.c b/lustre/osd-ldiskfs/osd_lproc.c index 89cdfee..85b2055 100644 --- a/lustre/osd-ldiskfs/osd_lproc.c +++ b/lustre/osd-ldiskfs/osd_lproc.c @@ -78,8 +78,6 @@ void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf) lprocfs_oh_tally(&s->hist[BRW_R_DISCONT_BLOCKS+rw], discont_blocks); } -#define pct(a, b) (b ? a * 100 / b : 0) - static void display_brw_stats(struct seq_file *seq, char *name, char *units, struct obd_histogram *read, struct obd_histogram *write, int scale) { @@ -109,7 +107,7 @@ static void display_brw_stats(struct seq_file *seq, char *name, char *units, else seq_printf(seq, "%uM", scale << (i-20)); - seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n", + seq_printf(seq, ":\t\t%10lu %3u %3u | %4lu %3u %3u\n", r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); @@ -158,8 +156,6 @@ static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats) &brw_stats->hist[BRW_W_DISK_IOSIZE], 1); } -#undef pct - static int osd_brw_stats_seq_show(struct seq_file *seq, void *v) { struct osd_device *osd = seq->private; diff --git a/lustre/osd-zfs/osd_lproc.c b/lustre/osd-zfs/osd_lproc.c index 7944f18..bedc478 100644 --- a/lustre/osd-zfs/osd_lproc.c +++ b/lustre/osd-zfs/osd_lproc.c @@ -46,8 +46,6 @@ #ifdef CONFIG_PROC_FS -#define pct(a, b) (b ? a * 100 / b : 0) - static void display_brw_stats(struct seq_file *seq, char *name, char *units, struct obd_histogram *read, struct obd_histogram *write, int scale) @@ -78,7 +76,7 @@ static void display_brw_stats(struct seq_file *seq, char *name, char *units, else seq_printf(seq, "%uM", scale << (i-20)); - seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n", + seq_printf(seq, ":\t\t%10lu %3u %3u | %4lu %3u %3u\n", r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); @@ -124,8 +122,6 @@ static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats) &brw_stats->hist[BRW_W_DISK_IOSIZE], 1); } -#undef pct - static int osd_brw_stats_seq_show(struct seq_file *seq, void *v) { struct osd_device *osd = seq->private; -- 1.8.3.1