This patch changes the check of PMU access in pfm_read_pmds().

In the cell-spe-follow mode, 
we need to call the special function to check 
whether the target SPU program is running.

Signed-off-by: Takashi Yamamoto <TakashiA.Yamamoto@jp.sony.com>
---
 include/asm-powerpc/perfmon_kern.h |   13 +++++++++++++
 perfmon/perfmon_rw.c               |   12 +++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

--- a/include/asm-powerpc/perfmon_kern.h
+++ b/include/asm-powerpc/perfmon_kern.h
@@ -450,6 +450,19 @@ struct pfm_arch_context {
 	void                    *arg;
 };
 
+/*
+ * This function returns whether the target SPU program is running.
+ */
+static inline int pfm_cell_can_access_pmu(
+	struct pfm_context *ctx)
+{
+	struct pfm_arch_context *ctx_arch = pfm_ctx_arch(ctx);
+	if (ctx->flags.not_dflt_ctxsw && ctx_arch->arg)
+		return 1;
+	else
+		return 0;
+}
+
 #define PFM_ARCH_CTX_SIZE sizeof(struct pfm_arch_context)
 /*
  * PowerPC does not need extra alignment requirements for the sampling buffer
--- a/perfmon/perfmon_rw.c
+++ b/perfmon/perfmon_rw.c
@@ -506,7 +506,17 @@ int __pfm_read_pmds(struct pfm_context *
 
 	if (likely(ctx->state == PFM_CTX_LOADED)) {
 		can_access_pmu = __get_cpu_var(pmu_owner) == ctx->task
-			       || ctx->flags.system;
+			|| ctx->flags.system;
+
+#ifdef CONFIG_PPC
+		/*
+		 * In the cell_spe_follow mode,
+		 * The target SPU program may run on the other CPU's SPU,
+		 * So pfm_cell_can_access_pmu(ctx) is used here.
+		 */
+		if (!ctx->flags.system)
+			can_access_pmu = pfm_cell_can_access_pmu(ctx);
+#endif
 
 		if (can_access_pmu)
 			pfm_arch_serialize();
