mirror of
https://github.com/torvalds/linux.git
synced 2024-12-19 17:41:29 +00:00
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>
This commit is contained in:
parent
9dfc3bc7d2
commit
cc1dc6d039
@ -232,54 +232,46 @@ static DEFINE_PER_CPU(struct ds_context *, system_context_array);
|
|||||||
|
|
||||||
#define system_context per_cpu(system_context_array, smp_processor_id())
|
#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 =
|
struct ds_context **p_context =
|
||||||
(task ? &task->thread.ds_ctx : &system_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;
|
unsigned long irq;
|
||||||
|
|
||||||
|
/* Chances are small that we already have a context. */
|
||||||
|
new_context = kzalloc(sizeof(*new_context), GFP_KERNEL);
|
||||||
|
if (!new_context)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&ds_lock, irq);
|
||||||
|
|
||||||
|
context = *p_context;
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = kzalloc(sizeof(*context), GFP_KERNEL);
|
context = new_context;
|
||||||
if (!context)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&ds_lock, irq);
|
context->this = p_context;
|
||||||
|
context->task = task;
|
||||||
|
context->count = 0;
|
||||||
|
|
||||||
if (*p_context) {
|
if (task)
|
||||||
kfree(context);
|
set_tsk_thread_flag(task, TIF_DS_AREA_MSR);
|
||||||
|
|
||||||
context = *p_context;
|
if (!task || (task == current))
|
||||||
} else {
|
wrmsrl(MSR_IA32_DS_AREA, (unsigned long)context->ds);
|
||||||
*p_context = context;
|
|
||||||
|
|
||||||
context->this = p_context;
|
*p_context = context;
|
||||||
context->task = task;
|
|
||||||
|
|
||||||
if (task)
|
|
||||||
set_tsk_thread_flag(task, TIF_DS_AREA_MSR);
|
|
||||||
|
|
||||||
if (!task || (task == current))
|
|
||||||
wrmsrl(MSR_IA32_DS_AREA,
|
|
||||||
(unsigned long)context->ds);
|
|
||||||
}
|
|
||||||
|
|
||||||
context->count++;
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&ds_lock, irq);
|
|
||||||
} else {
|
|
||||||
spin_lock_irqsave(&ds_lock, irq);
|
|
||||||
|
|
||||||
context = *p_context;
|
|
||||||
if (context)
|
|
||||||
context->count++;
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&ds_lock, irq);
|
|
||||||
|
|
||||||
if (!context)
|
|
||||||
context = ds_get_context(task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context->count++;
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&ds_lock, irq);
|
||||||
|
|
||||||
|
if (context != new_context)
|
||||||
|
kfree(new_context);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user