Skip to content

Commit ccbf62d

Browse files
KAGA-KOKOjohnstultz-work
authored andcommitted
sched: Make task->start_time nanoseconds based
Simplify the timespec to nsec/usec conversions. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 57e0be0 commit ccbf62d

4 files changed

Lines changed: 14 additions & 19 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ struct task_struct {
13671367
} vtime_snap_whence;
13681368
#endif
13691369
unsigned long nvcsw, nivcsw; /* context switch counts */
1370-
struct timespec start_time; /* monotonic time */
1370+
u64 start_time; /* monotonic time in nsec */
13711371
u64 real_start_time; /* boot based time in nsec */
13721372
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
13731373
unsigned long min_flt, maj_flt;

‎kernel/acct.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
458458
acct_t ac;
459459
mm_segment_t fs;
460460
unsigned long flim;
461-
u64 elapsed;
462-
u64 run_time;
463-
struct timespec uptime;
461+
u64 elapsed, run_time;
464462
struct tty_struct *tty;
465463
const struct cred *orig_cred;
466464

@@ -484,10 +482,8 @@ static void do_acct_process(struct bsd_acct_struct *acct,
484482
strlcpy(ac.ac_comm, current->comm, sizeof(ac.ac_comm));
485483

486484
/* calculate run_time in nsec*/
487-
ktime_get_ts(&uptime);
488-
run_time = (u64)uptime.tv_sec*NSEC_PER_SEC + uptime.tv_nsec;
489-
run_time -= (u64)current->group_leader->start_time.tv_sec * NSEC_PER_SEC
490-
+ current->group_leader->start_time.tv_nsec;
485+
run_time = ktime_get_ns();
486+
run_time -= current->group_leader->start_time;
491487
/* convert nsec -> AHZ */
492488
elapsed = nsec_to_AHZ(run_time);
493489
#if ACCT_VERSION==3

‎kernel/fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
12621262

12631263
posix_cpu_timers_init(p);
12641264

1265-
ktime_get_ts(&p->start_time);
1265+
p->start_time = ktime_get_ns();
12661266
p->real_start_time = ktime_get_boot_ns();
12671267
p->io_context = NULL;
12681268
p->audit_context = NULL;

‎kernel/tsacct.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@ void bacct_add_tsk(struct user_namespace *user_ns,
3131
struct taskstats *stats, struct task_struct *tsk)
3232
{
3333
const struct cred *tcred;
34-
struct timespec uptime, ts;
3534
cputime_t utime, stime, utimescaled, stimescaled;
36-
u64 ac_etime;
35+
u64 delta;
3736

3837
BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);
3938

40-
/* calculate task elapsed time in timespec */
41-
ktime_get_ts(&uptime);
42-
ts = timespec_sub(uptime, tsk->start_time);
43-
/* rebase elapsed time to usec (should never be negative) */
44-
ac_etime = timespec_to_ns(&ts);
45-
do_div(ac_etime, NSEC_PER_USEC);
46-
stats->ac_etime = ac_etime;
47-
stats->ac_btime = get_seconds() - ts.tv_sec;
39+
/* calculate task elapsed time in nsec */
40+
delta = ktime_get_ns() - tsk->start_time;
41+
/* Convert to micro seconds */
42+
do_div(delta, NSEC_PER_USEC);
43+
stats->ac_etime = delta;
44+
/* Convert to seconds for btime */
45+
do_div(delta, USEC_PER_SEC);
46+
stats->ac_btime = get_seconds() - delta;
4847
if (thread_group_leader(tsk)) {
4948
stats->ac_exitcode = tsk->exit_code;
5049
if (tsk->flags & PF_FORKNOEXEC)

0 commit comments

Comments
 (0)