cputime: Convert core use of cputime_t to nsecs v3
Subsystems (33)
cover cputime: Convert core use of cputime_t to nsecs v3
Summary of this patchset in v1 (actually v2 as the v1 got posted 2 years ago): https://lkml.org/lkml/2016/11/17/583
Changes in this version:
* Rebase against latest cputime changes (vtime accumulation and accounting delayed on tick and context switch)
* Fix leaking cputime remainder on s390
* Fix build errors
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
cputime/nsecs-v3
HEAD: 358818bd88b82c22bf3d45f82ba30ced534e3cd2
Thanks,
Frederic
---
Frederic Weisbecker (37):
jiffies: Reuse TICK_NSEC instead of NSEC_PER_JIFFY
time: Introduce jiffies64_to_nsecs()
sched: Remove unused INIT_CPUTIME macro
cputime: Convert kcpustat to nsecs
macintosh/rack-meter: Remove cputime_t internal use
cputime: Convert guest time accounting to nsecs
cputime: Special API to return old-typed cputime
cputime: Convert task/group cputime to nsecs
alpha: Convert obsolete cputime_t to nsecs
x86: Convert obsolete cputime type to nsecs
isdn: Convert obsolete cputime type to nsecs
binfmt: Convert obsolete cputime type to nsecs
acct: Convert obsolete cputime type to nsecs
delaycct: Convert obsolete cputime type to nsecs
tsacct: Convert obsolete cputime type to nsecs
signal: Convert obsolete cputime type to nsecs
cputime: Increment kcpustat directly on irqtime account
posix-timers: Use TICK_NSEC instead of a dynamically ad-hoc calculated version
posix-timers: Convert internals to use nsecs
itimer: Convert internal cputime_t units to nsec
sched: Remove temporary cputime_t accessors
cputime: Push time to account_user_time() in nsecs
cputime: Push time to account_steal_time() in nsecs
cputime: Push time to account_idle_time() in nsecs
cputime: Push time to account_system_time() in nsecs
cputime: Complete nsec conversion of tick based accounting
vtime: Return nsecs instead of cputime_t to account
cputime: Remove jiffies based cputime
ia64: Move nsecs based cputime headers to the last arch using it
ia64: Convert vtime to use nsec units directly
ia64: Remove unused cputime definitions
s390: Make arch_cpu_idle_time() to return nsecs
powerpc: Remove unused cputime definitions
s390: Remove unused cputime definitions
cputime: Remove unused nsec_to_cputime
cputime: Remove asm generic headers
s390: Prevent from cputime leaks
arch/alpha/include/asm/Kbuild | 1 - arch/alpha/kernel/osf_sys.c | 10 +- arch/arc/include/asm/Kbuild | 1 - arch/arm/include/asm/Kbuild | 1 - arch/arm64/include/asm/Kbuild | 1 - arch/avr32/include/asm/Kbuild | 1 - arch/blackfin/include/asm/Kbuild | 1 - arch/c6x/include/asm/Kbuild | 1 - arch/cris/include/asm/Kbuild | 1 - arch/frv/include/asm/Kbuild | 1 - arch/h8300/include/asm/Kbuild | 1 - arch/hexagon/include/asm/Kbuild | 1 - arch/ia64/include/asm/cputime.h | 6 +- arch/ia64/kernel/head.S | 4 +- arch/ia64/kernel/time.c | 17 ++-- arch/m32r/include/asm/Kbuild | 1 - arch/m68k/include/asm/Kbuild | 1 - arch/metag/include/asm/Kbuild | 1 - arch/microblaze/include/asm/Kbuild | 1 - arch/mips/include/asm/Kbuild | 1 - arch/mips/kernel/binfmt_elfn32.c | 12 +-- arch/mips/kernel/binfmt_elfo32.c | 12 +-- arch/mn10300/include/asm/Kbuild | 1 - arch/nios2/include/asm/Kbuild | 1 - arch/openrisc/include/asm/Kbuild | 1 - arch/parisc/include/asm/Kbuild | 1 - arch/parisc/kernel/binfmt_elf32.c | 11 +-- arch/powerpc/include/asm/cputime.h | 177 +--------------------------------- arch/powerpc/kernel/time.c | 45 +++------ arch/s390/appldata/appldata_os.c | 16 +-- arch/s390/include/asm/cputime.h | 109 +-------------------- arch/s390/kernel/idle.c | 9 +- arch/s390/kernel/vtime.c | 31 +++--- arch/score/include/asm/Kbuild | 1 - arch/sh/include/asm/Kbuild | 1 - arch/sparc/include/asm/Kbuild | 1 - arch/tile/include/asm/Kbuild | 1 - arch/um/include/asm/Kbuild | 1 - arch/unicore32/include/asm/Kbuild | 1 - arch/x86/include/asm/Kbuild | 1 - arch/x86/kernel/apm_32.c | 6 +- arch/x86/kvm/hyperv.c | 5 +- arch/xtensa/include/asm/Kbuild | 1 - drivers/cpufreq/cpufreq.c | 6 +- drivers/cpufreq/cpufreq_governor.c | 2 +- drivers/cpufreq/cpufreq_stats.c | 1 - drivers/isdn/mISDN/stack.c | 4 +- drivers/macintosh/rack-meter.c | 28 +++--- fs/binfmt_elf.c | 15 +-- fs/binfmt_elf_fdpic.c | 14 +-- fs/compat_binfmt_elf.c | 18 +--- fs/proc/array.c | 16 +-- fs/proc/stat.c | 64 ++++++------ fs/proc/uptime.c | 7 +- include/asm-generic/cputime.h | 15 --- include/asm-generic/cputime_jiffies.h | 75 -------------- include/asm-generic/cputime_nsecs.h | 121 ----------------------- include/linux/compat.h | 20 +++- include/linux/cputime.h | 7 +- include/linux/jiffies.h | 2 + include/linux/kernel_stat.h | 13 ++- include/linux/posix-timers.h | 14 +-- include/linux/sched.h | 62 +++++------- include/trace/events/timer.h | 26 ++--- kernel/acct.c | 7 +- kernel/delayacct.c | 6 +- kernel/exit.c | 4 +- kernel/fork.c | 2 +- kernel/sched/cpuacct.c | 2 +- kernel/sched/cputime.c | 166 +++++++++++++------------------ kernel/sched/sched.h | 7 +- kernel/sched/stats.h | 4 +- kernel/signal.c | 12 +-- kernel/sys.c | 16 +-- kernel/time/itimer.c | 60 ++++-------- kernel/time/jiffies.c | 32 +++--- kernel/time/posix-cpu-timers.c | 170 ++++++++++++-------------------- kernel/time/time.c | 10 ++ kernel/time/timeconst.bc | 6 ++ kernel/tsacct.c | 21 ++-- 80 files changed, 450 insertions(+), 1103 deletions(-)
PATCH 4/37 cputime: Convert kcpustat to nsecs
Kernel cpu stats are stored in cputime_t which is an architecture defined type, and hence a bit opaque and requiring accessors and mutators for any operation.
Converting them to nsecs simplifies the code and is one step toward the removal of cputime_t in the core code.
--- arch/s390/appldata/appldata_os.c | 16 ++++----- drivers/cpufreq/cpufreq.c | 6 ++-- drivers/cpufreq/cpufreq_governor.c | 2 +- drivers/cpufreq/cpufreq_stats.c | 1 - drivers/macintosh/rack-meter.c | 2 +- fs/proc/stat.c | 68 +++++++++++++++++++------------------- fs/proc/uptime.c | 7 ++-- kernel/sched/cpuacct.c | 2 +- kernel/sched/cputime.c | 22 ++++++------ 9 files changed, 61 insertions(+), 65 deletions(-)
arch/s390/appldata/appldata_os.c +8 -8
@@ -113,21 +113,21 @@ static void appldata_get_os_data(void *data) j =0 ;for_each_online_cpu (i) { os_data->os_cpu[j].per_cpu_user = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_USER ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_USER ]); os_data->os_cpu[j].per_cpu_nice = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_NICE ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_NICE ]); os_data->os_cpu[j].per_cpu_system = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_SYSTEM ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_SYSTEM ]); os_data->os_cpu[j].per_cpu_idle = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_IDLE ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_IDLE ]); os_data->os_cpu[j].per_cpu_irq = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_IRQ ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_IRQ ]); os_data->os_cpu[j].per_cpu_softirq = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_SOFTIRQ ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_SOFTIRQ ]); os_data->os_cpu[j].per_cpu_iowait = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_IOWAIT ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_IOWAIT ]); os_data->os_cpu[j].per_cpu_steal = -cputime_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_STEAL ]); +nsecs_to_jiffies (kcpustat_cpu (i).cpustat[CPUTIME_STEAL ]); os_data->os_cpu[j].cpu_id = i; j++; }
drivers/cpufreq/cpufreq.c +3 -3
@@ -132,7 +132,7 @@ static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)u64 cur_wall_time;u64 busy_time; - cur_wall_time =jiffies64_to_cputime64 (get_jiffies_64 ()); + cur_wall_time =jiffies64_to_nsecs (get_jiffies_64 ()); busy_time =kcpustat_cpu (cpu).cpustat[CPUTIME_USER ]; busy_time +=kcpustat_cpu (cpu).cpustat[CPUTIME_SYSTEM ];
@@ -143,9 +143,9 @@ static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) idle_time = cur_wall_time - busy_time;if (wall) - *wall =cputime_to_usecs (cur_wall_time); + *wall =div_u64 (cur_wall_time,NSEC_PER_USEC ); -return cputime_to_usecs (idle_time); +return div_u64 (idle_time,NSEC_PER_USEC ); }u64 get_cpu_idle_time (unsigned int cpu,u64 *wall,int io_busy)
drivers/cpufreq/cpufreq_governor.c +1 -1
@@ -152,7 +152,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy)if (ignore_nice) {u64 cur_nice =kcpustat_cpu (j).cpustat[CPUTIME_NICE ]; - idle_time +=cputime_to_usecs (cur_nice - j_cdbs->prev_cpu_nice); + idle_time +=div_u64 (cur_nice - j_cdbs->prev_cpu_nice,NSEC_PER_USEC ); j_cdbs->prev_cpu_nice = cur_nice; }
drivers/cpufreq/cpufreq_stats.c +0 -1
@@ -13,7 +13,6 @@#include <linux/cpufreq.h> #include <linux/module.h> #include <linux/slab.h> -#include <linux/cputime.h> static DEFINE_SPINLOCK (cpufreq_stats_lock);
drivers/macintosh/rack-meter.c +1 -1
@@ -91,7 +91,7 @@ static inline cputime64_t get_cpu_idle_time(unsigned int cpu)if (rackmeter_ignore_nice) retval +=kcpustat_cpu (cpu).cpustat[CPUTIME_NICE ]; -return retval; +return nsecs_to_cputime64 (retval); }static void rackmeter_setup_i2s (struct rackmeter *rm)
fs/proc/stat.c +34 -34
121 lines not on this page · raw message
fs/proc/uptime.c +2 -5
@@ -5,23 +5,20 @@#include <linux/seq_file.h> #include <linux/time.h> #include <linux/kernel_stat.h> -#include <linux/cputime.h> static int uptime_proc_show (struct seq_file *m,void *v) {struct timespec uptime;struct timespec idle; -u64 idletime;u64 nsec;u32 rem;int i; - idletime =0 ; + nsec =0 ;for_each_possible_cpu (i) - idletime += (__force u64 )kcpustat_cpu (i).cpustat[CPUTIME_IDLE ]; + nsec += (__force u64 )kcpustat_cpu (i).cpustat[CPUTIME_IDLE ];get_monotonic_boottime (&uptime); - nsec =cputime64_to_jiffies64 (idletime) *TICK_NSEC ; idle.tv_sec =div_u64_rem (nsec,NSEC_PER_SEC , &rem); idle.tv_nsec = rem; seq_printf(m, "%lu.%02lu %lu.%02lu\n",
kernel/sched/cpuacct.c +1 -1
@@ -297,7 +297,7 @@ static int cpuacct_stats_show(struct seq_file *sf, void *v)for (stat =0 ; stat <CPUACCT_STAT_NSTATS ; stat++) {seq_printf (sf,"%s %lld\n" , cpuacct_stat_desc[stat], - (long long )cputime64_to_clock_t (val[stat])); + (long long )nsec_to_clock_t (val[stat])); }return 0 ;
kernel/sched/cputime.c +11 -11
@@ -75,9 +75,9 @@ static cputime_t irqtime_account_update(u64 irqtime, int idx, cputime_t maxtime)u64 *cpustat = kcpustat_this_cpu->cpustat;cputime_t irq_cputime; - irq_cputime =nsecs_to_cputime64 (irqtime) - cpustat[idx]; + irq_cputime =nsecs_to_cputime64 (irqtime - cpustat[idx]); irq_cputime =min (irq_cputime, maxtime); - cpustat[idx] += irq_cputime; + cpustat[idx] +=cputime_to_nsecs (irq_cputime);return irq_cputime; }
@@ -140,7 +140,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime) index = (task_nice (p) >0 ) ?CPUTIME_NICE :CPUTIME_USER ;/* Add user time to cpustat. */ -task_group_account_field (p, index, (__force u64 ) cputime); +task_group_account_field (p, index,cputime_to_nsecs (cputime));/* Account for user time used */ acct_account_cputime (p);
@@ -162,11 +162,11 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)/* Add guest time to cpustat. */ if (task_nice (p) >0 ) { - cpustat[CPUTIME_NICE ] += (__force u64 ) cputime; - cpustat[CPUTIME_GUEST_NICE ] += (__force u64 ) cputime; + cpustat[CPUTIME_NICE ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_GUEST_NICE ] +=cputime_to_nsecs (cputime); }else { - cpustat[CPUTIME_USER ] += (__force u64 ) cputime; - cpustat[CPUTIME_GUEST ] += (__force u64 ) cputime; + cpustat[CPUTIME_USER ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_GUEST ] +=cputime_to_nsecs (cputime); } }
@@ -184,7 +184,7 @@ void account_system_index_time(struct task_struct *p,account_group_system_time (p, cputime);/* Add system time to cpustat. */ -task_group_account_field (p, index, (__force u64 ) cputime); +task_group_account_field (p, index,cputime_to_nsecs (cputime));/* Account for system time used */ acct_account_cputime (p);
@@ -224,7 +224,7 @@ void account_steal_time(cputime_t cputime) {u64 *cpustat = kcpustat_this_cpu->cpustat; - cpustat[CPUTIME_STEAL ] += (__force u64 ) cputime; + cpustat[CPUTIME_STEAL ] +=cputime_to_nsecs (cputime); }/*
@@ -237,9 +237,9 @@ void account_idle_time(cputime_t cputime)struct rq *rq =this_rq ();if (atomic_read (&rq->nr_iowait) >0 ) - cpustat[CPUTIME_IOWAIT ] += (__force u64 ) cputime; + cpustat[CPUTIME_IOWAIT ] +=cputime_to_nsecs (cputime);else - cpustat[CPUTIME_IDLE ] += (__force u64 ) cputime; + cpustat[CPUTIME_IDLE ] +=cputime_to_nsecs (cputime); }/*
Signature · 1 line
2.7.4
PATCH 3/37 sched: Remove unused INIT_CPUTIME macro
In reply to Frederic WeisbeckerIt's a leftover from removed code.
--- include/linux/sched.h | 7 ------- 1 file changed, 7 deletions(-)
include/linux/sched.h +0 -7
@@ -620,13 +620,6 @@ struct task_cputime {#define prof_exp stime#define sched_exp sum_exec_runtime -#define INIT_CPUTIME \ - (struct task_cputime) { \ - .utime = 0, \ - .stime = 0, \ - .sum_exec_runtime = 0, \ - } -/* * This is the atomic variant of task_cputime, which can be used for * storing and updating task_cputime statistics without locking.
Signature · 1 line
2.7.4
PATCH 5/37 macintosh/rack-meter: Remove cputime_t internal use
In reply to Frederic Weisbeckercputime_t is being obsolete and replaced by nsecs units.
--- drivers/macintosh/rack-meter.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/macintosh/rack-meter.c +15 -15
@@ -52,8 +52,8 @@ struct rackmeter_dma {struct rackmeter_cpu {struct delayed_work sniffer;struct rackmeter *rm; -cputime64_t prev_wall; -cputime64_t prev_idle; +u64 prev_wall; +u64 prev_idle;int zero; }____cacheline_aligned ;
@@ -81,7 +81,7 @@ static int rackmeter_ignore_nice;/* This is copied from cpufreq_ondemand, maybe we should put it in * a common header somewhere */ -static inline cputime64_t get_cpu_idle_time (unsigned int cpu) +static inline u64 get_cpu_idle_time (unsigned int cpu) {u64 retval;
@@ -91,7 +91,7 @@ static inline cputime64_t get_cpu_idle_time(unsigned int cpu)if (rackmeter_ignore_nice) retval +=kcpustat_cpu (cpu).cpustat[CPUTIME_NICE ]; -return nsecs_to_cputime64 (retval); +return retval; }static void rackmeter_setup_i2s (struct rackmeter *rm)
@@ -217,23 +217,23 @@ static void rackmeter_do_timer(struct work_struct *work) container_of(work, struct rackmeter_cpu, sniffer.work);struct rackmeter *rm = rcpu->rm;unsigned int cpu =smp_processor_id (); -cputime64_t cur_jiffies, total_idle_ticks; -unsigned int total_ticks, idle_ticks; +u64 cur_nsecs, total_idle_nsecs; +u64 total_nsecs, idle_nsecs;int i, offset, load, cumm, pause; - cur_jiffies =jiffies64_to_cputime64 (get_jiffies_64 ()); - total_ticks = (unsigned int ) (cur_jiffies - rcpu->prev_wall); - rcpu->prev_wall = cur_jiffies; + cur_nsecs =jiffies64_to_nsecs (get_jiffies_64 ()); + total_nsecs = cur_nsecs - rcpu->prev_wall; + rcpu->prev_wall = cur_nsecs; - total_idle_ticks =get_cpu_idle_time (cpu); - idle_ticks = (unsigned int ) (total_idle_ticks - rcpu->prev_idle); - idle_ticks =min (idle_ticks, total_ticks); - rcpu->prev_idle = total_idle_ticks; + total_idle_nsecs =get_cpu_idle_time (cpu); + idle_nsecs = total_idle_nsecs - rcpu->prev_idle; + idle_nsecs =min (idle_nsecs, total_nsecs); + rcpu->prev_idle = total_idle_nsecs;/* We do a very dumb calculation to update the LEDs for now, * we'll do better once we have actual PWM implemented */ - load = (9 * (total_ticks - idle_ticks)) / total_ticks; + load =div64_u64 (9 * (total_nsecs - idle_nsecs), total_nsecs); offset = cpu <<3 ; cumm =0 ;
@@ -278,7 +278,7 @@ static void rackmeter_init_cpu_sniffer(struct rackmeter *rm)continue ; rcpu = &rm->cpu[cpu]; rcpu->prev_idle =get_cpu_idle_time (cpu); - rcpu->prev_wall =jiffies64_to_cputime64 (get_jiffies_64 ()); + rcpu->prev_wall =jiffies64_to_nsecs (get_jiffies_64 ());schedule_delayed_work_on (cpu, &rm->cpu[cpu].sniffer,msecs_to_jiffies (CPU_SAMPLING_RATE )); }
Signature · 1 line
2.7.4
PATCH 6/37 cputime: Convert guest time accounting to nsecs
In reply to Frederic Weisbeckercputime_t is being obsolete and replaced by nsecs units in order to make internal timestamps less opaque and more granular.
--- fs/proc/array.c | 6 +++--- include/linux/sched.h | 10 +++++----- kernel/sched/cputime.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-)
fs/proc/array.c +3 -3
@@ -402,7 +402,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,unsigned long cmin_flt =0 , cmaj_flt =0 ;unsigned long min_flt =0 , maj_flt =0 ;cputime_t cutime, cstime, utime, stime; -cputime_t cgtime, gtime; +u64 cgtime, gtime;unsigned long rsslim =0 ;char tcomm[sizeof (task->comm)];unsigned long flags;
@@ -542,8 +542,8 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,seq_put_decimal_ull (m," " , task->rt_priority);seq_put_decimal_ull (m," " , task->policy);seq_put_decimal_ull (m," " ,delayacct_blkio_ticks (task)); -seq_put_decimal_ull (m," " ,cputime_to_clock_t (gtime)); -seq_put_decimal_ll (m," " ,cputime_to_clock_t (cgtime)); +seq_put_decimal_ull (m," " ,nsec_to_clock_t (gtime)); +seq_put_decimal_ll (m," " ,nsec_to_clock_t (cgtime));if (mm && permitted) {seq_put_decimal_ull (m," " , mm->start_data);
include/linux/sched.h +5 -5
@@ -774,8 +774,8 @@ struct signal_struct {*/ seqlock_t stats_lock;cputime_t utime, stime, cutime, cstime; -cputime_t gtime; -cputime_t cgtime; +u64 gtime; +u64 cgtime;struct prev_cputime prev_cputime;unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
@@ -1658,7 +1658,7 @@ struct task_struct {#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME cputime_t utimescaled, stimescaled;#endif -cputime_t gtime; +u64 gtime;struct prev_cputime prev_cputime;#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN seqcount_t vtime_seqcount;
@@ -2254,7 +2254,7 @@ struct task_struct *try_get_task_struct(struct task_struct **ptask);#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN extern void task_cputime (struct task_struct *t,cputime_t *utime,cputime_t *stime); -extern cputime_t task_gtime (struct task_struct *t); +extern u64 task_gtime (struct task_struct *t);#else static inline void task_cputime (struct task_struct *t,cputime_t *utime,cputime_t *stime)
@@ -2263,7 +2263,7 @@ static inline void task_cputime(struct task_struct *t, *stime = t->stime; } -static inline cputime_t task_gtime (struct task_struct *t) +static inline u64 task_gtime (struct task_struct *t) {return t->gtime; }
kernel/sched/cputime.c +4 -4
@@ -158,7 +158,7 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)/* Add guest time to process. */ p->utime += cputime;account_group_user_time (p, cputime); - p->gtime += cputime; + p->gtime +=cputime_to_nsecs (cputime);/* Add guest time to cpustat. */ if (task_nice (p) >0 ) {
@@ -824,10 +824,10 @@ void vtime_init_idle(struct task_struct *t, int cpu)local_irq_restore (flags); } -cputime_t task_gtime (struct task_struct *t) +u64 task_gtime (struct task_struct *t) {unsigned int seq; -cputime_t gtime; +u64 gtime;if (!vtime_accounting_enabled ())return t->gtime;
@@ -837,7 +837,7 @@ cputime_t task_gtime(struct task_struct *t) gtime = t->gtime;if (t->vtime_snap_whence ==VTIME_SYS && t->flags &PF_VCPU ) - gtime +=vtime_delta (t); + gtime +=cputime_to_nsecs (vtime_delta (t)); }while (read_seqcount_retry (&t->vtime_seqcount, seq));
Signature · 1 line
2.7.4
PATCH 10/37 x86: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- arch/x86/kernel/apm_32.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/apm_32.c +4 -4
@@ -905,21 +905,21 @@ static int apm_cpu_idle(struct cpuidle_device *dev, {static int use_apm_idle;/* = 0 */ static unsigned int last_jiffies;/* = 0 */ -static unsigned int last_stime;/* = 0 */ -cputime_t stime, utime; +static u64 last_stime;/* = 0 */ +u64 stime, utime;int apm_idle_done =0 ;unsigned int jiffies_since_last_check = jiffies - last_jiffies;unsigned int bucket; recalc: -task_cputime_t (current, &utime, &stime); +task_cputime (current, &utime, &stime);if (jiffies_since_last_check >IDLE_CALC_LIMIT ) { use_apm_idle =0 ; }else if (jiffies_since_last_check > idle_period) {unsigned int idle_percentage; - idle_percentage =cputime_to_jiffies (stime - last_stime); + idle_percentage =nsecs_to_jiffies (stime - last_stime); idle_percentage *=100 ; idle_percentage /= jiffies_since_last_check; use_apm_idle = (idle_percentage > idle_threshold);
Signature · 1 line
2.7.4
PATCH 9/37 alpha: Convert obsolete cputime_t to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- arch/alpha/kernel/osf_sys.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/alpha/kernel/osf_sys.c +4 -4
@@ -1145,7 +1145,7 @@ struct rusage32 { SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru) {struct rusage32 r; -cputime_t utime, stime; +u64 utime, stime;unsigned long utime_jiffies, stime_jiffies;if (who !=RUSAGE_SELF && who !=RUSAGE_CHILDREN )
@@ -1154,9 +1154,9 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)memset (&r,0 ,sizeof (r));switch (who) {case RUSAGE_SELF : -task_cputime_t (current, &utime, &stime); - utime_jiffies =cputime_to_jiffies (utime); - stime_jiffies =cputime_to_jiffies (stime); +task_cputime (current, &utime, &stime); + utime_jiffies =nsecs_to_jiffies (utime); + stime_jiffies =nsecs_to_jiffies (stime);jiffies_to_timeval32 (utime_jiffies, &r.ru_utime);jiffies_to_timeval32 (stime_jiffies, &r.ru_stime); r.ru_minflt = current->min_flt;
Signature · 1 line
2.7.4
PATCH 8/37 cputime: Convert task/group cputime to nsecs
In reply to Frederic WeisbeckerNow that most cputime readers use the transition API which return the task cputime in old style cputime_t, we can safely store the cputime in nsecs. This will eventually make cputime statistics less opaque and more granular. Back and forth convertions between cputime_t and nsecs in order to deal with cputime_t random granularity won't be needed anymore.
--- arch/alpha/kernel/osf_sys.c | 4 ++-- arch/powerpc/kernel/time.c | 4 ++-- arch/s390/kernel/vtime.c | 6 ++--- arch/x86/kvm/hyperv.c | 5 +++-- fs/binfmt_elf.c | 11 +++++++-- fs/binfmt_elf_fdpic.c | 4 ++-- fs/proc/array.c | 10 ++++----- include/linux/sched.h | 55 ++++++++++++++++++++++++++++----------------- kernel/exit.c | 4 ++-- kernel/sched/cputime.c | 35 ++++++++++++++--------------- kernel/signal.c | 4 ++-- kernel/sys.c | 16 ++++++------- 12 files changed, 89 insertions(+), 69 deletions(-)
arch/alpha/kernel/osf_sys.c +2 -2
@@ -1163,8 +1163,8 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru) r.ru_majflt = current->maj_flt;break ;case RUSAGE_CHILDREN : - utime_jiffies =cputime_to_jiffies (current->signal->cutime); - stime_jiffies =cputime_to_jiffies (current->signal->cstime); + utime_jiffies =nsecs_to_jiffies (current->signal->cutime); + stime_jiffies =nsecs_to_jiffies (current->signal->cstime);jiffies_to_timeval32 (utime_jiffies, &r.ru_utime);jiffies_to_timeval32 (stime_jiffies, &r.ru_stime); r.ru_minflt = current->signal->cmin_flt;
arch/powerpc/kernel/time.c +2 -2
@@ -396,7 +396,7 @@ void vtime_flush(struct task_struct *tsk)account_user_time (tsk, acct->utime);if (acct->utime_scaled) - tsk->utimescaled += acct->utime_scaled; + tsk->utimescaled +=cputime_to_nsecs (acct->utime_scaled);if (acct->gtime)account_guest_time (tsk, acct->gtime);
@@ -411,7 +411,7 @@ void vtime_flush(struct task_struct *tsk)account_system_index_time (tsk, acct->stime,CPUTIME_SYSTEM );if (acct->stime_scaled) - tsk->stimescaled += acct->stime_scaled; + tsk->stimescaled +=cputime_to_nsecs (acct->stime_scaled);if (acct->hardirq_time)account_system_index_time (tsk, acct->hardirq_time,CPUTIME_IRQ );
arch/s390/kernel/vtime.c +3 -3
@@ -114,7 +114,7 @@ static void account_system_index_scaled(struct task_struct *p, cputime_t cputime, cputime_t scaled, enum cpu_usage_stat index) { - p->stimescaled += scaled; + p->stimescaled += cputime_to_nsecs(scaled);account_system_index_time (p, cputime, index); }
@@ -167,12 +167,12 @@ static int do_account_vtime(struct task_struct *tsk)/* Push account value */ if (user) {account_user_time (tsk, user); - tsk->utimescaled +=scale_vtime (user); + tsk->utimescaled +=cputime_to_nsecs (scale_vtime (user)); }if (guest) {account_guest_time (tsk, guest); - tsk->utimescaled +=scale_vtime (guest); + tsk->utimescaled +=cputime_to_nsecs (scale_vtime (guest)); }if (system)
arch/x86/kvm/hyperv.c +3 -2
@@ -964,10 +964,11 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,/* Calculate cpu time spent by current task in 100ns units */ static u64 current_task_runtime_100ns (void ) { -cputime_t utime, stime; +u64 utime, stime;task_cputime_adjusted (current, &utime, &stime); -return div_u64 (cputime_to_nsecs (utime + stime),100 ); + +return div_u64 (utime + stime,100 ); }static int kvm_hv_set_msr (struct kvm_vcpu *vcpu,u32 msr,u64 data,bool host)
fs/binfmt_elf.c +9 -2
@@ -1411,6 +1411,8 @@ static void fill_note(struct memelfnote *note, const char *name, int type,static void fill_prstatus (struct elf_prstatus *prstatus,struct task_struct *p,long signr) { +struct timeval tv; + prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; prstatus->pr_sigpend = p->pending.signal.sig[0 ]; prstatus->pr_sighold = p->blocked.sig[0 ];
@@ -1437,8 +1439,13 @@ static void fill_prstatus(struct elf_prstatus *prstatus,cputime_to_timeval (utime, &prstatus->pr_utime);cputime_to_timeval (stime, &prstatus->pr_stime); } -cputime_to_timeval (p->signal->cutime, &prstatus->pr_cutime); -cputime_to_timeval (p->signal->cstime, &prstatus->pr_cstime); + tv =ns_to_timeval (p->signal->cutime); + prstatus->pr_cutime.tv_sec = tv.tv_sec; + prstatus->pr_cutime.tv_usec = tv.tv_usec; + + tv =ns_to_timeval (p->signal->cstime); + prstatus->pr_cstime.tv_sec = tv.tv_sec; + prstatus->pr_cstime.tv_usec = tv.tv_usec; } static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
fs/binfmt_elf_fdpic.c +2 -2
@@ -1358,8 +1358,8 @@ static void fill_prstatus(struct elf_prstatus *prstatus,cputime_to_timeval (utime, &prstatus->pr_utime);cputime_to_timeval (stime, &prstatus->pr_stime); } -cputime_to_timeval (p->signal->cutime, &prstatus->pr_cutime); -cputime_to_timeval (p->signal->cstime, &prstatus->pr_cstime); + prstatus->pr_cutime =ns_to_timeval (p->signal->cutime); + prstatus->pr_cstime =ns_to_timeval (p->signal->cstime); prstatus->pr_exec_fdpic_loadmap = p->mm->context.exec_fdpic_loadmap; prstatus->pr_interp_fdpic_loadmap = p->mm->context.interp_fdpic_loadmap;
fs/proc/array.c +5 -5
@@ -401,7 +401,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,unsigned long long start_time;unsigned long cmin_flt =0 , cmaj_flt =0 ;unsigned long min_flt =0 , maj_flt =0 ; -cputime_t cutime, cstime, utime, stime; +u64 cutime, cstime, utime, stime;u64 cgtime, gtime;unsigned long rsslim =0 ;char tcomm[sizeof (task->comm)];
@@ -497,10 +497,10 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,seq_put_decimal_ull (m," " , cmin_flt);seq_put_decimal_ull (m," " , maj_flt);seq_put_decimal_ull (m," " , cmaj_flt); -seq_put_decimal_ull (m," " ,cputime_to_clock_t (utime)); -seq_put_decimal_ull (m," " ,cputime_to_clock_t (stime)); -seq_put_decimal_ll (m," " ,cputime_to_clock_t (cutime)); -seq_put_decimal_ll (m," " ,cputime_to_clock_t (cstime)); +seq_put_decimal_ull (m," " ,nsec_to_clock_t (utime)); +seq_put_decimal_ull (m," " ,nsec_to_clock_t (stime)); +seq_put_decimal_ll (m," " ,nsec_to_clock_t (cutime)); +seq_put_decimal_ll (m," " ,nsec_to_clock_t (cstime));seq_put_decimal_ll (m," " , priority);seq_put_decimal_ll (m," " , nice);seq_put_decimal_ll (m," " , num_threads);
include/linux/sched.h +34 -21
128 lines not on this page · raw message
kernel/exit.c +2 -2
@@ -86,7 +86,7 @@ static void __exit_signal(struct task_struct *tsk)bool group_dead =thread_group_leader (tsk);struct sighand_struct *sighand;struct tty_struct *uninitialized_var (tty ); -cputime_t utime, stime; +u64 utime, stime; sighand =rcu_dereference_check (tsk->sighand,lockdep_tasklist_lock_is_held ());
@@ -1091,7 +1091,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)struct signal_struct *sig = p->signal;struct signal_struct *psig = current->signal;unsigned long maxrss; -cputime_t tgutime, tgstime; +u64 tgutime, tgstime;/* * The resource counters for the group leader are in its
kernel/sched/cputime.c +17 -18
@@ -134,7 +134,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime)int index;/* Add user time to process. */ - p->utime += cputime; + p->utime +=cputime_to_nsecs (cputime);account_group_user_time (p, cputime); index = (task_nice (p) >0 ) ?CPUTIME_NICE :CPUTIME_USER ;
@@ -156,7 +156,7 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)u64 *cpustat = kcpustat_this_cpu->cpustat;/* Add guest time to process. */ - p->utime += cputime; + p->utime +=cputime_to_nsecs (cputime);account_group_user_time (p, cputime); p->gtime +=cputime_to_nsecs (cputime);
@@ -180,7 +180,7 @@ void account_system_index_time(struct task_struct *p, cputime_t cputime, enum cpu_usage_stat index) {/* Add system time to process. */ - p->stime += cputime; + p->stime += cputime_to_nsecs(cputime);account_group_system_time (p, cputime);/* Add system time to cpustat. */
@@ -315,7 +315,7 @@ static u64 read_sum_exec_runtime(struct task_struct *t)void thread_group_cputime (struct task_struct *tsk,struct task_cputime *times) {struct signal_struct *sig = tsk->signal; -cputime_t utime, stime; +u64 utime, stime;struct task_struct *t;unsigned int seq, nextseq;unsigned long flags;
@@ -465,14 +465,14 @@ void vtime_account_irq_enter(struct task_struct *tsk)EXPORT_SYMBOL_GPL (vtime_account_irq_enter);#endif /* __ARCH_HAS_VTIME_ACCOUNT */ -void task_cputime_adjusted (struct task_struct *p,cputime_t *ut,cputime_t *st) +void task_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st) { *ut = p->utime; *st = p->stime; }EXPORT_SYMBOL_GPL (task_cputime_adjusted); -void thread_group_cputime_adjusted (struct task_struct *p,cputime_t *ut,cputime_t *st) +void thread_group_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st) {struct task_cputime cputime;
@@ -543,7 +543,7 @@ void account_idle_ticks(unsigned long ticks)* Perform (stime * rtime) / total, but avoid multiplication overflow by * loosing precision when the numbers are big. */ -static cputime_t scale_stime (u64 stime,u64 rtime,u64 total) +static u64 scale_stime (u64 stime,u64 rtime,u64 total) {u64 scaled;
@@ -580,7 +580,7 @@ static cputime_t scale_stime(u64 stime, u64 rtime, u64 total)* followed by a 64/32->64 divide. */ scaled =div_u64 ((u64 ) (u32 ) stime * (u64 ) (u32 ) rtime, (u32 )total); -return (__force cputime_t ) scaled; +return scaled; }/*
@@ -605,14 +605,14 @@ static cputime_t scale_stime(u64 stime, u64 rtime, u64 total)*/ static void cputime_adjust (struct task_cputime *curr,struct prev_cputime *prev, -cputime_t *ut,cputime_t *st) +u64 *ut,u64 *st) { -cputime_t rtime, stime, utime; +u64 rtime, stime, utime;unsigned long flags;/* Serialize concurrent callers such that we can honour our guarantees */ raw_spin_lock_irqsave (&prev->lock, flags); - rtime =nsecs_to_cputime (curr->sum_exec_runtime); + rtime = curr->sum_exec_runtime;/* * This is possible under two circumstances:
@@ -643,8 +643,7 @@ static void cputime_adjust(struct task_cputime *curr, goto update; } - stime =scale_stime ((__force u64 )stime, (__force u64 )rtime, - (__force u64)(stime + utime)); + stime =scale_stime (stime, rtime, stime + utime); update:/*
@@ -677,7 +676,7 @@ static void cputime_adjust(struct task_cputime *curr,raw_spin_unlock_irqrestore (&prev->lock, flags); } -void task_cputime_adjusted (struct task_struct *p,cputime_t *ut,cputime_t *st) +void task_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st) {struct task_cputime cputime = { .sum_exec_runtime = p->se.sum_exec_runtime,
@@ -688,7 +687,7 @@ void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st) }EXPORT_SYMBOL_GPL (task_cputime_adjusted); -void thread_group_cputime_adjusted (struct task_struct *p,cputime_t *ut,cputime_t *st) +void thread_group_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st) {struct task_cputime cputime;
@@ -849,9 +848,9 @@ u64 task_gtime(struct task_struct *t)* add up the pending nohz execution time since the last * cputime snapshot. */ -void task_cputime (struct task_struct *t,cputime_t *utime,cputime_t *stime) +void task_cputime (struct task_struct *t,u64 *utime,u64 *stime) { -cputime_t delta; +u64 delta;unsigned int seq;if (!vtime_accounting_enabled ()) {
@@ -870,7 +869,7 @@ void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)if (t->vtime_snap_whence ==VTIME_INACTIVE ||is_idle_task (t))continue ; - delta =vtime_delta (t); + delta =cputime_to_nsecs (vtime_delta (t));/* * Task runs either in user or kernel space, add pending nohz time to
kernel/signal.c +2 -2
@@ -1620,8 +1620,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig)rcu_read_unlock ();task_cputime_t (tsk, &utime, &stime); - info.si_utime =cputime_to_clock_t (utime + tsk->signal->utime); - info.si_stime =cputime_to_clock_t (stime + tsk->signal->stime); + info.si_utime =cputime_to_clock_t (utime +nsecs_to_cputime (tsk->signal->utime)); + info.si_stime =cputime_to_clock_t (stime +nsecs_to_cputime (tsk->signal->stime)); info.si_status = tsk->exit_code &0x7f ;if (tsk->exit_code &0x80 )
kernel/sys.c +8 -8
@@ -881,15 +881,15 @@ SYSCALL_DEFINE0(getegid)void do_sys_times (struct tms *tms) { -cputime_t tgutime, tgstime, cutime, cstime; +u64 tgutime, tgstime, cutime, cstime;thread_group_cputime_adjusted (current, &tgutime, &tgstime); cutime = current->signal->cutime; cstime = current->signal->cstime; - tms->tms_utime =cputime_to_clock_t (tgutime); - tms->tms_stime =cputime_to_clock_t (tgstime); - tms->tms_cutime =cputime_to_clock_t (cutime); - tms->tms_cstime =cputime_to_clock_t (cstime); + tms->tms_utime =nsec_to_clock_t (tgutime); + tms->tms_stime =nsec_to_clock_t (tgstime); + tms->tms_cutime =nsec_to_clock_t (cutime); + tms->tms_cstime =nsec_to_clock_t (cstime); } SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
@@ -1544,7 +1544,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) {struct task_struct *t;unsigned long flags; -cputime_t tgutime, tgstime, utime, stime; +u64 tgutime, tgstime, utime, stime;unsigned long maxrss =0 ;memset ((char *)r,0 ,sizeof (*r));
@@ -1600,8 +1600,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)unlock_task_sighand (p, &flags); out: -cputime_to_timeval (utime, &r->ru_utime); -cputime_to_timeval (stime, &r->ru_stime); + r->ru_utime =ns_to_timeval (utime); + r->ru_stime =ns_to_timeval (stime);if (who !=RUSAGE_CHILDREN ) {struct mm_struct *mm =get_task_mm (p);
Signature · 1 line
2.7.4
PATCH 12/37 binfmt: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- arch/mips/kernel/binfmt_elfn32.c | 12 ++---------- arch/mips/kernel/binfmt_elfo32.c | 12 ++---------- arch/parisc/kernel/binfmt_elf32.c | 11 ++--------- fs/binfmt_elf.c | 26 ++++++++++---------------- fs/binfmt_elf_fdpic.c | 16 ++++++++-------- fs/compat_binfmt_elf.c | 18 ++---------------- include/linux/compat.h | 20 +++++++++++++++++++- 7 files changed, 45 insertions(+), 70 deletions(-)
arch/mips/kernel/binfmt_elfn32.c +2 -10
@@ -99,15 +99,7 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)#undef TASK_SIZE#define TASK_SIZE TASK_SIZE32 -#undef cputime_to_timeval -#define cputime_to_timeval cputime_to_compat_timeval -static __inline__void -cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) -{ -unsigned long jiffies =cputime_to_jiffies (cputime); - - value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); - value->tv_sec = jiffies /HZ ; -} +#undef ns_to_timeval +#define ns_to_timeval ns_to_compat_timeval#include "../../../fs/binfmt_elf.c"
arch/mips/kernel/binfmt_elfo32.c +2 -10
@@ -102,15 +102,7 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)#undef TASK_SIZE#define TASK_SIZE TASK_SIZE32 -#undef cputime_to_timeval -#define cputime_to_timeval cputime_to_compat_timeval -static __inline__void -cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) -{ -unsigned long jiffies =cputime_to_jiffies (cputime); - - value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); - value->tv_sec = jiffies /HZ ; -} +#undef ns_to_timeval +#define ns_to_timeval ns_to_compat_timeval#include "../../../fs/binfmt_elf.c"
arch/parisc/kernel/binfmt_elf32.c +2 -9
@@ -91,14 +91,7 @@ struct elf_prpsinfo32 current->thread.map_base =DEFAULT_MAP_BASE32 ; \ current->thread.task_size = DEFAULT_TASK_SIZE32 \ -#undef cputime_to_timeval -#define cputime_to_timeval cputime_to_compat_timeval -static __inline__void -cputime_to_compat_timeval (const cputime_t cputime,struct compat_timeval *value) -{ -unsigned long jiffies =cputime_to_jiffies (cputime); - value->tv_usec = (jiffies %HZ ) * (1000000L /HZ ); - value->tv_sec = jiffies /HZ ; -} +#undef ns_to_timeval +#define ns_to_timeval ns_to_compat_timeval#include "../../../fs/binfmt_elf.c"
fs/binfmt_elf.c +10 -16
@@ -1411,8 +1411,6 @@ static void fill_note(struct memelfnote *note, const char *name, int type,static void fill_prstatus (struct elf_prstatus *prstatus,struct task_struct *p,long signr) { -struct timeval tv; - prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; prstatus->pr_sigpend = p->pending.signal.sig[0 ]; prstatus->pr_sighold = p->blocked.sig[0 ];
@@ -1423,29 +1421,25 @@ static void fill_prstatus(struct elf_prstatus *prstatus, prstatus->pr_pgrp =task_pgrp_vnr (p); prstatus->pr_sid =task_session_vnr (p);if (thread_group_leader (p)) { -struct task_cputime_t cputime; +struct task_cputime cputime;/* * This is the record for the group leader. It shows the * group-wide total, not its individual thread total. */ -thread_group_cputime_t (p, &cputime); -cputime_to_timeval (cputime.utime, &prstatus->pr_utime); -cputime_to_timeval (cputime.stime, &prstatus->pr_stime); +thread_group_cputime (p, &cputime); + prstatus->pr_utime =ns_to_timeval (cputime.utime); + prstatus->pr_stime =ns_to_timeval (cputime.stime); }else { -cputime_t utime, stime; +u64 utime, stime; -task_cputime_t (p, &utime, &stime); -cputime_to_timeval (utime, &prstatus->pr_utime); -cputime_to_timeval (stime, &prstatus->pr_stime); +task_cputime (p, &utime, &stime); + prstatus->pr_utime =ns_to_timeval (utime); + prstatus->pr_stime =ns_to_timeval (stime); } - tv =ns_to_timeval (p->signal->cutime); - prstatus->pr_cutime.tv_sec = tv.tv_sec; - prstatus->pr_cutime.tv_usec = tv.tv_usec; - tv =ns_to_timeval (p->signal->cstime); - prstatus->pr_cstime.tv_sec = tv.tv_sec; - prstatus->pr_cstime.tv_usec = tv.tv_usec; + prstatus->pr_cutime =ns_to_timeval (p->signal->cutime); + prstatus->pr_cstime =ns_to_timeval (p->signal->cstime); } static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
fs/binfmt_elf_fdpic.c +8 -8
@@ -1342,21 +1342,21 @@ static void fill_prstatus(struct elf_prstatus *prstatus, prstatus->pr_pgrp =task_pgrp_vnr (p); prstatus->pr_sid =task_session_vnr (p);if (thread_group_leader (p)) { -struct task_cputime_t cputime; +struct task_cputime cputime;/* * This is the record for the group leader. It shows the * group-wide total, not its individual thread total. */ -thread_group_cputime_t (p, &cputime); -cputime_to_timeval (cputime.utime, &prstatus->pr_utime); -cputime_to_timeval (cputime.stime, &prstatus->pr_stime); +thread_group_cputime (p, &cputime); + prstatus->pr_utime =ns_to_timeval (cputime.utime); + prstatus->pr_stime =ns_to_timeval (cputime.stime); }else { -cputime_t utime, stime; +u64 utime, stime; -task_cputime_t (p, &utime, &stime); -cputime_to_timeval (utime, &prstatus->pr_utime); -cputime_to_timeval (stime, &prstatus->pr_stime); +task_cputime (p, &utime, &stime); + prstatus->pr_utime =ns_to_timeval (utime); + prstatus->pr_stime =ns_to_timeval (stime); } prstatus->pr_cutime =ns_to_timeval (p->signal->cutime); prstatus->pr_cstime =ns_to_timeval (p->signal->cstime);
fs/compat_binfmt_elf.c +2 -16
@@ -51,22 +51,8 @@#define elf_prstatus compat_elf_prstatus#define elf_prpsinfo compat_elf_prpsinfo -/* -* Compat version of cputime_to_compat_timeval, perhaps this -* should be an inline in <linux/compat.h>. -*/ -static void cputime_to_compat_timeval (const cputime_t cputime, -struct compat_timeval *value) -{ -struct timeval tv; -cputime_to_timeval (cputime, &tv); - value->tv_sec = tv.tv_sec; - value->tv_usec = tv.tv_usec; -} - -#undef cputime_to_timeval -#define cputime_to_timeval cputime_to_compat_timeval - +#undef ns_to_timeval +#define ns_to_timeval ns_to_compat_timeval/* * To use this file, asm/elf.h must define compat_elf_check_arch.
include/linux/compat.h +19 -1
@@ -731,7 +731,25 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,static inline bool in_compat_syscall (void ) {return is_compat_task (); }#endif -#else +/** +* ns_to_compat_timeval - Compat version of ns_to_timeval +* @nsec: the nanoseconds value to be converted +* +* Returns the compat_timeval representation of the nsec parameter. +*/ +static inline struct compat_timeval ns_to_compat_timeval (s64 nsec) +{ +struct timeval tv; +struct compat_timeval ctv; + + tv =ns_to_timeval (nsec); + ctv.tv_sec = tv.tv_sec; + ctv.tv_usec = tv.tv_usec; + +return ctv; +} + +#else /* !CONFIG_COMPAT */ #define is_compat_task () (0)static inline bool in_compat_syscall (void ) {return false; }
Signature · 1 line
2.7.4
PATCH 15/37 tsacct: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- include/linux/sched.h | 2 +- kernel/tsacct.c | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-)
include/linux/sched.h +1 -1
@@ -1815,7 +1815,7 @@ struct task_struct {#if defined(CONFIG_TASK_XACCT )u64 acct_rss_mem1;/* accumulated rss usage */ u64 acct_vm_mem1;/* accumulated virtual memory usage */ -cputime_t acct_timexpd;/* stime + utime since last update */ +u64 acct_timexpd;/* stime + utime since last update */ #endif #ifdef CONFIG_CPUSETS nodemask_t mems_allowed;/* Protected by alloc_lock */
kernel/tsacct.c +12 -15
@@ -31,7 +31,7 @@ void bacct_add_tsk(struct user_namespace *user_ns, struct taskstats *stats, struct task_struct *tsk) { const struct cred *tcred; -cputime_t utime, stime, utimescaled, stimescaled; +u64 utime, stime, utimescaled, stimescaled;u64 delta;BUILD_BUG_ON (TS_COMM_LEN <TASK_COMM_LEN );
@@ -66,13 +66,13 @@ void bacct_add_tsk(struct user_namespace *user_ns, task_tgid_nr_ns(rcu_dereference(tsk->real_parent), pid_ns) : 0;rcu_read_unlock (); -task_cputime_t (tsk, &utime, &stime); - stats->ac_utime =cputime_to_usecs (utime); - stats->ac_stime =cputime_to_usecs (stime); +task_cputime (tsk, &utime, &stime); + stats->ac_utime =div_u64 (utime,NSEC_PER_USEC ); + stats->ac_stime =div_u64 (stime,NSEC_PER_USEC ); -task_cputime_t_scaled (tsk, &utimescaled, &stimescaled); - stats->ac_utimescaled =cputime_to_usecs (utimescaled); - stats->ac_stimescaled =cputime_to_usecs (stimescaled); +task_cputime_scaled (tsk, &utimescaled, &stimescaled); + stats->ac_utimescaled =div_u64 (utimescaled,NSEC_PER_USEC ); + stats->ac_stimescaled =div_u64 (stimescaled,NSEC_PER_USEC ); stats->ac_minflt = tsk->min_flt; stats->ac_majflt = tsk->maj_flt;
@@ -123,18 +123,15 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)#undef MBstatic void __acct_update_integrals (struct task_struct *tsk, -cputime_t utime,cputime_t stime) +u64 utime,u64 stime) { -cputime_t time, dtime; -u64 delta; +u64 time, delta;if (!likely (tsk->mm))return ; time = stime + utime; - dtime = time - tsk->acct_timexpd; -/* Avoid division: cputime_t is often in nanoseconds already. */ - delta =cputime_to_nsecs (dtime); + delta = time - tsk->acct_timexpd;if (delta <TICK_NSEC )return ;
@@ -155,11 +152,11 @@ static void __acct_update_integrals(struct task_struct *tsk,*/ void acct_update_integrals (struct task_struct *tsk) { -cputime_t utime, stime; +u64 utime, stime;unsigned long flags;local_irq_save (flags); -task_cputime_t (tsk, &utime, &stime); +task_cputime (tsk, &utime, &stime);__acct_update_integrals (tsk, utime, stime);local_irq_restore (flags); }
Signature · 1 line
2.7.4
PATCH 13/37 acct: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- include/linux/sched.h | 2 +- kernel/acct.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-)
include/linux/sched.h +1 -1
@@ -563,7 +563,7 @@ struct pacct_struct {int ac_flag;long ac_exitcode;unsigned long ac_mem; -cputime_t ac_utime, ac_stime; +u64 ac_utime, ac_stime;unsigned long ac_minflt, ac_majflt; };
kernel/acct.c +5 -4
@@ -453,8 +453,8 @@ static void fill_ac(acct_t *ac)spin_lock_irq (¤t->sighand->siglock); tty = current->signal->tty;/* Safe as we hold the siglock */ ac->ac_tty = tty ?old_encode_dev (tty_devnum (tty)) :0 ; - ac->ac_utime =encode_comp_t (jiffies_to_AHZ (cputime_to_jiffies (pacct->ac_utime))); - ac->ac_stime =encode_comp_t (jiffies_to_AHZ (cputime_to_jiffies (pacct->ac_stime))); + ac->ac_utime =encode_comp_t (nsec_to_AHZ (pacct->ac_utime)); + ac->ac_stime =encode_comp_t (nsec_to_AHZ (pacct->ac_stime)); ac->ac_flag = pacct->ac_flag; ac->ac_mem =encode_comp_t (pacct->ac_mem); ac->ac_minflt =encode_comp_t (pacct->ac_minflt);
@@ -530,7 +530,7 @@ static void do_acct_process(struct bsd_acct_struct *acct)void acct_collect (long exitcode,int group_dead) {struct pacct_struct *pacct = ¤t->signal->pacct; -cputime_t utime, stime; +u64 utime, stime;unsigned long vsize =0 ;if (group_dead && current->mm) {
@@ -559,7 +559,8 @@ void acct_collect(long exitcode, int group_dead) pacct->ac_flag |=ACORE ;if (current->flags &PF_SIGNALED ) pacct->ac_flag |=AXSIG ; -task_cputime_t (current, &utime, &stime); + +task_cputime (current, &utime, &stime); pacct->ac_utime += utime; pacct->ac_stime += stime; pacct->ac_minflt += current->min_flt;
Signature · 1 line
2.7.4
PATCH 20/37 itimer: Convert internal cputime_t units to nsec
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
Also convert itimers to use nsec based internal counters. This simplifies it and remove the whole game with error/inc_error which served to deal with cputime_t random granularity.
--- include/linux/posix-timers.h | 2 +- include/linux/sched.h | 6 ++-- include/trace/events/timer.h | 26 ++++++++--------- kernel/time/itimer.c | 64 +++++++++++++++--------------------------- kernel/time/posix-cpu-timers.c | 43 +++++++++++----------------- 5 files changed, 55 insertions(+), 86 deletions(-)
include/linux/posix-timers.h +1 -1
@@ -119,7 +119,7 @@ void run_posix_cpu_timers(struct task_struct *task);void posix_cpu_timers_exit (struct task_struct *task);void posix_cpu_timers_exit_group (struct task_struct *task);void set_process_cpu_timer (struct task_struct *task,unsigned int clock_idx, -cputime_t *newval,cputime_t *oldval); +u64 *newval,u64 *oldval);long clock_nanosleep_restart (struct restart_block *restart_block);
include/linux/sched.h +2 -4
@@ -568,10 +568,8 @@ struct pacct_struct { };struct cpu_itimer { -cputime_t expires; -cputime_t incr; -u32 error; -u32 incr_error; +u64 expires; +u64 incr; };/**
include/trace/events/timer.h +13 -13
@@ -269,17 +269,17 @@ DEFINE_EVENT(hrtimer_class, hrtimer_cancel, TRACE_EVENT(itimer_state, TP_PROTO(int which, const struct itimerval *const value, - cputime_t expires), + unsigned long long expires), TP_ARGS(which, value, expires), TP_STRUCT__entry( - __field( int, which ) - __field( cputime_t, expires ) - __field( long, value_sec ) - __field( long, value_usec ) - __field( long, interval_sec ) - __field( long, interval_usec ) + __field( int, which ) + __field( unsigned long long, expires ) + __field( long, value_sec ) + __field( long, value_usec ) + __field( long, interval_sec ) + __field( long, interval_usec ) ), TP_fast_assign(
@@ -292,7 +292,7 @@ TRACE_EVENT(itimer_state, ),TP_printk ("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld" , - __entry->which, (unsigned long long )__entry->expires, + __entry->which, __entry->expires, __entry->value_sec, __entry->value_usec, __entry->interval_sec, __entry->interval_usec) );
@@ -305,14 +305,14 @@ TRACE_EVENT(itimer_state,*/ TRACE_EVENT(itimer_expire, - TP_PROTO(int which, struct pid *pid, cputime_t now), + TP_PROTO(int which, struct pid *pid, unsigned long long now), TP_ARGS(which, pid, now), TP_STRUCT__entry( - __field( int , which ) - __field( pid_t, pid ) - __field( cputime_t, now ) + __field( int , which ) + __field( pid_t, pid ) + __field( unsigned long long, now ) ), TP_fast_assign(
@@ -322,7 +322,7 @@ TRACE_EVENT(itimer_expire, ),TP_printk ("which=%d pid=%d now=%llu" , __entry->which, - (int ) __entry->pid, (unsigned long long )__entry->now) + (int ) __entry->pid, __entry->now) );#ifdef CONFIG_NO_HZ_COMMON
kernel/time/itimer.c +22 -42
112 lines not on this page · raw message
kernel/time/posix-cpu-timers.c +17 -26
95 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 19/37 posix-timers: Convert internals to use nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
Also convert posix-cpu-timers to use nsec based internal counters to simplify it.
--- include/linux/posix-timers.h | 12 +-- include/linux/sched.h | 6 +- kernel/fork.c | 2 +- kernel/sched/cputime.c | 6 +- kernel/sched/stats.h | 4 +- kernel/time/itimer.c | 6 +- kernel/time/posix-cpu-timers.c | 210 +++++++++++++++++------------------------ 7 files changed, 100 insertions(+), 146 deletions(-)
include/linux/posix-timers.h +1 -11
@@ -8,19 +8,9 @@#include <linux/alarmtimer.h> -static inline unsigned long long cputime_to_expires (cputime_t expires) -{ -return (__force unsigned long long )expires; -} - -static inline cputime_t expires_to_cputime (unsigned long long expires) -{ -return (__force cputime_t )expires; -} -struct cpu_timer_list {struct list_head entry; -unsigned long long expires, incr; +u64 expires, incr;struct task_struct *task;int firing; };
include/linux/sched.h +3 -3
@@ -755,7 +755,7 @@ struct signal_struct {struct thread_group_cputimer cputimer;/* Earliest-expiration cache. */ -struct task_cputime_t cputime_expires; +struct task_cputime cputime_expires;#ifdef CONFIG_NO_HZ_FULL atomic_t tick_dep_mask;
@@ -1689,7 +1689,7 @@ struct task_struct {/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ unsigned long min_flt, maj_flt; -struct task_cputime_t cputime_expires; +struct task_cputime cputime_expires;struct list_head cpu_timers[3 ];/* process credentials */
@@ -3528,7 +3528,7 @@ static __always_inline bool need_resched(void)* Thread group CPU time accounting. */ void thread_group_cputime (struct task_struct *tsk,struct task_cputime *times); -void thread_group_cputimer (struct task_struct *tsk,struct task_cputime_t *times); +void thread_group_cputimer (struct task_struct *tsk,struct task_cputime *times);static inline void thread_group_cputime_t (struct task_struct *tsk,struct task_cputime_t *cputime)
kernel/fork.c +1 -1
@@ -1313,7 +1313,7 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig) cpu_limit =READ_ONCE (sig->rlim[RLIMIT_CPU ].rlim_cur);if (cpu_limit !=RLIM_INFINITY ) { - sig->cputime_expires.prof_exp =secs_to_cputime (cpu_limit); + sig->cputime_expires.prof_exp = cpu_limit *NSEC_PER_SEC ; sig->cputimer.running = true; }
kernel/sched/cputime.c +3 -3
@@ -122,7 +122,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime)/* Add user time to process. */ p->utime +=cputime_to_nsecs (cputime); -account_group_user_time (p, cputime); +account_group_user_time (p,cputime_to_nsecs (cputime)); index = (task_nice (p) >0 ) ?CPUTIME_NICE :CPUTIME_USER ;
@@ -144,7 +144,7 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)/* Add guest time to process. */ p->utime +=cputime_to_nsecs (cputime); -account_group_user_time (p, cputime); +account_group_user_time (p,cputime_to_nsecs (cputime)); p->gtime +=cputime_to_nsecs (cputime);/* Add guest time to cpustat. */
@@ -168,7 +168,7 @@ void account_system_index_time(struct task_struct *p, {/* Add system time to process. */ p->stime +=cputime_to_nsecs (cputime); -account_group_system_time (p, cputime); +account_group_system_time (p,cputime_to_nsecs (cputime));/* Add system time to cpustat. */ task_group_account_field (p, index,cputime_to_nsecs (cputime));
kernel/sched/stats.h +2 -2
@@ -216,7 +216,7 @@ static inline bool cputimer_running(struct task_struct *tsk)* running CPU and update the utime field there. */ static inline void account_group_user_time (struct task_struct *tsk, -cputime_t cputime) +u64 cputime) {struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
@@ -237,7 +237,7 @@ static inline void account_group_user_time(struct task_struct *tsk,* running CPU and update the stime field there. */ static inline void account_group_system_time (struct task_struct *tsk, -cputime_t cputime) +u64 cputime) {struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
kernel/time/itimer.c +3 -3
@@ -53,15 +53,15 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id, cval = it->expires; cinterval = it->incr;if (cval) { -struct task_cputime_t cputime; +struct task_cputime cputime;cputime_t t;thread_group_cputimer (tsk, &cputime);if (clock_id ==CPUCLOCK_PROF ) - t = cputime.utime + cputime.stime; + t =nsecs_to_cputime (cputime.utime + cputime.stime);else /* CPUCLOCK_VIRT */ - t = cputime.utime; + t =nsecs_to_cputime (cputime.utime);if (cval < t)/* about to fire */
kernel/time/posix-cpu-timers.c +87 -123
529 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 18/37 posix-timers: Use TICK_NSEC instead of a dynamically ad-hoc calculated version
In reply to Frederic Weisbecker--- kernel/time/posix-cpu-timers.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
kernel/time/posix-cpu-timers.c +2 -9
@@ -890,8 +890,6 @@ static inline void stop_process_timers(struct signal_struct *sig)tick_dep_clear_signal (sig,TICK_DEP_BIT_POSIX_TIMER ); } -static u32 onecputick; -static void check_cpu_itimer (struct task_struct *tsk,struct cpu_itimer *it,unsigned long long *expires,unsigned long long cur_time,int signo)
@@ -903,9 +901,9 @@ static void check_cpu_itimer(struct task_struct *tsk, struct cpu_itimer *it,if (it->incr) { it->expires += it->incr; it->error += it->incr_error; -if (it->error >= onecputick) { +if (it->error >=TICK_NSEC ) { it->expires -= cputime_one_jiffy; - it->error -= onecputick; + it->error -=TICK_NSEC ; } }else { it->expires =0 ;
@@ -1476,15 +1474,10 @@ static __init int init_posix_cpu_timers(void) .clock_get = thread_cpu_clock_get, .timer_create = thread_cpu_timer_create, }; -struct timespec ts;posix_timers_register_clock (CLOCK_PROCESS_CPUTIME_ID , &process);posix_timers_register_clock (CLOCK_THREAD_CPUTIME_ID , &thread); -cputime_to_timespec (cputime_one_jiffy, &ts); - onecputick = ts.tv_nsec; -WARN_ON (ts.tv_sec !=0 ); -return 0 ; }__initcall (init_posix_cpu_timers);
Signature · 1 line
2.7.4
PATCH 11/37 isdn: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerNot sure if MISDN stats are ABI but it displays task cputime in cputime_t raw value regardless of what type cputime_t wraps which could be either jiffies, nsecs, usecs, or whatever random time unit. Plus it wrongly assumes that cputime_t is long.
Given that this dump is broken anyway, lets just display the nanosec value and stick with that.
--- drivers/isdn/mISDN/stack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/isdn/mISDN/stack.c +3 -3
@@ -203,7 +203,7 @@ mISDNStackd(void *data) {struct mISDNstack *st = data;#ifdef MISDN_MSG_STATS -cputime_t utime, stime; +u64 utime, stime;#endif int err =0 ;
@@ -306,9 +306,9 @@ mISDNStackd(void *data)"msg %d sleep %d stopped\n" ,dev_name (&st->dev->dev), st->msg_cnt, st->sleep_cnt, st->stopped_cnt); -task_cputime_t (st->thread, &utime, &stime); +task_cputime (st->thread, &utime, &stime);printk (KERN_DEBUG -"mISDNStackd daemon for %s utime(%ld) stime(%ld)\n" , +"mISDNStackd daemon for %s utime(%llu) stime(%llu)\n" ,dev_name (&st->dev->dev), utime, stime); printk(KERN_DEBUG "mISDNStackd daemon for %s nvcsw(%ld) nivcsw(%ld)\n",
Signature · 1 line
2.7.4
PATCH 16/37 signal: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- kernel/signal.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
kernel/signal.c +8 -8
@@ -1581,7 +1581,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig)unsigned long flags;struct sighand_struct *psig;bool autoreap = false; -cputime_t utime, stime; +u64 utime, stime;BUG_ON (sig ==-1 );
@@ -1619,9 +1619,9 @@ bool do_notify_parent(struct task_struct *tsk, int sig) task_uid(tsk));rcu_read_unlock (); -task_cputime_t (tsk, &utime, &stime); - info.si_utime =cputime_to_clock_t (utime +nsecs_to_cputime (tsk->signal->utime)); - info.si_stime =cputime_to_clock_t (stime +nsecs_to_cputime (tsk->signal->stime)); +task_cputime (tsk, &utime, &stime); + info.si_utime =nsec_to_clock_t (utime + tsk->signal->utime); + info.si_stime =nsec_to_clock_t (stime + tsk->signal->stime); info.si_status = tsk->exit_code &0x7f ;if (tsk->exit_code &0x80 )
@@ -1685,7 +1685,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk,unsigned long flags;struct task_struct *parent;struct sighand_struct *sighand; -cputime_t utime, stime; +u64 utime, stime;if (for_ptracer) { parent = tsk->parent;
@@ -1704,9 +1704,9 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, info.si_uid =from_kuid_munged (task_cred_xxx (parent, user_ns),task_uid (tsk));rcu_read_unlock (); -task_cputime_t (tsk, &utime, &stime); - info.si_utime =cputime_to_clock_t (utime); - info.si_stime =cputime_to_clock_t (stime); +task_cputime (tsk, &utime, &stime); + info.si_utime =nsec_to_clock_t (utime); + info.si_stime =nsec_to_clock_t (stime); info.si_code = why;switch (why) {
Signature · 1 line
2.7.4
PATCH 21/37 sched: Remove temporary cputime_t accessors
In reply to Frederic WeisbeckerNow that the whole cputime conversion to nsec units is complete, we can remove the compatibility accessors.
--- include/linux/sched.h | 40 ---------------------------------------- 1 file changed, 40 deletions(-)
include/linux/sched.h +0 -40
@@ -29,7 +29,6 @@ struct sched_param {#include <asm/page.h> #include <asm/ptrace.h> -#include <linux/cputime.h> #include <linux/smp.h> #include <linux/sem.h>
@@ -613,13 +612,6 @@ struct task_cputime {unsigned long long sum_exec_runtime; }; -/* Temporary type to ease cputime_t to nsecs conversion */ -struct task_cputime_t { -cputime_t utime; -cputime_t stime; -unsigned long long sum_exec_runtime; -}; -/* Alternate field names when used to cache expirations. */ #define virt_exp utime#define prof_exp stime
@@ -2291,27 +2283,6 @@ static inline void task_cputime_scaled(struct task_struct *t, }#endif -static inline void task_cputime_t (struct task_struct *t, -cputime_t *utime,cputime_t *stime) -{ -u64 ut, st; - -task_cputime (t, &ut, &st); - *utime =nsecs_to_cputime (ut); - *stime =nsecs_to_cputime (st); -} - -static inline void task_cputime_t_scaled (struct task_struct *t, -cputime_t *utimescaled, -cputime_t *stimescaled) -{ -u64 ut, st; - -task_cputime_scaled (t, &ut, &st); - *utimescaled =nsecs_to_cputime (ut); - *stimescaled =nsecs_to_cputime (st); -} -extern void task_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st);extern void thread_group_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st);
@@ -3528,17 +3499,6 @@ static __always_inline bool need_resched(void)void thread_group_cputime (struct task_struct *tsk,struct task_cputime *times);void thread_group_cputimer (struct task_struct *tsk,struct task_cputime *times); -static inline void thread_group_cputime_t (struct task_struct *tsk, -struct task_cputime_t *cputime) -{ -struct task_cputime times; - -thread_group_cputime (tsk, ×); - cputime->utime =nsecs_to_cputime (times.utime); - cputime->stime =nsecs_to_cputime (times.stime); - cputime->sum_exec_runtime = times.sum_exec_runtime; -} -/* * Reevaluate whether the task has signals pending delivery. * Wake the task if so.
Signature · 1 line
2.7.4
PATCH 25/37 cputime: Push time to account_system_time() in nsecs
In reply to Frederic WeisbeckerThis is one more step toward converting cputime accounting to pure nsecs.
--- arch/ia64/kernel/time.c | 11 ++++++----- arch/powerpc/kernel/time.c | 15 ++++++++------- arch/s390/kernel/idle.c | 2 +- arch/s390/kernel/vtime.c | 6 +++--- include/linux/kernel_stat.h | 7 +++---- kernel/sched/cputime.c | 39 +++++++++++++++++++-------------------- 6 files changed, 40 insertions(+), 40 deletions(-)
arch/ia64/kernel/time.c +6 -5
@@ -21,6 +21,7 @@#include <linux/timex.h> #include <linux/timekeeper_internal.h> #include <linux/platform_device.h> +#include <linux/cputime.h> #include <asm/machvec.h> #include <asm/delay.h>
@@ -64,29 +65,29 @@ extern cputime_t cycle_to_cputime(u64 cyc);void vtime_flush (struct task_struct *tsk) {struct thread_info *ti =task_thread_info (tsk); -cputime_t delta; +u64 delta;if (ti->utime)account_user_time (tsk,cputime_to_nsecs (cycle_to_cputime (ti->utime)));if (ti->gtime) -account_guest_time (tsk,cycle_to_cputime (ti->gtime)); +account_guest_time (tsk,cputime_to_nsecs (cycle_to_cputime (ti->gtime)));if (ti->idle_time)account_idle_time (cputime_to_nsecs (cycle_to_cputime (ti->idle_time)));if (ti->stime) { - delta =cycle_to_cputime (ti->stime); + delta =cputime_to_nsecs (cycle_to_cputime (ti->stime));account_system_index_time (tsk, delta,CPUTIME_SYSTEM ); }if (ti->hardirq_time) { - delta =cycle_to_cputime (ti->hardirq_time); + delta =cputime_to_nsecs (cycle_to_cputime (ti->hardirq_time));account_system_index_time (tsk, delta,CPUTIME_IRQ ); }if (ti->softirq_time) { - delta =cycle_to_cputime (ti->softirq_time); + delta =cputime_to_nsecs (cycle_to_cputime (ti->softirq_time));account_system_index_time (tsk, delta,CPUTIME_SOFTIRQ ); }
arch/powerpc/kernel/time.c +8 -7
@@ -57,6 +57,7 @@#include <linux/clk-provider.h> #include <linux/suspend.h> #include <linux/rtc.h> +#include <linux/cputime.h> #include <asm/trace.h> #include <asm/io.h>
@@ -72,7 +73,6 @@#include <asm/smp.h> #include <asm/vdso_datapage.h> #include <asm/firmware.h> -#include <asm/cputime.h> #include <asm/asm-prototypes.h> /* powerpc clocksource/clockevent code */
@@ -399,7 +399,7 @@ void vtime_flush(struct task_struct *tsk) tsk->utimescaled +=cputime_to_nsecs (acct->utime_scaled);if (acct->gtime) -account_guest_time (tsk, acct->gtime); +account_guest_time (tsk,cputime_to_nsecs (acct->gtime));if (acct->steal_time)account_steal_time (cputime_to_nsecs (acct->steal_time));
@@ -408,16 +408,17 @@ void vtime_flush(struct task_struct *tsk)account_idle_time (cputime_to_nsecs (acct->idle_time));if (acct->stime) -account_system_index_time (tsk, acct->stime,CPUTIME_SYSTEM ); - +account_system_index_time (tsk,cputime_to_nsecs (acct->stime), +CPUTIME_SYSTEM );if (acct->stime_scaled) tsk->stimescaled +=cputime_to_nsecs (acct->stime_scaled);if (acct->hardirq_time) -account_system_index_time (tsk, acct->hardirq_time,CPUTIME_IRQ ); - +account_system_index_time (tsk,cputime_to_nsecs (acct->hardirq_time), +CPUTIME_IRQ );if (acct->softirq_time) -account_system_index_time (tsk, acct->softirq_time,CPUTIME_SOFTIRQ ); +account_system_index_time (tsk,cputime_to_nsecs (acct->softirq_time), +CPUTIME_SOFTIRQ ); acct->utime =0 ; acct->utime_scaled =0 ;
arch/s390/kernel/idle.c +1 -1
@@ -12,7 +12,7 @@#include <linux/notifier.h> #include <linux/init.h> #include <linux/cpu.h> -#include <asm/cputime.h> +#include <linux/cputime.h> #include <asm/nmi.h> #include <asm/smp.h> #include "entry.h"
arch/s390/kernel/vtime.c +3 -3
@@ -6,13 +6,13 @@*/ #include <linux/kernel_stat.h> +#include <linux/cputime.h> #include <linux/export.h> #include <linux/kernel.h> #include <linux/timex.h> #include <linux/types.h> #include <linux/time.h> -#include <asm/cputime.h> #include <asm/vtimer.h> #include <asm/vtime.h> #include <asm/cpu_mf.h>
@@ -115,7 +115,7 @@ static void account_system_index_scaled(struct task_struct *p, enum cpu_usage_stat index) { p->stimescaled +=cputime_to_nsecs (scaled); -account_system_index_time (p, cputime, index); +account_system_index_time (p,cputime_to_nsecs (cputime), index); }/*
@@ -171,7 +171,7 @@ static int do_account_vtime(struct task_struct *tsk) }if (guest) { -account_guest_time (tsk, guest); +account_guest_time (tsk,cputime_to_nsecs (guest)); tsk->utimescaled +=cputime_to_nsecs (scale_vtime (guest)); }
include/linux/kernel_stat.h +3 -4
@@ -9,7 +9,6 @@#include <linux/sched.h> #include <linux/vtime.h> #include <asm/irq.h> -#include <linux/cputime.h> /* * 'kernel_stat.h' contains the definitions needed for doing
@@ -79,9 +78,9 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) }extern void account_user_time (struct task_struct *,u64 ); -extern void account_guest_time (struct task_struct *,cputime_t ); -extern void account_system_time (struct task_struct *,int ,cputime_t ); -extern void account_system_index_time (struct task_struct *,cputime_t , +extern void account_guest_time (struct task_struct *,u64 ); +extern void account_system_time (struct task_struct *,int ,u64 ); +extern void account_system_index_time (struct task_struct *,u64 ,enum cpu_usage_stat );extern void account_steal_time (u64 );extern void account_idle_time (u64 );
kernel/sched/cputime.c +19 -20
@@ -4,6 +4,7 @@#include <linux/kernel_stat.h> #include <linux/static_key.h> #include <linux/context_tracking.h> +#include <linux/cputime.h> #include "sched.h" #ifdef CONFIG_PARAVIRT #include <asm/paravirt.h>
@@ -138,22 +139,22 @@ void account_user_time(struct task_struct *p, u64 cputime)* @p: the process that the cpu time gets accounted to * @cputime: the cpu time spent in virtual machine since the last update */ -void account_guest_time (struct task_struct *p,cputime_t cputime) +void account_guest_time (struct task_struct *p,u64 cputime) {u64 *cpustat = kcpustat_this_cpu->cpustat;/* Add guest time to process. */ - p->utime +=cputime_to_nsecs (cputime); -account_group_user_time (p,cputime_to_nsecs (cputime)); - p->gtime +=cputime_to_nsecs (cputime); + p->utime += cputime; +account_group_user_time (p, cputime); + p->gtime += cputime;/* Add guest time to cpustat. */ if (task_nice (p) >0 ) { - cpustat[CPUTIME_NICE ] +=cputime_to_nsecs (cputime); - cpustat[CPUTIME_GUEST_NICE ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_NICE ] += cputime; + cpustat[CPUTIME_GUEST_NICE ] += cputime; }else { - cpustat[CPUTIME_USER ] +=cputime_to_nsecs (cputime); - cpustat[CPUTIME_GUEST ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_USER ] += cputime; + cpustat[CPUTIME_GUEST ] += cputime; } }
@@ -164,14 +165,14 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)* @index: pointer to cpustat field that has to be updated */ void account_system_index_time (struct task_struct *p, -cputime_t cputime,enum cpu_usage_stat index) +u64 cputime,enum cpu_usage_stat index) {/* Add system time to process. */ - p->stime +=cputime_to_nsecs (cputime); -account_group_system_time (p,cputime_to_nsecs (cputime)); + p->stime += cputime; +account_group_system_time (p, cputime);/* Add system time to cpustat. */ -task_group_account_field (p, index,cputime_to_nsecs (cputime)); +task_group_account_field (p, index, cputime);/* Account for system time used */ acct_account_cputime (p);
@@ -183,8 +184,7 @@ void account_system_index_time(struct task_struct *p,* @hardirq_offset: the offset to subtract from hardirq_count() * @cputime: the cpu time spent in kernel space since the last update */ -void account_system_time (struct task_struct *p,int hardirq_offset, -cputime_t cputime) +void account_system_time (struct task_struct *p,int hardirq_offset,u64 cputime) {int index;
@@ -388,16 +388,15 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,* So, we have to handle it separately here. * Also, p->stime needs to be updated for ksoftirqd. */ -account_system_index_time (p, old_cputime,CPUTIME_SOFTIRQ ); +account_system_index_time (p, cputime,CPUTIME_SOFTIRQ ); }else if (user_tick) {account_user_time (p, cputime); }else if (p == rq->idle) {account_idle_time (cputime); }else if (p->flags &PF_VCPU ) {/* System time or guest time */ - -account_guest_time (p, old_cputime); +account_guest_time (p, cputime); }else { -account_system_index_time (p, old_cputime,CPUTIME_SYSTEM ); +account_system_index_time (p, cputime,CPUTIME_SYSTEM ); } }
@@ -502,7 +501,7 @@ void account_process_tick(struct task_struct *p, int user_tick)if (user_tick)account_user_time (p, cputime);else if ((p != rq->idle) || (irq_count () !=HARDIRQ_OFFSET )) -account_system_time (p,HARDIRQ_OFFSET , old_cputime); +account_system_time (p,HARDIRQ_OFFSET , cputime);else account_idle_time (cputime); }
@@ -722,7 +721,7 @@ static void __vtime_account_system(struct task_struct *tsk) {cputime_t delta_cpu =get_vtime_delta (tsk); -account_system_time (tsk,irq_count (), delta_cpu); +account_system_time (tsk,irq_count (),cputime_to_nsecs (delta_cpu)); }void vtime_account_system (struct task_struct *tsk)
Signature · 1 line
2.7.4
PATCH 26/37 cputime: Complete nsec conversion of tick based accounting
In reply to Frederic WeisbeckerThis is the final step toward tick based cputime conversion. Now that whole cputime accounting engine accounts in nsecs, we can convert the very source of the cputime to account into nsec.
--- kernel/sched/cputime.c | 52 +++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 30 deletions(-)
kernel/sched/cputime.c +22 -30
@@ -75,14 +75,13 @@ void irqtime_account_irq(struct task_struct *curr) }EXPORT_SYMBOL_GPL (irqtime_account_irq); -static cputime_t irqtime_tick_accounted (cputime_t maxtime) +static u64 irqtime_tick_accounted (u64 maxtime) {struct irqtime *irqtime =this_cpu_ptr (&cpu_irqtime); -cputime_t delta; +u64 delta; - delta =nsecs_to_cputime (irqtime->tick_delta); - delta =min (delta, maxtime); - irqtime->tick_delta -=cputime_to_nsecs (delta); + delta =min (irqtime->tick_delta, maxtime); + irqtime->tick_delta -= delta;return delta; }
@@ -91,7 +90,7 @@ static cputime_t irqtime_tick_accounted(cputime_t maxtime)#define sched_clock_irqtime (0) -static cputime_t irqtime_tick_accounted (cputime_t dummy) +static u64 irqtime_tick_accounted (u64 dummy) {return 0 ; }
@@ -234,22 +233,19 @@ void account_idle_time(u64 cputime)* ticks are not redelivered later. Due to that, this function may on * occasion account more time than the calling functions think elapsed. */ -static __always_inline cputime_t steal_account_process_time(cputime_t maxtime) +static __always_inline u64 steal_account_process_time(u64 maxtime) {#ifdef CONFIG_PARAVIRT if (static_key_false (¶virt_steal_enabled)) { -cputime_t steal_cputime; -u64 steal, rounded; +u64 steal; steal =paravirt_steal_clock (smp_processor_id ()); steal -=this_rq ()->prev_steal_time; + steal =min (steal, maxtime); +account_steal_time (steal); +this_rq ()->prev_steal_time += steal; - steal_cputime =min (nsecs_to_cputime (steal), maxtime); - rounded =cputime_to_nsecs (steal_cputime); -account_steal_time (rounded); -this_rq ()->prev_steal_time += rounded; - -return steal_cputime; +return steal; }#endif return 0 ;
@@ -258,9 +254,9 @@ static __always_inline cputime_t steal_account_process_time(cputime_t maxtime)/* * Account how much elapsed time was spent in steal, irq, or softirq time. */ -static inline cputime_t account_other_time (cputime_t max) +static inline u64 account_other_time (u64 max) { -cputime_t accounted; +u64 accounted;/* Shall be converted to a lockdep-enabled lightweight check */ WARN_ON_ONCE (!irqs_disabled ());
@@ -364,9 +360,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)static void irqtime_account_process_tick (struct task_struct *p,int user_tick,struct rq *rq,int ticks) { -u64 old_cputime = (__force u64 ) cputime_one_jiffy * ticks; -cputime_t other; -u64 cputime; +u64 other, cputime =TICK_NSEC * ticks;/* * When returning from idle, many ticks can get accounted at
@@ -376,11 +370,10 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,* other time can exceed ticks occasionally. */ other =account_other_time (ULONG_MAX ); -if (other >= old_cputime) +if (other >= cputime)return ; - old_cputime -= other; - cputime =cputime_to_nsecs (old_cputime); + cputime -= other;if (this_cpu_ksoftirqd () == p) {/*
@@ -477,8 +470,7 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)*/ void account_process_tick (struct task_struct *p,int user_tick) { -cputime_t old_cputime, steal; -u64 cputime; +u64 cputime, steal;struct rq *rq =this_rq ();if (vtime_accounting_cpu_enabled ())
@@ -489,14 +481,13 @@ void account_process_tick(struct task_struct *p, int user_tick)return ; } - old_cputime = cputime_one_jiffy; + cputime =TICK_NSEC ; steal =steal_account_process_time (ULONG_MAX ); -if (steal >= old_cputime) +if (steal >= cputime)return ; - old_cputime -= steal; - cputime =cputime_to_nsecs (old_cputime); + cputime -= steal;if (user_tick)account_user_time (p, cputime);
@@ -520,7 +511,7 @@ void account_idle_ticks(unsigned long ticks) } cputime = ticks *TICK_NSEC ; - steal =cputime_to_nsecs (steal_account_process_time (ULONG_MAX )); + steal =steal_account_process_time (ULONG_MAX );if (steal >= cputime)return ;
@@ -741,6 +732,7 @@ void vtime_account_user(struct task_struct *tsk)write_seqcount_begin (&tsk->vtime_seqcount); tsk->vtime_snap_whence =VTIME_SYS ;if (vtime_delta (tsk)) { +u64 nsecs; delta_cpu =get_vtime_delta (tsk);account_user_time (tsk,cputime_to_nsecs (delta_cpu)); }
Signature · 1 line
2.7.4
PATCH 28/37 cputime: Remove jiffies based cputime
In reply to Frederic WeisbeckerThis cputime_t implementation is now unused, we can remove it.
--- include/asm-generic/cputime.h | 4 -- include/asm-generic/cputime_jiffies.h | 75 ----------------------------------- 2 files changed, 79 deletions(-) delete mode 100644 include/asm-generic/cputime_jiffies.h
include/asm-generic/cputime.h +0 -4
@@ -4,10 +4,6 @@#include <linux/time.h> #include <linux/jiffies.h> -#ifndef CONFIG_VIRT_CPU_ACCOUNTING -# include <asm-generic/cputime_jiffies.h> -#endif -#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN # include <asm-generic/cputime_nsecs.h> #endif
include/asm-generic/cputime_jiffies.h deleted +0 -75
75 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 27/37 vtime: Return nsecs instead of cputime_t to account
In reply to Frederic WeisbeckerTurn the full dynticks cputime clock source to return nsec while keeping its very internals jiffies based for performance reasons.
--- kernel/sched/cputime.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-)
kernel/sched/cputime.c +11 -20
@@ -678,20 +678,20 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)#endif /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN -static cputime_t vtime_delta (struct task_struct *tsk) +static u64 vtime_delta (struct task_struct *tsk) {unsigned long now =READ_ONCE (jiffies);if (time_before (now, (unsigned long )tsk->vtime_snap))return 0 ; -return jiffies_to_cputime (now - tsk->vtime_snap); +return jiffies_to_nsecs (now - tsk->vtime_snap); } -static cputime_t get_vtime_delta (struct task_struct *tsk) +static u64 get_vtime_delta (struct task_struct *tsk) {unsigned long now =READ_ONCE (jiffies); -cputime_t delta, other; +u64 delta, other;/* * Unlike tick based timing, vtime based timing never has lost
@@ -700,7 +700,7 @@ static cputime_t get_vtime_delta(struct task_struct *tsk)* elapsed time. Limit account_other_time to prevent rounding * errors from causing elapsed vtime to go negative. */ - delta =jiffies_to_cputime (now - tsk->vtime_snap); + delta =jiffies_to_nsecs (now - tsk->vtime_snap); other =account_other_time (delta);WARN_ON_ONCE (tsk->vtime_snap_whence ==VTIME_INACTIVE ); tsk->vtime_snap = now;
@@ -710,9 +710,7 @@ static cputime_t get_vtime_delta(struct task_struct *tsk)static void __vtime_account_system (struct task_struct *tsk) { -cputime_t delta_cpu =get_vtime_delta (tsk); - -account_system_time (tsk,irq_count (),cputime_to_nsecs (delta_cpu)); +account_system_time (tsk,irq_count (),get_vtime_delta (tsk)); }void vtime_account_system (struct task_struct *tsk)
@@ -727,15 +725,10 @@ void vtime_account_system(struct task_struct *tsk)void vtime_account_user (struct task_struct *tsk) { -cputime_t delta_cpu; -write_seqcount_begin (&tsk->vtime_seqcount); tsk->vtime_snap_whence =VTIME_SYS ; -if (vtime_delta (tsk)) { -u64 nsecs; - delta_cpu =get_vtime_delta (tsk); -account_user_time (tsk,cputime_to_nsecs (delta_cpu)); - } +if (vtime_delta (tsk)) +account_user_time (tsk,get_vtime_delta (tsk));write_seqcount_end (&tsk->vtime_seqcount); }
@@ -776,9 +769,7 @@ EXPORT_SYMBOL_GPL(vtime_guest_exit);void vtime_account_idle (struct task_struct *tsk) { -cputime_t delta_cpu =get_vtime_delta (tsk); - -account_idle_time (cputime_to_nsecs (delta_cpu)); +account_idle_time (get_vtime_delta (tsk)); }void arch_vtime_task_switch (struct task_struct *prev)
@@ -818,7 +809,7 @@ u64 task_gtime(struct task_struct *t) gtime = t->gtime;if (t->vtime_snap_whence ==VTIME_SYS && t->flags &PF_VCPU ) - gtime +=cputime_to_nsecs (vtime_delta (t)); + gtime +=vtime_delta (t); }while (read_seqcount_retry (&t->vtime_seqcount, seq));
@@ -851,7 +842,7 @@ void task_cputime(struct task_struct *t, u64 *utime, u64 *stime)if (t->vtime_snap_whence ==VTIME_INACTIVE ||is_idle_task (t))continue ; - delta =cputime_to_nsecs (vtime_delta (t)); + delta =vtime_delta (t);/* * Task runs either in user or kernel space, add pending nohz time to
Signature · 1 line
2.7.4
PATCH 32/37 s390: Make arch_cpu_idle_time() to return nsecs
In reply to Frederic WeisbeckerThis way we don't need to deal with cputime_t details from the core code.
--- arch/s390/include/asm/cputime.h | 2 +- arch/s390/kernel/idle.c | 5 +++-- fs/proc/stat.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)
arch/s390/include/asm/cputime.h +1 -1
@@ -141,7 +141,7 @@ static inline clock_t cputime64_to_clock_t(cputime64_t cputime)return clock; } -cputime64_t arch_cpu_idle_time (int cpu); +u64 arch_cpu_idle_time (int cpu);#define arch_idle_time (cpu) arch_cpu_idle_time(cpu)
arch/s390/kernel/idle.c +3 -2
@@ -84,7 +84,7 @@ static ssize_t show_idle_time(struct device *dev, }DEVICE_ATTR (idle_time_us,0444 , show_idle_time,NULL ); -cputime64_t arch_cpu_idle_time (int cpu) +u64 arch_cpu_idle_time (int cpu) {struct s390_idle_data *idle = &per_cpu (s390_idle, cpu);unsigned long long now, idle_enter, idle_exit;
@@ -96,7 +96,8 @@ cputime64_t arch_cpu_idle_time(int cpu) idle_enter =ACCESS_ONCE (idle->clock_idle_enter); idle_exit =ACCESS_ONCE (idle->clock_idle_exit); }while (read_seqcount_retry (&idle->seqcount, seq)); -return idle_enter ? ((idle_exit ?: now) - idle_enter) :0 ; + +return cputime_to_nsecs (idle_enter ? ((idle_exit ?: now) - idle_enter) :0 ); }void arch_cpu_idle_enter (void )
fs/proc/stat.c +2 -2
@@ -27,7 +27,7 @@ static u64 get_idle_time(int cpu) idle =kcpustat_cpu (cpu).cpustat[CPUTIME_IDLE ];if (cpu_online (cpu) && !nr_iowait_cpu (cpu)) - idle +=cputime_to_nsecs (arch_idle_time (cpu)); + idle +=arch_idle_time (cpu);return idle; }
@@ -37,7 +37,7 @@ static u64 get_iowait_time(int cpu) iowait =kcpustat_cpu (cpu).cpustat[CPUTIME_IOWAIT ];if (cpu_online (cpu) &&nr_iowait_cpu (cpu)) - iowait +=cputime_to_nsecs (arch_idle_time (cpu)); + iowait +=arch_idle_time (cpu);return iowait; }
Signature · 1 line
2.7.4
PATCH 36/37 cputime: Remove asm generic headers
In reply to Frederic Weisbeckercputime_t is now only used by two archs:
* powerpc (when CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y)
* s390
And since the core doesn't use it anymore, we don't need any arch support from the others. So we can remove their stub implementations.
A final cleanup would be to provide an efficient pure arch implementation of cputime_to_nsec() for s390 and powerpc and finally remove include/linux/cputime.h .
--- arch/alpha/include/asm/Kbuild | 1 - arch/arc/include/asm/Kbuild | 1 - arch/arm/include/asm/Kbuild | 1 - arch/arm64/include/asm/Kbuild | 1 - arch/avr32/include/asm/Kbuild | 1 - arch/blackfin/include/asm/Kbuild | 1 - arch/c6x/include/asm/Kbuild | 1 - arch/cris/include/asm/Kbuild | 1 - arch/frv/include/asm/Kbuild | 1 - arch/h8300/include/asm/Kbuild | 1 - arch/hexagon/include/asm/Kbuild | 1 - arch/ia64/include/asm/cputime.h | 4 +--- arch/m32r/include/asm/Kbuild | 1 - arch/m68k/include/asm/Kbuild | 1 - arch/metag/include/asm/Kbuild | 1 - arch/microblaze/include/asm/Kbuild | 1 - arch/mips/include/asm/Kbuild | 1 - arch/mn10300/include/asm/Kbuild | 1 - arch/nios2/include/asm/Kbuild | 1 - arch/openrisc/include/asm/Kbuild | 1 - arch/parisc/include/asm/Kbuild | 1 - arch/powerpc/include/asm/cputime.h | 4 +--- arch/score/include/asm/Kbuild | 1 - arch/sh/include/asm/Kbuild | 1 - arch/sparc/include/asm/Kbuild | 1 - arch/tile/include/asm/Kbuild | 1 - arch/um/include/asm/Kbuild | 1 - arch/unicore32/include/asm/Kbuild | 1 - arch/x86/include/asm/Kbuild | 1 - arch/xtensa/include/asm/Kbuild | 1 - include/asm-generic/cputime.h | 7 ------- include/linux/cputime.h | 2 ++ 32 files changed, 4 insertions(+), 41 deletions(-) delete mode 100644 include/asm-generic/cputime.h
arch/alpha/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += clkdev.h -generic-y += cputime.h generic-y += exec.h generic-y += export.h generic-y += irq_work.h
arch/arc/include/asm/Kbuild +0 -1
@@ -2,7 +2,6 @@ generic-y += auxvec.h generic-y += bitsperlong.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += device.h generic-y += div64.h generic-y += emergency-restart.h
arch/arm/include/asm/Kbuild +0 -1
@@ -2,7 +2,6 @@ generic-y += bitsperlong.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += early_ioremap.h generic-y += emergency-restart.h
arch/arm64/include/asm/Kbuild +0 -1
@@ -1,6 +1,5 @@ generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += delay.h generic-y += div64.h generic-y += dma.h
arch/avr32/include/asm/Kbuild +0 -1
@@ -1,6 +1,5 @@ generic-y += clkdev.h -generic-y += cputime.h generic-y += delay.h generic-y += device.h generic-y += div64.h
arch/blackfin/include/asm/Kbuild +0 -1
@@ -2,7 +2,6 @@ generic-y += auxvec.h generic-y += bitsperlong.h generic-y += bugs.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += div64.h
arch/c6x/include/asm/Kbuild +0 -1
@@ -5,7 +5,6 @@ generic-y += barrier.h generic-y += bitsperlong.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += div64.h
arch/cris/include/asm/Kbuild +0 -1
@@ -4,7 +4,6 @@ generic-y += barrier.h generic-y += bitsperlong.h generic-y += clkdev.h generic-y += cmpxchg.h -generic-y += cputime.h generic-y += device.h generic-y += div64.h generic-y += errno.h
arch/frv/include/asm/Kbuild +0 -1
@@ -1,6 +1,5 @@ generic-y += clkdev.h -generic-y += cputime.h generic-y += exec.h generic-y += irq_work.h generic-y += mcs_spinlock.h
arch/h8300/include/asm/Kbuild +0 -1
@@ -5,7 +5,6 @@ generic-y += bugs.h generic-y += cacheflush.h generic-y += checksum.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += delay.h generic-y += device.h
arch/hexagon/include/asm/Kbuild +0 -1
@@ -6,7 +6,6 @@ generic-y += barrier.h generic-y += bug.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += div64.h
arch/ia64/include/asm/cputime.h +1 -3
@@ -18,9 +18,7 @@#ifndef __IA64_CPUTIME_H#define __IA64_CPUTIME_H -#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE -# include <asm-generic/cputime.h> -#else +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE extern void arch_vtime_task_switch (struct task_struct *tsk);#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
arch/m32r/include/asm/Kbuild +0 -1
@@ -1,6 +1,5 @@ generic-y += clkdev.h -generic-y += cputime.h generic-y += exec.h generic-y += irq_work.h generic-y += kvm_para.h
arch/m68k/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += barrier.h generic-y += bitsperlong.h generic-y += clkdev.h -generic-y += cputime.h generic-y += device.h generic-y += emergency-restart.h generic-y += errno.h
arch/metag/include/asm/Kbuild +0 -1
@@ -2,7 +2,6 @@ generic-y += auxvec.h generic-y += bitsperlong.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += dma.h
arch/microblaze/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += barrier.h generic-y += clkdev.h -generic-y += cputime.h generic-y += device.h generic-y += exec.h generic-y += irq_work.h
arch/mips/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ # MIPS headers generic-(CONFIG_GENERIC_CSUM) += checksum.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += dma-contiguous.h generic-y += emergency-restart.h
arch/mn10300/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += barrier.h generic-y += clkdev.h -generic-y += cputime.h generic-y += exec.h generic-y += irq_work.h generic-y += mcs_spinlock.h
arch/nios2/include/asm/Kbuild +0 -1
@@ -6,7 +6,6 @@ generic-y += bitsperlong.h generic-y += bug.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += div64.h
arch/openrisc/include/asm/Kbuild +0 -1
@@ -12,7 +12,6 @@ generic-y += checksum.h generic-y += clkdev.h generic-y += cmpxchg-local.h generic-y += cmpxchg.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += div64.h
arch/parisc/include/asm/Kbuild +0 -1
@@ -2,7 +2,6 @@ generic-y += auxvec.h generic-y += barrier.h generic-y += clkdev.h -generic-y += cputime.h generic-y += device.h generic-y += div64.h generic-y += emergency-restart.h
arch/powerpc/include/asm/cputime.h +1 -3
@@ -16,9 +16,7 @@#ifndef __POWERPC_CPUTIME_H#define __POWERPC_CPUTIME_H -#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE -#include <asm-generic/cputime.h> -#else +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE #include <linux/types.h> #include <linux/time.h>
arch/score/include/asm/Kbuild +0 -1
@@ -4,7 +4,6 @@ header-y += generic-y += barrier.h generic-y += clkdev.h -generic-y += cputime.h generic-y += irq_work.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h
arch/sh/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += bitsperlong.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += delay.h generic-y += div64.h
arch/sparc/include/asm/Kbuild +0 -1
@@ -2,7 +2,6 @@ generic-y += clkdev.h -generic-y += cputime.h generic-y += div64.h generic-y += emergency-restart.h generic-y += exec.h
arch/tile/include/asm/Kbuild +0 -1
@@ -4,7 +4,6 @@ header-y += ../arch/ generic-y += bug.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += div64.h generic-y += emergency-restart.h generic-y += errno.h
arch/um/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += barrier.h generic-y += bug.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += delay.h generic-y += device.h
arch/unicore32/include/asm/Kbuild +0 -1
@@ -4,7 +4,6 @@ generic-y += auxvec.h generic-y += bitsperlong.h generic-y += bugs.h generic-y += clkdev.h -generic-y += cputime.h generic-y += current.h generic-y += device.h generic-y += div64.h
arch/x86/include/asm/Kbuild +0 -1
@@ -7,7 +7,6 @@ generated-y += unistd_64_x32.h generated-y += xen-hypercalls.h generic-y += clkdev.h -generic-y += cputime.h generic-y += dma-contiguous.h generic-y += early_ioremap.h generic-y += mcs_spinlock.h
arch/xtensa/include/asm/Kbuild +0 -1
@@ -1,7 +1,6 @@ generic-y += bitsperlong.h generic-y += bug.h generic-y += clkdev.h -generic-y += cputime.h generic-y += div64.h generic-y += dma-contiguous.h generic-y += emergency-restart.h
include/asm-generic/cputime.h deleted +0 -7
@@ -1,7 +0,0 @@ -#ifndef _ASM_GENERIC_CPUTIME_H -#define _ASM_GENERIC_CPUTIME_H - -#include <linux/time.h> -#include <linux/jiffies.h> - -#endif
include/linux/cputime.h +2 -0
@@ -1,6 +1,7 @@#ifndef __LINUX_CPUTIME_H#define __LINUX_CPUTIME_H +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE #include <asm/cputime.h> #ifndef cputime_to_nsecs
@@ -8,4 +9,5 @@ (cputime_to_usecs(__ct) * NSEC_PER_USEC)#endif +#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ #endif /* __LINUX_CPUTIME_H */
Signature · 1 line
2.7.4
PATCH 35/37 cputime: Remove unused nsec_to_cputime
In reply to Frederic WeisbeckerIt's unused now.
--- include/linux/cputime.h | 5 ----- 1 file changed, 5 deletions(-)
include/linux/cputime.h +0 -5
@@ -8,9 +8,4 @@ (cputime_to_usecs(__ct) * NSEC_PER_USEC)#endif -#ifndef nsecs_to_cputime -# define nsecs_to_cputime (__nsecs) \ - usecs_to_cputime((__nsecs) / NSEC_PER_USEC) -#endif -#endif /* __LINUX_CPUTIME_H */
Signature · 1 line
2.7.4
PATCH 37/37 s390: Prevent from cputime leaks
In reply to Frederic WeisbeckerThe s390 clock has a higher granularity than nanoseconds. 1 nanosec equals 4.096 in s390 cputime_t. Therefore we leak a remainder while flushing the cputime through cputime_to_nsecs().
For more precision, make sure we keep that remainder on cputime accumulators for later accounting.
--- arch/s390/include/asm/cputime.h | 4 ++++ arch/s390/kernel/vtime.c | 33 +++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-)
arch/s390/include/asm/cputime.h +4 -0
@@ -33,6 +33,10 @@ static inline unsigned int cputime_to_usecs(const cputime_t cputime)return (__force unsigned long long ) cputime >>12 ; } +static inline cputime_t nsecs_to_cputime (u64 cputime) +{ +return (__force cputime_t ) cputime *CPUTIME_PER_USEC *NSEC_PER_USEC ; +}u64 arch_cpu_idle_time (int cpu);
arch/s390/kernel/vtime.c +21 -12
@@ -94,8 +94,14 @@ static inline u64 update_tsk_timer(unsigned long *tsk_vtime, u64 new) {u64 delta; - delta = new - *tsk_vtime; - *tsk_vtime = new; +/* +* Since nsecs is less granular than cputime_t in s390, +* the conversion to nsecs is rounded. Make sure we don't +* lose the remainder. +*/ + delta =cputime_to_nsecs (new - *tsk_vtime); + *tsk_vtime +=nsecs_to_cputime (delta); +return delta; }
@@ -124,7 +130,8 @@ static void account_system_index_scaled(struct task_struct *p,*/ static int do_account_vtime (struct task_struct *tsk) { -u64 timer, clock, user, guest, system, hardirq, softirq, steal; +u64 timer, clock, delta; +u64 user, guest, system, hardirq, softirq, steal; timer = S390_lowcore.last_update_timer; clock = S390_lowcore.last_update_clock;
@@ -161,18 +168,19 @@ static int do_account_vtime(struct task_struct *tsk) READ_ONCE(S390_lowcore.hardirq_timer)); softirq =update_tsk_timer (&tsk->thread.softirq_timer,READ_ONCE (S390_lowcore.softirq_timer)); - S390_lowcore.steal_timer += - clock - user - guest - system - hardirq - softirq; + + delta =nsecs_to_cputime (user + guest + system + hardirq + softirq); + S390_lowcore.steal_timer += clock - delta;/* Push account value */ if (user) { -account_user_time (tsk,cputime_to_nsecs (user)); - tsk->utimescaled +=cputime_to_nsecs (scale_vtime (user)); +account_user_time (tsk, user); + tsk->utimescaled +=scale_vtime (user); }if (guest) { -account_guest_time (tsk,cputime_to_nsecs (guest)); - tsk->utimescaled +=cputime_to_nsecs (scale_vtime (guest)); +account_guest_time (tsk, guest); + tsk->utimescaled +=scale_vtime (guest); }if (system)
@@ -187,11 +195,12 @@ static int do_account_vtime(struct task_struct *tsk) steal = S390_lowcore.steal_timer;if ((s64 ) steal >0 ) { - S390_lowcore.steal_timer =0 ; -account_steal_time (cputime_to_nsecs (steal)); +u64 nsecs =cputime_to_nsecs (steal); + S390_lowcore.steal_timer -=nsecs_to_cputime (nsecs); +account_steal_time (nsecs); } -return virt_timer_forward (user + guest + system + hardirq + softirq); +return virt_timer_forward (delta); }void vtime_task_switch (struct task_struct *prev)
Signature · 1 line
2.7.4
PATCH 34/37 s390: Remove unused cputime definitions
In reply to Frederic WeisbeckerSince the core doesn't deal with cputime_t anymore, most of these APIs have been left unused. Lets remove these.
--- arch/s390/include/asm/cputime.h | 107 ---------------------------------------- 1 file changed, 107 deletions(-)
arch/s390/include/asm/cputime.h +0 -107
@@ -25,33 +25,6 @@ static inline unsigned long __div(unsigned long long n, unsigned long base)return n / base; } -#define cputime_one_jiffy jiffies_to_cputime(1) - -/* -* Convert cputime to jiffies and back. -*/ -static inline unsigned long cputime_to_jiffies (const cputime_t cputime) -{ -return __div ((__force unsigned long long ) cputime,CPUTIME_PER_SEC /HZ ); -} - -static inline cputime_t jiffies_to_cputime (const unsigned int jif) -{ -return (__force cputime_t)(jif * (CPUTIME_PER_SEC /HZ )); -} - -static inline u64 cputime64_to_jiffies64 (cputime64_t cputime) -{ -unsigned long long jif = (__force unsigned long long ) cputime; -do_div (jif,CPUTIME_PER_SEC /HZ ); -return jif; -} - -static inline cputime64_t jiffies64_to_cputime64 (const u64 jif) -{ -return (__force cputime64_t)(jif * (CPUTIME_PER_SEC /HZ )); -} -/* * Convert cputime to microseconds and back. */
@@ -60,86 +33,6 @@ static inline unsigned int cputime_to_usecs(const cputime_t cputime)return (__force unsigned long long ) cputime >>12 ; } -static inline cputime_t usecs_to_cputime (const unsigned int m) -{ -return (__force cputime_t)(m *CPUTIME_PER_USEC ); -} - -#define usecs_to_cputime64 (m) usecs_to_cputime(m) - -/* -* Convert cputime to milliseconds and back. -*/ -static inline unsigned int cputime_to_secs (const cputime_t cputime) -{ -return __div ((__force unsigned long long ) cputime,CPUTIME_PER_SEC /2 ) >>1 ; -} - -static inline cputime_t secs_to_cputime (const unsigned int s) -{ -return (__force cputime_t)(s *CPUTIME_PER_SEC ); -} - -/* -* Convert cputime to timespec and back. -*/ -static inline cputime_t timespec_to_cputime (const struct timespec *value) -{ -unsigned long long ret = value->tv_sec *CPUTIME_PER_SEC ; -return (__force cputime_t)(ret +__div (value->tv_nsec *CPUTIME_PER_USEC ,NSEC_PER_USEC )); -} - -static inline void cputime_to_timespec (const cputime_t cputime, -struct timespec *value) -{ -unsigned long long __cputime = (__force unsigned long long ) cputime; - value->tv_nsec = (__cputime %CPUTIME_PER_SEC ) *NSEC_PER_USEC /CPUTIME_PER_USEC ; - value->tv_sec = __cputime /CPUTIME_PER_SEC ; -} - -/* -* Convert cputime to timeval and back. -* Since cputime and timeval have the same resolution (microseconds) -* this is easy. -*/ -static inline cputime_t timeval_to_cputime (const struct timeval *value) -{ -unsigned long long ret = value->tv_sec *CPUTIME_PER_SEC ; -return (__force cputime_t)(ret + value->tv_usec *CPUTIME_PER_USEC ); -} - -static inline void cputime_to_timeval (const cputime_t cputime, -struct timeval *value) -{ -unsigned long long __cputime = (__force unsigned long long ) cputime; - value->tv_usec = (__cputime %CPUTIME_PER_SEC ) /CPUTIME_PER_USEC ; - value->tv_sec = __cputime /CPUTIME_PER_SEC ; -} - -/* -* Convert cputime to clock and back. -*/ -static inline clock_t cputime_to_clock_t (cputime_t cputime) -{ -unsigned long long clock = (__force unsigned long long ) cputime; -do_div (clock,CPUTIME_PER_SEC /USER_HZ ); -return clock; -} - -static inline cputime_t clock_t_to_cputime (unsigned long x) -{ -return (__force cputime_t)(x * (CPUTIME_PER_SEC /USER_HZ )); -} - -/* -* Convert cputime64 to clock. -*/ -static inline clock_t cputime64_to_clock_t (cputime64_t cputime) -{ -unsigned long long clock = (__force unsigned long long ) cputime; -do_div (clock,CPUTIME_PER_SEC /USER_HZ ); -return clock; -}u64 arch_cpu_idle_time (int cpu);
Signature · 1 line
2.7.4
PATCH 33/37 powerpc: Remove unused cputime definitions
In reply to Frederic WeisbeckerSince the core doesn't deal with cputime_t anymore, most of these APIs have been left unused. Lets remove these.
--- arch/powerpc/include/asm/cputime.h | 173 ------------------------------------- arch/powerpc/kernel/time.c | 20 +---- 2 files changed, 2 insertions(+), 191 deletions(-)
arch/powerpc/include/asm/cputime.h +0 -173
@@ -18,9 +18,6 @@#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE #include <asm-generic/cputime.h> -#ifdef __KERNEL__ -static inline void setup_cputime_one_jiffy (void ) { } -#endif #else #include <linux/types.h>
@@ -36,65 +33,6 @@ typedef u64 __nocast cputime64_t;#define cmpxchg_cputime (ptr, old, new) cmpxchg(ptr, old, new)#ifdef __KERNEL__ - -/* -* One jiffy in timebase units computed during initialization -*/ -extern cputime_t cputime_one_jiffy; - -/* -* Convert cputime <-> jiffies -*/ -extern u64 __cputime_jiffies_factor; - -static inline unsigned long cputime_to_jiffies (const cputime_t ct) -{ -return mulhdu ((__force u64 ) ct, __cputime_jiffies_factor); -} - -static inline cputime_t jiffies_to_cputime (const unsigned long jif) -{ -u64 ct; -unsigned long sec; - -/* have to be a little careful about overflow */ - ct = jif %HZ ; - sec = jif /HZ ; -if (ct) { - ct *= tb_ticks_per_sec; -do_div (ct,HZ ); - } -if (sec) - ct += (cputime_t ) sec * tb_ticks_per_sec; -return (__force cputime_t ) ct; -} - -static inline void setup_cputime_one_jiffy (void ) -{ - cputime_one_jiffy =jiffies_to_cputime (1 ); -} - -static inline cputime64_t jiffies64_to_cputime64 (const u64 jif) -{ -u64 ct; -u64 sec = jif; - -/* have to be a little careful about overflow */ - ct =do_div (sec,HZ ); -if (ct) { - ct *= tb_ticks_per_sec; -do_div (ct,HZ ); - } -if (sec) - ct += (u64 ) sec * tb_ticks_per_sec; -return (__force cputime64_t ) ct; -} - -static inline u64 cputime64_to_jiffies64 (const cputime_t ct) -{ -return mulhdu ((__force u64 ) ct, __cputime_jiffies_factor); -} -/* * Convert cputime <-> microseconds */
@@ -105,117 +43,6 @@ static inline unsigned long cputime_to_usecs(const cputime_t ct)return mulhdu ((__force u64 ) ct, __cputime_usec_factor); } -static inline cputime_t usecs_to_cputime (const unsigned long us) -{ -u64 ct; -unsigned long sec; - -/* have to be a little careful about overflow */ - ct = us %1000000 ; - sec = us /1000000 ; -if (ct) { - ct *= tb_ticks_per_sec; -do_div (ct,1000000 ); - } -if (sec) - ct += (cputime_t ) sec * tb_ticks_per_sec; -return (__force cputime_t ) ct; -} - -#define usecs_to_cputime64 (us) usecs_to_cputime(us) - -/* -* Convert cputime <-> seconds -*/ -extern u64 __cputime_sec_factor; - -static inline unsigned long cputime_to_secs (const cputime_t ct) -{ -return mulhdu ((__force u64 ) ct, __cputime_sec_factor); -} - -static inline cputime_t secs_to_cputime (const unsigned long sec) -{ -return (__force cputime_t)((u64 ) sec * tb_ticks_per_sec); -} - -/* -* Convert cputime <-> timespec -*/ -static inline void cputime_to_timespec (const cputime_t ct,struct timespec *p) -{ -u64 x = (__force u64 ) ct; -unsigned int frac; - - frac =do_div (x, tb_ticks_per_sec); - p->tv_sec = x; - x = (u64 ) frac *1000000000 ; -do_div (x, tb_ticks_per_sec); - p->tv_nsec = x; -} - -static inline cputime_t timespec_to_cputime (const struct timespec *p) -{ -u64 ct; - - ct = (u64 ) p->tv_nsec * tb_ticks_per_sec; -do_div (ct,1000000000 ); -return (__force cputime_t)(ct + (u64 ) p->tv_sec * tb_ticks_per_sec); -} - -/* -* Convert cputime <-> timeval -*/ -static inline void cputime_to_timeval (const cputime_t ct,struct timeval *p) -{ -u64 x = (__force u64 ) ct; -unsigned int frac; - - frac =do_div (x, tb_ticks_per_sec); - p->tv_sec = x; - x = (u64 ) frac *1000000 ; -do_div (x, tb_ticks_per_sec); - p->tv_usec = x; -} - -static inline cputime_t timeval_to_cputime (const struct timeval *p) -{ -u64 ct; - - ct = (u64 ) p->tv_usec * tb_ticks_per_sec; -do_div (ct,1000000 ); -return (__force cputime_t)(ct + (u64 ) p->tv_sec * tb_ticks_per_sec); -} - -/* -* Convert cputime <-> clock_t (units of 1/USER_HZ seconds) -*/ -extern u64 __cputime_clockt_factor; - -static inline unsigned long cputime_to_clock_t (const cputime_t ct) -{ -return mulhdu ((__force u64 ) ct, __cputime_clockt_factor); -} - -static inline cputime_t clock_t_to_cputime (const unsigned long clk) -{ -u64 ct; -unsigned long sec; - -/* have to be a little careful about overflow */ - ct = clk %USER_HZ ; - sec = clk /USER_HZ ; -if (ct) { - ct *= tb_ticks_per_sec; -do_div (ct,USER_HZ ); - } -if (sec) - ct += (u64 ) sec * tb_ticks_per_sec; -return (__force cputime_t ) ct; -} - -#define cputime64_to_clock_t (ct) cputime_to_clock_t((cputime_t)(ct)) -/* * PPC64 uses PACA which is task independent for storing accounting data while * PPC32 uses struct thread_info, therefore at task switch the accounting data
arch/powerpc/kernel/time.c +2 -18
@@ -152,20 +152,11 @@ EXPORT_SYMBOL_GPL(ppc_tb_freq);#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE /* -* Factors for converting from cputime_t (timebase ticks) to -* jiffies, microseconds, seconds, and clock_t (1/USER_HZ seconds). -* These are all stored as 0.64 fixed-point binary fractions. +* Factor for converting from cputime_t (timebase ticks) to +* microseconds. This is stored as 0.64 fixed-point binary fraction. */ -u64 __cputime_jiffies_factor; -EXPORT_SYMBOL (__cputime_jiffies_factor);u64 __cputime_usec_factor;EXPORT_SYMBOL (__cputime_usec_factor); -u64 __cputime_sec_factor; -EXPORT_SYMBOL (__cputime_sec_factor); -u64 __cputime_clockt_factor; -EXPORT_SYMBOL (__cputime_clockt_factor); - -cputime_t cputime_one_jiffy;#ifdef CONFIG_PPC_SPLPAR void (*dtl_consumer)(struct dtl_entry *,u64 );
@@ -181,14 +172,8 @@ static void calc_cputime_factors(void) {struct div_result res; -div128_by_32 (HZ ,0 , tb_ticks_per_sec, &res); - __cputime_jiffies_factor = res.result_low;div128_by_32 (1000000 ,0 , tb_ticks_per_sec, &res); __cputime_usec_factor = res.result_low; -div128_by_32 (1 ,0 , tb_ticks_per_sec, &res); - __cputime_sec_factor = res.result_low; -div128_by_32 (USER_HZ ,0 , tb_ticks_per_sec, &res); - __cputime_clockt_factor = res.result_low; }/*
@@ -1053,7 +1038,6 @@ void __init time_init(void) tb_ticks_per_sec = ppc_tb_freq; tb_ticks_per_usec = ppc_tb_freq /1000000 ;calc_cputime_factors (); -setup_cputime_one_jiffy ();/* * Compute scale factor for sched_clock.
Signature · 1 line
2.7.4
PATCH 24/37 cputime: Push time to account_idle_time() in nsecs
In reply to Frederic WeisbeckerThis is one more step toward converting cputime accounting to pure nsecs.
--- arch/ia64/kernel/time.c | 2 +- arch/powerpc/kernel/time.c | 2 +- arch/s390/kernel/idle.c | 2 +- include/linux/kernel_stat.h | 2 +- kernel/sched/cputime.c | 18 +++++++++--------- 5 files changed, 13 insertions(+), 13 deletions(-)
arch/ia64/kernel/time.c +1 -1
@@ -73,7 +73,7 @@ void vtime_flush(struct task_struct *tsk)account_guest_time (tsk,cycle_to_cputime (ti->gtime));if (ti->idle_time) -account_idle_time (cycle_to_cputime (ti->idle_time)); +account_idle_time (cputime_to_nsecs (cycle_to_cputime (ti->idle_time)));if (ti->stime) { delta =cycle_to_cputime (ti->stime);
arch/powerpc/kernel/time.c +1 -1
@@ -405,7 +405,7 @@ void vtime_flush(struct task_struct *tsk)account_steal_time (cputime_to_nsecs (acct->steal_time));if (acct->idle_time) -account_idle_time (acct->idle_time); +account_idle_time (cputime_to_nsecs (acct->idle_time));if (acct->stime)account_system_index_time (tsk, acct->stime,CPUTIME_SYSTEM );
arch/s390/kernel/idle.c +1 -1
@@ -43,7 +43,7 @@ void enabled_wait(void) idle->clock_idle_enter = idle->clock_idle_exit =0ULL ; idle->idle_time += idle_time; idle->idle_count++; -account_idle_time (idle_time); +account_idle_time (cputime_to_nsecs (idle_time));write_seqcount_end (&idle->seqcount); }NOKPROBE_SYMBOL (enabled_wait);
include/linux/kernel_stat.h +1 -1
@@ -84,7 +84,7 @@ extern void account_system_time(struct task_struct *, int, cputime_t);extern void account_system_index_time (struct task_struct *,cputime_t ,enum cpu_usage_stat );extern void account_steal_time (u64 ); -extern void account_idle_time (cputime_t ); +extern void account_idle_time (u64 );#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE static inline void account_process_tick (struct task_struct *tsk,int user)
kernel/sched/cputime.c +9 -9
@@ -218,15 +218,15 @@ void account_steal_time(u64 cputime)* Account for idle time. * @cputime: the cpu time spent in idle wait */ -void account_idle_time (cputime_t cputime) +void account_idle_time (u64 cputime) {u64 *cpustat = kcpustat_this_cpu->cpustat;struct rq *rq =this_rq ();if (atomic_read (&rq->nr_iowait) >0 ) - cpustat[CPUTIME_IOWAIT ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_IOWAIT ] += cputime;else - cpustat[CPUTIME_IDLE ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_IDLE ] += cputime; }/*
@@ -392,7 +392,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, }else if (user_tick) {account_user_time (p, cputime); }else if (p == rq->idle) { -account_idle_time (old_cputime); +account_idle_time (cputime); }else if (p->flags &PF_VCPU ) {/* System time or guest time */ account_guest_time (p, old_cputime);
@@ -504,7 +504,7 @@ void account_process_tick(struct task_struct *p, int user_tick)else if ((p != rq->idle) || (irq_count () !=HARDIRQ_OFFSET ))account_system_time (p,HARDIRQ_OFFSET , old_cputime);else -account_idle_time (old_cputime); +account_idle_time (cputime); }/*
@@ -513,15 +513,15 @@ void account_process_tick(struct task_struct *p, int user_tick)*/ void account_idle_ticks (unsigned long ticks) { -cputime_t cputime, steal; +u64 cputime, steal;if (sched_clock_irqtime) {irqtime_account_idle_ticks (ticks);return ; } - cputime =jiffies_to_cputime (ticks); - steal =steal_account_process_time (ULONG_MAX ); + cputime = ticks *TICK_NSEC ; + steal =cputime_to_nsecs (steal_account_process_time (ULONG_MAX ));if (steal >= cputime)return ;
@@ -787,7 +787,7 @@ void vtime_account_idle(struct task_struct *tsk) {cputime_t delta_cpu =get_vtime_delta (tsk); -account_idle_time (delta_cpu); +account_idle_time (cputime_to_nsecs (delta_cpu)); }void arch_vtime_task_switch (struct task_struct *prev)
Signature · 1 line
2.7.4
PATCH 29/37 ia64: Move nsecs based cputime headers to the last arch using it
In reply to Frederic WeisbeckerInitially, nsec based cputime_t implementation belonged to ia64. It got exported later for CONFIG_VIRT_CPU_ACCOUNTING_GEN but now it is again only used by ia64. So let's move it back there.
--- arch/ia64/include/asm/cputime.h | 108 +++++++++++++++++++++++++++++++- include/asm-generic/cputime.h | 4 -- include/asm-generic/cputime_nsecs.h | 121 ------------------------------------ 3 files changed, 106 insertions(+), 127 deletions(-) delete mode 100644 include/asm-generic/cputime_nsecs.h
arch/ia64/include/asm/cputime.h +106 -2
@@ -20,9 +20,113 @@#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE # include <asm-generic/cputime.h> +#else -# include <asm/processor.h> -# include <asm-generic/cputime_nsecs.h> + +#include <asm/processor.h> +#include <linux/math64.h> + +typedef u64 __nocast cputime_t ; +typedef u64 __nocast cputime64_t ; + +#define cmpxchg_cputime (ptr, old, new) cmpxchg64(ptr, old, new) + +#define cputime_one_jiffy jiffies_to_cputime(1) + +#define cputime_div (__ct, divisor) div_u64((__force u64)__ct, divisor) +#define cputime_div_rem (__ct, divisor, remainder) \ + div_u64_rem((__force u64)__ct, divisor, remainder); + +/* +* Convert cputime <-> jiffies (HZ) +*/ +#define cputime_to_jiffies (__ct) \ + cputime_div(__ct, NSEC_PER_SEC / HZ) +#define jiffies_to_cputime (__jif) \ + (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ)) +#define cputime64_to_jiffies64 (__ct) \ + cputime_div(__ct, NSEC_PER_SEC / HZ) +#define jiffies64_to_cputime64 (__jif) \ + (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ)) + + +/* +* Convert cputime <-> nanoseconds +*/ +#define cputime_to_nsecs (__ct) \ + (__force u64)(__ct) +#define nsecs_to_cputime (__nsecs) \ + (__force cputime_t)(__nsecs) +#define nsecs_to_cputime64 (__nsecs) \ + (__force cputime64_t)(__nsecs) + + +/* +* Convert cputime <-> microseconds +*/ +#define cputime_to_usecs (__ct) \ + cputime_div(__ct, NSEC_PER_USEC) +#define usecs_to_cputime (__usecs) \ + (__force cputime_t)((__usecs) * NSEC_PER_USEC) +#define usecs_to_cputime64 (__usecs) \ + (__force cputime64_t)((__usecs) * NSEC_PER_USEC) + +/* +* Convert cputime <-> seconds +*/ +#define cputime_to_secs (__ct) \ + cputime_div(__ct, NSEC_PER_SEC) +#define secs_to_cputime (__secs) \ + (__force cputime_t)((__secs) * NSEC_PER_SEC) + +/* +* Convert cputime <-> timespec (nsec) +*/ +static inline cputime_t timespec_to_cputime (const struct timespec *val) +{ +u64 ret = (u64 )val->tv_sec *NSEC_PER_SEC + val->tv_nsec; +return (__force cputime_t ) ret; +} +static inline void cputime_to_timespec (const cputime_t ct,struct timespec *val) +{ +u32 rem; + + val->tv_sec =cputime_div_rem (ct,NSEC_PER_SEC , &rem); + val->tv_nsec = rem; +} + +/* +* Convert cputime <-> timeval (msec) +*/ +static inline cputime_t timeval_to_cputime (const struct timeval *val) +{ +u64 ret = (u64 )val->tv_sec *NSEC_PER_SEC + + val->tv_usec *NSEC_PER_USEC ; +return (__force cputime_t ) ret; +} +static inline void cputime_to_timeval (const cputime_t ct,struct timeval *val) +{ +u32 rem; + + val->tv_sec =cputime_div_rem (ct,NSEC_PER_SEC , &rem); + val->tv_usec = rem /NSEC_PER_USEC ; +} + +/* +* Convert cputime <-> clock (USER_HZ) +*/ +#define cputime_to_clock_t (__ct) \ + cputime_div(__ct, (NSEC_PER_SEC / USER_HZ)) +#define clock_t_to_cputime (__x) \ + (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ)) + +/* +* Convert cputime64 to clock. +*/ +#define cputime64_to_clock_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_NATIVE */
include/asm-generic/cputime.h +0 -4
@@ -4,8 +4,4 @@#include <linux/time.h> #include <linux/jiffies.h> -#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN -# include <asm-generic/cputime_nsecs.h> -#endif -#endif
include/asm-generic/cputime_nsecs.h deleted +0 -121
121 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 31/37 ia64: Remove unused cputime definitions
In reply to Frederic WeisbeckerThis nsec based cputime_t implementation isn't used anymore. We can remove it.
--- arch/ia64/include/asm/cputime.h | 106 ---------------------------------------- 1 file changed, 106 deletions(-)
arch/ia64/include/asm/cputime.h +0 -106
@@ -20,113 +20,7 @@#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE # include <asm-generic/cputime.h> -#else - -#include <asm/processor.h> -#include <linux/math64.h> - -typedef u64 __nocast cputime_t ; -typedef u64 __nocast cputime64_t ; - -#define cmpxchg_cputime (ptr, old, new) cmpxchg64(ptr, old, new) - -#define cputime_one_jiffy jiffies_to_cputime(1) - -#define cputime_div (__ct, divisor) div_u64((__force u64)__ct, divisor) -#define cputime_div_rem (__ct, divisor, remainder) \ - div_u64_rem((__force u64)__ct, divisor, remainder); - -/* -* Convert cputime <-> jiffies (HZ) -*/ -#define cputime_to_jiffies (__ct) \ - cputime_div(__ct, NSEC_PER_SEC / HZ) -#define jiffies_to_cputime (__jif) \ - (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ)) -#define cputime64_to_jiffies64 (__ct) \ - cputime_div(__ct, NSEC_PER_SEC / HZ) -#define jiffies64_to_cputime64 (__jif) \ - (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ)) - - -/* -* Convert cputime <-> nanoseconds -*/ -#define cputime_to_nsecs (__ct) \ - (__force u64)(__ct) -#define nsecs_to_cputime (__nsecs) \ - (__force cputime_t)(__nsecs) -#define nsecs_to_cputime64 (__nsecs) \ - (__force cputime64_t)(__nsecs) - - -/* -* Convert cputime <-> microseconds -*/ -#define cputime_to_usecs (__ct) \ - cputime_div(__ct, NSEC_PER_USEC) -#define usecs_to_cputime (__usecs) \ - (__force cputime_t)((__usecs) * NSEC_PER_USEC) -#define usecs_to_cputime64 (__usecs) \ - (__force cputime64_t)((__usecs) * NSEC_PER_USEC) - -/* -* Convert cputime <-> seconds -*/ -#define cputime_to_secs (__ct) \ - cputime_div(__ct, NSEC_PER_SEC) -#define secs_to_cputime (__secs) \ - (__force cputime_t)((__secs) * NSEC_PER_SEC) - -/* -* Convert cputime <-> timespec (nsec) -*/ -static inline cputime_t timespec_to_cputime (const struct timespec *val) -{ -u64 ret = (u64 )val->tv_sec *NSEC_PER_SEC + val->tv_nsec; -return (__force cputime_t ) ret; -} -static inline void cputime_to_timespec (const cputime_t ct,struct timespec *val) -{ -u32 rem; - - val->tv_sec =cputime_div_rem (ct,NSEC_PER_SEC , &rem); - val->tv_nsec = rem; -} - -/* -* Convert cputime <-> timeval (msec) -*/ -static inline cputime_t timeval_to_cputime (const struct timeval *val) -{ -u64 ret = (u64 )val->tv_sec *NSEC_PER_SEC + - val->tv_usec *NSEC_PER_USEC ; -return (__force cputime_t ) ret; -} -static inline void cputime_to_timeval (const cputime_t ct,struct timeval *val) -{ -u32 rem; - - val->tv_sec =cputime_div_rem (ct,NSEC_PER_SEC , &rem); - val->tv_usec = rem /NSEC_PER_USEC ; -} - -/* -* Convert cputime <-> clock (USER_HZ) -*/ -#define cputime_to_clock_t (__ct) \ - cputime_div(__ct, (NSEC_PER_SEC / USER_HZ)) -#define clock_t_to_cputime (__x) \ - (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ)) - -/* -* Convert cputime64 to clock. -*/ -#define cputime64_to_clock_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_NATIVE */
Signature · 1 line
2.7.4
PATCH 30/37 ia64: Convert vtime to use nsec units directly
In reply to Frederic WeisbeckerThere is no need anymore for this cputime_t midlayer. Let's use nsec units directly.
--- arch/ia64/kernel/head.S | 4 ++-- arch/ia64/kernel/time.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-)
arch/ia64/kernel/head.S +2 -2
@@ -1031,7 +1031,7 @@ GLOBAL_ENTRY(ia64_native_sched_clock) END(ia64_native_sched_clock) #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE -GLOBAL_ENTRY(cycle_to_cputime) +GLOBAL_ENTRY(cycle_to_nsec) alloc r16=ar.pfs,1,0,0,0 addl r8=THIS_CPU(ia64_cpu_info) + IA64_CPUINFO_NSEC_PER_CYC_OFFSET,r0 ;;
@@ -1047,7 +1047,7 @@ GLOBAL_ENTRY(cycle_to_cputime) ;; shrp r8=r9,r8,IA64_NSEC_PER_CYC_SHIFT br.ret.sptk.many rp -END(cycle_to_cputime) +END(cycle_to_nsec) #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ #ifdef CONFIG_IA64_BRL_EMU
arch/ia64/kernel/time.c +7 -7
@@ -60,7 +60,7 @@ static struct clocksource *itc_clocksource;#include <linux/kernel_stat.h> -extern cputime_t cycle_to_cputime (u64 cyc); +extern u64 cycle_to_nsec (u64 cyc);void vtime_flush (struct task_struct *tsk) {
@@ -68,26 +68,26 @@ void vtime_flush(struct task_struct *tsk)u64 delta;if (ti->utime) -account_user_time (tsk,cputime_to_nsecs (cycle_to_cputime (ti->utime))); +account_user_time (tsk,cycle_to_nsec (ti->utime));if (ti->gtime) -account_guest_time (tsk,cputime_to_nsecs (cycle_to_cputime (ti->gtime))); +account_guest_time (tsk,cycle_to_nsec (ti->gtime));if (ti->idle_time) -account_idle_time (cputime_to_nsecs (cycle_to_cputime (ti->idle_time))); +account_idle_time (cycle_to_nsec (ti->idle_time));if (ti->stime) { - delta =cputime_to_nsecs (cycle_to_cputime (ti->stime)); + delta =cycle_to_nsec (ti->stime);account_system_index_time (tsk, delta,CPUTIME_SYSTEM ); }if (ti->hardirq_time) { - delta =cputime_to_nsecs (cycle_to_cputime (ti->hardirq_time)); + delta =cycle_to_nsec (ti->hardirq_time);account_system_index_time (tsk, delta,CPUTIME_IRQ ); }if (ti->softirq_time) { - delta =cputime_to_nsecs (cycle_to_cputime (ti->softirq_time)); + delta = cycle_to_nsec(ti->softirq_time));account_system_index_time (tsk, delta,CPUTIME_SOFTIRQ ); }
Signature · 1 line
2.7.4
PATCH 23/37 cputime: Push time to account_steal_time() in nsecs
In reply to Frederic WeisbeckerThis is one more step toward converting cputime accounting to pure nsecs.
--- arch/powerpc/kernel/time.c | 2 +- arch/s390/kernel/vtime.c | 2 +- include/linux/kernel_stat.h | 2 +- kernel/sched/cputime.c | 11 ++++++----- 4 files changed, 9 insertions(+), 8 deletions(-)
arch/powerpc/kernel/time.c +1 -1
@@ -402,7 +402,7 @@ void vtime_flush(struct task_struct *tsk)account_guest_time (tsk, acct->gtime);if (acct->steal_time) -account_steal_time (acct->steal_time); +account_steal_time (cputime_to_nsecs (acct->steal_time));if (acct->idle_time)account_idle_time (acct->idle_time);
arch/s390/kernel/vtime.c +1 -1
@@ -188,7 +188,7 @@ static int do_account_vtime(struct task_struct *tsk) steal = S390_lowcore.steal_timer;if ((s64 ) steal >0 ) { S390_lowcore.steal_timer =0 ; -account_steal_time (steal); +account_steal_time (cputime_to_nsecs (steal)); }return virt_timer_forward (user + guest + system + hardirq + softirq);
include/linux/kernel_stat.h +1 -1
@@ -83,7 +83,7 @@ extern void account_guest_time(struct task_struct *, cputime_t);extern void account_system_time (struct task_struct *,int ,cputime_t );extern void account_system_index_time (struct task_struct *,cputime_t ,enum cpu_usage_stat ); -extern void account_steal_time (cputime_t ); +extern void account_steal_time (u64 );extern void account_idle_time (cputime_t );#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
kernel/sched/cputime.c +6 -5
@@ -207,11 +207,11 @@ void account_system_time(struct task_struct *p, int hardirq_offset,* Account for involuntary wait time. * @cputime: the cpu time spent in involuntary wait */ -void account_steal_time (cputime_t cputime) +void account_steal_time (u64 cputime) {u64 *cpustat = kcpustat_this_cpu->cpustat; - cpustat[CPUTIME_STEAL ] +=cputime_to_nsecs (cputime); + cpustat[CPUTIME_STEAL ] += cputime; }/*
@@ -239,14 +239,15 @@ static __always_inline cputime_t steal_account_process_time(cputime_t maxtime)#ifdef CONFIG_PARAVIRT if (static_key_false (¶virt_steal_enabled)) {cputime_t steal_cputime; -u64 steal; +u64 steal, rounded; steal =paravirt_steal_clock (smp_processor_id ()); steal -=this_rq ()->prev_steal_time; steal_cputime =min (nsecs_to_cputime (steal), maxtime); -account_steal_time (steal_cputime); -this_rq ()->prev_steal_time +=cputime_to_nsecs (steal_cputime); + rounded =cputime_to_nsecs (steal_cputime); +account_steal_time (rounded); +this_rq ()->prev_steal_time += rounded;return steal_cputime; }
Signature · 1 line
2.7.4
PATCH 22/37 cputime: Push time to account_user_time() in nsecs
In reply to Frederic WeisbeckerThis is one more step toward converting cputime accounting to pure nsecs.
--- arch/ia64/kernel/time.c | 2 +- arch/powerpc/kernel/time.c | 2 +- arch/s390/kernel/vtime.c | 2 +- include/linux/kernel_stat.h | 2 +- kernel/sched/cputime.c | 42 ++++++++++++++++++++++++------------------ 5 files changed, 28 insertions(+), 22 deletions(-)
arch/ia64/kernel/time.c +1 -1
@@ -67,7 +67,7 @@ void vtime_flush(struct task_struct *tsk)cputime_t delta;if (ti->utime) -account_user_time (tsk,cycle_to_cputime (ti->utime)); +account_user_time (tsk,cputime_to_nsecs (cycle_to_cputime (ti->utime)));if (ti->gtime)account_guest_time (tsk,cycle_to_cputime (ti->gtime));
arch/powerpc/kernel/time.c +1 -1
@@ -393,7 +393,7 @@ void vtime_flush(struct task_struct *tsk)struct cpu_accounting_data *acct =get_accounting (tsk);if (acct->utime) -account_user_time (tsk, acct->utime); +account_user_time (tsk,cputime_to_nsecs (acct->utime));if (acct->utime_scaled) tsk->utimescaled +=cputime_to_nsecs (acct->utime_scaled);
arch/s390/kernel/vtime.c +1 -1
@@ -166,7 +166,7 @@ static int do_account_vtime(struct task_struct *tsk)/* Push account value */ if (user) { -account_user_time (tsk, user); +account_user_time (tsk,cputime_to_nsecs (user)); tsk->utimescaled +=cputime_to_nsecs (scale_vtime (user)); }
include/linux/kernel_stat.h +1 -1
@@ -78,7 +78,7 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)return kstat_cpu (cpu).irqs_sum; } -extern void account_user_time (struct task_struct *,cputime_t ); +extern void account_user_time (struct task_struct *,u64 );extern void account_guest_time (struct task_struct *,cputime_t );extern void account_system_time (struct task_struct *,int ,cputime_t ); extern void account_system_index_time(struct task_struct *, cputime_t,
kernel/sched/cputime.c +24 -18
108 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 17/37 cputime: Increment kcpustat directly on irqtime account
In reply to Frederic WeisbeckerThe irqtime is accounted is nsecs and stored in cpu_irq_time.hardirq_time and cpu_irq_time.softirq_time. Once the accumulated amount reaches a new jiffy, this one gets accounted to the kcpustat.
This was necessary when kcpustat was stored in cputime_t, which could at worst have a jiffies granularity. But now kcpustat is stored in nsecs so this whole discretization game with temporary irqtime storage has become unnecessary.
We can now directly account the irqtime to the kcpustat.
--- kernel/sched/cputime.c | 50 +++++++++++++++++--------------------------------- kernel/sched/sched.h | 7 ++++--- 2 files changed, 21 insertions(+), 36 deletions(-)
kernel/sched/cputime.c +17 -33
@@ -44,6 +44,7 @@ void disable_sched_clock_irqtime(void)void irqtime_account_irq (struct task_struct *curr) {struct irqtime *irqtime =this_cpu_ptr (&cpu_irqtime); +u64 *cpustat = kcpustat_this_cpu->cpustat;s64 delta;int cpu;
@@ -61,49 +62,35 @@ void irqtime_account_irq(struct task_struct *curr)* in that case, so as not to confuse scheduler with a special task * that do not consume any time, but still wants to run. */ -if (hardirq_count ()) - irqtime->hardirq_time += delta; -else if (in_serving_softirq () && curr !=this_cpu_ksoftirqd ()) - irqtime->softirq_time += delta; +if (hardirq_count ()) { + cpustat[CPUTIME_IRQ ] += delta; + irqtime->tick_delta += delta; + }else if (in_serving_softirq () && curr !=this_cpu_ksoftirqd ()) { + cpustat[CPUTIME_SOFTIRQ ] += delta; + irqtime->tick_delta += delta; + } u64_stats_update_end(&irqtime->sync); }EXPORT_SYMBOL_GPL (irqtime_account_irq); -static cputime_t irqtime_account_update (u64 irqtime,int idx,cputime_t maxtime) +static cputime_t irqtime_tick_accounted (cputime_t maxtime) { -u64 *cpustat = kcpustat_this_cpu->cpustat; -cputime_t irq_cputime; +struct irqtime *irqtime =this_cpu_ptr (&cpu_irqtime); +cputime_t delta; - irq_cputime =nsecs_to_cputime64 (irqtime - cpustat[idx]); - irq_cputime =min (irq_cputime, maxtime); - cpustat[idx] +=cputime_to_nsecs (irq_cputime); + delta =nsecs_to_cputime (irqtime->tick_delta); + delta =min (delta, maxtime); + irqtime->tick_delta -=cputime_to_nsecs (delta); -return irq_cputime; -} - -static cputime_t irqtime_account_hi_update (cputime_t maxtime) -{ -return irqtime_account_update (__this_cpu_read (cpu_irqtime.hardirq_time), -CPUTIME_IRQ , maxtime); -} - -static cputime_t irqtime_account_si_update (cputime_t maxtime) -{ -return irqtime_account_update (__this_cpu_read (cpu_irqtime.softirq_time), -CPUTIME_SOFTIRQ , maxtime); +return delta; }#else /* CONFIG_IRQ_TIME_ACCOUNTING */ #define sched_clock_irqtime (0) -static cputime_t irqtime_account_hi_update (cputime_t dummy) -{ -return 0 ; -} - -static cputime_t irqtime_account_si_update (cputime_t dummy) +static cputime_t irqtime_tick_accounted (cputime_t dummy) {return 0 ; }
@@ -280,10 +267,7 @@ static inline cputime_t account_other_time(cputime_t max) accounted =steal_account_process_time (max);if (accounted < max) - accounted +=irqtime_account_hi_update (max - accounted); - -if (accounted < max) - accounted +=irqtime_account_si_update (max - accounted); + accounted +=irqtime_tick_accounted (max - accounted);return accounted; }
kernel/sched/sched.h +4 -3
@@ -4,6 +4,7 @@#include <linux/sched/rt.h> #include <linux/u64_stats_sync.h> #include <linux/sched/deadline.h> +#include <linux/kernel_stat.h> #include <linux/binfmts.h> #include <linux/mutex.h> #include <linux/spinlock.h>
@@ -1827,8 +1828,7 @@ static inline void nohz_balance_exit_idle(unsigned int cpu) { }#ifdef CONFIG_IRQ_TIME_ACCOUNTING struct irqtime { -u64 hardirq_time; -u64 softirq_time; +u64 tick_delta;u64 irq_start_time;struct u64_stats_sync sync; };
@@ -1838,12 +1838,13 @@ DECLARE_PER_CPU(struct irqtime, cpu_irqtime);static inline u64 irq_time_read (int cpu) {struct irqtime *irqtime = &per_cpu (cpu_irqtime, cpu); +u64 *cpustat =kcpustat_cpu (cpu).cpustat;unsigned int seq;u64 total;do { seq =__u64_stats_fetch_begin (&irqtime->sync); - total = irqtime->softirq_time + irqtime->hardirq_time; + total = cpustat[CPUTIME_SOFTIRQ ] + cpustat[CPUTIME_IRQ ]; }while (__u64_stats_fetch_retry (&irqtime->sync, seq));return total;
Signature · 1 line
2.7.4
PATCH 14/37 delaycct: Convert obsolete cputime type to nsecs
In reply to Frederic WeisbeckerUse the new nsec based cputime accessors as part of the whole cputime conversion from cputime_t to nsecs.
--- kernel/delayacct.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/delayacct.c +5 -5
@@ -82,19 +82,19 @@ void __delayacct_blkio_end(void)int __delayacct_add_tsk (struct taskstats *d,struct task_struct *tsk) { -cputime_t utime, stime, stimescaled, utimescaled; +u64 utime, stime, stimescaled, utimescaled;unsigned long long t2, t3;unsigned long flags, t1;s64 tmp; -task_cputime_t (tsk, &utime, &stime); +task_cputime (tsk, &utime, &stime); tmp = (s64 )d->cpu_run_real_total; - tmp +=cputime_to_nsecs (utime + stime); + tmp += utime + stime; d->cpu_run_real_total = (tmp < (s64 )d->cpu_run_real_total) ?0 : tmp; -task_cputime_t_scaled (tsk, &utimescaled, &stimescaled); +task_cputime_scaled (tsk, &utimescaled, &stimescaled); tmp = (s64 )d->cpu_scaled_run_real_total; - tmp +=cputime_to_nsecs (utimescaled + stimescaled); + tmp += utimescaled + stimescaled; d->cpu_scaled_run_real_total = (tmp < (s64 )d->cpu_scaled_run_real_total) ?0 : tmp;
Signature · 1 line
2.7.4
PATCH 7/37 cputime: Special API to return old-typed cputime
In reply to Frederic WeisbeckerThis API returns the tasks cputime in cputime_t in order to ease the conversion of cputime internals to use nsecs units instead. Blindly converting all cputime readers to use this API now will later let us convert more smoothly and step by step all these places to use the new nsec based cputime.
--- arch/alpha/kernel/osf_sys.c | 2 +- arch/x86/kernel/apm_32.c | 2 +- drivers/isdn/mISDN/stack.c | 2 +- fs/binfmt_elf.c | 6 +++--- fs/binfmt_elf_fdpic.c | 6 +++--- include/linux/sched.h | 32 ++++++++++++++++++++++++++--- kernel/acct.c | 2 +- kernel/delayacct.c | 4 ++-- kernel/signal.c | 4 ++-- kernel/time/itimer.c | 2 +- kernel/time/posix-cpu-timers.c | 46 +++++++++++++++++++++--------------------- kernel/tsacct.c | 6 +++--- 12 files changed, 70 insertions(+), 44 deletions(-)
arch/alpha/kernel/osf_sys.c +1 -1
@@ -1154,7 +1154,7 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)memset (&r,0 ,sizeof (r));switch (who) {case RUSAGE_SELF : -task_cputime (current, &utime, &stime); +task_cputime_t (current, &utime, &stime); utime_jiffies =cputime_to_jiffies (utime); stime_jiffies =cputime_to_jiffies (stime);jiffies_to_timeval32 (utime_jiffies, &r.ru_utime);
arch/x86/kernel/apm_32.c +1 -1
@@ -913,7 +913,7 @@ static int apm_cpu_idle(struct cpuidle_device *dev,unsigned int bucket; recalc: -task_cputime (current, &utime, &stime); +task_cputime_t (current, &utime, &stime);if (jiffies_since_last_check >IDLE_CALC_LIMIT ) { use_apm_idle =0 ; }else if (jiffies_since_last_check > idle_period) {
drivers/isdn/mISDN/stack.c +1 -1
@@ -306,7 +306,7 @@ mISDNStackd(void *data)"msg %d sleep %d stopped\n" ,dev_name (&st->dev->dev), st->msg_cnt, st->sleep_cnt, st->stopped_cnt); -task_cputime (st->thread, &utime, &stime); +task_cputime_t (st->thread, &utime, &stime);printk (KERN_DEBUG "mISDNStackd daemon for %s utime(%ld) stime(%ld)\n" ,dev_name (&st->dev->dev), utime, stime);
fs/binfmt_elf.c +3 -3
@@ -1421,19 +1421,19 @@ static void fill_prstatus(struct elf_prstatus *prstatus, prstatus->pr_pgrp =task_pgrp_vnr (p); prstatus->pr_sid =task_session_vnr (p);if (thread_group_leader (p)) { -struct task_cputime cputime; +struct task_cputime_t cputime;/* * This is the record for the group leader. It shows the * group-wide total, not its individual thread total. */ -thread_group_cputime (p, &cputime); +thread_group_cputime_t (p, &cputime);cputime_to_timeval (cputime.utime, &prstatus->pr_utime);cputime_to_timeval (cputime.stime, &prstatus->pr_stime); }else {cputime_t utime, stime; -task_cputime (p, &utime, &stime); +task_cputime_t (p, &utime, &stime);cputime_to_timeval (utime, &prstatus->pr_utime);cputime_to_timeval (stime, &prstatus->pr_stime); }
fs/binfmt_elf_fdpic.c +3 -3
@@ -1342,19 +1342,19 @@ static void fill_prstatus(struct elf_prstatus *prstatus, prstatus->pr_pgrp =task_pgrp_vnr (p); prstatus->pr_sid =task_session_vnr (p);if (thread_group_leader (p)) { -struct task_cputime cputime; +struct task_cputime_t cputime;/* * This is the record for the group leader. It shows the * group-wide total, not its individual thread total. */ -thread_group_cputime (p, &cputime); +thread_group_cputime_t (p, &cputime);cputime_to_timeval (cputime.utime, &prstatus->pr_utime);cputime_to_timeval (cputime.stime, &prstatus->pr_stime); }else {cputime_t utime, stime; -task_cputime (p, &utime, &stime); +task_cputime_t (p, &utime, &stime);cputime_to_timeval (utime, &prstatus->pr_utime);cputime_to_timeval (stime, &prstatus->pr_stime); }
include/linux/sched.h +29 -3
@@ -615,6 +615,13 @@ struct task_cputime {unsigned long long sum_exec_runtime; }; +/* Temporary type to ease cputime_t to nsecs conversion */ +struct task_cputime_t { +cputime_t utime; +cputime_t stime; +unsigned long long sum_exec_runtime; +}; +/* Alternate field names when used to cache expirations. */ #define virt_exp utime#define prof_exp stime
@@ -748,7 +755,7 @@ struct signal_struct {struct thread_group_cputimer cputimer;/* Earliest-expiration cache. */ -struct task_cputime cputime_expires; +struct task_cputime_t cputime_expires;#ifdef CONFIG_NO_HZ_FULL atomic_t tick_dep_mask;
@@ -1682,7 +1689,7 @@ struct task_struct {/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ unsigned long min_flt, maj_flt; -struct task_cputime cputime_expires; +struct task_cputime_t cputime_expires;struct list_head cpu_timers[3 ];/* process credentials */
@@ -2286,6 +2293,19 @@ static inline void task_cputime_scaled(struct task_struct *t, }#endif +static inline void task_cputime_t (struct task_struct *t, +cputime_t *utime,cputime_t *stime) +{ +task_cputime (t, utime, stime); +} + +static inline void task_cputime_t_scaled (struct task_struct *t, +cputime_t *utimescaled, +cputime_t *stimescaled) +{ +task_cputime_scaled (t, utimescaled, stimescaled); +} +extern void task_cputime_adjusted (struct task_struct *p,cputime_t *ut,cputime_t *st);extern void thread_group_cputime_adjusted (struct task_struct *p,cputime_t *ut,cputime_t *st);
@@ -3500,7 +3520,13 @@ static __always_inline bool need_resched(void)* Thread group CPU time accounting. */ void thread_group_cputime (struct task_struct *tsk,struct task_cputime *times); -void thread_group_cputimer (struct task_struct *tsk,struct task_cputime *times); +void thread_group_cputimer (struct task_struct *tsk,struct task_cputime_t *times); + +static inline void thread_group_cputime_t (struct task_struct *tsk, +struct task_cputime_t *times) +{ +thread_group_cputime (tsk, (struct task_cputime *)times); +}/* * Reevaluate whether the task has signals pending delivery.
kernel/acct.c +1 -1
@@ -559,7 +559,7 @@ void acct_collect(long exitcode, int group_dead) pacct->ac_flag |=ACORE ;if (current->flags &PF_SIGNALED ) pacct->ac_flag |=AXSIG ; -task_cputime (current, &utime, &stime); +task_cputime_t (current, &utime, &stime); pacct->ac_utime += utime; pacct->ac_stime += stime; pacct->ac_minflt += current->min_flt;
kernel/delayacct.c +2 -2
@@ -87,12 +87,12 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)unsigned long flags, t1;s64 tmp; -task_cputime (tsk, &utime, &stime); +task_cputime_t (tsk, &utime, &stime); tmp = (s64 )d->cpu_run_real_total; tmp +=cputime_to_nsecs (utime + stime); d->cpu_run_real_total = (tmp < (s64 )d->cpu_run_real_total) ?0 : tmp; -task_cputime_scaled (tsk, &utimescaled, &stimescaled); +task_cputime_t_scaled (tsk, &utimescaled, &stimescaled); tmp = (s64 )d->cpu_scaled_run_real_total; tmp +=cputime_to_nsecs (utimescaled + stimescaled); d->cpu_scaled_run_real_total =
kernel/signal.c +2 -2
@@ -1619,7 +1619,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig) task_uid(tsk));rcu_read_unlock (); -task_cputime (tsk, &utime, &stime); +task_cputime_t (tsk, &utime, &stime); info.si_utime =cputime_to_clock_t (utime + tsk->signal->utime); info.si_stime =cputime_to_clock_t (stime + tsk->signal->stime);
@@ -1704,7 +1704,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, info.si_uid =from_kuid_munged (task_cred_xxx (parent, user_ns),task_uid (tsk));rcu_read_unlock (); -task_cputime (tsk, &utime, &stime); +task_cputime_t (tsk, &utime, &stime); info.si_utime =cputime_to_clock_t (utime); info.si_stime =cputime_to_clock_t (stime);
kernel/time/itimer.c +1 -1
@@ -53,7 +53,7 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id, cval = it->expires; cinterval = it->incr;if (cval) { -struct task_cputime cputime; +struct task_cputime_t cputime;cputime_t t;thread_group_cputimer (tsk, &cputime);
kernel/time/posix-cpu-timers.c +23 -23
162 lines not on this page · raw message
kernel/tsacct.c +3 -3
@@ -66,11 +66,11 @@ void bacct_add_tsk(struct user_namespace *user_ns, task_tgid_nr_ns(rcu_dereference(tsk->real_parent), pid_ns) : 0;rcu_read_unlock (); -task_cputime (tsk, &utime, &stime); +task_cputime_t (tsk, &utime, &stime); stats->ac_utime =cputime_to_usecs (utime); stats->ac_stime =cputime_to_usecs (stime); -task_cputime_scaled (tsk, &utimescaled, &stimescaled); +task_cputime_t_scaled (tsk, &utimescaled, &stimescaled); stats->ac_utimescaled =cputime_to_usecs (utimescaled); stats->ac_stimescaled =cputime_to_usecs (stimescaled);
@@ -159,7 +159,7 @@ void acct_update_integrals(struct task_struct *tsk)unsigned long flags;local_irq_save (flags); -task_cputime (tsk, &utime, &stime); +task_cputime_t (tsk, &utime, &stime);__acct_update_integrals (tsk, utime, stime);local_irq_restore (flags); }
Signature · 1 line
2.7.4
PATCH 2/37 time: Introduce jiffies64_to_nsecs()
In reply to Frederic WeisbeckerThis will be needed for the cputime_t to nsec conversion.
--- include/linux/jiffies.h | 2 ++ kernel/time/time.c | 10 ++++++++++ kernel/time/timeconst.bc | 6 ++++++ 3 files changed, 18 insertions(+)
include/linux/jiffies.h +2 -0
@@ -293,6 +293,8 @@ static inline u64 jiffies_to_nsecs(const unsigned long j)return (u64 )jiffies_to_usecs (j) *NSEC_PER_USEC ; } +extern u64 jiffies64_to_nsecs (u64 j); +extern unsigned long __msecs_to_jiffies (const unsigned int m);#if HZ <=MSEC_PER_SEC && !(MSEC_PER_SEC %HZ )/*
kernel/time/time.c +10 -0
@@ -702,6 +702,16 @@ u64 nsec_to_clock_t(u64 x)#endif } +u64 jiffies64_to_nsecs (u64 j) +{ +#if !(NSEC_PER_SEC %HZ ) +return (NSEC_PER_SEC /HZ ) * j; +# else +return div_u64 (j *HZ_TO_NSEC_NUM ,HZ_TO_NSEC_DEN ); +#endif +} +EXPORT_SYMBOL (jiffies64_to_nsecs); +/** * nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64 *
kernel/time/timeconst.bc +6 -0
@@ -98,6 +98,12 @@ define timeconst(hz) { print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "\n" print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "\n" print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "\n" + + cd=gcd(hz,1000000000) + print "#define HZ_TO_NSEC_NUM\t\t", 1000000000/cd, "\n" + print "#define HZ_TO_NSEC_DEN\t\t", hz/cd, "\n" + print "#define NSEC_TO_HZ_NUM\t\t", hz/cd, "\n" + print "#define NSEC_TO_HZ_DEN\t\t", 1000000000/cd, "\n" print "\n" print "#endif /* KERNEL_TIMECONST_H */\n"
Signature · 1 line
2.7.4
PATCH 1/37 jiffies: Reuse TICK_NSEC instead of NSEC_PER_JIFFY
In reply to Frederic WeisbeckerNSEC_PER_JIFFY is an ad-hoc redefinition of TICK_NSEC. Let's rather use a unique and well maintained version.
--- kernel/time/jiffies.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
kernel/time/jiffies.c +16 -16
@@ -27,19 +27,8 @@#include "timekeeping.h" -/* The Jiffies based clocksource is the lowest common -* denominator clock source which should function on -* all systems. It has the same coarse resolution as -* the timer interrupt frequency HZ and it suffers -* inaccuracies caused by missed or lost timer -* interrupts and the inability for the timer -* interrupt hardware to accuratly tick at the -* requested HZ value. It is also not recommended -* for "tick-less" systems. -*/ -#define NSEC_PER_JIFFY ((NSEC_PER_SEC+HZ/2)/HZ) -/* Since jiffies uses a simple NSEC_PER_JIFFY multiplier +/* Since jiffies uses a simple TICK_NSEC multiplier * conversion, the .shift value could be zero. However * this would make NTP adjustments impossible as they are * in units of 1/2^.shift. Thus we use JIFFIES_SHIFT to
@@ -47,8 +36,8 @@* amount, and give ntp adjustments in units of 1/2^8 * * The value 8 is somewhat carefully chosen, as anything -* larger can result in overflows. NSEC_PER_JIFFY grows as -* HZ shrinks, so values greater than 8 overflow 32bits when +* larger can result in overflows. TICK_NSEC grows as HZ +* shrinks, so values greater than 8 overflow 32bits when * HZ=100. */ #if HZ <34
@@ -64,12 +53,23 @@ static u64 jiffies_read(struct clocksource *cs)return (u64 ) jiffies; } +/* +* The Jiffies based clocksource is the lowest common +* denominator clock source which should function on +* all systems. It has the same coarse resolution as +* the timer interrupt frequency HZ and it suffers +* inaccuracies caused by missed or lost timer +* interrupts and the inability for the timer +* interrupt hardware to accuratly tick at the +* requested HZ value. It is also not recommended +* for "tick-less" systems. +*/ static struct clocksource clocksource_jiffies = { .name ="jiffies" , .rating =1 ,/* lowest valid rating*/ .read = jiffies_read, .mask =CLOCKSOURCE_MASK (32 ), - .mult =NSEC_PER_JIFFY <<JIFFIES_SHIFT ,/* details above */ + .mult =TICK_NSEC <<JIFFIES_SHIFT ,/* details above */ .shift =JIFFIES_SHIFT , .max_cycles =10 , };
@@ -125,7 +125,7 @@ int register_refined_jiffies(long cycles_per_second) shift_hz += cycles_per_tick/2 ;do_div (shift_hz, cycles_per_tick);/* Calculate nsec_per_tick using shift_hz */ - nsec_per_tick = (u64 )NSEC_PER_SEC <<8 ; + nsec_per_tick = (u64 )TICK_NSEC <<8 ; nsec_per_tick += (u32 )shift_hz/2 ;do_div (nsec_per_tick, (u32 )shift_hz);
Signature · 1 line
2.7.4
Re: [PATCH 37/37] s390: Prevent from cputime leaks
In reply to Frederic WeisbeckerQuoted 7 lines · On Sun, 22 Jan 2017 19:20:13 +0100 Frederic Weisbecker <[email protected]>…
The s390 clock has a higher granularity than nanoseconds. 1 nanosec equals 4.096 in s390
cputime_t. Therefore we leak a remainder while flushing the cputime throughcputime_to_nsecs().For more precision, make sure we keep that remainder on cputime accumulators for later accounting.
Quoted 15 lines
Reported-by Martin Schwidefsky <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Heiko Carstens <[email protected]>Cc Martin Schwidefsky <[email protected]>Cc Tony Luck <[email protected]>Cc Fenghua Yu <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Rik van Riel <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Stanislaw Gruszka <[email protected]>Cc Wanpeng Li <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>
NAK. Good intention but the patch is just broken. with 36 of the 37 patches applied all looks good but the last one completely breaks the accounting for s390. This is from an idle system:
top - 10:39:33 up 0 min, 1 user, load average: 0,00, 0,00, 0,00
Tasks: 106 total, 1 running, 105 sleeping, 0 stopped, 0 zombie
%Cpu0 : 8,9 us, 21,6 sy, 0,0 ni, 0,0 id, 0,0 wa, 10,8 hi, 4,3 si, 54,4 st %Cpu1 : 0,0 us, 23,5 sy, 0,0 ni, 0,0 id, 0,0 wa, 19,0 hi, 13,1 si, 44,3 st %Cpu2 : 0,0 us, 30,3 sy, 0,0 ni, 0,0 id, 0,0 wa, 14,7 hi, 14,8 si, 40,2 st KiB Mem : 1009304 total, 818808 free, 57284 used, 133212 buff/cache
KiB Swap: 1048556 total, 1048556 free, 0 used. 917356 avail Mem
There is another issue that affects precision, there is no s390 specific version of cputime_to_nsecs. The generic version uses cputime_to_usecs and mulitplies by 1000 to get nano-seconds. That already looses precision.
For now just drop that last patch please.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
Re: [PATCH 37/37] s390: Prevent from cputime leaks
Quoted 30 lines · Martin Schwidefsky
Quoted 7 lines · On Sun, 22 Jan 2017 19:20:13 +0100 Frederic Weisbecker <[email protected]>…
The s390 clock has a higher granularity than nanoseconds. 1 nanosec equals 4.096 in s390
cputime_t. Therefore we leak a remainder while flushing the cputime throughcputime_to_nsecs().For more precision, make sure we keep that remainder on cputime accumulators for later accounting.
Quoted 15 lines
Reported-by Martin Schwidefsky <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Heiko Carstens <[email protected]>Cc Martin Schwidefsky <[email protected]>Cc Tony Luck <[email protected]>Cc Fenghua Yu <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Rik van Riel <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Stanislaw Gruszka <[email protected]>Cc Wanpeng Li <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>NAK. Good intention but the patch is just broken. with 36 of the 37 patches applied all looks good but the last one completely breaks the accounting for s390. This is from an idle system:
Quoted 7 lines
top - 10:39:33 up 0 min, 1 user, load average: 0,00, 0,00, 0,00
Tasks: 106 total, 1 running, 105 sleeping, 0 stopped, 0 zombie%Cpu0 : 8,9 us, 21,6 sy, 0,0 ni, 0,0 id, 0,0 wa, 10,8 hi, 4,3 si, 54,4 st %Cpu1 : 0,0 us, 23,5 sy, 0,0 ni, 0,0 id, 0,0 wa, 19,0 hi, 13,1 si, 44,3 st %Cpu2 : 0,0 us, 30,3 sy, 0,0 ni, 0,0 id, 0,0 wa, 14,7 hi, 14,8 si, 40,2 st KiB Mem : 1009304 total, 818808 free, 57284 used, 133212 buff/cacheKiB Swap: 1048556 total, 1048556 free, 0 used. 917356 avail Mem
Oh ok. I must have done something wrong.
Quoted 4 lines
There is another issue that affects precision, there is no s390 specific version of
cputime_to_nsecs. The generic version usescputime_to_usecsand mulitplies by 1000 to get nano-seconds. That already looses precision.
That's right. And that's the point of this patch. I'm not sure we can have a more precise version of cputime_to_nsecs() if 1 nsec == 4.096 cputime_t
Quoted 2 lines
For now just drop that last patch please.
Ok, I'm leaving it apart.
Thanks.
Re: [PATCH 37/37] s390: Prevent from cputime leaks
Quoted 42 lines · On Wed, 25 Jan 2017 16:25:20 +0100 Frederic Weisbecker <[email protected]>…
Quoted 30 lines · Martin Schwidefsky
Quoted 7 lines · On Sun, 22 Jan 2017 19:20:13 +0100 Frederic Weisbecker <[email protected]>…
The s390 clock has a higher granularity than nanoseconds. 1 nanosec equals 4.096 in s390
cputime_t. Therefore we leak a remainder while flushing the cputime throughcputime_to_nsecs().For more precision, make sure we keep that remainder on cputime accumulators for later accounting.
Quoted 15 lines
Reported-by Martin Schwidefsky <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Heiko Carstens <[email protected]>Cc Martin Schwidefsky <[email protected]>Cc Tony Luck <[email protected]>Cc Fenghua Yu <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Rik van Riel <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Stanislaw Gruszka <[email protected]>Cc Wanpeng Li <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>NAK. Good intention but the patch is just broken. with 36 of the 37 patches applied all looks good but the last one completely breaks the accounting for s390. This is from an idle system:
Quoted 7 lines
top - 10:39:33 up 0 min, 1 user, load average: 0,00, 0,00, 0,00
Tasks: 106 total, 1 running, 105 sleeping, 0 stopped, 0 zombie%Cpu0 : 8,9 us, 21,6 sy, 0,0 ni, 0,0 id, 0,0 wa, 10,8 hi, 4,3 si, 54,4 st %Cpu1 : 0,0 us, 23,5 sy, 0,0 ni, 0,0 id, 0,0 wa, 19,0 hi, 13,1 si, 44,3 st %Cpu2 : 0,0 us, 30,3 sy, 0,0 ni, 0,0 id, 0,0 wa, 14,7 hi, 14,8 si, 40,2 st KiB Mem : 1009304 total, 818808 free, 57284 used, 133212 buff/cacheKiB Swap: 1048556 total, 1048556 free, 0 used. 917356 avail Mem
Oh ok. I must have done something wrong.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
There is another issue that affects precision, there is no s390 specific version of
cputime_to_nsecs. The generic version usescputime_to_usecsand mulitplies by 1000 to get nano-seconds. That already looses precision.That's right. And that's the point of this patch. I'm not sure we can have a more precise version of
cputime_to_nsecs()if 1 nsec == 4.096cputime_t
I am thinking about a version that does the calculation (cputime * 1000) >> 12 in several steps, like this
nsecs = (((((cputime * 5) >> 3) * 5) >> 3) * 5) >> 3
To multiply with 5 is a shift by 2 and an add. In total that would gives us 6 shifts and 3 adds for the conversion.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
Re: [PATCH 08/37] cputime: Convert task/group cputime to nsecs
In reply to Frederic WeisbeckerHi Frederic and sorry for late comment.
Quoted 5 lines · Frederic Weisbecker
Now that most cputime readers use the transition API which return the task cputime in old style
cputime_t, we can safely store the cputime in nsecs. This will eventually make cputime statistics less opaque and more granular. Back and forth convertions betweencputime_tand nsecs in order to deal withcputime_trandom granularity won't be needed anymore.
<snip>
Quoted 6 lines
include/linux/sched.h +2
-2-cputime_t utime; -cputime_t stime; +u64 utime; +u64 stime;unsigned long long sum_exec_runtime; };
<snip>
Quoted 7 lines
kernel/sched/cputime.c +1
-1@@ -134,7 +134,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime)int index;/* Add user time to process. */ - p->utime += cputime; + p->utime +=cputime_to_nsecs (cputime);account_group_user_time (p, cputime);
<snip>
Quoted 5 lines
kernel/sched/cputime.c +1
-0+void task_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st) { *ut = p->utime; *st = p->stime;o }
On 32 bit architectures 64bit store/load is not atomic and if not protected - 64bit variables can be mangled. I do not see any protection (lock) between utime/stime store and load in the patch and seems that {u/s}time store/load can be performed at the same time. Though problem is very very improbable it still can happen at least theoretically when lower and upper 32 bits are changed at the same time i.e. process {u,s}time become near to multiple of 2**32 nsec (aprox: 4sec) and 64bit {u,s}time is stored and loaded at the same time on different cpus. As said this is very improbable situation, but eventually could be possible on long lived processes.
BTW we have already similar problem with sum_exec_runtime. I posted some patches to solve the problem, but non of them was good:
- https://lkml.org/lkml/2016/9/1/172
this one slow down scheduler hot path's and Peter hates it.
- https://lkml.org/lkml/2016/9/6/305
this one was fine for Peter, but I dislike it for taking task_rq_lock() and do not push it forward.
I considering fixing problem of sum_exec_runtime possible mangling by using prev_sum_exec_runtime:
u64 read_sum_exec_runtime(struct task_struct *t)
{
u64 ns, prev_ns;
do {
prev_ns = READ_ONCE(t->se.prev_sum_exec_runtime);
ns = READ_ONCE(t->se.sum_exec_runtime);
} while (ns < prev_ns || ns > (prev_ns + U32_MAX));
return ns;
}This should work based on fact that prev_sum_exec_runtime and sum_exec_runtime are not modified and stored at the same time, so only one of those variabled can be mangled. Though I need to think about correctnes of that a bit more.
Stanislaw
Re: [PATCH 08/37] cputime: Convert task/group cputime to nsecs
Quoted 30 lines · Stanislaw Gruszka
Hi Frederic and sorry for late comment.
Quoted 5 lines · Frederic Weisbecker
Now that most cputime readers use the transition API which return the task cputime in old style
cputime_t, we can safely store the cputime in nsecs. This will eventually make cputime statistics less opaque and more granular. Back and forth convertions betweencputime_tand nsecs in order to deal withcputime_trandom granularity won't be needed anymore.<snip>
Quoted 6 lines
include/linux/sched.h +2
-2-cputime_t utime; -cputime_t stime; +u64 utime; +u64 stime;unsigned long long sum_exec_runtime; };<snip>
Quoted 7 lines
kernel/sched/cputime.c +1
-1@@ -134,7 +134,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime)int index;/* Add user time to process. */ - p->utime += cputime; + p->utime +=cputime_to_nsecs (cputime);account_group_user_time (p, cputime);<snip>
Quoted 5 lines
kernel/sched/cputime.c +1
-0+void task_cputime_adjusted (struct task_struct *p,u64 *ut,u64 *st) { *ut = p->utime; *st = p->stime;o }
Quoted 10 lines
On 32 bit architectures 64bit store/load is not atomic and if not protected - 64bit variables can be mangled. I do not see any protection (lock) between utime/stime store and load in the patch and seems that {u/s}time store/load can be performed at the same time. Though problem is very very improbable it still can happen at least theoretically when lower and upper 32 bits are changed at the same time i.e. process {u,s}time become near to multiple of 2**32 nsec (aprox: 4sec) and 64bit {u,s}time is stored and loaded at the same time on different cpus. As said this is very improbable situation, but eventually could be possible on long lived processes.
"Improbable situation" doesn't appply to Linux. With millions (billion?) of machines using it, a rare issue in the core turns into likely to happen somewhere in the planet every second.
So it's definetly a race we want to consider. Note it goes beyond the scope of this patchset as the issue was already there before since cputime_t can already map to u64 on 32 bits systems upstream. But this patchset definetly extends the issue on all 32 bits configs.
kcpustat has the same issue upstream. It's is made of u64 on all configs.
Quoted 5 lines
BTW we have already similar problem with
sum_exec_runtime. I posted some patches to solve the problem, but non of them was good:
- https://lkml.org/lkml/2016/9/1/172
this one slow down scheduler hot path's and Peter hates it.
Note u64_stats_sync handles the ifdeffery for this solution.
Quoted 4 lines
- https://lkml.org/lkml/2016/9/6/305
this one was fine for Peter, but I dislike it for takingtask_rq_lock()and do not push it forward.
Yeah taking rq lock looks too much.
Quoted 16 lines
I considering fixing problem of
sum_exec_runtimepossible mangling by usingprev_sum_exec_runtime:u64
read_sum_exec_runtime(struct task_struct *t){ u64 ns, prev_ns; do { prev_ns = READ_ONCE(t->se.prev_sum_exec_runtime); ns = READ_ONCE(t->se.sum_exec_runtime); } while (ns < prev_ns || ns > (prev_ns + U32_MAX)); return ns; }
Quoted 4 lines
This should work based on fact that
prev_sum_exec_runtimeandsum_exec_runtimeare not modified and stored at the same time, so only one of those variabled can be mangled. Though I need to think about correctnes of that a bit more.
I'm not sure that would be enough. READ_ONCE prevents from reordering by the compiler but not by the CPU. You'd need memory barriers between reads and writes of prev_ns and ns.
WRITE ns READ prev_ns smp_wmb() smp_rmb() WRITE prev_ns READ ns smp_wmb() smp_rmb()
It seems to be the only way to make sure that at least one of the reads (prev_ns or ns) is correct.
But then I think that seqlock through u64_stats_sync would be more efficient.
It's indeed very complicated to solve such issue without bothering the fast path. Irqtime accounting uses a per cpu u64_stats_sync which could be extended to the whole cputime accounting. I fear that would only solve the issue for kcpustat though as task cputime would need a per task u64_stats_sync.
Thanks.
Re: [PATCH 08/37] cputime: Convert task/group cputime to nsecs
Quoted 16 lines · Frederic Weisbecker
Quoted 10 lines · Stanislaw Gruszka
On 32 bit architectures 64bit store/load is not atomic and if not protected - 64bit variables can be mangled. I do not see any protection (lock) between utime/stime store and load in the patch and seems that {u/s}time store/load can be performed at the same time. Though problem is very very improbable it still can happen at least theoretically when lower and upper 32 bits are changed at the same time i.e. process {u,s}time become near to multiple of 2**32 nsec (aprox: 4sec) and 64bit {u,s}time is stored and loaded at the same time on different cpus. As said this is very improbable situation, but eventually could be possible on long lived processes.
"Improbable situation" doesn't appply to Linux. With millions (billion?) of machines using it, a rare issue in the core turns into likely to happen somewhere in the planet every second.
Quoted 6 lines
So it's definetly a race we want to consider. Note it goes beyond the scope of this patchset as the issue was already there before since
cputime_tcan already map to u64 on 32 bits systems upstream. But this patchset definetly extends the issue on all 32 bits configs.kcpustat has the same issue upstream. It's is made of u64 on all configs.
I would like to add what are possible consequences if value will be mangled. For sum_exec_runtime, utime and stime we could get wrong values on cpu-clock related syscalls like clock_gettime() or clock_nanosleep() and cpu-clock timers like timer_create(CLOCK_PROCESS_CPUTIME_ID) can be triggered before or long after expected. For kcpustat this seems to be wrong values read by procfs and 3 drivers (cpufreq, appldata, macintosh).
Quoted 15 lines
Quoted 15 lines
I considering fixing problem of
sum_exec_runtimepossible mangling by usingprev_sum_exec_runtime:u64
read_sum_exec_runtime(struct task_struct *t){ u64 ns, prev_ns; do { prev_ns = READ_ONCE(t->se.prev_sum_exec_runtime); ns = READ_ONCE(t->se.sum_exec_runtime); } while (ns < prev_ns || ns > (prev_ns + U32_MAX)); return ns; }
Quoted 8 lines
Quoted 4 lines
This should work based on fact that
prev_sum_exec_runtimeandsum_exec_runtimeare not modified and stored at the same time, so only one of those variabled can be mangled. Though I need to think about correctnes of that a bit more.I'm not sure that would be enough.
READ_ONCEprevents from reordering by the compiler but not by the CPU. You'd need memory barriers between reads and writes ofprev_nsand ns.
It will not be enough, this _suppose_ to work based on that sum_exec_runtime and prev_sum_exec_runtime are not written at the same time. i.e. only one variable can be mangled as another one sits already in the memory. However "not written at the same time" is weak part of reasoning. Even if those variables are stored at different part of code (sum_exec_runtime on update_curr() and prev_sum_exec_runtime on set_next_entity()) we can not assume store of one variable is finished before another one starts.
Quoted 7 lines
WRITE ns READ prev_ns smp_wmb() smp_rmb() WRITE prev_ns READ ns smp_wmb() smp_rmb()It seems to be the only way to make sure that at least one of the reads (
prev_nsor ns) is correct.
I think you have right, but seems on much code paths we have scenario:
WRITE ns READ prev_ns
smp_wmb() smp_rmb()
WRITE prev_ns READ ns
and we have already smp_wmb() after write of sum_exec_runtime on update_min_vruntime().
Stanislaw
Re: [PATCH 08/37] cputime: Convert task/group cputime to nsecs
Quoted 22 lines · Stanislaw Gruszka
Quoted 21 lines · Frederic Weisbecker
Quoted 10 lines · Stanislaw Gruszka
On 32 bit architectures 64bit store/load is not atomic and if not protected - 64bit variables can be mangled. I do not see any protection (lock) between utime/stime store and load in the patch and seems that {u/s}time store/load can be performed at the same time. Though problem is very very improbable it still can happen at least theoretically when lower and upper 32 bits are changed at the same time i.e. process {u,s}time become near to multiple of 2**32 nsec (aprox: 4sec) and 64bit {u,s}time is stored and loaded at the same time on different cpus. As said this is very improbable situation, but eventually could be possible on long lived processes.
"Improbable situation" doesn't appply to Linux. With millions (billion?) of machines using it, a rare issue in the core turns into likely to happen somewhere in the planet every second.
So it's definetly a race we want to consider. Note it goes beyond the scope of this patchset as the issue was already there before since
cputime_tcan already map to u64 on 32 bits systems upstream. But this patchset definetly extends the issue on all 32 bits configs.
Quoted 8 lines
Quoted 1 line
kcpustat has the same issue upstream. It's is made of u64 on all configs.
I would like to add what are possible consequences if value will be mangled. For
sum_exec_runtime, utime and stime we could get wrong values on cpu-clock related syscalls likeclock_gettime()orclock_nanosleep()and cpu-clock timers liketimer_create(CLOCK_PROCESS_CPUTIME_ID)can be triggered before or long after expected. For kcpustat this seems to be wrong values read by procfs and 3 drivers (cpufreq, appldata, macintosh).
Yep, all agreed.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
I considering fixing problem of
sum_exec_runtimepossible mangling by usingprev_sum_exec_runtime:u64
read_sum_exec_runtime(struct task_struct *t){ u64 ns, prev_ns; do { prev_ns = READ_ONCE(t->se.prev_sum_exec_runtime); ns = READ_ONCE(t->se.sum_exec_runtime); } while (ns < prev_ns || ns > (prev_ns + U32_MAX)); return ns; }Quoted 8 lines
Quoted 4 lines
This should work based on fact that
prev_sum_exec_runtimeandsum_exec_runtimeare not modified and stored at the same time, so only one of those variabled can be mangled. Though I need to think about correctnes of that a bit more.I'm not sure that would be enough.
READ_ONCEprevents from reordering by the compiler but not by the CPU. You'd need memory barriers between reads and writes ofprev_nsand ns.
Quoted 7 lines
It will not be enough, this _suppose_ to work based on that
sum_exec_runtimeandprev_sum_exec_runtimeare not written at the same time. i.e. only one variable can be mangled as another one sits already in the memory. However "not written at the same time" is weak part of reasoning. Even if those variables are stored at different part of code (sum_exec_runtimeonupdate_curr()andprev_sum_exec_runtimeonset_next_entity()) we can not assume store of one variable is finished before another one starts.
Right.
Quoted 8 lines
Quoted 8 lines
WRITE ns READ prev_ns smp_wmb() smp_rmb() WRITE prev_ns READ ns smp_wmb() smp_rmb()It seems to be the only way to make sure that at least one of the reads (
prev_nsor ns) is correct.
Well reading that again, I'm not 100% sure about the correctness guarantee. But it might work.
Quoted 9 lines
I think you have right, but seems on much code paths we have scenario:
WRITE ns READ
prev_ns
smp_wmb()smp_rmb()
WRITEprev_nsREAD nsand we have already
smp_wmb()after write ofsum_exec_runtimeonupdate_min_vruntime().
You still need a second barrier after the second write and read (or before the first write and read, it's the same) to ensure that if you read a mangled version of ns, prev_ns is ok.
Still I think u64_stats_sync is less trouble and more reliable.
Thanks.