Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754466AbbKWJvn (ORCPT ); Mon, 23 Nov 2015 04:51:43 -0500 Received: from casper.infradead.org ([85.118.1.10]:46390 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753303AbbKWJvl (ORCPT ); Mon, 23 Nov 2015 04:51:41 -0500 Date: Mon, 23 Nov 2015 10:51:36 +0100 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, Scott J Norton , Douglas Hatch , Davidlohr Bueso Subject: Re: [PATCH tip/locking/core v10 5/7] locking/pvqspinlock: Collect slowpath lock statistics Message-ID: <20151123095136.GI17308@twins.programming.kicks-ass.net> References: <1447114167-47185-1-git-send-email-Waiman.Long@hpe.com> <1447114167-47185-6-git-send-email-Waiman.Long@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1447114167-47185-6-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2686 Lines: 97 On Mon, Nov 09, 2015 at 07:09:25PM -0500, Waiman Long wrote: > +static ssize_t qstat_read(struct file *file, char __user *user_buf, > + size_t count, loff_t *ppos) > +{ > + char buf[64]; > + int cpu, counter, len; > + u64 stat = 0, kicks = 0; > + > + /* > + * Get the counter ID stored in file->f_inode->i_private > + */ > + if (!file->f_inode) { > + WARN_ON_ONCE(1); > + return -EBADF; > + } > + counter = (long)(file->f_inode->i_private); > + > + if (counter >= qstat_num) > + return -EBADF; > + > + for_each_possible_cpu(cpu) { > + stat += per_cpu(qstats[counter], cpu); > + /* > + * Need to sum additional counter for some of them > + */ > + switch (counter) { > + > + case qstat_pv_latency_kick: > + case qstat_pv_hash_hops: > + kicks += per_cpu(qstats[qstat_pv_kick_unlock], cpu); > + break; > + > + case qstat_pv_latency_wake: > + kicks += per_cpu(qstats[qstat_pv_kick_wake], cpu); > + break; > + } > + } > + > + if (counter == qstat_pv_hash_hops) { > + /* > + * Return a X.XX decimal number > + */ > + len = snprintf(buf, sizeof(buf) - 1, "%llu.%02llu\n", > + stat/kicks, ((stat%kicks)*100 + kicks/2)/kicks); > + } else { > + /* > + * Round to the nearest ns > + */ > + if ((counter == qstat_pv_latency_kick) || > + (counter == qstat_pv_latency_wake)) > + stat = kicks ? (stat + kicks/2)/kicks : 0; > + len = snprintf(buf, sizeof(buf) - 1, "%llu\n", stat); > + } > + > + return simple_read_from_buffer(user_buf, count, ppos, buf, len); > +} That doesn't work on 32bit. --- --- a/kernel/locking/qspinlock_stat.h +++ b/kernel/locking/qspinlock_stat.h @@ -127,18 +127,25 @@ static ssize_t qstat_read(struct file *f } if (counter == qstat_pv_hash_hops) { + u64 frac; + + frac = 100ULL * do_div(stat, kicks); + frac = DIV_ROUND_CLOSEST_ULL(frac, kicks); + /* * Return a X.XX decimal number */ - len = snprintf(buf, sizeof(buf) - 1, "%llu.%02llu\n", - stat/kicks, ((stat%kicks)*100 + kicks/2)/kicks); + len = snprintf(buf, sizeof(buf) - 1, "%llu.%02llu\n", stat, frac); } else { /* * Round to the nearest ns */ if ((counter == qstat_pv_latency_kick) || - (counter == qstat_pv_latency_wake)) - stat = kicks ? (stat + kicks/2)/kicks : 0; + (counter == qstat_pv_latency_wake)) { + stat = 0; + if (kicks) + stat = DIV_ROUND_CLOSEST_ULL(stat, kicks); + } len = snprintf(buf, sizeof(buf) - 1, "%llu\n", stat); } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/