mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: kan.liang@intel.com
To: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com
Cc: alexander.shishkin@linux.intel.com, eranian@google.com,
	ak@linux.intel.com, Kan Liang <kan.liang@intel.com>
Subject: [PATCH 1/2] perf,core: try parent pmu first when init child event
Date: Wed, 18 Jan 2017 08:21:01 -0500	[thread overview]
Message-ID: <1484745662-15928-2-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1484745662-15928-1-git-send-email-kan.liang@intel.com>

From: Kan Liang <kan.liang@intel.com>

perf brings additional overhead when monitoring the task which
frequently generates child task.

perf_init_event is one of the hotspot for the additional overhead.
Currently, to get the pmu, it tries to search the type in pmu_idr at
first. But it is not always successful, especially for the widely used
PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE events. So it has to go to the
slow path which go through the whole pmus list.
It will be a big performance issue, if the pmus list is long (E.g. server
with many uncore boxes) and the task frequently generates child tasks.

The child event inherits its parent event. So the child event should
tries its parent pmu first.

Here is some data from the overhead test on Broadwell server
  perf record -e $TEST_EVENTS -- ./loop.sh 50000

loop.sh
  start=$(date +%s%N)
  i=0
  while [ "$i" -le "$1" ]
  do
          date > /dev/null
          i=`expr $i + 1`
  done
  end=$(date +%s%N)
  elapsed=`expr $end - $start`

Event#	Original elapsed time	Elapsed time with patch		delta
1	196,573,192,397		189,162,029,998			-3.77%
2	257,567,753,013		241,620,788,683			-6.19%
4	398,730,726,971		370,518,938,714			-7.08%
8	824,983,761,120		740,702,489,329			-10.22%
16	1,883,411,923,498	1,672,027,508,355		-11.22%

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 kernel/events/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 110b38a..924268c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8977,6 +8977,14 @@ static struct pmu *perf_init_event(struct perf_event *event)
 
 	idx = srcu_read_lock(&pmus_srcu);
 
+	/* try parent's pmu first */
+	if (event->parent && event->parent->pmu) {
+		pmu = event->parent->pmu;
+		ret = perf_try_init_event(pmu, event);
+		if (!ret)
+			goto unlock;
+	}
+
 	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, event->attr.type);
 	rcu_read_unlock();
-- 
2.4.3

  reply	other threads:[~2017-01-18 20:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 13:21 [PATCH 0/2] patches to reduce perf overhead kan.liang
2017-01-18 13:21 ` kan.liang [this message]
2017-01-30 11:59   ` [tip:perf/core] perf/core: Try parent PMU first when initializing a child event tip-bot for Kan Liang
2017-01-18 13:21 ` [PATCH 2/2] perf,core: use parent avg sample period as child initial period kan.liang
2017-01-25 15:33   ` Peter Zijlstra
2017-01-29 15:24     ` Liang, Kan

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=1484745662-15928-2-git-send-email-kan.liang@intel.com \
    --to=kan.liang@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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

Powered by JetHome