From: eranian@googlemail.com
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, mingo@elte.hu, x86@kernel.org,
andi@firstfloor.org, eranian@gmail.com, sfr@canb.auug.org.au
Subject: [patch 07/24] perfmon: OProfile hooks (x86)
Date: Wed, 26 Nov 2008 00:42:15 -0800 (PST) [thread overview]
Message-ID: <492d0be7.0f975e0a.1ba8.5380@mx.google.com> (raw)
Provides PMU access synchronization between Perfmon and OProfile.
Both subsystems can be compiled in. Only one of them can be active
at any one time. It is necessary to issue opcontrol --shutdown
to terminate the OProfile session.
Signed-off-by: Stephane Eranian <eranian@gmail.com>
--
Index: o3/arch/x86/oprofile/nmi_int.c
===================================================================
--- o3.orig/arch/x86/oprofile/nmi_int.c 2008-11-03 10:46:42.000000000 +0100
+++ o3/arch/x86/oprofile/nmi_int.c 2008-11-03 10:58:17.000000000 +0100
@@ -17,6 +17,7 @@
#include <linux/moduleparam.h>
#include <linux/kdebug.h>
#include <linux/cpu.h>
+#include <linux/perfmon_kern.h>
#include <asm/nmi.h>
#include <asm/msr.h>
#include <asm/apic.h>
@@ -142,12 +143,18 @@
int err = 0;
int cpu;
- if (!allocate_msrs())
+ if (pfm_session_allcpus_acquire())
+ return -EBUSY;
+
+ if (!allocate_msrs()) {
+ pfm_session_allcpus_release();
return -ENOMEM;
+ }
err = register_die_notifier(&profile_exceptions_nb);
if (err) {
free_msrs();
+ pfm_session_allcpus_release();
return err;
}
@@ -228,6 +235,7 @@
msrs = &get_cpu_var(cpu_msrs);
model->shutdown(msrs);
free_msrs();
+ pfm_session_allcpus_release();
put_cpu_var(cpu_msrs);
}
Index: o3/include/linux/perfmon_kern.h
===================================================================
--- o3.orig/include/linux/perfmon_kern.h 2008-11-03 10:49:47.000000000 +0100
+++ o3/include/linux/perfmon_kern.h 2008-11-03 10:58:17.000000000 +0100
@@ -192,6 +192,9 @@
void pfm_interrupt_handler(unsigned long ip, struct pt_regs *regs);
+int pfm_session_allcpus_acquire(void);
+void pfm_session_allcpus_release(void);
+
static inline void pfm_exit_thread(void)
{
if (current->pfm_context)
@@ -272,5 +275,13 @@
static inline void pfm_ctxsw_out(struct task_struct *p, struct task_struct *n)
{}
+
+static inline void pfm_session_allcpus_release(void)
+{}
+
+static inline int pfm_session_allcpus_acquire(void)
+{
+ return 0;
+}
#endif /* CONFIG_PERFMON */
#endif /* __LINUX_PERFMON_KERN_H__ */
Index: o3/perfmon/perfmon_res.c
===================================================================
--- o3.orig/perfmon/perfmon_res.c 2008-11-03 10:49:37.000000000 +0100
+++ o3/perfmon/perfmon_res.c 2008-11-03 10:58:17.000000000 +0100
@@ -36,6 +36,7 @@
* 02111-1307 USA
*/
#include <linux/kernel.h>
+#include <linux/module.h>
#include <linux/perfmon_kern.h>
#include "perfmon_priv.h"
@@ -103,3 +104,87 @@
spin_unlock_irqrestore(&pfm_res_lock, flags);
}
+
+/**
+ * pfm_session_allcpus_acquire - acquire per-cpu sessions on all available cpus
+ *
+ * currently used by Oprofile on X86
+ */
+int pfm_session_allcpus_acquire(void)
+{
+ unsigned long flags;
+ u32 nsys_cpus, cpu;
+ int ret = -EBUSY;
+
+ spin_lock_irqsave(&pfm_res_lock, flags);
+
+ nsys_cpus = cpus_weight(pfm_res.sys_cpumask);
+
+ PFM_DBG("in sys=%u task=%u",
+ nsys_cpus,
+ pfm_res.thread_sessions);
+
+ if (nsys_cpus) {
+ PFM_DBG("already some system-wide sessions");
+ goto abort;
+ }
+
+ /*
+ * cannot mix system wide and per-task sessions
+ */
+ if (pfm_res.thread_sessions) {
+ PFM_DBG("%u conflicting thread_sessions",
+ pfm_res.thread_sessions);
+ goto abort;
+ }
+
+ for_each_online_cpu(cpu) {
+ cpu_set(cpu, pfm_res.sys_cpumask);
+ nsys_cpus++;
+ }
+
+ PFM_DBG("out sys=%u task=%u",
+ nsys_cpus,
+ pfm_res.thread_sessions);
+
+ ret = 0;
+abort:
+ spin_unlock_irqrestore(&pfm_res_lock, flags);
+
+ return ret;
+}
+EXPORT_SYMBOL(pfm_session_allcpus_acquire);
+
+/**
+ * pfm_session_allcpus_release - relase per-cpu sessions on all cpus
+ *
+ * currently used by Oprofile code
+ */
+void pfm_session_allcpus_release(void)
+{
+ unsigned long flags;
+ u32 nsys_cpus, cpu;
+
+ spin_lock_irqsave(&pfm_res_lock, flags);
+
+ nsys_cpus = cpus_weight(pfm_res.sys_cpumask);
+
+ PFM_DBG("in sys=%u task=%u",
+ nsys_cpus,
+ pfm_res.thread_sessions);
+
+ /*
+ * XXX: could use __cpus_clear() with nbits
+ */
+ for_each_online_cpu(cpu) {
+ cpu_clear(cpu, pfm_res.sys_cpumask);
+ nsys_cpus--;
+ }
+
+ PFM_DBG("out sys=%u task=%u",
+ nsys_cpus,
+ pfm_res.thread_sessions);
+
+ spin_unlock_irqrestore(&pfm_res_lock, flags);
+}
+EXPORT_SYMBOL(pfm_session_allcpus_release);
--
next reply other threads:[~2008-11-26 8:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-26 8:42 eranian [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-11-25 21:36 [patch 07/24] perfmon: OProfile hooks (x86) eranian
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=492d0be7.0f975e0a.1ba8.5380@mx.google.com \
--to=eranian@googlemail.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=eranian@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=sfr@canb.auug.org.au \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.