* [PATCH 0/4] perf_counter: fixes and an optimization
@ 2009-04-09 8:53 Peter Zijlstra
2009-04-09 8:53 ` [PATCH 1/4] perf_counter: fix off-by-one on the string lengths Peter Zijlstra
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 8:53 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Paul Mackerras, Corey Ashford, linux-kernel, Peter Zijlstra
- fixes an off-by-one in string handling
- fixes the mmap tracing to provide the full path
- allows unpriviledged use of cpu counters
- optimize mmap/comm tracing
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/4] perf_counter: fix off-by-one on the string lengths
2009-04-09 8:53 [PATCH 0/4] perf_counter: fixes and an optimization Peter Zijlstra
@ 2009-04-09 8:53 ` Peter Zijlstra
2009-04-09 8:53 ` [PATCH 2/4] perf_counter: optimize mmap/comm tracking Peter Zijlstra
` (3 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 8:53 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Paul Mackerras, Corey Ashford, linux-kernel, Peter Zijlstra
[-- Attachment #1: perf_counter-fix-strings.patch --]
[-- Type: text/plain, Size: 891 bytes --]
strlen() does _not_ include the terminating \0.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
kernel/perf_counter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -1989,7 +1989,7 @@ static void perf_counter_comm_event(stru
unsigned int size;
char *comm = comm_event->task->comm;
- size = ALIGN(strlen(comm), sizeof(u64));
+ size = ALIGN(strlen(comm)+1, sizeof(u64));
comm_event->comm = comm;
comm_event->comm_size = size;
@@ -2109,7 +2109,7 @@ static void perf_counter_mmap_event(stru
}
got_name:
- size = ALIGN(strlen(name), sizeof(u64));
+ size = ALIGN(strlen(name)+1, sizeof(u64));
mmap_event->file_name = name;
mmap_event->file_size = size;
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/4] perf_counter: optimize mmap/comm tracking
2009-04-09 8:53 [PATCH 0/4] perf_counter: fixes and an optimization Peter Zijlstra
2009-04-09 8:53 ` [PATCH 1/4] perf_counter: fix off-by-one on the string lengths Peter Zijlstra
@ 2009-04-09 8:53 ` Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
` (2 more replies)
2009-04-09 8:53 ` [PATCH 3/4] perf_counter: sysctl for system wide perf counters Peter Zijlstra
` (2 subsequent siblings)
4 siblings, 3 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 8:53 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Paul Mackerras, Corey Ashford, linux-kernel, Peter Zijlstra
[-- Attachment #1: perf_counter-opt-tracing.patch --]
[-- Type: text/plain, Size: 2339 bytes --]
The mmap/comm tracking code does quite a lot of work before it discovers
there's no interest in it, avoid that by keeping a counter.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
kernel/perf_counter.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -38,6 +38,10 @@ int perf_max_counters __read_mostly = 1;
static int perf_reserved_percpu __read_mostly;
static int perf_overcommit __read_mostly = 1;
+static atomic_t nr_mmap_tracking __read_mostly;
+static atomic_t nr_munmap_tracking __read_mostly;
+static atomic_t nr_comm_tracking __read_mostly;
+
/*
* Mutex for (sysadmin-configurable) counter reservations:
*/
@@ -1186,6 +1190,13 @@ static void free_counter(struct perf_cou
{
perf_pending_sync(counter);
+ if (counter->hw_event.mmap)
+ atomic_dec(&nr_mmap_tracking);
+ if (counter->hw_event.munmap)
+ atomic_dec(&nr_munmap_tracking);
+ if (counter->hw_event.comm)
+ atomic_dec(&nr_comm_tracking);
+
if (counter->destroy)
counter->destroy(counter);
@@ -2128,7 +2139,12 @@ got_name:
void perf_counter_mmap(unsigned long addr, unsigned long len,
unsigned long pgoff, struct file *file)
{
- struct perf_mmap_event mmap_event = {
+ struct perf_mmap_event mmap_event;
+
+ if (!atomic_read(&nr_mmap_tracking))
+ return;
+
+ mmap_event = (struct perf_mmap_event){
.file = file,
.event = {
.header = { .type = PERF_EVENT_MMAP, },
@@ -2146,7 +2162,12 @@ void perf_counter_mmap(unsigned long add
void perf_counter_munmap(unsigned long addr, unsigned long len,
unsigned long pgoff, struct file *file)
{
- struct perf_mmap_event mmap_event = {
+ struct perf_mmap_event mmap_event;
+
+ if (!atomic_read(&nr_munmap_tracking))
+ return;
+
+ mmap_event = (struct perf_mmap_event){
.file = file,
.event = {
.header = { .type = PERF_EVENT_MUNMAP, },
@@ -2725,6 +2746,13 @@ done:
counter->hw_ops = hw_ops;
+ if (counter->hw_event.mmap)
+ atomic_inc(&nr_mmap_tracking);
+ if (counter->hw_event.munmap)
+ atomic_inc(&nr_munmap_tracking);
+ if (counter->hw_event.comm)
+ atomic_inc(&nr_comm_tracking);
+
return counter;
}
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/4] perf_counter: sysctl for system wide perf counters
2009-04-09 8:53 [PATCH 0/4] perf_counter: fixes and an optimization Peter Zijlstra
2009-04-09 8:53 ` [PATCH 1/4] perf_counter: fix off-by-one on the string lengths Peter Zijlstra
2009-04-09 8:53 ` [PATCH 2/4] perf_counter: optimize mmap/comm tracking Peter Zijlstra
@ 2009-04-09 8:53 ` Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 9:54 ` Peter Zijlstra
2009-04-09 8:53 ` [PATCH 4/4] perf_counter: log full path names Peter Zijlstra
2009-04-09 9:03 ` [PATCH 0/4] perf_counter: fixes and an optimization Ingo Molnar
4 siblings, 2 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 8:53 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Paul Mackerras, Corey Ashford, linux-kernel, Peter Zijlstra
[-- Attachment #1: pref_counter-sysctl-global.patch --]
[-- Type: text/plain, Size: 2470 bytes --]
Allow the use of system wide perf counters to everybody, but provide
a sysctl to disable it for the paranoid security minded.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
include/linux/perf_counter.h | 2 ++
kernel/perf_counter.c | 4 +++-
kernel/sysctl.c | 11 +++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
Index: linux-2.6/include/linux/perf_counter.h
===================================================================
--- linux-2.6.orig/include/linux/perf_counter.h
+++ linux-2.6/include/linux/perf_counter.h
@@ -568,6 +568,8 @@ struct perf_callchain_entry {
extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
+extern int sysctl_perf_counter_priv;
+
#else
static inline void
perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -42,6 +42,8 @@ static atomic_t nr_mmap_tracking __read_
static atomic_t nr_munmap_tracking __read_mostly;
static atomic_t nr_comm_tracking __read_mostly;
+int sysctl_perf_counter_priv; /* do we need to be privileged */
+
/*
* Mutex for (sysadmin-configurable) counter reservations:
*/
@@ -1132,7 +1134,7 @@ static struct perf_counter_context *find
*/
if (cpu != -1) {
/* Must be root to operate on a CPU counter: */
- if (!capable(CAP_SYS_ADMIN))
+ if (sysctl_perf_counter_priv && !capable(CAP_SYS_ADMIN))
return ERR_PTR(-EACCES);
if (cpu < 0 || cpu > num_possible_cpus())
Index: linux-2.6/kernel/sysctl.c
===================================================================
--- linux-2.6.orig/kernel/sysctl.c
+++ linux-2.6/kernel/sysctl.c
@@ -50,6 +50,7 @@
#include <linux/reboot.h>
#include <linux/ftrace.h>
#include <linux/slow-work.h>
+#include <linux/perf_counter.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
@@ -931,6 +932,16 @@ static struct ctl_table kern_table[] = {
.child = slow_work_sysctls,
},
#endif
+#ifdef CONFIG_PERF_COUNTERS
+ {
+ .ctl_name = CTL_UNNUMBERED,
+ .procname = "perf_counter_privileged",
+ .data = &sysctl_perf_counter_priv,
+ .maxlen = sizeof(sysctl_perf_counter_priv),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec,
+ },
+#endif
/*
* NOTE: do not add new entries to this table unless you have read
* Documentation/sysctl/ctl_unnumbered.txt
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/4] perf_counter: log full path names
2009-04-09 8:53 [PATCH 0/4] perf_counter: fixes and an optimization Peter Zijlstra
` (2 preceding siblings ...)
2009-04-09 8:53 ` [PATCH 3/4] perf_counter: sysctl for system wide perf counters Peter Zijlstra
@ 2009-04-09 8:53 ` Peter Zijlstra
2009-04-09 9:07 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 9:54 ` Peter Zijlstra
2009-04-09 9:03 ` [PATCH 0/4] perf_counter: fixes and an optimization Ingo Molnar
4 siblings, 2 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 8:53 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Paul Mackerras, Corey Ashford, linux-kernel, Peter Zijlstra
[-- Attachment #1: perf_counter-fix-pathnames.patch --]
[-- Type: text/plain, Size: 780 bytes --]
dentry_path() only provide path-names up to the mount root, which is
unsuited for out purpose, use d_path() instead.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
kernel/perf_counter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -2111,7 +2111,7 @@ static void perf_counter_mmap_event(stru
name = strncpy(tmp, "//enomem", sizeof(tmp));
goto got_name;
}
- name = dentry_path(file->f_dentry, buf, PATH_MAX);
+ name = d_path(&file->f_path, buf, PATH_MAX);
if (IS_ERR(name)) {
name = strncpy(tmp, "//toolong", sizeof(tmp));
goto got_name;
--
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] perf_counter: fixes and an optimization
2009-04-09 8:53 [PATCH 0/4] perf_counter: fixes and an optimization Peter Zijlstra
` (3 preceding siblings ...)
2009-04-09 8:53 ` [PATCH 4/4] perf_counter: log full path names Peter Zijlstra
@ 2009-04-09 9:03 ` Ingo Molnar
4 siblings, 0 replies; 14+ messages in thread
From: Ingo Molnar @ 2009-04-09 9:03 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Paul Mackerras, Corey Ashford, linux-kernel
* Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> - fixes an off-by-one in string handling
> - fixes the mmap tracing to provide the full path
> - allows unpriviledged use of cpu counters
i made the variable here __read_mostly.
> - optimize mmap/comm tracing
Applied, thanks!
Ingo
^ permalink raw reply [flat|nested] 14+ messages in thread
* [tip:perfcounters/core] perf_counter: optimize mmap/comm tracking
2009-04-09 8:53 ` [PATCH 2/4] perf_counter: optimize mmap/comm tracking Peter Zijlstra
@ 2009-04-09 9:06 ` Peter Zijlstra
2009-04-09 9:16 ` [PATCH 2/4] " Ingo Molnar
2009-04-09 9:54 ` [tip:perfcounters/core] " Peter Zijlstra
2 siblings, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, tglx, cjashfor, mingo
Commit-ID: e37f8d14c1f56e274b3e827912f23f0b2fb7a7bb
Gitweb: http://git.kernel.org/tip/e37f8d14c1f56e274b3e827912f23f0b2fb7a7bb
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 9 Apr 2009 10:53:44 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 9 Apr 2009 11:00:53 +0200
perf_counter: optimize mmap/comm tracking
Impact: performance optimization
The mmap/comm tracking code does quite a lot of work before it discovers
there's no interest in it, avoid that by keeping a counter.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090409085524.427173196@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/perf_counter.c | 32 ++++++++++++++++++++++++++++++--
1 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index b07195b..af9fd89 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -38,6 +38,10 @@ int perf_max_counters __read_mostly = 1;
static int perf_reserved_percpu __read_mostly;
static int perf_overcommit __read_mostly = 1;
+static atomic_t nr_mmap_tracking __read_mostly;
+static atomic_t nr_munmap_tracking __read_mostly;
+static atomic_t nr_comm_tracking __read_mostly;
+
/*
* Mutex for (sysadmin-configurable) counter reservations:
*/
@@ -1186,6 +1190,13 @@ static void free_counter(struct perf_counter *counter)
{
perf_pending_sync(counter);
+ if (counter->hw_event.mmap)
+ atomic_dec(&nr_mmap_tracking);
+ if (counter->hw_event.munmap)
+ atomic_dec(&nr_munmap_tracking);
+ if (counter->hw_event.comm)
+ atomic_dec(&nr_comm_tracking);
+
if (counter->destroy)
counter->destroy(counter);
@@ -2128,7 +2139,12 @@ got_name:
void perf_counter_mmap(unsigned long addr, unsigned long len,
unsigned long pgoff, struct file *file)
{
- struct perf_mmap_event mmap_event = {
+ struct perf_mmap_event mmap_event;
+
+ if (!atomic_read(&nr_mmap_tracking))
+ return;
+
+ mmap_event = (struct perf_mmap_event){
.file = file,
.event = {
.header = { .type = PERF_EVENT_MMAP, },
@@ -2146,7 +2162,12 @@ void perf_counter_mmap(unsigned long addr, unsigned long len,
void perf_counter_munmap(unsigned long addr, unsigned long len,
unsigned long pgoff, struct file *file)
{
- struct perf_mmap_event mmap_event = {
+ struct perf_mmap_event mmap_event;
+
+ if (!atomic_read(&nr_munmap_tracking))
+ return;
+
+ mmap_event = (struct perf_mmap_event){
.file = file,
.event = {
.header = { .type = PERF_EVENT_MUNMAP, },
@@ -2725,6 +2746,13 @@ done:
counter->hw_ops = hw_ops;
+ if (counter->hw_event.mmap)
+ atomic_inc(&nr_mmap_tracking);
+ if (counter->hw_event.munmap)
+ atomic_inc(&nr_munmap_tracking);
+ if (counter->hw_event.comm)
+ atomic_inc(&nr_comm_tracking);
+
return counter;
}
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [tip:perfcounters/core] perf_counter: sysctl for system wide perf counters
2009-04-09 8:53 ` [PATCH 3/4] perf_counter: sysctl for system wide perf counters Peter Zijlstra
@ 2009-04-09 9:06 ` Peter Zijlstra
2009-04-09 9:54 ` Peter Zijlstra
1 sibling, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, tglx, cjashfor, mingo
Commit-ID: 79bbb0bfff331422caf8a353be68c4764bc1e47f
Gitweb: http://git.kernel.org/tip/79bbb0bfff331422caf8a353be68c4764bc1e47f
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 9 Apr 2009 10:53:45 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 9 Apr 2009 11:00:54 +0200
perf_counter: sysctl for system wide perf counters
Impact: add sysctl for paranoid/relaxed perfcounters policy
Allow the use of system wide perf counters to everybody, but provide
a sysctl to disable it for the paranoid security minded.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090409085524.514046352@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/perf_counter.h | 2 ++
kernel/perf_counter.c | 4 +++-
kernel/sysctl.c | 11 +++++++++++
3 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index c22363a..9814328 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -568,6 +568,8 @@ struct perf_callchain_entry {
extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
+extern int sysctl_perf_counter_priv;
+
#else
static inline void
perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index af9fd89..a2fa5bc 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -42,6 +42,8 @@ static atomic_t nr_mmap_tracking __read_mostly;
static atomic_t nr_munmap_tracking __read_mostly;
static atomic_t nr_comm_tracking __read_mostly;
+int sysctl_perf_counter_priv __read_mostly; /* do we need to be privileged */
+
/*
* Mutex for (sysadmin-configurable) counter reservations:
*/
@@ -1132,7 +1134,7 @@ static struct perf_counter_context *find_get_context(pid_t pid, int cpu)
*/
if (cpu != -1) {
/* Must be root to operate on a CPU counter: */
- if (!capable(CAP_SYS_ADMIN))
+ if (sysctl_perf_counter_priv && !capable(CAP_SYS_ADMIN))
return ERR_PTR(-EACCES);
if (cpu < 0 || cpu > num_possible_cpus())
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 4286b62..8ba4578 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -49,6 +49,7 @@
#include <linux/reboot.h>
#include <linux/ftrace.h>
#include <linux/slow-work.h>
+#include <linux/perf_counter.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
@@ -920,6 +921,16 @@ static struct ctl_table kern_table[] = {
.child = slow_work_sysctls,
},
#endif
+#ifdef CONFIG_PERF_COUNTERS
+ {
+ .ctl_name = CTL_UNNUMBERED,
+ .procname = "perf_counter_privileged",
+ .data = &sysctl_perf_counter_priv,
+ .maxlen = sizeof(sysctl_perf_counter_priv),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec,
+ },
+#endif
/*
* NOTE: do not add new entries to this table unless you have read
* Documentation/sysctl/ctl_unnumbered.txt
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [tip:perfcounters/core] perf_counter: log full path names
2009-04-09 8:53 ` [PATCH 4/4] perf_counter: log full path names Peter Zijlstra
@ 2009-04-09 9:07 ` Peter Zijlstra
2009-04-09 9:54 ` Peter Zijlstra
1 sibling, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, tglx, cjashfor, mingo
Commit-ID: 0a24487bebbee88609004bc5a5ae1b375b292897
Gitweb: http://git.kernel.org/tip/0a24487bebbee88609004bc5a5ae1b375b292897
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 9 Apr 2009 10:53:46 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 9 Apr 2009 11:00:54 +0200
perf_counter: log full path names
Impact: fix perf-report output for /home mounted binaries, etc.
dentry_path() only provide path-names up to the mount root, which is
unsuited for out purpose, use d_path() instead.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090409085524.601794134@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/perf_counter.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index a2fa5bc..0d646ac 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -2111,7 +2111,7 @@ static void perf_counter_mmap_event(struct perf_mmap_event *mmap_event)
name = strncpy(tmp, "//enomem", sizeof(tmp));
goto got_name;
}
- name = dentry_path(file->f_dentry, buf, PATH_MAX);
+ name = d_path(&file->f_path, buf, PATH_MAX);
if (IS_ERR(name)) {
name = strncpy(tmp, "//toolong", sizeof(tmp));
goto got_name;
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] perf_counter: optimize mmap/comm tracking
2009-04-09 8:53 ` [PATCH 2/4] perf_counter: optimize mmap/comm tracking Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
@ 2009-04-09 9:16 ` Ingo Molnar
2009-04-09 9:28 ` Peter Zijlstra
2009-04-09 9:54 ` [tip:perfcounters/core] " Peter Zijlstra
2 siblings, 1 reply; 14+ messages in thread
From: Ingo Molnar @ 2009-04-09 9:16 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: Paul Mackerras, Corey Ashford, linux-kernel
* Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> +static atomic_t nr_comm_tracking __read_mostly;
hm, nr_comm_tracking is not actually used by any fastpath - just
increased and then decreased.
Ingo
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] perf_counter: optimize mmap/comm tracking
2009-04-09 9:16 ` [PATCH 2/4] " Ingo Molnar
@ 2009-04-09 9:28 ` Peter Zijlstra
0 siblings, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:28 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Paul Mackerras, Corey Ashford, linux-kernel
On Thu, 2009-04-09 at 11:16 +0200, Ingo Molnar wrote:
> * Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
>
> > +static atomic_t nr_comm_tracking __read_mostly;
>
> hm, nr_comm_tracking is not actually used by any fastpath - just
> increased and then decreased.
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -2018,7 +2018,12 @@ static void perf_counter_comm_event(stru
void perf_counter_comm(struct task_struct *task)
{
- struct perf_comm_event comm_event = {
+ struct perf_comm_event comm_event;
+
+ if (!atomic_read(&nr_comm_tracking))
+ return;
+
+ comm_event = (struct perf_comm_event){
.task = task,
.event = {
.header = { .type = PERF_EVENT_COMM, },
^ permalink raw reply [flat|nested] 14+ messages in thread
* [tip:perfcounters/core] perf_counter: optimize mmap/comm tracking
2009-04-09 8:53 ` [PATCH 2/4] perf_counter: optimize mmap/comm tracking Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 9:16 ` [PATCH 2/4] " Ingo Molnar
@ 2009-04-09 9:54 ` Peter Zijlstra
2 siblings, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:54 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, tglx, cjashfor, mingo
Commit-ID: 9ee318a7825929bc3734110b83ae8e20e53d9de3
Gitweb: http://git.kernel.org/tip/9ee318a7825929bc3734110b83ae8e20e53d9de3
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 9 Apr 2009 10:53:44 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 9 Apr 2009 11:50:43 +0200
perf_counter: optimize mmap/comm tracking
Impact: performance optimization
The mmap/comm tracking code does quite a lot of work before it discovers
there's no interest in it, avoid that by keeping a counter.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090409085524.427173196@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/perf_counter.c | 39 ++++++++++++++++++++++++++++++++++++---
1 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index b07195b..76376ec 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -38,6 +38,10 @@ int perf_max_counters __read_mostly = 1;
static int perf_reserved_percpu __read_mostly;
static int perf_overcommit __read_mostly = 1;
+static atomic_t nr_mmap_tracking __read_mostly;
+static atomic_t nr_munmap_tracking __read_mostly;
+static atomic_t nr_comm_tracking __read_mostly;
+
/*
* Mutex for (sysadmin-configurable) counter reservations:
*/
@@ -1186,6 +1190,13 @@ static void free_counter(struct perf_counter *counter)
{
perf_pending_sync(counter);
+ if (counter->hw_event.mmap)
+ atomic_dec(&nr_mmap_tracking);
+ if (counter->hw_event.munmap)
+ atomic_dec(&nr_munmap_tracking);
+ if (counter->hw_event.comm)
+ atomic_dec(&nr_comm_tracking);
+
if (counter->destroy)
counter->destroy(counter);
@@ -2005,7 +2016,12 @@ static void perf_counter_comm_event(struct perf_comm_event *comm_event)
void perf_counter_comm(struct task_struct *task)
{
- struct perf_comm_event comm_event = {
+ struct perf_comm_event comm_event;
+
+ if (!atomic_read(&nr_comm_tracking))
+ return;
+
+ comm_event = (struct perf_comm_event){
.task = task,
.event = {
.header = { .type = PERF_EVENT_COMM, },
@@ -2128,7 +2144,12 @@ got_name:
void perf_counter_mmap(unsigned long addr, unsigned long len,
unsigned long pgoff, struct file *file)
{
- struct perf_mmap_event mmap_event = {
+ struct perf_mmap_event mmap_event;
+
+ if (!atomic_read(&nr_mmap_tracking))
+ return;
+
+ mmap_event = (struct perf_mmap_event){
.file = file,
.event = {
.header = { .type = PERF_EVENT_MMAP, },
@@ -2146,7 +2167,12 @@ void perf_counter_mmap(unsigned long addr, unsigned long len,
void perf_counter_munmap(unsigned long addr, unsigned long len,
unsigned long pgoff, struct file *file)
{
- struct perf_mmap_event mmap_event = {
+ struct perf_mmap_event mmap_event;
+
+ if (!atomic_read(&nr_munmap_tracking))
+ return;
+
+ mmap_event = (struct perf_mmap_event){
.file = file,
.event = {
.header = { .type = PERF_EVENT_MUNMAP, },
@@ -2725,6 +2751,13 @@ done:
counter->hw_ops = hw_ops;
+ if (counter->hw_event.mmap)
+ atomic_inc(&nr_mmap_tracking);
+ if (counter->hw_event.munmap)
+ atomic_inc(&nr_munmap_tracking);
+ if (counter->hw_event.comm)
+ atomic_inc(&nr_comm_tracking);
+
return counter;
}
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [tip:perfcounters/core] perf_counter: sysctl for system wide perf counters
2009-04-09 8:53 ` [PATCH 3/4] perf_counter: sysctl for system wide perf counters Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
@ 2009-04-09 9:54 ` Peter Zijlstra
1 sibling, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:54 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, tglx, cjashfor, mingo
Commit-ID: 1ccd15497869f3ed83b5225d410df53a96e52757
Gitweb: http://git.kernel.org/tip/1ccd15497869f3ed83b5225d410df53a96e52757
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 9 Apr 2009 10:53:45 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 9 Apr 2009 11:50:52 +0200
perf_counter: sysctl for system wide perf counters
Impact: add sysctl for paranoid/relaxed perfcounters policy
Allow the use of system wide perf counters to everybody, but provide
a sysctl to disable it for the paranoid security minded.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090409085524.514046352@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/perf_counter.h | 2 ++
kernel/perf_counter.c | 4 +++-
kernel/sysctl.c | 11 +++++++++++
3 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index c22363a..9814328 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -568,6 +568,8 @@ struct perf_callchain_entry {
extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
+extern int sysctl_perf_counter_priv;
+
#else
static inline void
perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 76376ec..7efb7eb 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -42,6 +42,8 @@ static atomic_t nr_mmap_tracking __read_mostly;
static atomic_t nr_munmap_tracking __read_mostly;
static atomic_t nr_comm_tracking __read_mostly;
+int sysctl_perf_counter_priv __read_mostly; /* do we need to be privileged */
+
/*
* Mutex for (sysadmin-configurable) counter reservations:
*/
@@ -1132,7 +1134,7 @@ static struct perf_counter_context *find_get_context(pid_t pid, int cpu)
*/
if (cpu != -1) {
/* Must be root to operate on a CPU counter: */
- if (!capable(CAP_SYS_ADMIN))
+ if (sysctl_perf_counter_priv && !capable(CAP_SYS_ADMIN))
return ERR_PTR(-EACCES);
if (cpu < 0 || cpu > num_possible_cpus())
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 4286b62..8ba4578 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -49,6 +49,7 @@
#include <linux/reboot.h>
#include <linux/ftrace.h>
#include <linux/slow-work.h>
+#include <linux/perf_counter.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
@@ -920,6 +921,16 @@ static struct ctl_table kern_table[] = {
.child = slow_work_sysctls,
},
#endif
+#ifdef CONFIG_PERF_COUNTERS
+ {
+ .ctl_name = CTL_UNNUMBERED,
+ .procname = "perf_counter_privileged",
+ .data = &sysctl_perf_counter_priv,
+ .maxlen = sizeof(sysctl_perf_counter_priv),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec,
+ },
+#endif
/*
* NOTE: do not add new entries to this table unless you have read
* Documentation/sysctl/ctl_unnumbered.txt
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [tip:perfcounters/core] perf_counter: log full path names
2009-04-09 8:53 ` [PATCH 4/4] perf_counter: log full path names Peter Zijlstra
2009-04-09 9:07 ` [tip:perfcounters/core] " Peter Zijlstra
@ 2009-04-09 9:54 ` Peter Zijlstra
1 sibling, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2009-04-09 9:54 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, tglx, cjashfor, mingo
Commit-ID: d3d21c412d8525eb2e208d990ab5eee5fb0fe03d
Gitweb: http://git.kernel.org/tip/d3d21c412d8525eb2e208d990ab5eee5fb0fe03d
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Thu, 9 Apr 2009 10:53:46 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 9 Apr 2009 11:50:54 +0200
perf_counter: log full path names
Impact: fix perf-report output for /home mounted binaries, etc.
dentry_path() only provide path-names up to the mount root, which is
unsuited for out purpose, use d_path() instead.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090409085524.601794134@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/perf_counter.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 7efb7eb..7f9521c 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -2116,7 +2116,7 @@ static void perf_counter_mmap_event(struct perf_mmap_event *mmap_event)
name = strncpy(tmp, "//enomem", sizeof(tmp));
goto got_name;
}
- name = dentry_path(file->f_dentry, buf, PATH_MAX);
+ name = d_path(&file->f_path, buf, PATH_MAX);
if (IS_ERR(name)) {
name = strncpy(tmp, "//toolong", sizeof(tmp));
goto got_name;
^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2009-04-09 9:56 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-09 8:53 [PATCH 0/4] perf_counter: fixes and an optimization Peter Zijlstra
2009-04-09 8:53 ` [PATCH 1/4] perf_counter: fix off-by-one on the string lengths Peter Zijlstra
2009-04-09 8:53 ` [PATCH 2/4] perf_counter: optimize mmap/comm tracking Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 9:16 ` [PATCH 2/4] " Ingo Molnar
2009-04-09 9:28 ` Peter Zijlstra
2009-04-09 9:54 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 8:53 ` [PATCH 3/4] perf_counter: sysctl for system wide perf counters Peter Zijlstra
2009-04-09 9:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 9:54 ` Peter Zijlstra
2009-04-09 8:53 ` [PATCH 4/4] perf_counter: log full path names Peter Zijlstra
2009-04-09 9:07 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-09 9:54 ` Peter Zijlstra
2009-04-09 9:03 ` [PATCH 0/4] perf_counter: fixes and an optimization Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).