Commit 38130ec0 authored by Ingo Molnar's avatar Ingo Molnar

Merge tag 'sched-cputime-for-mingo' of...

Merge tag 'sched-cputime-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks into sched/core

Pull more cputime cleanups from Frederic Weisbecker:

 * Get rid of underscores polluting the vtime namespace

 * Consolidate context switch and tick handling

 * Improve debuggability by detecting irq unsafe callers
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents e783377e 1b2852b1
...@@ -103,5 +103,7 @@ static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val) ...@@ -103,5 +103,7 @@ static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val)
#define cputime64_to_clock_t(__ct) \ #define cputime64_to_clock_t(__ct) \
cputime_to_clock_t((__force cputime_t)__ct) cputime_to_clock_t((__force cputime_t)__ct)
extern void arch_vtime_task_switch(struct task_struct *tsk);
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ #endif /* CONFIG_VIRT_CPU_ACCOUNTING */
#endif /* __IA64_CPUTIME_H */ #endif /* __IA64_CPUTIME_H */
...@@ -83,7 +83,7 @@ static struct clocksource *itc_clocksource; ...@@ -83,7 +83,7 @@ static struct clocksource *itc_clocksource;
extern cputime_t cycle_to_cputime(u64 cyc); extern cputime_t cycle_to_cputime(u64 cyc);
static void vtime_account_user(struct task_struct *tsk) void vtime_account_user(struct task_struct *tsk)
{ {
cputime_t delta_utime; cputime_t delta_utime;
struct thread_info *ti = task_thread_info(tsk); struct thread_info *ti = task_thread_info(tsk);
...@@ -100,18 +100,11 @@ static void vtime_account_user(struct task_struct *tsk) ...@@ -100,18 +100,11 @@ static void vtime_account_user(struct task_struct *tsk)
* accumulated times to the current process, and to prepare accounting on * accumulated times to the current process, and to prepare accounting on
* the next process. * the next process.
*/ */
void vtime_task_switch(struct task_struct *prev) void arch_vtime_task_switch(struct task_struct *prev)
{ {
struct thread_info *pi = task_thread_info(prev); struct thread_info *pi = task_thread_info(prev);
struct thread_info *ni = task_thread_info(current); struct thread_info *ni = task_thread_info(current);
if (idle_task(smp_processor_id()) != prev)
__vtime_account_system(prev);
else
__vtime_account_idle(prev);
vtime_account_user(prev);
pi->ac_stamp = ni->ac_stamp; pi->ac_stamp = ni->ac_stamp;
ni->ac_stime = ni->ac_utime = 0; ni->ac_stime = ni->ac_utime = 0;
} }
...@@ -126,6 +119,8 @@ static cputime_t vtime_delta(struct task_struct *tsk) ...@@ -126,6 +119,8 @@ static cputime_t vtime_delta(struct task_struct *tsk)
cputime_t delta_stime; cputime_t delta_stime;
__u64 now; __u64 now;
WARN_ON_ONCE(!irqs_disabled());
now = ia64_get_itc(); now = ia64_get_itc();
delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp)); delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp));
...@@ -135,27 +130,18 @@ static cputime_t vtime_delta(struct task_struct *tsk) ...@@ -135,27 +130,18 @@ static cputime_t vtime_delta(struct task_struct *tsk)
return delta_stime; return delta_stime;
} }
void __vtime_account_system(struct task_struct *tsk) void vtime_account_system(struct task_struct *tsk)
{ {
cputime_t delta = vtime_delta(tsk); cputime_t delta = vtime_delta(tsk);
account_system_time(tsk, 0, delta, delta); account_system_time(tsk, 0, delta, delta);
} }
void __vtime_account_idle(struct task_struct *tsk) void vtime_account_idle(struct task_struct *tsk)
{ {
account_idle_time(vtime_delta(tsk)); account_idle_time(vtime_delta(tsk));
} }
/*
* Called from the timer interrupt handler to charge accumulated user time
* to the current process. Must be called with interrupts disabled.
*/
void account_process_tick(struct task_struct *p, int user_tick)
{
vtime_account_user(p);
}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ #endif /* CONFIG_VIRT_CPU_ACCOUNTING */
static irqreturn_t static irqreturn_t
......
...@@ -228,6 +228,8 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk) ...@@ -228,6 +228,8 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk)
#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct)) #define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ #endif /* CONFIG_VIRT_CPU_ACCOUNTING */
#endif /* __POWERPC_CPUTIME_H */ #endif /* __POWERPC_CPUTIME_H */
...@@ -297,6 +297,8 @@ static u64 vtime_delta(struct task_struct *tsk, ...@@ -297,6 +297,8 @@ static u64 vtime_delta(struct task_struct *tsk,
u64 now, nowscaled, deltascaled; u64 now, nowscaled, deltascaled;
u64 udelta, delta, user_scaled; u64 udelta, delta, user_scaled;
WARN_ON_ONCE(!irqs_disabled());
now = mftb(); now = mftb();
nowscaled = read_spurr(now); nowscaled = read_spurr(now);
get_paca()->system_time += now - get_paca()->starttime; get_paca()->system_time += now - get_paca()->starttime;
...@@ -336,7 +338,7 @@ static u64 vtime_delta(struct task_struct *tsk, ...@@ -336,7 +338,7 @@ static u64 vtime_delta(struct task_struct *tsk,
return delta; return delta;
} }
void __vtime_account_system(struct task_struct *tsk) void vtime_account_system(struct task_struct *tsk)
{ {
u64 delta, sys_scaled, stolen; u64 delta, sys_scaled, stolen;
...@@ -346,7 +348,7 @@ void __vtime_account_system(struct task_struct *tsk) ...@@ -346,7 +348,7 @@ void __vtime_account_system(struct task_struct *tsk)
account_steal_time(stolen); account_steal_time(stolen);
} }
void __vtime_account_idle(struct task_struct *tsk) void vtime_account_idle(struct task_struct *tsk)
{ {
u64 delta, sys_scaled, stolen; u64 delta, sys_scaled, stolen;
...@@ -355,15 +357,15 @@ void __vtime_account_idle(struct task_struct *tsk) ...@@ -355,15 +357,15 @@ void __vtime_account_idle(struct task_struct *tsk)
} }
/* /*
* Transfer the user and system times accumulated in the paca * Transfer the user time accumulated in the paca
* by the exception entry and exit code to the generic process * by the exception entry and exit code to the generic
* user and system time records. * process user time records.
* Must be called with interrupts disabled. * Must be called with interrupts disabled.
* Assumes that vtime_account() has been called recently * Assumes that vtime_account_system/idle() has been called
* (i.e. since the last entry from usermode) so that * recently (i.e. since the last entry from usermode) so that
* get_paca()->user_time_scaled is up to date. * get_paca()->user_time_scaled is up to date.
*/ */
void account_process_tick(struct task_struct *tsk, int user_tick) void vtime_account_user(struct task_struct *tsk)
{ {
cputime_t utime, utimescaled; cputime_t utime, utimescaled;
...@@ -375,12 +377,6 @@ void account_process_tick(struct task_struct *tsk, int user_tick) ...@@ -375,12 +377,6 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
account_user_time(tsk, utime, utimescaled); account_user_time(tsk, utime, utimescaled);
} }
void vtime_task_switch(struct task_struct *prev)
{
vtime_account(prev);
account_process_tick(prev, 0);
}
#else /* ! CONFIG_VIRT_CPU_ACCOUNTING */ #else /* ! CONFIG_VIRT_CPU_ACCOUNTING */
#define calc_cputime_factors() #define calc_cputime_factors()
#endif #endif
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#define __ARCH_HAS_VTIME_ACCOUNT #define __ARCH_HAS_VTIME_ACCOUNT
#define __ARCH_HAS_VTIME_TASK_SWITCH
/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */ /* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
......
...@@ -112,7 +112,12 @@ void vtime_task_switch(struct task_struct *prev) ...@@ -112,7 +112,12 @@ void vtime_task_switch(struct task_struct *prev)
S390_lowcore.system_timer = ti->system_timer; S390_lowcore.system_timer = ti->system_timer;
} }
void account_process_tick(struct task_struct *tsk, int user_tick) /*
* In s390, accounting pending user time also implies
* accounting system time in order to correctly compute
* the stolen time accounting.
*/
void vtime_account_user(struct task_struct *tsk)
{ {
if (do_account_vtime(tsk, HARDIRQ_OFFSET)) if (do_account_vtime(tsk, HARDIRQ_OFFSET))
virt_timer_expire(); virt_timer_expire();
...@@ -127,6 +132,8 @@ void vtime_account(struct task_struct *tsk) ...@@ -127,6 +132,8 @@ void vtime_account(struct task_struct *tsk)
struct thread_info *ti = task_thread_info(tsk); struct thread_info *ti = task_thread_info(tsk);
u64 timer, system; u64 timer, system;
WARN_ON_ONCE(!irqs_disabled());
timer = S390_lowcore.last_update_timer; timer = S390_lowcore.last_update_timer;
S390_lowcore.last_update_timer = get_vtimer(); S390_lowcore.last_update_timer = get_vtimer();
S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer; S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
...@@ -140,9 +147,9 @@ void vtime_account(struct task_struct *tsk) ...@@ -140,9 +147,9 @@ void vtime_account(struct task_struct *tsk)
} }
EXPORT_SYMBOL_GPL(vtime_account); EXPORT_SYMBOL_GPL(vtime_account);
void __vtime_account_system(struct task_struct *tsk) void vtime_account_system(struct task_struct *tsk)
__attribute__((alias("vtime_account"))); __attribute__((alias("vtime_account")));
EXPORT_SYMBOL_GPL(__vtime_account_system); EXPORT_SYMBOL_GPL(vtime_account_system);
void __kprobes vtime_stop_cpu(void) void __kprobes vtime_stop_cpu(void)
{ {
......
...@@ -127,7 +127,15 @@ extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t) ...@@ -127,7 +127,15 @@ extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t)
extern void account_steal_time(cputime_t); extern void account_steal_time(cputime_t);
extern void account_idle_time(cputime_t); extern void account_idle_time(cputime_t);
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
static inline void account_process_tick(struct task_struct *tsk, int user)
{
vtime_account_user(tsk);
}
#else
extern void account_process_tick(struct task_struct *, int user); extern void account_process_tick(struct task_struct *, int user);
#endif
extern void account_steal_ticks(unsigned long ticks); extern void account_steal_ticks(unsigned long ticks);
extern void account_idle_ticks(unsigned long ticks); extern void account_idle_ticks(unsigned long ticks);
......
...@@ -730,7 +730,7 @@ static inline void kvm_guest_enter(void) ...@@ -730,7 +730,7 @@ static inline void kvm_guest_enter(void)
* This is running in ioctl context so we can avoid * This is running in ioctl context so we can avoid
* the call to vtime_account() with its unnecessary idle check. * the call to vtime_account() with its unnecessary idle check.
*/ */
vtime_account_system(current); vtime_account_system_irqsafe(current);
current->flags |= PF_VCPU; current->flags |= PF_VCPU;
/* KVM does not hold any references to rcu protected data when it /* KVM does not hold any references to rcu protected data when it
* switches CPU into a guest mode. In fact switching to a guest mode * switches CPU into a guest mode. In fact switching to a guest mode
...@@ -748,7 +748,7 @@ static inline void kvm_guest_exit(void) ...@@ -748,7 +748,7 @@ static inline void kvm_guest_exit(void)
* This is running in ioctl context so we can avoid * This is running in ioctl context so we can avoid
* the call to vtime_account() with its unnecessary idle check. * the call to vtime_account() with its unnecessary idle check.
*/ */
vtime_account_system(current); vtime_account_system_irqsafe(current);
current->flags &= ~PF_VCPU; current->flags &= ~PF_VCPU;
} }
......
...@@ -5,14 +5,15 @@ struct task_struct; ...@@ -5,14 +5,15 @@ struct task_struct;
#ifdef CONFIG_VIRT_CPU_ACCOUNTING #ifdef CONFIG_VIRT_CPU_ACCOUNTING
extern void vtime_task_switch(struct task_struct *prev); extern void vtime_task_switch(struct task_struct *prev);
extern void __vtime_account_system(struct task_struct *tsk);
extern void vtime_account_system(struct task_struct *tsk); extern void vtime_account_system(struct task_struct *tsk);
extern void __vtime_account_idle(struct task_struct *tsk); extern void vtime_account_system_irqsafe(struct task_struct *tsk);
extern void vtime_account_idle(struct task_struct *tsk);
extern void vtime_account_user(struct task_struct *tsk);
extern void vtime_account(struct task_struct *tsk); extern void vtime_account(struct task_struct *tsk);
#else #else
static inline void vtime_task_switch(struct task_struct *prev) { } static inline void vtime_task_switch(struct task_struct *prev) { }
static inline void __vtime_account_system(struct task_struct *tsk) { }
static inline void vtime_account_system(struct task_struct *tsk) { } static inline void vtime_account_system(struct task_struct *tsk) { }
static inline void vtime_account_system_irqsafe(struct task_struct *tsk) { }
static inline void vtime_account(struct task_struct *tsk) { } static inline void vtime_account(struct task_struct *tsk) { }
#endif #endif
...@@ -40,7 +41,7 @@ static inline void vtime_account_irq_enter(struct task_struct *tsk) ...@@ -40,7 +41,7 @@ static inline void vtime_account_irq_enter(struct task_struct *tsk)
static inline void vtime_account_irq_exit(struct task_struct *tsk) static inline void vtime_account_irq_exit(struct task_struct *tsk)
{ {
/* On hard|softirq exit we always account to hard|softirq cputime */ /* On hard|softirq exit we always account to hard|softirq cputime */
__vtime_account_system(tsk); vtime_account_system(tsk);
irqtime_account_irq(tsk); irqtime_account_irq(tsk);
} }
......
...@@ -461,20 +461,33 @@ void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime ...@@ -461,20 +461,33 @@ void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime
*st = cputime.stime; *st = cputime.stime;
} }
void vtime_account_system(struct task_struct *tsk) void vtime_account_system_irqsafe(struct task_struct *tsk)
{ {
unsigned long flags; unsigned long flags;
local_irq_save(flags); local_irq_save(flags);
__vtime_account_system(tsk); vtime_account_system(tsk);
local_irq_restore(flags); local_irq_restore(flags);
} }
EXPORT_SYMBOL_GPL(vtime_account_system); EXPORT_SYMBOL_GPL(vtime_account_system_irqsafe);
#ifndef __ARCH_HAS_VTIME_TASK_SWITCH
void vtime_task_switch(struct task_struct *prev)
{
if (is_idle_task(prev))
vtime_account_idle(prev);
else
vtime_account_system(prev);
vtime_account_user(prev);
arch_vtime_task_switch(prev);
}
#endif
/* /*
* Archs that account the whole time spent in the idle task * Archs that account the whole time spent in the idle task
* (outside irq) as idle time can rely on this and just implement * (outside irq) as idle time can rely on this and just implement
* __vtime_account_system() and __vtime_account_idle(). Archs that * vtime_account_system() and vtime_account_idle(). Archs that
* have other meaning of the idle time (s390 only includes the * have other meaning of the idle time (s390 only includes the
* time spent by the CPU when it's in low power mode) must override * time spent by the CPU when it's in low power mode) must override
* vtime_account(). * vtime_account().
...@@ -482,16 +495,10 @@ EXPORT_SYMBOL_GPL(vtime_account_system); ...@@ -482,16 +495,10 @@ EXPORT_SYMBOL_GPL(vtime_account_system);
#ifndef __ARCH_HAS_VTIME_ACCOUNT #ifndef __ARCH_HAS_VTIME_ACCOUNT
void vtime_account(struct task_struct *tsk) void vtime_account(struct task_struct *tsk)
{ {
unsigned long flags;
local_irq_save(flags);
if (in_interrupt() || !is_idle_task(tsk)) if (in_interrupt() || !is_idle_task(tsk))
__vtime_account_system(tsk); vtime_account_system(tsk);
else else
__vtime_account_idle(tsk); vtime_account_idle(tsk);
local_irq_restore(flags);
} }
EXPORT_SYMBOL_GPL(vtime_account); EXPORT_SYMBOL_GPL(vtime_account);
#endif /* __ARCH_HAS_VTIME_ACCOUNT */ #endif /* __ARCH_HAS_VTIME_ACCOUNT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment