From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Stephane Eranian <eranian@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Jiri Olsa <jolsa@kernel.org>,
Milian Wolff <milian.wolff@kdab.com>,
linux-perf-users@vger.kernel.org,
Namhyung Kim <namhyung@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: measuring system wide CPU usage ignoring idle process
Date: Tue, 17 Apr 2018 10:41:31 -0300 [thread overview]
Message-ID: <20180417134131.GA3027@kernel.org> (raw)
In-Reply-To: <20171123151536.3vzjtbs5e4pccxpw@hirez.programming.kicks-ass.net>
Em Thu, Nov 23, 2017 at 04:15:36PM +0100, Peter Zijlstra escreveu:
> On Thu, Nov 23, 2017 at 11:42:20AM -0300, Arnaldo Carvalho de Melo wrote:
> > What is wrong with perf_event_attr.exclude_idle? :-)
>
> Neither task- nor cpu-clock actually implement that..
>
> Something like the _completely_untested_ below might cure that for
> cpu-clock. I have the nagging feeling we actually already account the
> idle time _somewhere_, but I couldn't remember and was too lazy to go
> find -- but someone should if this were to become an actual patch.
>
Stephane, this was the thread,
- Arnaldo
> ---
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index a59fe11558a4..5386d551b373 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8900,6 +8908,10 @@ static void cpu_clock_event_update(struct perf_event *event)
> u64 now;
>
> now = local_clock();
> +
> + if (event->attr.exclude_idle)
> + now -= idle_task(event->oncpu)->se.sum_exec_runtime;
> +
> prev = local64_xchg(&event->hw.prev_count, now);
> local64_add(now - prev, &event->count);
> }
> diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c
> index d518664cce4f..419c620510c6 100644
> --- a/kernel/sched/idle_task.c
> +++ b/kernel/sched/idle_task.c
> @@ -27,9 +27,14 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl
> static struct task_struct *
> pick_next_task_idle(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
> {
> + struct task_struct *idle = rq->idle;
> +
> put_prev_task(rq, prev);
> update_idle_core(rq);
> schedstat_inc(rq->sched_goidle);
> +
> + idle->se.exec_start = rq_clock_task(rq);
> +
> return rq->idle;
> }
>
> @@ -48,6 +53,17 @@ dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags)
>
> static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
> {
> + struct task_struct *idle = rq->idle;
> + u64 delta, now;
> +
> + now = rq_clock_task(rq);
> + delta = now - idle->se.exec_start;
> + if (unlikely((s64)delta < 0))
> + delta = 0;
> +
> + idle->se.sum_exec_runtime += delta;
> + idle->se.exec_start = now;
> +
> rq_last_tick_reset(rq);
> }
>
> @@ -57,6 +73,9 @@ static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
>
> static void set_curr_task_idle(struct rq *rq)
> {
> + struct task_struct *idle = rq->idle;
> +
> + idle->se.exec_start = rq_clock_task(rq);
> }
>
> static void switched_to_idle(struct rq *rq, struct task_struct *p)
prev parent reply other threads:[~2018-04-17 13:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 14:00 measuring system wide CPU usage ignoring idle process Milian Wolff
2017-11-20 14:29 ` Jiri Olsa
2017-11-20 20:24 ` Milian Wolff
2017-11-20 23:44 ` Jiri Olsa
2017-11-23 13:40 ` Milian Wolff
2017-11-23 14:09 ` Jiri Olsa
2017-11-23 14:21 ` Jiri Olsa
2017-11-23 14:42 ` Arnaldo Carvalho de Melo
2017-11-23 15:12 ` Jiri Olsa
2017-11-23 18:59 ` Arnaldo Carvalho de Melo
2017-11-24 8:14 ` Jiri Olsa
2017-11-23 15:15 ` Peter Zijlstra
2018-04-17 13:41 ` Arnaldo Carvalho de Melo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180417134131.GA3027@kernel.org \
--to=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=milian.wolff@kdab.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).