Skip to content

Commit

Permalink
timers/posix-timers: Convert internals to use nsecs
Browse files Browse the repository at this point in the history
Use 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.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Link: http://lkml.kernel.org/r/1485832191-26889-19-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
fweisbec authored and Ingo Molnar committed Feb 1, 2017
1 parent 715eb7a commit ebd7e7f
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 146 deletions.
12 changes: 1 addition & 11 deletions include/linux/posix-timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
6 changes: 3 additions & 3 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -3527,7 +3527,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)
Expand Down
2 changes: 1 addition & 1 deletion kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions kernel/sched/cputime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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. */
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions kernel/sched/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions kernel/time/itimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit ebd7e7f

Please sign in to comment.