History

sched/cputime: Add vtime guest task state

Record guest as a VTIME state instead of guessing it from VTIME_SYS and PF_VCPU. This is going to simplify the cputime read side especially as its state machine is going to further expand in order to fully support kcpustat on nohz_full.

Frederic Weisbecker committed 7 years ago

Commit e6d5bf31 parent 14faf6f2 files · +13 −7Browse files

Unified · Split

2 files
  1. include/linux/sched.h +2 −0
  2. kernel/sched/cputime.c +11 −7
include/linux/sched.h+2−0
@@ -255,6 +255,8 @@ enum vtime_state { · 254 unmodified lines
255255 VTIME_SYS,
256256 /* Task runs in userspace in a CPU with VTIME active: */
257257 VTIME_USER,
258+ /* Task runs as guests in a CPU with VTIME active: */
259+ VTIME_GUEST,
258260 };
259261
260262 struct vtime {
kernel/sched/cputime.c+11−7
@@ -733,7 +733,7 @@ static void __vtime_account_kernel(struct task_struct *tsk, · 732 unmodified lines
733733 struct vtime *vtime)
734734 {
735735 /* We might have scheduled out from guest path */
736− if (tsk->flags & PF_VCPU)
736+ if (vtime->state == VTIME_GUEST)
737737 vtime_account_guest(tsk, vtime);
738738 else
739739 vtime_account_system(tsk, vtime);
@@ -788,6 +788,7 @@ void vtime_guest_enter(struct task_struct *tsk) · 48 unmodified lines
788788 write_seqcount_begin(&vtime->seqcount);
789789 vtime_account_system(tsk, vtime);
790790 tsk->flags |= PF_VCPU;
791+ vtime->state = VTIME_GUEST;
791792 write_seqcount_end(&vtime->seqcount);
792793 }
793794 EXPORT_SYMBOL_GPL(vtime_guest_enter);
@@ -799,6 +800,7 @@ void vtime_guest_exit(struct task_struct *tsk) · 5 unmodified lines
799800 write_seqcount_begin(&vtime->seqcount);
800801 vtime_account_guest(tsk, vtime);
801802 tsk->flags &= ~PF_VCPU;
803+ vtime->state = VTIME_SYS;
802804 write_seqcount_end(&vtime->seqcount);
803805 }
804806 EXPORT_SYMBOL_GPL(vtime_guest_exit);
@@ -826,6 +828,8 @@ void vtime_task_switch_generic(struct task_struct *prev) · 21 unmodified lines
826828 write_seqcount_begin(&vtime->seqcount);
827829 if (is_idle_task(current))
828830 vtime->state = VTIME_IDLE;
831+ else if (current->flags & PF_VCPU)
832+ vtime->state = VTIME_GUEST;
829833 else
830834 vtime->state = VTIME_SYS;
831835 vtime->starttime = sched_clock();
@@ -860,7 +864,7 @@ u64 task_gtime(struct task_struct *t) · 28 unmodified lines
860864 seq = read_seqcount_begin(&vtime->seqcount);
861865
862866 gtime = t->gtime;
863− if (vtime->state == VTIME_SYS && t->flags & PF_VCPU)
867+ if (vtime->state == VTIME_GUEST)
864868 gtime += vtime->gtime + vtime_delta(vtime);
865869
866870 } while (read_seqcount_retry(&vtime->seqcount, seq));
@@ -898,13 +902,13 @@ void task_cputime(struct task_struct *t, u64 *utime, u64 *stime) · 31 unmodified lines
898902 delta = vtime_delta(vtime);
899903
900904 /*
901− * Task runs either in user or kernel space, add pending nohz time to
902− * the right place.
905+ * Task runs either in user (including guest) or kernel space,
906+ * add pending nohz time to the right place.
903907 */
904− if (vtime->state == VTIME_USER || t->flags & PF_VCPU)
905− *utime += vtime->utime + delta;
906− else if (vtime->state == VTIME_SYS)
908+ if (vtime->state == VTIME_SYS)
907909 *stime += vtime->stime + delta;
910+ else
911+ *utime += vtime->utime + delta;
908912 } while (read_seqcount_retry(&vtime->seqcount, seq));
909913 }
910914 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t