From: Jian Yu Date: Mon, 8 Nov 2010 10:09:36 +0000 (+0800) Subject: b=23289 lprocfs_counter cleanup X-Git-Tag: 2.0.56.0~30 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=1cb2b41a12176f30b0a36be75bec0e1253d8f3ef b=23289 lprocfs_counter cleanup Eliminate unnecessary atomic operations in lprocfs_counter. o=liang i=andreas.dilger i=maxim.patlasov --- diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index c7b077c..bebcbf5 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -169,8 +169,6 @@ enum lprocfs_stats_flags { LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */ LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu * area and need locking */ - LPROCFS_STATS_GET_SMP_ID = 0x0002, /* just record locking with - * LPROCFS_GET_SMP_ID flag */ }; enum lprocfs_fields_flags { @@ -347,33 +345,48 @@ static inline void s2dhms(struct dhms *ts, time_t secs) #ifdef LPROCFS -static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int type) +static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int opc) { - int rc = 0; - - if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) { - if (type & LPROCFS_GET_NUM_CPU) - rc = 1; - if (type & LPROCFS_GET_SMP_ID) - rc = 0; - cfs_spin_lock(&stats->ls_lock); - } else { - if (type & LPROCFS_GET_NUM_CPU) - rc = cfs_num_possible_cpus(); - if (type & LPROCFS_GET_SMP_ID) { - stats->ls_flags |= LPROCFS_STATS_GET_SMP_ID; - rc = cfs_get_cpu(); + switch (opc) { + default: + LBUG(); + + case LPROCFS_GET_SMP_ID: + if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) { + cfs_spin_lock(&stats->ls_lock); + return 0; + } else { + return cfs_get_cpu(); + } + + case LPROCFS_GET_NUM_CPU: + if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) { + cfs_spin_lock(&stats->ls_lock); + return 1; + } else { + return cfs_num_possible_cpus(); } } - return rc; } -static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats) +static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc) { - if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) - cfs_spin_unlock(&stats->ls_lock); - else if (stats->ls_flags & LPROCFS_STATS_GET_SMP_ID) - cfs_put_cpu(); + switch (opc) { + default: + LBUG(); + + case LPROCFS_GET_SMP_ID: + if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) + cfs_spin_unlock(&stats->ls_lock); + else + cfs_put_cpu(); + return; + + case LPROCFS_GET_NUM_CPU: + if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) + cfs_spin_unlock(&stats->ls_lock); + return; + } } /* Two optimized LPROCFS counter increment functions are provided: @@ -724,6 +737,8 @@ static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int index, long amount) { return; } static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int index) { return; } +static inline void lprocfs_counter_decr(struct lprocfs_stats *stats, + int index) { return; } static inline void lprocfs_counter_sub(struct lprocfs_stats *stats, int index, long amount) { return; } static inline void lprocfs_counter_init(struct lprocfs_stats *stats, diff --git a/lustre/lvfs/lvfs_lib.c b/lustre/lvfs/lvfs_lib.c index 9ec5e6f..7bfe92d 100644 --- a/lustre/lvfs/lvfs_lib.c +++ b/lustre/lvfs/lvfs_lib.c @@ -172,7 +172,8 @@ void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID); percpu_cntr = &(stats->ls_percpu[smp_id]->lp_cntr[idx]); - cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry); + if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)) + cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry); percpu_cntr->lc_count++; if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) { @@ -187,8 +188,9 @@ void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, if (amount > percpu_cntr->lc_max) percpu_cntr->lc_max = amount; } - cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit); - lprocfs_stats_unlock(stats); + if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)) + cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit); + lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID); } EXPORT_SYMBOL(lprocfs_counter_add); @@ -206,7 +208,8 @@ void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID); percpu_cntr = &(stats->ls_percpu[smp_id]->lp_cntr[idx]); - cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry); + if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)) + cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry); if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) { /* * currently lprocfs_count_add() can only be called in thread @@ -221,8 +224,9 @@ void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, else percpu_cntr->lc_sum -= amount; } - cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit); - lprocfs_stats_unlock(stats); + if (!(stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)) + cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit); + lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID); } EXPORT_SYMBOL(lprocfs_counter_sub); #endif /* LPROCFS */ diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 6926153..2a5d742 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -701,10 +701,7 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, cnt->lc_min = LC_MIN_INIT; - if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) - num_cpu = 1; - else - num_cpu = cfs_num_possible_cpus(); + num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU); for (i = 0; i < num_cpu; i++) { percpu_cntr = &(stats->ls_percpu[i])->lp_cntr[idx]; @@ -731,6 +728,7 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, } cnt->lc_units = stats->ls_percpu[0]->lp_cntr[idx].lc_units; + lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU); } /** @@ -1258,7 +1256,7 @@ void lprocfs_clear_stats(struct lprocfs_stats *stats) } } - lprocfs_stats_unlock(stats); + lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU); } static ssize_t lprocfs_stats_seq_write(struct file *file, const char *buf, @@ -1414,7 +1412,7 @@ void lprocfs_counter_init(struct lprocfs_stats *stats, int index, c->lc_units = units; } - lprocfs_stats_unlock(stats); + lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU); } EXPORT_SYMBOL(lprocfs_counter_init);