From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Andi Kleen <ak@linux.intel.com>, David Ahern <dsahern@gmail.com>
Subject: [PATCH 2/9] perf tools: Add precise object to interface sysfs precise
Date: Sat, 26 Jan 2013 18:27:48 +0100 [thread overview]
Message-ID: <1359221275-24254-3-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1359221275-24254-1-git-send-email-jolsa@redhat.com>
Adding precise util object to get maximum value for
perf_event_attr::precise_ip. The value is exported
via sysfs file '/sys/devices/cpu/precise'.
The interface is:
int perf_precise__get(void)
Returns:
maximum value allowed for perf_event_attr::precise_ip
0 if sysfs attribute is not found (supported)
-1 if we failed to read the sysfs attribute
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
---
tools/perf/Makefile | 1 +
tools/perf/util/precise.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/util.h | 2 ++
3 files changed, 48 insertions(+)
create mode 100644 tools/perf/util/precise.c
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index a84021a..541d242 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -463,6 +463,7 @@ LIB_OBJS += $(OUTPUT)util/rblist.o
LIB_OBJS += $(OUTPUT)util/intlist.o
LIB_OBJS += $(OUTPUT)util/vdso.o
LIB_OBJS += $(OUTPUT)util/stat.o
+LIB_OBJS += $(OUTPUT)util/precise.o
LIB_OBJS += $(OUTPUT)ui/setup.o
LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/util/precise.c b/tools/perf/util/precise.c
new file mode 100644
index 0000000..d801f3e
--- /dev/null
+++ b/tools/perf/util/precise.c
@@ -0,0 +1,45 @@
+
+#include <linux/kernel.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "sysfs.h"
+#include "util.h"
+
+/*
+ * Returns maximum value allowed for
+ * perf_event_attr::precise_ip, and:
+ * 0 if sysfs attribute is not found (supported)
+ * -1 if we failed to read the sysfs attribute
+ */
+int perf_precise__get(void)
+{
+ static int precise = -1;
+ struct stat st;
+ char path[PATH_MAX];
+
+ if (precise != -1)
+ return precise;
+
+ scnprintf(path, PATH_MAX, "%s/devices/cpu/precise",
+ sysfs_find_mountpoint());
+
+ if (!lstat(path, &st)) {
+ FILE *file;
+
+ file = fopen(path, "r");
+ if (!file)
+ return -1;
+
+ if (1 != fscanf(file, "%d", &precise))
+ pr_debug("failed to read precise info\n");
+
+ fclose(file);
+ } else
+ /* Return 0 if there's no sysfs precise support. */
+ precise = 0;
+
+
+ return precise;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 09b4c26..6d846e9 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -275,4 +275,6 @@ extern unsigned int page_size;
struct winsize;
void get_term_dimensions(struct winsize *ws);
+int perf_precise__get(void);
+
#endif
--
1.7.11.7
next prev parent reply other threads:[~2013-01-26 17:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-26 17:27 [PATCH 0/9] perf: Adding better precise_ip field handling Jiri Olsa
2013-01-26 17:27 ` [PATCH 1/9] perf x86: Add precise sysfs cpu pmu attribute Jiri Olsa
2013-01-26 17:27 ` Jiri Olsa [this message]
2013-01-26 17:27 ` [PATCH 3/9] perf tests: Add precise event automated test Jiri Olsa
2013-01-26 17:27 ` [PATCH 4/9] perf tools: Add a precise event qualifier Jiri Olsa
2013-01-26 17:27 ` [PATCH 5/9] perf tools: Read maximal precise value for 'precise' term Jiri Olsa
2013-01-26 17:27 ` [PATCH 6/9] perf tools: Favor 'p' modifier before 'precise' term properly Jiri Olsa
2013-01-26 17:27 ` [PATCH 7/9] perf tests: Add automated precise term test Jiri Olsa
2013-01-26 17:27 ` [PATCH 8/9] perf: Document the ABI for 'precise' sysfs attribute Jiri Olsa
2013-01-26 17:27 ` [PATCH 9/9] perf: Document the ABI for 'rdpmc' " Jiri Olsa
2013-01-26 18:53 ` [PATCH 0/9] perf: Adding better precise_ip field handling Jiri Olsa
2013-01-27 12:41 ` Ingo Molnar
2013-01-27 12:57 ` Jiri Olsa
2013-01-27 13:02 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2013-05-09 13:32 Jiri Olsa
2013-05-09 13:32 ` [PATCH 2/9] perf tools: Add precise object to interface sysfs precise Jiri Olsa
2013-05-10 1:34 ` Namhyung Kim
2013-05-10 9:06 ` Jiri Olsa
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=1359221275-24254-3-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=namhyung@kernel.org \
--cc=paulus@samba.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).