Message ID | 1471396611-3347-1-git-send-email-wanpeng.li@hotmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, 2016-08-17 at 09:16 +0800, Wanpeng Li wrote: > > @@ -694,6 +699,12 @@ static cputime_t get_vtime_delta(struct > task_struct *tsk) > unsigned long now = READ_ONCE(jiffies); > cputime_t delta, other; > > + /* > + * The interval returned by account_other_time() is NOT > + * rounded down to the nearest jiffy, while the base > + * interval it is subtracted from is. So the max cputime > + * limit is required to avoid underflow. > + */ > delta = jiffies_to_cputime(now - tsk->vtime_snap); > other = account_other_time(delta); > WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE); That comment makes sense in the context of the discussion we have been having over the past few days, but could be somewhat cryptic to someone looking at it 3 years from now. How about something like the following? /* * Unlike tick based timing, vtime based timing never has lost * ticks, and no need for steal time accounting to make up for * lost ticks. Vtime accounts a rounded version of actual * elapsed time. Limit account_other_time to prevent rounding * errors from causing elapsed vtime to go negative. */ -- All Rights Reversed.
2016-08-17 9:54 GMT+08:00 Rik van Riel <riel@redhat.com>: > On Wed, 2016-08-17 at 09:16 +0800, Wanpeng Li wrote: >> >> @@ -694,6 +699,12 @@ static cputime_t get_vtime_delta(struct >> task_struct *tsk) >> unsigned long now = READ_ONCE(jiffies); >> cputime_t delta, other; >> >> + /* >> + * The interval returned by account_other_time() is NOT >> + * rounded down to the nearest jiffy, while the base >> + * interval it is subtracted from is. So the max cputime >> + * limit is required to avoid underflow. >> + */ >> delta = jiffies_to_cputime(now - tsk->vtime_snap); >> other = account_other_time(delta); >> WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE); > > That comment makes sense in the context of the discussion > we have been having over the past few days, but could be > somewhat cryptic to someone looking at it 3 years from now. > > How about something like the following? > > /* > * Unlike tick based timing, vtime based timing never has lost > * ticks, and no need for steal time accounting to make up for > * lost ticks. Vtime accounts a rounded version of actual > * elapsed time. Limit account_other_time to prevent rounding > * errors from causing elapsed vtime to go negative. > */ Great, thanks for your help. I will send out a new version soon. :) Regards, Wanpeng Li -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 9858266..e52cf7f 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -263,6 +263,11 @@ void account_idle_time(cputime_t cputime) cpustat[CPUTIME_IDLE] += (__force u64) cputime; } +/* + * When a guest is interrupted for a longer amount of time, missed clock + * ticks are not redelivered later. Due to that, this function may on + * occasion account more time than the calling functions think elapsed. + */ static __always_inline cputime_t steal_account_process_time(cputime_t maxtime) { #ifdef CONFIG_PARAVIRT @@ -371,7 +376,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, * idle, or potentially user or system time. Due to rounding, * other time can exceed ticks occasionally. */ - other = account_other_time(cputime); + other = account_other_time(ULONG_MAX); if (other >= cputime) return; cputime -= other; @@ -486,7 +491,7 @@ void account_process_tick(struct task_struct *p, int user_tick) } cputime = cputime_one_jiffy; - steal = steal_account_process_time(cputime); + steal = steal_account_process_time(ULONG_MAX); if (steal >= cputime) return; @@ -516,7 +521,7 @@ void account_idle_ticks(unsigned long ticks) } cputime = jiffies_to_cputime(ticks); - steal = steal_account_process_time(cputime); + steal = steal_account_process_time(ULONG_MAX); if (steal >= cputime) return; @@ -694,6 +699,12 @@ static cputime_t get_vtime_delta(struct task_struct *tsk) unsigned long now = READ_ONCE(jiffies); cputime_t delta, other; + /* + * The interval returned by account_other_time() is NOT + * rounded down to the nearest jiffy, while the base + * interval it is subtracted from is. So the max cputime + * limit is required to avoid underflow. + */ delta = jiffies_to_cputime(now - tsk->vtime_snap); other = account_other_time(delta); WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);