Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1275193 > unrolled thread
| Started by | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| First post | 2015-11-23 11:00 +0100 |
| Last post | 2015-11-25 20:10 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH tip/locking/core v10 5/7] locking/pvqspinlock: Collect slowpath lock statistics Peter Zijlstra <peterz@infradead.org> - 2015-11-23 11:00 +0100
Re: [PATCH tip/locking/core v10 5/7] locking/pvqspinlock: Collect slowpath lock statistics Waiman Long <waiman.long@hpe.com> - 2015-11-25 20:10 +0100
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2015-11-23 11:00 +0100 |
| Subject | Re: [PATCH tip/locking/core v10 5/7] locking/pvqspinlock: Collect slowpath lock statistics |
| Message-ID | <qxW4H-8tT-21@gated-at.bofh.it> |
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/
[toc] | [next] | [standalone]
| From | Waiman Long <waiman.long@hpe.com> |
|---|---|
| Date | 2015-11-25 20:10 +0100 |
| Message-ID | <qyNC2-1Wc-21@gated-at.bofh.it> |
| In reply to | #1275193 |
[Multipart message — attachments visible in raw view] — view raw
On 11/23/2015 04:51 AM, Peter Zijlstra wrote:
> 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.
>
Thanks for catching that. I should not use u64 for the stat and kick
variables. I have attached the fixed version of the patch that should
work on 32-bit.
Cheers,
Longman
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web