2012-11-28 02:33:25 +08:00
|
|
|
#include <linux/context_tracking.h>
|
2012-12-17 03:00:34 +08:00
|
|
|
#include <linux/kvm_host.h>
|
2012-11-28 02:33:25 +08:00
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/hardirq.h>
|
2012-12-17 03:00:34 +08:00
|
|
|
#include <linux/export.h>
|
2012-11-28 02:33:25 +08:00
|
|
|
|
2013-01-08 01:12:14 +08:00
|
|
|
DEFINE_PER_CPU(struct context_tracking, context_tracking) = {
|
2012-11-28 02:33:25 +08:00
|
|
|
#ifdef CONFIG_CONTEXT_TRACKING_FORCE
|
|
|
|
.active = true,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
void user_enter(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some contexts may involve an exception occuring in an irq,
|
|
|
|
* leading to that nesting:
|
|
|
|
* rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit()
|
|
|
|
* This would mess up the dyntick_nesting count though. And rcu_irq_*()
|
|
|
|
* helpers are enough to protect RCU uses inside the exception. So
|
|
|
|
* just return immediately if we detect we are in an IRQ.
|
|
|
|
*/
|
|
|
|
if (in_interrupt())
|
|
|
|
return;
|
|
|
|
|
|
|
|
WARN_ON_ONCE(!current->mm);
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
if (__this_cpu_read(context_tracking.active) &&
|
|
|
|
__this_cpu_read(context_tracking.state) != IN_USER) {
|
2012-07-25 13:56:04 +08:00
|
|
|
vtime_user_enter(current);
|
2012-11-28 02:33:25 +08:00
|
|
|
rcu_user_enter();
|
2012-07-25 13:56:04 +08:00
|
|
|
__this_cpu_write(context_tracking.state, IN_USER);
|
2012-11-28 02:33:25 +08:00
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void user_exit(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some contexts may involve an exception occuring in an irq,
|
|
|
|
* leading to that nesting:
|
|
|
|
* rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit()
|
|
|
|
* This would mess up the dyntick_nesting count though. And rcu_irq_*()
|
|
|
|
* helpers are enough to protect RCU uses inside the exception. So
|
|
|
|
* just return immediately if we detect we are in an IRQ.
|
|
|
|
*/
|
|
|
|
if (in_interrupt())
|
|
|
|
return;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
if (__this_cpu_read(context_tracking.state) == IN_USER) {
|
|
|
|
rcu_user_exit();
|
2012-07-25 13:56:04 +08:00
|
|
|
vtime_user_exit(current);
|
|
|
|
__this_cpu_write(context_tracking.state, IN_KERNEL);
|
2012-11-28 02:33:25 +08:00
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2012-12-17 03:00:34 +08:00
|
|
|
void guest_enter(void)
|
|
|
|
{
|
|
|
|
if (vtime_accounting_enabled())
|
|
|
|
vtime_guest_enter(current);
|
|
|
|
else
|
|
|
|
__guest_enter();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(guest_enter);
|
|
|
|
|
|
|
|
void guest_exit(void)
|
|
|
|
{
|
|
|
|
if (vtime_accounting_enabled())
|
|
|
|
vtime_guest_exit(current);
|
|
|
|
else
|
|
|
|
__guest_exit();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(guest_exit);
|
|
|
|
|
2012-11-28 02:33:25 +08:00
|
|
|
void context_tracking_task_switch(struct task_struct *prev,
|
|
|
|
struct task_struct *next)
|
|
|
|
{
|
|
|
|
if (__this_cpu_read(context_tracking.active)) {
|
|
|
|
clear_tsk_thread_flag(prev, TIF_NOHZ);
|
|
|
|
set_tsk_thread_flag(next, TIF_NOHZ);
|
|
|
|
}
|
|
|
|
}
|