From: Peter Zijlstra <peterz@infradead.org>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, hpa@zytor.com,
mingo@redhat.com, a.p.zijlstra@chello.nl, efault@gmx.de,
peterz@infradead.org, arjan@infradead.org, tglx@linutronix.de,
mingo@elte.hu
Subject: [tip:perfcounters/core] perf_counter: fix perf_poll()
Date: Tue, 24 Mar 2009 13:06:29 GMT [thread overview]
Message-ID: <tip-47a6aae483f6b98509a4565ad2d8916de77ee078@git.kernel.org> (raw)
In-Reply-To: <1237897096.24918.181.camel@twins>
Commit-ID: 47a6aae483f6b98509a4565ad2d8916de77ee078
Gitweb: http://git.kernel.org/tip/47a6aae483f6b98509a4565ad2d8916de77ee078
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Tue, 24 Mar 2009 13:18:16 +0100
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 24 Mar 2009 13:28:56 +0100
perf_counter: fix perf_poll()
Impact: fix kerneltop 100% CPU usage
Only return a poll event when there's actually been one, poll_wait()
doesn't actually wait for the waitq you pass it, it only enqueues
you on it.
Only once all FDs have been iterated and none of thm returned a
poll-event will it schedule().
Also make it return POLL_HUP when there's not mmap() area to read from.
Further, fix a silly bug in the write code.
Reported-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arjan van de Ven <arjan@infradead.org>
LKML-Reference: <1237897096.24918.181.camel@twins>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/perf_counter.h | 1 +
kernel/perf_counter.c | 14 ++++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 2b5e66d..48212c1 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -246,6 +246,7 @@ struct file;
struct perf_mmap_data {
struct rcu_head rcu_head;
int nr_pages;
+ atomic_t wakeup;
atomic_t head;
struct perf_counter_mmap_page *user_page;
void *data_pages[0];
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 0dfe910..affe227 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -1161,7 +1161,16 @@ perf_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
static unsigned int perf_poll(struct file *file, poll_table *wait)
{
struct perf_counter *counter = file->private_data;
- unsigned int events = POLLIN;
+ struct perf_mmap_data *data;
+ unsigned int events;
+
+ rcu_read_lock();
+ data = rcu_dereference(counter->data);
+ if (data)
+ events = atomic_xchg(&data->wakeup, 0);
+ else
+ events = POLL_HUP;
+ rcu_read_unlock();
poll_wait(file, &counter->waitq, wait);
@@ -1425,7 +1434,7 @@ static int perf_output_write(struct perf_counter *counter, int nmi,
do {
offset = head = atomic_read(&data->head);
- head += sizeof(u64);
+ head += size;
} while (atomic_cmpxchg(&data->head, offset, head) != offset);
wakeup = (offset >> PAGE_SHIFT) != (head >> PAGE_SHIFT);
@@ -1446,6 +1455,7 @@ static int perf_output_write(struct perf_counter *counter, int nmi,
* generate a poll() wakeup for every page boundary crossed
*/
if (wakeup) {
+ atomic_xchg(&data->wakeup, POLL_IN);
__perf_counter_update_userpage(counter, data);
if (nmi) {
counter->wakeup_pending = 1;
prev parent reply other threads:[~2009-03-24 13:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 5:52 [PATCH] perf_counter tools: remove glib dependency and fix bugs in kerneltop.c Paul Mackerras
2009-03-24 7:57 ` Peter Zijlstra
2009-03-24 9:20 ` Ingo Molnar
2009-03-24 9:36 ` [tip:perfcounters/core] " Paul Mackerras
2009-03-24 9:38 ` Ingo Molnar
2009-03-24 10:12 ` Paul Mackerras
2009-03-24 10:14 ` Ingo Molnar
2009-03-24 10:00 ` [tip:perfcounters/core] perf_counter tools: remove glib dependency and fix bugs in kerneltop.c, fix poll() Peter Zijlstra
[not found] ` <1237875063.7530.11.camel@marge.simson.net>
[not found] ` <1237875580.7827.3.camel@marge.simson.net>
[not found] ` <1237877884.8754.2.camel@marge.simson.net>
[not found] ` <18888.38308.223722.602357@cargo.ozlabs.ibm.com>
[not found] ` <1237888224.24918.159.camel@twins>
[not found] ` <1237891863.13862.27.camel@marge.simson.net>
[not found] ` <1237892368.24918.160.camel@twins>
2009-03-24 12:18 ` [PATCH] perf_counter: fix perf_poll() Peter Zijlstra
2009-03-24 12:21 ` Peter Zijlstra
2009-03-24 12:25 ` Ingo Molnar
2009-03-24 13:06 ` Peter Zijlstra [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-47a6aae483f6b98509a4565ad2d8916de77ee078@git.kernel.org \
--to=peterz@infradead.org \
--cc=a.p.zijlstra@chello.nl \
--cc=arjan@infradead.org \
--cc=efault@gmx.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox