Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull scheduler fixes from Ingo Molnar:
"Two cputime fixes - hopefully the last ones"

* 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
sched/cputime: Resync steal time when guest & host lose sync
sched/cputime: Fix NO_HZ_FULL getrusage() monotonicity regression

+25 -8
+25 -8
kernel/sched/cputime.c
··· 263 263 cpustat[CPUTIME_IDLE] += (__force u64) cputime; 264 264 } 265 265 266 + /* 267 + * When a guest is interrupted for a longer amount of time, missed clock 268 + * ticks are not redelivered later. Due to that, this function may on 269 + * occasion account more time than the calling functions think elapsed. 270 + */ 266 271 static __always_inline cputime_t steal_account_process_time(cputime_t maxtime) 267 272 { 268 273 #ifdef CONFIG_PARAVIRT ··· 376 371 * idle, or potentially user or system time. Due to rounding, 377 372 * other time can exceed ticks occasionally. 378 373 */ 379 - other = account_other_time(cputime); 374 + other = account_other_time(ULONG_MAX); 380 375 if (other >= cputime) 381 376 return; 382 377 cputime -= other; ··· 491 486 } 492 487 493 488 cputime = cputime_one_jiffy; 494 - steal = steal_account_process_time(cputime); 489 + steal = steal_account_process_time(ULONG_MAX); 495 490 496 491 if (steal >= cputime) 497 492 return; ··· 521 516 } 522 517 523 518 cputime = jiffies_to_cputime(ticks); 524 - steal = steal_account_process_time(cputime); 519 + steal = steal_account_process_time(ULONG_MAX); 525 520 526 521 if (steal >= cputime) 527 522 return; ··· 619 614 stime = curr->stime; 620 615 utime = curr->utime; 621 616 622 - if (utime == 0) { 623 - stime = rtime; 617 + /* 618 + * If either stime or both stime and utime are 0, assume all runtime is 619 + * userspace. Once a task gets some ticks, the monotonicy code at 620 + * 'update' will ensure things converge to the observed ratio. 621 + */ 622 + if (stime == 0) { 623 + utime = rtime; 624 624 goto update; 625 625 } 626 626 627 - if (stime == 0) { 628 - utime = rtime; 627 + if (utime == 0) { 628 + stime = rtime; 629 629 goto update; 630 630 } 631 631 632 632 stime = scale_stime((__force u64)stime, (__force u64)rtime, 633 633 (__force u64)(stime + utime)); 634 634 635 + update: 635 636 /* 636 637 * Make sure stime doesn't go backwards; this preserves monotonicity 637 638 * for utime because rtime is monotonic. ··· 660 649 stime = rtime - utime; 661 650 } 662 651 663 - update: 664 652 prev->stime = stime; 665 653 prev->utime = utime; 666 654 out: ··· 704 694 unsigned long now = READ_ONCE(jiffies); 705 695 cputime_t delta, other; 706 696 697 + /* 698 + * Unlike tick based timing, vtime based timing never has lost 699 + * ticks, and no need for steal time accounting to make up for 700 + * lost ticks. Vtime accounts a rounded version of actual 701 + * elapsed time. Limit account_other_time to prevent rounding 702 + * errors from causing elapsed vtime to go negative. 703 + */ 707 704 delta = jiffies_to_cputime(now - tsk->vtime_snap); 708 705 other = account_other_time(delta); 709 706 WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);