From d7c14aa2d74475f9de9eccf350df204da8f10442 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 19 Feb 2018 22:14:33 +0000 Subject: lib: Cache the debugfs mountpoint When using igt_debugfs_*() inside a tight loop, the overhead of calling xstat64 (from is_mountpoint()) creeps up in the profiles. Eliminate it by caching the resultant path for finding/mounting debugfs. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- lib/igt_debugfs.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib/igt_debugfs.c') diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index 4a119985..09d42ea0 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -110,6 +110,20 @@ static bool is_mountpoint(const char *path) return dev != st.st_dev; } +static const char *__igt_debugfs_mount(void) +{ + if (is_mountpoint("/sys/kernel/debug")) + return "/sys/kernel/debug"; + + if (is_mountpoint("/debug")) + return "/debug"; + + if (mount("debug", "/sys/kernel/debug", "debugfs", 0, 0)) + return NULL; + + return "/sys/kernel/debug"; +} + /** * igt_debugfs_mount: * @@ -121,16 +135,12 @@ static bool is_mountpoint(const char *path) */ const char *igt_debugfs_mount(void) { - if (is_mountpoint("/sys/kernel/debug")) - return "/sys/kernel/debug"; + static const char *path; - if (is_mountpoint("/debug")) - return "/debug"; + if (!path) + path = __igt_debugfs_mount(); - if (mount("debug", "/sys/kernel/debug", "debugfs", 0, 0)) - return NULL; - - return "/sys/kernel/debug"; + return path; } /** -- cgit v1.2.3