[igt-dev] [PATCH igt 02/16] lib: Cache the debugfs mountpoint
Chris Wilson
chris at chris-wilson.co.uk
Tue Feb 20 08:45:06 UTC 2018
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 <chris at chris-wilson.co.uk>
---
lib/igt_debugfs.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
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;
}
/**
--
2.16.1
More information about the igt-dev
mailing list