mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: <linux-kernel@vger.kernel.org>
Subject: [PATCH 11/21] perf: Export /proc/mounts parser
Date: Thu,  1 Jul 2010 17:55:53 +0200	[thread overview]
Message-ID: <1277999763-20357-12-git-send-email-bp@amd64.org> (raw)
In-Reply-To: <1277999763-20357-1-git-send-email-bp@amd64.org>

From: Borislav Petkov <borislav.petkov@amd.com>

Carve out relevant debugfs setup utils for general use.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 tools/lib/lk/debugfs.c         |   25 +++++++++++++++++++++++++
 tools/lib/lk/debugfs.h         |    5 +++++
 tools/perf/perf.c              |   27 ++++-----------------------
 tools/perf/util/parse-events.c |    2 --
 tools/perf/util/parse-events.h |    1 -
 5 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/tools/lib/lk/debugfs.c b/tools/lib/lk/debugfs.c
index bbe3a83..8ef3fa6 100644
--- a/tools/lib/lk/debugfs.c
+++ b/tools/lib/lk/debugfs.c
@@ -3,6 +3,8 @@
 
 static int debugfs_premounted;
 static char debugfs_mountpoint[MAX_PATH+1];
+char debugfs_mntpt[MAXPATHLEN];
+char debugfs_path[MAXPATHLEN];
 
 static const char *debugfs_known_mountpoints[] = {
 	"/sys/kernel/debug/",
@@ -237,3 +239,26 @@ int debugfs_read(const char *entry, char *buffer, size_t size)
 	/* return the number of chars read */
 	return ret;
 }
+
+void set_debugfs_path(void)
+{
+	char *path;
+
+	path = getenv(PERF_DEBUGFS_ENVIRONMENT);
+	snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
+		 "tracing/events");
+}
+
+/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
+int get_debugfs_mntpt(void)
+{
+	const char *path = debugfs_mount(NULL);
+
+	if (path) {
+		strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
+		return 0;
+	}
+
+	debugfs_mntpt[0] = '\0';
+	return 1;
+}
diff --git a/tools/lib/lk/debugfs.h b/tools/lib/lk/debugfs.h
index 8c02e72..1187fa8 100644
--- a/tools/lib/lk/debugfs.h
+++ b/tools/lib/lk/debugfs.h
@@ -14,6 +14,9 @@
 
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 
+extern char debugfs_path[];
+extern char debugfs_mntpt[];
+
 extern const char *debugfs_find_mountpoint(void);
 extern int debugfs_valid_mountpoint(const char *debugfs);
 extern int debugfs_valid_entry(const char *path);
@@ -23,5 +26,7 @@ extern int debugfs_write(const char *entry, const char *value);
 extern int debugfs_read(const char *entry, char *buffer, size_t size);
 extern void debugfs_force_cleanup(void);
 extern int debugfs_make_path(const char *element, char *buffer, int size);
+extern int get_debugfs_mntpt(void);
+extern void set_debugfs_path(void);
 
 #endif /* __DEBUGFS_H__ */
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index b92b3fd..58c1a56 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -32,8 +32,6 @@ struct pager_config {
 	int val;
 };
 
-static char debugfs_mntpt[MAXPATHLEN];
-
 static int pager_command_config(const char *var, const char *value, void *data)
 {
 	struct pager_config *c = data;
@@ -84,15 +82,6 @@ static void commit_pager_choice(void)
 	}
 }
 
-static void set_debugfs_path(void)
-{
-	char *path;
-
-	path = getenv(PERF_DEBUGFS_ENVIRONMENT);
-	snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
-		 "tracing/events");
-}
-
 static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
 	int handled = 0;
@@ -418,17 +407,6 @@ static int run_argv(int *argcp, const char ***argv)
 	return done_alias;
 }
 
-/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
-static void get_debugfs_mntpt(void)
-{
-	const char *path = debugfs_mount(NULL);
-
-	if (path)
-		strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
-	else
-		debugfs_mntpt[0] = '\0';
-}
-
 int main(int argc, const char **argv)
 {
 	const char *cmd;
@@ -436,8 +414,11 @@ int main(int argc, const char **argv)
 	cmd = perf_extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
+
 	/* get debugfs mount point from /proc/mounts */
-	get_debugfs_mntpt();
+	if (get_debugfs_mntpt())
+		die("Can't establish valid debugfs mountpoint!\n");
+
 	/*
 	 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
 	 *
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index f298a43..215d4f3 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -29,8 +29,6 @@ enum event_result {
 	EVT_HANDLED_ALL
 };
 
-char debugfs_path[MAXPATHLEN];
-
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
 
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index fc4ab3f..436c831 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -30,7 +30,6 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
 
 extern void print_events(void);
 
-extern char debugfs_path[];
 extern int valid_debugfs_mount(const char *debugfs);
 
 
-- 
1.7.1


  parent reply	other threads:[~2010-07-01 15:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-01 15:55 [RFC PATCH 00/21] RAS daemon prototype, v1 Borislav Petkov
2010-07-01 15:55 ` [PATCH 01/21] perf_events: Export buffer handling functions Borislav Petkov
2010-07-01 15:55 ` [PATCH 02/21] mce: Add persistent events Borislav Petkov
2010-07-01 15:55 ` [PATCH 03/21] perf_events: Add a helper to search for an event in a context Borislav Petkov
2010-07-01 15:55 ` [PATCH 04/21] perf_events: Handle persistent events accordingly Borislav Petkov
2010-07-01 15:55 ` [PATCH 05/21] perf: rewire generic library stuff, p1 Borislav Petkov
2010-07-01 15:55 ` [PATCH 06/21] perf: rewire generic library stuff, p2 Borislav Petkov
2010-07-01 15:55 ` [PATCH 07/21] perf: rewire generic library stuff, p3 Borislav Petkov
2010-07-01 15:55 ` [PATCH 08/21] perf: rewire generic library stuff, p4 Borislav Petkov
2010-07-01 15:55 ` [PATCH 09/21] perf: rewire generic library stuff, p5 Borislav Petkov
2010-07-01 15:55 ` [PATCH 10/21] perf: rewire generic library stuff, p6 Borislav Petkov
2010-07-01 15:55 ` Borislav Petkov [this message]
2010-07-01 15:55 ` [PATCH 12/21] perf: Carve out perf bits for general usage, p1 Borislav Petkov
2010-07-01 15:55 ` [PATCH 13/21] perf: Carve out perf bits for general usage, p2 Borislav Petkov
2010-07-01 15:55 ` [PATCH 14/21] perf: Carve out perf bits for general usage, p3 Borislav Petkov
2010-07-01 15:55 ` [PATCH 15/21] perf: Export trace event utils Borislav Petkov
2010-07-06 22:18   ` Steven Rostedt
2010-07-07  7:57     ` Borislav Petkov
2010-07-01 15:55 ` [PATCH 16/21] perf: Add a common misc.c compilation unit Borislav Petkov
2010-07-01 15:55 ` [PATCH 17/21] perf: Carve out mmap helpers for general use Borislav Petkov
2010-07-01 15:56 ` [PATCH 18/21] perf: Split build-id.c Borislav Petkov
2010-07-01 15:56 ` [PATCH 19/21] x86, mce: Notify about corrected events too Borislav Petkov
2010-07-01 15:56 ` [PATCH 20/21] amd64_edac: Remove polling mechanism Borislav Petkov
2010-07-01 15:56 ` [PATCH 21/21] tools, ras: Add a RAS daemon Borislav Petkov

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=1277999763-20357-12-git-send-email-bp@amd64.org \
    --to=bp@amd64.org \
    --cc=linux-kernel@vger.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

Powered by JetHome