* [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue
@ 2008-06-16 9:41 bharathravi1
2008-06-16 9:55 ` Peter Zijlstra
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: bharathravi1 @ 2008-06-16 9:41 UTC (permalink / raw)
To: mingo
Cc: linux-kernel, peterz, dhaval, vatsa, balbir, Bharath Ravi,
Madhava K R
From: Bharath Ravi <bharathravi1@gmail.com>
This patch corrects the incorrect value of per process run-queue wait time
reported by delay statistics. The anomaly was due to the following reason.
When a process leaves the CPU and immediately starts waiting for CPU on
the runqueue (which means it remains in the TASK_RUNNABLE state), the time
of re-entry into the run-queue is never recorded. Due to this, the waiting time
on the runqueue from this point of re-entry upto the next time it hits the CPU
is not accounted for. This is solved by recording the time of re-entry of a
process leaving the CPU in the sched_info_depart() function IF the process will
go back to waiting on the run-queue. This IF condition is verified by checking
whether the process is still in the TASK_RUNNABLE state.
The patch was tested on 2.6.26-rc6 using two simple CPU hog programs. The
values noted prior to the fix did not account for the time spent on the
runqueue waiting. After the fix, the correct values were reported back
to user space.
Signed-off-by: Bharath Ravi <bharathravi1@gmail.com>
Signed-off-by: Madhava K R <madhavakr@gmail.com>
---
kernel/sched_stats.h | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h
index a38878e..80179ef 100644
--- a/kernel/sched_stats.h
+++ b/kernel/sched_stats.h
@@ -198,6 +198,9 @@ static inline void sched_info_queued(struct task_struct *t)
/*
* Called when a process ceases being the active-running process, either
* voluntarily or involuntarily. Now we can calculate how long we ran.
+ * Also, if the process is still in the TASK_RUNNING state, call
+ * sched_info_queued() to mark that it has now again started waiting on
+ * the runqueue.
*/
static inline void sched_info_depart(struct task_struct *t)
{
@@ -206,6 +209,9 @@ static inline void sched_info_depart(struct task_struct *t)
t->sched_info.cpu_time += delta;
rq_sched_info_depart(task_rq(t), delta);
+
+ if (t->state == TASK_RUNNING)
+ sched_info_queued(t);
}
/*
--
1.5.5.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue 2008-06-16 9:41 [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue bharathravi1 @ 2008-06-16 9:55 ` Peter Zijlstra 2008-06-16 12:00 ` Madhava K R 2008-06-16 16:34 ` Balbir Singh 2008-06-19 10:01 ` Peter Zijlstra 2 siblings, 1 reply; 7+ messages in thread From: Peter Zijlstra @ 2008-06-16 9:55 UTC (permalink / raw) To: bharathravi1 Cc: mingo, linux-kernel, dhaval, vatsa, balbir, Madhava K R, Ankita Garg On Mon, 2008-06-16 at 15:11 +0530, bharathravi1@gmail.com wrote: > From: Bharath Ravi <bharathravi1@gmail.com> > > This patch corrects the incorrect value of per process run-queue wait time > reported by delay statistics. The anomaly was due to the following reason. > When a process leaves the CPU and immediately starts waiting for CPU on > the runqueue (which means it remains in the TASK_RUNNABLE state), the time > of re-entry into the run-queue is never recorded. Due to this, the waiting time > on the runqueue from this point of re-entry upto the next time it hits the CPU > is not accounted for. This is solved by recording the time of re-entry of a > process leaving the CPU in the sched_info_depart() function IF the process will > go back to waiting on the run-queue. This IF condition is verified by checking > whether the process is still in the TASK_RUNNABLE state. > > The patch was tested on 2.6.26-rc6 using two simple CPU hog programs. The > values noted prior to the fix did not account for the time spent on the > runqueue waiting. After the fix, the correct values were reported back > to user space. Have you considered: http://lkml.org/lkml/2008/6/5/10 I'm sad to say it is still pending in my todo list :-( - sorry Ankita. > Signed-off-by: Bharath Ravi <bharathravi1@gmail.com> > Signed-off-by: Madhava K R <madhavakr@gmail.com> > --- > kernel/sched_stats.h | 6 ++++++ > 1 files changed, 6 insertions(+), 0 deletions(-) > > diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h > index a38878e..80179ef 100644 > --- a/kernel/sched_stats.h > +++ b/kernel/sched_stats.h > @@ -198,6 +198,9 @@ static inline void sched_info_queued(struct task_struct *t) > /* > * Called when a process ceases being the active-running process, either > * voluntarily or involuntarily. Now we can calculate how long we ran. > + * Also, if the process is still in the TASK_RUNNING state, call > + * sched_info_queued() to mark that it has now again started waiting on > + * the runqueue. > */ > static inline void sched_info_depart(struct task_struct *t) > { > @@ -206,6 +209,9 @@ static inline void sched_info_depart(struct task_struct *t) > > t->sched_info.cpu_time += delta; > rq_sched_info_depart(task_rq(t), delta); > + > + if (t->state == TASK_RUNNING) > + sched_info_queued(t); > } > > /* ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue 2008-06-16 9:55 ` Peter Zijlstra @ 2008-06-16 12:00 ` Madhava K R 2008-06-16 12:42 ` Ankita Garg 0 siblings, 1 reply; 7+ messages in thread From: Madhava K R @ 2008-06-16 12:00 UTC (permalink / raw) To: Peter Zijlstra Cc: bharathravi1, mingo, linux-kernel, dhaval, vatsa, balbir, Ankita Garg Hello, On Mon, Jun 16, 2008 at 3:25 PM, Peter Zijlstra <peterz@infradead.org> wrote: > On Mon, 2008-06-16 at 15:11 +0530, bharathravi1@gmail.com wrote: >> From: Bharath Ravi <bharathravi1@gmail.com> >> >> This patch corrects the incorrect value of per process run-queue wait time >> reported by delay statistics. The anomaly was due to the following reason. >> When a process leaves the CPU and immediately starts waiting for CPU on >> the runqueue (which means it remains in the TASK_RUNNABLE state), the time >> of re-entry into the run-queue is never recorded. Due to this, the waiting time >> on the runqueue from this point of re-entry upto the next time it hits the CPU >> is not accounted for. This is solved by recording the time of re-entry of a >> process leaving the CPU in the sched_info_depart() function IF the process will >> go back to waiting on the run-queue. This IF condition is verified by checking >> whether the process is still in the TASK_RUNNABLE state. >> >> The patch was tested on 2.6.26-rc6 using two simple CPU hog programs. The >> values noted prior to the fix did not account for the time spent on the >> runqueue waiting. After the fix, the correct values were reported back >> to user space. > > > Have you considered: http://lkml.org/lkml/2008/6/5/10 > > I'm sad to say it is still pending in my todo list :-( - sorry Ankita. > It seems that Ankita's patch addresses the scenario where a process is already on the run-queue, and is shuffled about CPUs. This patch addresses the scenario where a process is pre-empted and returns to the run-queue, where the last_queued value is not recorded. I tried our test case with Ankita's patch, and the problem remains. Our test case involves running two tight loops on an idle CPU. Ideally, both should experience a run time of 50% and a delay time of 50%. But the results show negligible delay time for both processes. The problems appear mutually exclusive... >> Signed-off-by: Bharath Ravi <bharathravi1@gmail.com> >> Signed-off-by: Madhava K R <madhavakr@gmail.com> >> --- >> kernel/sched_stats.h | 6 ++++++ >> 1 files changed, 6 insertions(+), 0 deletions(-) >> >> diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h >> index a38878e..80179ef 100644 >> --- a/kernel/sched_stats.h >> +++ b/kernel/sched_stats.h >> @@ -198,6 +198,9 @@ static inline void sched_info_queued(struct task_struct *t) >> /* >> * Called when a process ceases being the active-running process, either >> * voluntarily or involuntarily. Now we can calculate how long we ran. >> + * Also, if the process is still in the TASK_RUNNING state, call >> + * sched_info_queued() to mark that it has now again started waiting on >> + * the runqueue. >> */ >> static inline void sched_info_depart(struct task_struct *t) >> { >> @@ -206,6 +209,9 @@ static inline void sched_info_depart(struct task_struct *t) >> >> t->sched_info.cpu_time += delta; >> rq_sched_info_depart(task_rq(t), delta); >> + >> + if (t->state == TASK_RUNNING) >> + sched_info_queued(t); >> } >> >> /* > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue 2008-06-16 12:00 ` Madhava K R @ 2008-06-16 12:42 ` Ankita Garg 0 siblings, 0 replies; 7+ messages in thread From: Ankita Garg @ 2008-06-16 12:42 UTC (permalink / raw) To: Madhava K R Cc: Peter Zijlstra, bharathravi1, mingo, linux-kernel, dhaval, vatsa, balbir Hi, On Mon, Jun 16, 2008 at 05:30:26PM +0530, Madhava K R wrote: > Hello, > > On Mon, Jun 16, 2008 at 3:25 PM, Peter Zijlstra <peterz@infradead.org> wrote: > > On Mon, 2008-06-16 at 15:11 +0530, bharathravi1@gmail.com wrote: > >> From: Bharath Ravi <bharathravi1@gmail.com> > >> > >> This patch corrects the incorrect value of per process run-queue wait time > >> reported by delay statistics. The anomaly was due to the following reason. > >> When a process leaves the CPU and immediately starts waiting for CPU on > >> the runqueue (which means it remains in the TASK_RUNNABLE state), the time > >> of re-entry into the run-queue is never recorded. Due to this, the waiting time > >> on the runqueue from this point of re-entry upto the next time it hits the CPU > >> is not accounted for. This is solved by recording the time of re-entry of a > >> process leaving the CPU in the sched_info_depart() function IF the process will > >> go back to waiting on the run-queue. This IF condition is verified by checking > >> whether the process is still in the TASK_RUNNABLE state. > >> > >> The patch was tested on 2.6.26-rc6 using two simple CPU hog programs. The > >> values noted prior to the fix did not account for the time spent on the > >> runqueue waiting. After the fix, the correct values were reported back > >> to user space. > > > > > > Have you considered: http://lkml.org/lkml/2008/6/5/10 > > > > I'm sad to say it is still pending in my todo list :-( - sorry Ankita. > > > > It seems that Ankita's patch addresses the scenario where a process is > already on the run-queue, and is shuffled about CPUs. This patch > addresses the scenario where a process is pre-empted and returns to > the run-queue, where the last_queued value is not recorded. > Right, so looks like the two patches are addressing different scenarios. The patch I had sent earlier was addressing the case where the accounting of the task had already begun and then it was migrated to another runqueue, leading to skews. This patch addresses the issue that the task delay accounting could potentially miss some delay stats, as explained by Madhava. > I tried our test case with Ankita's patch, and the problem remains. > Our test case involves running two tight loops on an idle CPU. > Ideally, both should experience a run time of 50% and a delay time of > 50%. But the results show negligible delay time for both processes. > > The problems appear mutually exclusive... > > >> Signed-off-by: Bharath Ravi <bharathravi1@gmail.com> > >> Signed-off-by: Madhava K R <madhavakr@gmail.com> > >> --- > >> kernel/sched_stats.h | 6 ++++++ > >> 1 files changed, 6 insertions(+), 0 deletions(-) > >> > >> diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h > >> index a38878e..80179ef 100644 > >> --- a/kernel/sched_stats.h > >> +++ b/kernel/sched_stats.h > >> @@ -198,6 +198,9 @@ static inline void sched_info_queued(struct task_struct *t) > >> /* > >> * Called when a process ceases being the active-running process, either > >> * voluntarily or involuntarily. Now we can calculate how long we ran. > >> + * Also, if the process is still in the TASK_RUNNING state, call > >> + * sched_info_queued() to mark that it has now again started waiting on > >> + * the runqueue. > >> */ > >> static inline void sched_info_depart(struct task_struct *t) > >> { > >> @@ -206,6 +209,9 @@ static inline void sched_info_depart(struct task_struct *t) > >> > >> t->sched_info.cpu_time += delta; > >> rq_sched_info_depart(task_rq(t), delta); > >> + > >> + if (t->state == TASK_RUNNING) > >> + sched_info_queued(t); > >> } > >> > >> /* > > > > -- Regards, Ankita Garg (ankita@in.ibm.com) Linux Technology Center IBM India Systems & Technology Labs, Bangalore, India ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue 2008-06-16 9:41 [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue bharathravi1 2008-06-16 9:55 ` Peter Zijlstra @ 2008-06-16 16:34 ` Balbir Singh 2008-06-19 10:01 ` Peter Zijlstra 2 siblings, 0 replies; 7+ messages in thread From: Balbir Singh @ 2008-06-16 16:34 UTC (permalink / raw) To: bharathravi1; +Cc: mingo, linux-kernel, peterz, dhaval, vatsa, Madhava K R On Mon, Jun 16, 2008 at 3:11 PM, <bharathravi1@gmail.com> wrote: > From: Bharath Ravi <bharathravi1@gmail.com> > > This patch corrects the incorrect value of per process run-queue wait time > reported by delay statistics. The anomaly was due to the following reason. > When a process leaves the CPU and immediately starts waiting for CPU on > the runqueue (which means it remains in the TASK_RUNNABLE state), the time > of re-entry into the run-queue is never recorded. Due to this, the waiting time > on the runqueue from this point of re-entry upto the next time it hits the CPU > is not accounted for. This is solved by recording the time of re-entry of a > process leaving the CPU in the sched_info_depart() function IF the process will > go back to waiting on the run-queue. This IF condition is verified by checking > whether the process is still in the TASK_RUNNABLE state. > > The patch was tested on 2.6.26-rc6 using two simple CPU hog programs. The > values noted prior to the fix did not account for the time spent on the > runqueue waiting. After the fix, the correct values were reported back > to user space. > > Signed-off-by: Bharath Ravi <bharathravi1@gmail.com> > Signed-off-by: Madhava K R <madhavakr@gmail.com> Looks very good to me Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Balbir ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue 2008-06-16 9:41 [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue bharathravi1 2008-06-16 9:55 ` Peter Zijlstra 2008-06-16 16:34 ` Balbir Singh @ 2008-06-19 10:01 ` Peter Zijlstra 2008-06-19 12:17 ` Ingo Molnar 2 siblings, 1 reply; 7+ messages in thread From: Peter Zijlstra @ 2008-06-19 10:01 UTC (permalink / raw) To: bharathravi1; +Cc: mingo, linux-kernel, dhaval, vatsa, balbir, Madhava K R On Mon, 2008-06-16 at 15:11 +0530, bharathravi1@gmail.com wrote: > From: Bharath Ravi <bharathravi1@gmail.com> > > This patch corrects the incorrect value of per process run-queue wait time > reported by delay statistics. The anomaly was due to the following reason. > When a process leaves the CPU and immediately starts waiting for CPU on > the runqueue (which means it remains in the TASK_RUNNABLE state), the time > of re-entry into the run-queue is never recorded. Due to this, the waiting time > on the runqueue from this point of re-entry upto the next time it hits the CPU > is not accounted for. This is solved by recording the time of re-entry of a > process leaving the CPU in the sched_info_depart() function IF the process will > go back to waiting on the run-queue. This IF condition is verified by checking > whether the process is still in the TASK_RUNNABLE state. > > The patch was tested on 2.6.26-rc6 using two simple CPU hog programs. The > values noted prior to the fix did not account for the time spent on the > runqueue waiting. After the fix, the correct values were reported back > to user space. > > Signed-off-by: Bharath Ravi <bharathravi1@gmail.com> > Signed-off-by: Madhava K R <madhavakr@gmail.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> > --- > kernel/sched_stats.h | 6 ++++++ > 1 files changed, 6 insertions(+), 0 deletions(-) > > diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h > index a38878e..80179ef 100644 > --- a/kernel/sched_stats.h > +++ b/kernel/sched_stats.h > @@ -198,6 +198,9 @@ static inline void sched_info_queued(struct task_struct *t) > /* > * Called when a process ceases being the active-running process, either > * voluntarily or involuntarily. Now we can calculate how long we ran. > + * Also, if the process is still in the TASK_RUNNING state, call > + * sched_info_queued() to mark that it has now again started waiting on > + * the runqueue. > */ > static inline void sched_info_depart(struct task_struct *t) > { > @@ -206,6 +209,9 @@ static inline void sched_info_depart(struct task_struct *t) > > t->sched_info.cpu_time += delta; > rq_sched_info_depart(task_rq(t), delta); > + > + if (t->state == TASK_RUNNING) > + sched_info_queued(t); > } > > /* ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue 2008-06-19 10:01 ` Peter Zijlstra @ 2008-06-19 12:17 ` Ingo Molnar 0 siblings, 0 replies; 7+ messages in thread From: Ingo Molnar @ 2008-06-19 12:17 UTC (permalink / raw) To: Peter Zijlstra Cc: bharathravi1, linux-kernel, dhaval, vatsa, balbir, Madhava K R * Peter Zijlstra <peterz@infradead.org> wrote: > > The patch was tested on 2.6.26-rc6 using two simple CPU hog > > programs. The values noted prior to the fix did not account for the > > time spent on the runqueue waiting. After the fix, the correct > > values were reported back to user space. > > > > Signed-off-by: Bharath Ravi <bharathravi1@gmail.com> > > Signed-off-by: Madhava K R <madhavakr@gmail.com> > > Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> applied to tip/sched/urgent - thanks. Ingo ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-06-19 12:18 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-06-16 9:41 [PATCH] Delay accounting, fix incorrect delay time when constantly waiting on runqueue bharathravi1 2008-06-16 9:55 ` Peter Zijlstra 2008-06-16 12:00 ` Madhava K R 2008-06-16 12:42 ` Ankita Garg 2008-06-16 16:34 ` Balbir Singh 2008-06-19 10:01 ` Peter Zijlstra 2008-06-19 12:17 ` Ingo Molnar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox