Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756199AbYJQPHl (ORCPT ); Fri, 17 Oct 2008 11:07:41 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755250AbYJQPFa (ORCPT ); Fri, 17 Oct 2008 11:05:30 -0400 Received: from gv-out-0910.google.com ([216.239.58.184]:55326 "EHLO gv-out-0910.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754777AbYJQPF1 (ORCPT ); Fri, 17 Oct 2008 11:05:27 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=to:subject:from:date:message-id; b=GJlaApTwqFmmuil3gu8HOMs8bvhxVYFw0NXAa68pyLhjLQeysWvoyniSfn0WSqlkSJ PMmEXFLQCxG61ylRl8/CMNtZ8vSq/SSnSxy4lzx+t2/U1gjRBGitL2+QByPOWouB2nlv ofC3XTbliUPh1zWfMUmpao1BoY4X7Xz/eBbWA= To: linux-kernel@vger.kernel.org Subject: [patch 07/24] perfmon3: X86 OProfile hooks From: eranian@googlemail.com Date: Fri, 17 Oct 2008 08:05:25 -0700 (PDT) Message-ID: <48f8a9b5.05a0660a.7463.6aa3@mx.google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4482 Lines: 185 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 -- Index: o3/arch/x86/oprofile/nmi_int.c =================================================================== --- o3.orig/arch/x86/oprofile/nmi_int.c 2008-10-15 15:53:25.000000000 +0200 +++ o3/arch/x86/oprofile/nmi_int.c 2008-10-15 15:53:27.000000000 +0200 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -217,12 +218,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; } @@ -303,6 +310,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-10-15 15:53:25.000000000 +0200 +++ o3/include/linux/perfmon_kern.h 2008-10-15 15:53:27.000000000 +0200 @@ -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-10-15 15:53:25.000000000 +0200 +++ o3/perfmon/perfmon_res.c 2008-10-15 15:53:27.000000000 +0200 @@ -36,6 +36,7 @@ * 02111-1307 USA */ #include +#include #include #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); -- -- 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/