linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 07/14] perf tools: Add a helper function to probe whether cpu-wide tracing is possible
Date: Mon, 17 Aug 2015 16:12:00 -0300	[thread overview]
Message-ID: <1439838727-6824-8-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1439838727-6824-1-git-send-email-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

Add a helper function to probe whether cpu-wide tracing is possible.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1439458857-30636-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evlist.h |  1 +
 tools/perf/util/record.c | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 397757063da1..436e358300b1 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -115,6 +115,7 @@ void perf_evlist__close(struct perf_evlist *evlist);
 void perf_evlist__set_id_pos(struct perf_evlist *evlist);
 bool perf_can_sample_identifier(void);
 bool perf_can_record_switch_events(void);
+bool perf_can_record_cpu_wide(void);
 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts);
 int record_opts__config(struct record_opts *opts);
 
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 0d228a29526d..0467367dc315 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -105,6 +105,30 @@ bool perf_can_record_switch_events(void)
 	return perf_probe_api(perf_probe_context_switch);
 }
 
+bool perf_can_record_cpu_wide(void)
+{
+	struct perf_event_attr attr = {
+		.type = PERF_TYPE_SOFTWARE,
+		.config = PERF_COUNT_SW_CPU_CLOCK,
+		.exclude_kernel = 1,
+	};
+	struct cpu_map *cpus;
+	int cpu, fd;
+
+	cpus = cpu_map__new(NULL);
+	if (!cpus)
+		return false;
+	cpu = cpus->map[0];
+	cpu_map__put(cpus);
+
+	fd = sys_perf_event_open(&attr, -1, cpu, -1, 0);
+	if (fd < 0)
+		return false;
+	close(fd);
+
+	return true;
+}
+
 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts)
 {
 	struct perf_evsel *evsel;
-- 
2.1.0


  parent reply	other threads:[~2015-08-17 19:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-17 19:11 [GIT PULL 00/14] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-08-17 19:11 ` [PATCH 01/14] perf tools: Support static linking with libdw Arnaldo Carvalho de Melo
2015-08-17 19:11 ` [PATCH 02/14] perf probe: Fix to add missed brace around if block Arnaldo Carvalho de Melo
2015-08-17 19:11 ` [PATCH 03/14] perf trace: Move vfs_getname storage to per thread area Arnaldo Carvalho de Melo
2015-08-17 19:11 ` [PATCH 04/14] perf script: Initialize callchain_param.record_mode Arnaldo Carvalho de Melo
2015-08-17 19:11 ` [PATCH 05/14] perf annotate: Fix 32-bit compilation error in util/annotate.c Arnaldo Carvalho de Melo
2015-08-17 19:11 ` [PATCH 06/14] perf symbols: Fix annotation of vdso Arnaldo Carvalho de Melo
2015-08-17 19:12 ` Arnaldo Carvalho de Melo [this message]
2015-08-17 19:12 ` [PATCH 08/14] perf auxtrace: Add Intel PT as an AUX area tracing type Arnaldo Carvalho de Melo
2015-08-17 19:12 ` [PATCH 09/14] perf tools: Add Intel PT packet decoder Arnaldo Carvalho de Melo
2015-08-17 19:12 ` [PATCH 10/14] perf tools: Add Intel PT instruction decoder Arnaldo Carvalho de Melo
2015-08-17 19:12 ` [PATCH 11/14] perf tools: Add Intel PT log Arnaldo Carvalho de Melo
2015-08-17 19:12 ` [PATCH 12/14] perf tools: Add Intel PT decoder Arnaldo Carvalho de Melo
2015-08-17 19:12 ` [PATCH 13/14] perf tools: Add Intel PT support Arnaldo Carvalho de Melo
2015-08-17 19:12 ` [PATCH 14/14] perf tools: Take Intel PT into use Arnaldo Carvalho de Melo
2015-08-20  9:50 ` [GIT PULL 00/14] perf/core improvements and fixes Ingo Molnar

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=1439838727-6824-8-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.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).