Commit ccbf62d8a284cf181ac28c8e8407dd077d90dd4b

Authored by Thomas Gleixner
Committed by John Stultz
1 parent 57e0be041d

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>

Showing 4 changed files with 14 additions and 19 deletions Side-by-side Diff

include/linux/sched.h
... ... @@ -1367,7 +1367,7 @@
1367 1367 } vtime_snap_whence;
1368 1368 #endif
1369 1369 unsigned long nvcsw, nivcsw; /* context switch counts */
1370   - struct timespec start_time; /* monotonic time */
  1370 + u64 start_time; /* monotonic time in nsec */
1371 1371 u64 real_start_time; /* boot based time in nsec */
1372 1372 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
1373 1373 unsigned long min_flt, maj_flt;
... ... @@ -458,9 +458,7 @@
458 458 acct_t ac;
459 459 mm_segment_t fs;
460 460 unsigned long flim;
461   - u64 elapsed;
462   - u64 run_time;
463   - struct timespec uptime;
  461 + u64 elapsed, run_time;
464 462 struct tty_struct *tty;
465 463 const struct cred *orig_cred;
466 464  
... ... @@ -484,10 +482,8 @@
484 482 strlcpy(ac.ac_comm, current->comm, sizeof(ac.ac_comm));
485 483  
486 484 /* 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;
491 487 /* convert nsec -> AHZ */
492 488 elapsed = nsec_to_AHZ(run_time);
493 489 #if ACCT_VERSION==3
... ... @@ -1262,7 +1262,7 @@
1262 1262  
1263 1263 posix_cpu_timers_init(p);
1264 1264  
1265   - ktime_get_ts(&p->start_time);
  1265 + p->start_time = ktime_get_ns();
1266 1266 p->real_start_time = ktime_get_boot_ns();
1267 1267 p->io_context = NULL;
1268 1268 p->audit_context = NULL;
... ... @@ -31,20 +31,19 @@
31 31 struct taskstats *stats, struct task_struct *tsk)
32 32 {
33 33 const struct cred *tcred;
34   - struct timespec uptime, ts;
35 34 cputime_t utime, stime, utimescaled, stimescaled;
36   - u64 ac_etime;
  35 + u64 delta;
37 36  
38 37 BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);
39 38  
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;
48 47 if (thread_group_leader(tsk)) {
49 48 stats->ac_exitcode = tsk->exit_code;
50 49 if (tsk->flags & PF_FORKNOEXEC)