From cc1dc6d039ced64c2f8b8457bf1cccf4ecfc5942 Mon Sep 17 00:00:00 2001
From: Markus Metzger <markus.t.metzger@intel.com>
Date: Tue, 16 Dec 2008 15:51:03 +0100
Subject: x86, bts: remove recursion from get_context

Impact: cleanup

Optimistically allocate a DS context. It is extremely unlikely that
one already existed. This simplifies the code a lot.

Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/ds.c | 58 ++++++++++++++++++++++------------------------------
 1 file changed, 25 insertions(+), 33 deletions(-)

(limited to 'arch/x86')

diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c
index dc1e7123ea4e..0dc795951d73 100644
--- a/arch/x86/kernel/ds.c
+++ b/arch/x86/kernel/ds.c
@@ -232,53 +232,45 @@ static DEFINE_PER_CPU(struct ds_context *, system_context_array);
 
 #define system_context per_cpu(system_context_array, smp_processor_id())
 
-static struct ds_context *ds_get_context(struct task_struct *task)
+
+static inline struct ds_context *ds_get_context(struct task_struct *task)
 {
 	struct ds_context **p_context =
 		(task ? &task->thread.ds_ctx : &system_context);
-	struct ds_context *context = *p_context;
+	struct ds_context *context = NULL;
+	struct ds_context *new_context = NULL;
 	unsigned long irq;
 
-	if (!context) {
-		context = kzalloc(sizeof(*context), GFP_KERNEL);
-		if (!context)
-			return NULL;
-
-		spin_lock_irqsave(&ds_lock, irq);
-
-		if (*p_context) {
-			kfree(context);
+	/* Chances are small that we already have a context. */
+	new_context = kzalloc(sizeof(*new_context), GFP_KERNEL);
+	if (!new_context)
+		return NULL;
 
-			context = *p_context;
-		} else {
-			*p_context = context;
+	spin_lock_irqsave(&ds_lock, irq);
 
-			context->this = p_context;
-			context->task = task;
+	context = *p_context;
+	if (!context) {
+		context = new_context;
 
-			if (task)
-				set_tsk_thread_flag(task, TIF_DS_AREA_MSR);
+		context->this = p_context;
+		context->task = task;
+		context->count = 0;
 
-			if (!task || (task == current))
-				wrmsrl(MSR_IA32_DS_AREA,
-				       (unsigned long)context->ds);
-		}
+		if (task)
+			set_tsk_thread_flag(task, TIF_DS_AREA_MSR);
 
-		context->count++;
+		if (!task || (task == current))
+			wrmsrl(MSR_IA32_DS_AREA, (unsigned long)context->ds);
 
-		spin_unlock_irqrestore(&ds_lock, irq);
-	} else {
-		spin_lock_irqsave(&ds_lock, irq);
+		*p_context = context;
+	}
 
-		context = *p_context;
-		if (context)
-			context->count++;
+	context->count++;
 
-		spin_unlock_irqrestore(&ds_lock, irq);
+	spin_unlock_irqrestore(&ds_lock, irq);
 
-		if (!context)
-			context = ds_get_context(task);
-	}
+	if (context != new_context)
+		kfree(new_context);
 
 	return context;
 }
-- 
cgit v1.2.2


From d072c25f531c6513994960401d2c7f059434c0d2 Mon Sep 17 00:00:00 2001
From: Markus Metzger <markus.t.metzger@intel.com>
Date: Tue, 16 Dec 2008 15:53:11 +0100
Subject: x86, bts: correctly report invalid bts records

Impact: change the reporting of empty BTS records

Correctly report a cleared BTS record as invalid. Used to be reported
as branch from 0 to 0.

Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/ds.c | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'arch/x86')

diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c
index 0dc795951d73..98d271e60e08 100644
--- a/arch/x86/kernel/ds.c
+++ b/arch/x86/kernel/ds.c
@@ -484,6 +484,9 @@ static int bts_read(struct bts_tracer *tracer, const void *at,
 		out->qualifier = bts_branch;
 		out->variant.lbr.from = bts_get(at, bts_from);
 		out->variant.lbr.to   = bts_get(at, bts_to);
+
+		if (!out->variant.lbr.from && !out->variant.lbr.to)
+			out->qualifier = bts_invalid;
 	}
 
 	return ds_cfg.sizeof_rec[ds_bts];
-- 
cgit v1.2.2