Skip to content

Commit ebd7e7f

Browse files
fweisbecingomolnar
authored andcommitted
timers/posix-timers: Convert internals to use nsecs
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>
1 parent 715eb7a commit ebd7e7f

7 files changed

Lines changed: 100 additions & 146 deletions

File tree

‎include/linux/posix-timers.h‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,9 @@
88
#include <linux/alarmtimer.h>
99

1010

11-
static inline unsigned long long cputime_to_expires(cputime_t expires)
12-
{
13-
return (__force unsigned long long)expires;
14-
}
15-
16-
static inline cputime_t expires_to_cputime(unsigned long long expires)
17-
{
18-
return (__force cputime_t)expires;
19-
}
20-
2111
struct cpu_timer_list {
2212
struct list_head entry;
23-
unsigned long long expires, incr;
13+
u64 expires, incr;
2414
struct task_struct *task;
2515
int firing;
2616
};

‎include/linux/sched.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ struct signal_struct {
755755
struct thread_group_cputimer cputimer;
756756

757757
/* Earliest-expiration cache. */
758-
struct task_cputime_t cputime_expires;
758+
struct task_cputime cputime_expires;
759759

760760
#ifdef CONFIG_NO_HZ_FULL
761761
atomic_t tick_dep_mask;
@@ -1689,7 +1689,7 @@ struct task_struct {
16891689
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
16901690
unsigned long min_flt, maj_flt;
16911691

1692-
struct task_cputime_t cputime_expires;
1692+
struct task_cputime cputime_expires;
16931693
struct list_head cpu_timers[3];
16941694

16951695
/* process credentials */
@@ -3527,7 +3527,7 @@ static __always_inline bool need_resched(void)
35273527
* Thread group CPU time accounting.
35283528
*/
35293529
void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
3530-
void thread_group_cputimer(struct task_struct *tsk, struct task_cputime_t *times);
3530+
void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
35313531

35323532
static inline void thread_group_cputime_t(struct task_struct *tsk,
35333533
struct task_cputime_t *cputime)

‎kernel/fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
13131313

13141314
cpu_limit = READ_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur);
13151315
if (cpu_limit != RLIM_INFINITY) {
1316-
sig->cputime_expires.prof_exp = secs_to_cputime(cpu_limit);
1316+
sig->cputime_expires.prof_exp = cpu_limit * NSEC_PER_SEC;
13171317
sig->cputimer.running = true;
13181318
}
13191319

‎kernel/sched/cputime.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
122122

123123
/* Add user time to process. */
124124
p->utime += cputime_to_nsecs(cputime);
125-
account_group_user_time(p, cputime);
125+
account_group_user_time(p, cputime_to_nsecs(cputime));
126126

127127
index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
128128

@@ -144,7 +144,7 @@ void account_guest_time(struct task_struct *p, cputime_t cputime)
144144

145145
/* Add guest time to process. */
146146
p->utime += cputime_to_nsecs(cputime);
147-
account_group_user_time(p, cputime);
147+
account_group_user_time(p, cputime_to_nsecs(cputime));
148148
p->gtime += cputime_to_nsecs(cputime);
149149

150150
/* Add guest time to cpustat. */
@@ -168,7 +168,7 @@ void account_system_index_time(struct task_struct *p,
168168
{
169169
/* Add system time to process. */
170170
p->stime += cputime_to_nsecs(cputime);
171-
account_group_system_time(p, cputime);
171+
account_group_system_time(p, cputime_to_nsecs(cputime));
172172

173173
/* Add system time to cpustat. */
174174
task_group_account_field(p, index, cputime_to_nsecs(cputime));

‎kernel/sched/stats.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static inline bool cputimer_running(struct task_struct *tsk)
216216
* running CPU and update the utime field there.
217217
*/
218218
static inline void account_group_user_time(struct task_struct *tsk,
219-
cputime_t cputime)
219+
u64 cputime)
220220
{
221221
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
222222

@@ -237,7 +237,7 @@ static inline void account_group_user_time(struct task_struct *tsk,
237237
* running CPU and update the stime field there.
238238
*/
239239
static inline void account_group_system_time(struct task_struct *tsk,
240-
cputime_t cputime)
240+
u64 cputime)
241241
{
242242
struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
243243

‎kernel/time/itimer.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
5353
cval = it->expires;
5454
cinterval = it->incr;
5555
if (cval) {
56-
struct task_cputime_t cputime;
56+
struct task_cputime cputime;
5757
cputime_t t;
5858

5959
thread_group_cputimer(tsk, &cputime);
6060
if (clock_id == CPUCLOCK_PROF)
61-
t = cputime.utime + cputime.stime;
61+
t = nsecs_to_cputime(cputime.utime + cputime.stime);
6262
else
6363
/* CPUCLOCK_VIRT */
64-
t = cputime.utime;
64+
t = nsecs_to_cputime(cputime.utime);
6565

6666
if (cval < t)
6767
/* about to fire */

0 commit comments

Comments
 (0)