Skip to content

Commit

Permalink
Merge branch 'cputime' of git://git390.osdl.marist.edu/pub/scm/linux-2.6
Browse files Browse the repository at this point in the history
* 'cputime' of git://git390.osdl.marist.edu/pub/scm/linux-2.6:
  [PATCH] fast vdso implementation for CLOCK_THREAD_CPUTIME_ID
  [PATCH] improve idle cputime accounting
  [PATCH] improve precision of idle time detection.
  [PATCH] improve precision of process accounting.
  [PATCH] idle cputime accounting
  [PATCH] fix scaled & unscaled cputime accounting
  • Loading branch information
Linus Torvalds committed Jan 3, 2009
2 parents d97106a + c742b31 commit 61420f5
Show file tree
Hide file tree
Showing 30 changed files with 683 additions and 456 deletions.
18 changes: 10 additions & 8 deletions arch/ia64/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ void ia64_account_on_switch(struct task_struct *prev, struct task_struct *next)
now = ia64_get_itc();

delta_stime = cycle_to_cputime(pi->ac_stime + (now - pi->ac_stamp));
account_system_time(prev, 0, delta_stime);
account_system_time_scaled(prev, delta_stime);
if (idle_task(smp_processor_id()) != prev)
account_system_time(prev, 0, delta_stime, delta_stime);
else
account_idle_time(delta_stime);

if (pi->ac_utime) {
delta_utime = cycle_to_cputime(pi->ac_utime);
account_user_time(prev, delta_utime);
account_user_time_scaled(prev, delta_utime);
account_user_time(prev, delta_utime, delta_utime);
}

pi->ac_stamp = ni->ac_stamp = now;
Expand All @@ -122,8 +123,10 @@ void account_system_vtime(struct task_struct *tsk)
now = ia64_get_itc();

delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp));
account_system_time(tsk, 0, delta_stime);
account_system_time_scaled(tsk, delta_stime);
if (irq_count() || idle_task(smp_processor_id()) != tsk)
account_system_time(tsk, 0, delta_stime, delta_stime);
else
account_idle_time(delta_stime);
ti->ac_stime = 0;

ti->ac_stamp = now;
Expand All @@ -143,8 +146,7 @@ void account_process_tick(struct task_struct *p, int user_tick)

if (ti->ac_utime) {
delta_utime = cycle_to_cputime(ti->ac_utime);
account_user_time(p, delta_utime);
account_user_time_scaled(p, delta_utime);
account_user_time(p, delta_utime, delta_utime);
ti->ac_utime = 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/mqueue.h>
#include <linux/hardirq.h>
#include <linux/utsname.h>
#include <linux/kernel_stat.h>

#include <asm/pgtable.h>
#include <asm/uaccess.h>
Expand Down
18 changes: 11 additions & 7 deletions arch/powerpc/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ void account_system_vtime(struct task_struct *tsk)
delta += sys_time;
get_paca()->system_time = 0;
}
account_system_time(tsk, 0, delta);
account_system_time_scaled(tsk, deltascaled);
if (in_irq() || idle_task(smp_processor_id()) != tsk)
account_system_time(tsk, 0, delta, deltascaled);
else
account_idle_time(delta);
per_cpu(cputime_last_delta, smp_processor_id()) = delta;
per_cpu(cputime_scaled_last_delta, smp_processor_id()) = deltascaled;
local_irq_restore(flags);
Expand All @@ -275,10 +277,8 @@ void account_process_tick(struct task_struct *tsk, int user_tick)

utime = get_paca()->user_time;
get_paca()->user_time = 0;
account_user_time(tsk, utime);

utimescaled = cputime_to_scaled(utime);
account_user_time_scaled(tsk, utimescaled);
account_user_time(tsk, utime, utimescaled);
}

/*
Expand Down Expand Up @@ -338,8 +338,12 @@ void calculate_steal_time(void)
tb = mftb();
purr = mfspr(SPRN_PURR);
stolen = (tb - pme->tb) - (purr - pme->purr);
if (stolen > 0)
account_steal_time(current, stolen);
if (stolen > 0) {
if (idle_task(smp_processor_id()) != current)
account_steal_time(stolen);
else
account_idle_time(stolen);
}
pme->tb = tb;
pme->purr = purr;
}
Expand Down
7 changes: 3 additions & 4 deletions arch/s390/include/asm/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@

struct s390_idle_data {
spinlock_t lock;
unsigned int in_idle;
unsigned long long idle_count;
unsigned long long idle_enter;
unsigned long long idle_time;
};

DECLARE_PER_CPU(struct s390_idle_data, s390_idle);

void s390_idle_leave(void);
void vtime_start_cpu(void);

static inline void s390_idle_check(void)
{
if ((&__get_cpu_var(s390_idle))->in_idle)
s390_idle_leave();
if ((&__get_cpu_var(s390_idle))->idle_enter != 0ULL)
vtime_start_cpu();
}

#endif /* _ASM_S390_CPU_H_ */
42 changes: 21 additions & 21 deletions arch/s390/include/asm/cputime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <asm/div64.h>

/* We want to use micro-second resolution. */
/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */

typedef unsigned long long cputime_t;
typedef unsigned long long cputime64_t;
Expand Down Expand Up @@ -53,9 +53,9 @@ __div(unsigned long long n, unsigned int base)
#define cputime_ge(__a, __b) ((__a) >= (__b))
#define cputime_lt(__a, __b) ((__a) < (__b))
#define cputime_le(__a, __b) ((__a) <= (__b))
#define cputime_to_jiffies(__ct) (__div((__ct), 1000000 / HZ))
#define cputime_to_jiffies(__ct) (__div((__ct), 4096000000ULL / HZ))
#define cputime_to_scaled(__ct) (__ct)
#define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (1000000 / HZ))
#define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (4096000000ULL / HZ))

#define cputime64_zero (0ULL)
#define cputime64_add(__a, __b) ((__a) + (__b))
Expand All @@ -64,7 +64,7 @@ __div(unsigned long long n, unsigned int base)
static inline u64
cputime64_to_jiffies64(cputime64_t cputime)
{
do_div(cputime, 1000000 / HZ);
do_div(cputime, 4096000000ULL / HZ);
return cputime;
}

Expand All @@ -74,13 +74,13 @@ cputime64_to_jiffies64(cputime64_t cputime)
static inline unsigned int
cputime_to_msecs(const cputime_t cputime)
{
return __div(cputime, 1000);
return __div(cputime, 4096000);
}

static inline cputime_t
msecs_to_cputime(const unsigned int m)
{
return (cputime_t) m * 1000;
return (cputime_t) m * 4096000;
}

/*
Expand All @@ -89,13 +89,13 @@ msecs_to_cputime(const unsigned int m)
static inline unsigned int
cputime_to_secs(const cputime_t cputime)
{
return __div(cputime, 1000000);
return __div(cputime, 2048000000) >> 1;
}

static inline cputime_t
secs_to_cputime(const unsigned int s)
{
return (cputime_t) s * 1000000;
return (cputime_t) s * 4096000000ULL;
}

/*
Expand All @@ -104,7 +104,7 @@ secs_to_cputime(const unsigned int s)
static inline cputime_t
timespec_to_cputime(const struct timespec *value)
{
return value->tv_nsec / 1000 + (u64) value->tv_sec * 1000000;
return value->tv_nsec * 4096 / 1000 + (u64) value->tv_sec * 4096000000ULL;
}

static inline void
Expand All @@ -114,12 +114,12 @@ cputime_to_timespec(const cputime_t cputime, struct timespec *value)
register_pair rp;

rp.pair = cputime >> 1;
asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
value->tv_nsec = rp.subreg.even * 1000;
asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
value->tv_nsec = rp.subreg.even * 1000 / 4096;
value->tv_sec = rp.subreg.odd;
#else
value->tv_nsec = (cputime % 1000000) * 1000;
value->tv_sec = cputime / 1000000;
value->tv_nsec = (cputime % 4096000000ULL) * 1000 / 4096;
value->tv_sec = cputime / 4096000000ULL;
#endif
}

Expand All @@ -131,7 +131,7 @@ cputime_to_timespec(const cputime_t cputime, struct timespec *value)
static inline cputime_t
timeval_to_cputime(const struct timeval *value)
{
return value->tv_usec + (u64) value->tv_sec * 1000000;
return value->tv_usec * 4096 + (u64) value->tv_sec * 4096000000ULL;
}

static inline void
Expand All @@ -141,12 +141,12 @@ cputime_to_timeval(const cputime_t cputime, struct timeval *value)
register_pair rp;

rp.pair = cputime >> 1;
asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
value->tv_usec = rp.subreg.even;
asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
value->tv_usec = rp.subreg.even / 4096;
value->tv_sec = rp.subreg.odd;
#else
value->tv_usec = cputime % 1000000;
value->tv_sec = cputime / 1000000;
value->tv_usec = cputime % 4096000000ULL;
value->tv_sec = cputime / 4096000000ULL;
#endif
}

Expand All @@ -156,13 +156,13 @@ cputime_to_timeval(const cputime_t cputime, struct timeval *value)
static inline clock_t
cputime_to_clock_t(cputime_t cputime)
{
return __div(cputime, 1000000 / USER_HZ);
return __div(cputime, 4096000000ULL / USER_HZ);
}

static inline cputime_t
clock_t_to_cputime(unsigned long x)
{
return (cputime_t) x * (1000000 / USER_HZ);
return (cputime_t) x * (4096000000ULL / USER_HZ);
}

/*
Expand All @@ -171,7 +171,7 @@ clock_t_to_cputime(unsigned long x)
static inline clock_t
cputime64_to_clock_t(cputime64_t cputime)
{
return __div(cputime, 1000000 / USER_HZ);
return __div(cputime, 4096000000ULL / USER_HZ);
}

#endif /* _S390_CPUTIME_H */
49 changes: 28 additions & 21 deletions arch/s390/include/asm/lowcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
#define __LC_SYNC_ENTER_TIMER 0x248
#define __LC_ASYNC_ENTER_TIMER 0x250
#define __LC_EXIT_TIMER 0x258
#define __LC_LAST_UPDATE_TIMER 0x260
#define __LC_USER_TIMER 0x268
#define __LC_SYSTEM_TIMER 0x270
#define __LC_LAST_UPDATE_CLOCK 0x278
#define __LC_STEAL_CLOCK 0x280
#define __LC_USER_TIMER 0x260
#define __LC_SYSTEM_TIMER 0x268
#define __LC_STEAL_TIMER 0x270
#define __LC_LAST_UPDATE_TIMER 0x278
#define __LC_LAST_UPDATE_CLOCK 0x280
#define __LC_RETURN_MCCK_PSW 0x288
#define __LC_KERNEL_STACK 0xC40
#define __LC_THREAD_INFO 0xC44
Expand All @@ -89,11 +89,11 @@
#define __LC_SYNC_ENTER_TIMER 0x250
#define __LC_ASYNC_ENTER_TIMER 0x258
#define __LC_EXIT_TIMER 0x260
#define __LC_LAST_UPDATE_TIMER 0x268
#define __LC_USER_TIMER 0x270
#define __LC_SYSTEM_TIMER 0x278
#define __LC_LAST_UPDATE_CLOCK 0x280
#define __LC_STEAL_CLOCK 0x288
#define __LC_USER_TIMER 0x268
#define __LC_SYSTEM_TIMER 0x270
#define __LC_STEAL_TIMER 0x278
#define __LC_LAST_UPDATE_TIMER 0x280
#define __LC_LAST_UPDATE_CLOCK 0x288
#define __LC_RETURN_MCCK_PSW 0x290
#define __LC_KERNEL_STACK 0xD40
#define __LC_THREAD_INFO 0xD48
Expand All @@ -106,8 +106,10 @@
#define __LC_IPLDEV 0xDB8
#define __LC_CURRENT 0xDD8
#define __LC_INT_CLOCK 0xDE8
#define __LC_VDSO_PER_CPU 0xE38
#endif /* __s390x__ */

#define __LC_PASTE 0xE40

#define __LC_PANIC_MAGIC 0xE00
#ifndef __s390x__
Expand Down Expand Up @@ -252,11 +254,11 @@ struct _lowcore
__u64 sync_enter_timer; /* 0x248 */
__u64 async_enter_timer; /* 0x250 */
__u64 exit_timer; /* 0x258 */
__u64 last_update_timer; /* 0x260 */
__u64 user_timer; /* 0x268 */
__u64 system_timer; /* 0x270 */
__u64 last_update_clock; /* 0x278 */
__u64 steal_clock; /* 0x280 */
__u64 user_timer; /* 0x260 */
__u64 system_timer; /* 0x268 */
__u64 steal_timer; /* 0x270 */
__u64 last_update_timer; /* 0x278 */
__u64 last_update_clock; /* 0x280 */
psw_t return_mcck_psw; /* 0x288 */
__u8 pad8[0xc00-0x290]; /* 0x290 */

Expand Down Expand Up @@ -343,11 +345,11 @@ struct _lowcore
__u64 sync_enter_timer; /* 0x250 */
__u64 async_enter_timer; /* 0x258 */
__u64 exit_timer; /* 0x260 */
__u64 last_update_timer; /* 0x268 */
__u64 user_timer; /* 0x270 */
__u64 system_timer; /* 0x278 */
__u64 last_update_clock; /* 0x280 */
__u64 steal_clock; /* 0x288 */
__u64 user_timer; /* 0x268 */
__u64 system_timer; /* 0x270 */
__u64 steal_timer; /* 0x278 */
__u64 last_update_timer; /* 0x280 */
__u64 last_update_clock; /* 0x288 */
psw_t return_mcck_psw; /* 0x290 */
__u8 pad8[0xc00-0x2a0]; /* 0x2a0 */
/* System info area */
Expand Down Expand Up @@ -381,7 +383,12 @@ struct _lowcore
/* whether the kernel died with panic() or not */
__u32 panic_magic; /* 0xe00 */

__u8 pad13[0x11b8-0xe04]; /* 0xe04 */
/* Per cpu primary space access list */
__u8 pad_0xe04[0xe3c-0xe04]; /* 0xe04 */
__u32 vdso_per_cpu_data; /* 0xe3c */
__u32 paste[16]; /* 0xe40 */

__u8 pad13[0x11b8-0xe80]; /* 0xe80 */

/* 64 bit extparam used for pfault, diag 250 etc */
__u64 ext_params2; /* 0x11B8 */
Expand Down
4 changes: 2 additions & 2 deletions arch/s390/include/asm/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static inline void restore_access_regs(unsigned int *acrs)
prev = __switch_to(prev,next); \
} while (0)

extern void account_vtime(struct task_struct *);
extern void account_vtime(struct task_struct *, struct task_struct *);
extern void account_tick_vtime(struct task_struct *);
extern void account_system_vtime(struct task_struct *);

Expand All @@ -121,7 +121,7 @@ static inline void cmma_init(void) { }

#define finish_arch_switch(prev) do { \
set_fs(current->thread.mm_segment); \
account_vtime(prev); \
account_vtime(prev, current); \
} while (0)

#define nop() asm volatile("nop")
Expand Down
2 changes: 2 additions & 0 deletions arch/s390/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct thread_info {
unsigned int cpu; /* current CPU */
int preempt_count; /* 0 => preemptable, <0 => BUG */
struct restart_block restart_block;
__u64 user_timer;
__u64 system_timer;
};

/*
Expand Down
Loading

0 comments on commit 61420f5

Please sign in to comment.