From patchwork Tue Aug 8 11:27:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9887561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 36E03601EB for ; Tue, 8 Aug 2017 11:27:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2909D28776 for ; Tue, 8 Aug 2017 11:27:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DD69287A0; Tue, 8 Aug 2017 11:27:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F2AB828776 for ; Tue, 8 Aug 2017 11:27:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33DD089DBF; Tue, 8 Aug 2017 11:27:22 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 543B089DBF for ; Tue, 8 Aug 2017 11:27:21 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 8163651-1500050 for multiple; Tue, 08 Aug 2017 12:27:10 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Tue, 08 Aug 2017 12:27:12 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 8 Aug 2017 12:27:11 +0100 Message-Id: <20170808112712.32303-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.13.3 MIME-Version: 1.0 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH igt 1/2] lib: Add hooks for enabling ftrace X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP If the kernel has tracing support builtin, we can enable around troublesome tests to obtain greater detail from the kernel that may prove invaluable in debugging the problem. Signed-off-by: Chris Wilson --- lib/Makefile.sources | 2 + lib/igt_core.c | 5 ++ lib/igt_ftrace.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_ftrace.h | 46 +++++++++++++ 4 files changed, 231 insertions(+) create mode 100644 lib/igt_ftrace.c create mode 100644 lib/igt_ftrace.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index 53fdb54c..90ff6468 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -12,6 +12,8 @@ lib_source_list = \ igt_aux.c \ igt_aux.h \ igt_edid_template.h \ + igt_ftrace.c \ + igt_ftrace.h \ igt_gt.c \ igt_gt.h \ igt_gvt.c \ diff --git a/lib/igt_core.c b/lib/igt_core.c index c0488e94..2509bc64 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -63,6 +63,7 @@ #include "intel_chipset.h" #include "intel_io.h" #include "igt_debugfs.h" +#include "igt_ftrace.h" #include "version.h" #include "config.h" @@ -563,6 +564,8 @@ static void low_mem_killer_disable(bool disable) bool igt_exit_called; static void common_exit_handler(int sig) { + igt_ftrace_close(); + if (!igt_only_list_subtests()) { low_mem_killer_disable(false); kick_fbcon(true); @@ -856,6 +859,8 @@ out: oom_adjust_for_doom(); low_mem_killer_disable(true); + + igt_ftrace_open(); } /* install exit handler, to ensure we clean up */ diff --git a/lib/igt_ftrace.c b/lib/igt_ftrace.c new file mode 100644 index 00000000..486acf71 --- /dev/null +++ b/lib/igt_ftrace.c @@ -0,0 +1,178 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#include +#include +#include +#include + +#include "igt.h" +#include "igt_ftrace.h" +#include "igt_debugfs.h" +#include "igt_sysfs.h" + +#define BIT(x) (1ul << (x)) + +/* Only a single tracer in the kernel, so we can use a singleton */ +struct igt_ftrace { + int dir; + + unsigned long flags; +#define PID_SET BIT(0) +#define INCLUDE_SET BIT(1) +#define EXCLUDE_SET BIT(2) + +} igt_ftrace = { -1 }; + +int igt_ftrace_open(void) +{ + int dir; + int err; + + dir = open(igt_debugfs_mount(), O_RDONLY); + if (dir < 0) + return -errno; + + igt_ftrace.dir = openat(dir, "tracing", O_RDONLY); + close(dir); + if (igt_ftrace.dir < 0) + return -errno; + + err = igt_ftrace_disable(); + if (err) + goto ft_close; + + return 0; + +ft_close: + close(igt_ftrace.dir); + igt_ftrace.dir = -1; + return err; +} + +int __igt_ftrace_enable(const char *mode, + const struct igt_ftrace_options *opts) +{ + int err; + + if (igt_ftrace.dir < 0) + return -ENODEV; + + if (!mode) + return -EINVAL; + + err = igt_sysfs_set(igt_ftrace.dir, "current_tracer", mode); + if (err < 0) + return err; + + if (opts && opts->pid) { + err = igt_sysfs_printf(igt_ftrace.dir, + "set_ftrace_pid", "%d", + opts->pid); + if (err < 0) + goto disable; + + igt_ftrace.flags |= PID_SET; + } + + if (opts && opts->include) { + err = igt_sysfs_set(igt_ftrace.dir, + "set_ftrace_filter", + opts->include); + if (err < 0) + goto disable; + + igt_ftrace.flags |= INCLUDE_SET; + } + + if (opts && opts->exclude) { + err = igt_sysfs_set(igt_ftrace.dir, + "set_ftrace_notrace", + opts->exclude); + if (err < 0) + goto disable; + + igt_ftrace.flags |= EXCLUDE_SET; + } + + err = igt_sysfs_set(igt_ftrace.dir, "tracer_on", "1"); + if (err < 0) + return err; + + return 0; + +disable: + igt_ftrace_disable(); + return err; +} + +int igt_ftrace_disable(void) +{ + int err; + + if (igt_ftrace.dir < 0) + return -ENODEV; + + err = igt_sysfs_set(igt_ftrace.dir, "tracer_on", "0"); + if (err < 0) + return err; + + if (igt_ftrace.flags & PID_SET) { + igt_sysfs_set(igt_ftrace.dir, "set_ftrace_pid", ""); + igt_ftrace.flags &= ~PID_SET; + } + + if (igt_ftrace.flags & INCLUDE_SET) { + igt_sysfs_set(igt_ftrace.dir, "set_ftrace_filter", ""); + igt_ftrace.flags &= ~INCLUDE_SET; + } + + if (igt_ftrace.flags & EXCLUDE_SET) { + igt_sysfs_set(igt_ftrace.dir, "set_ftrace_notrace", ""); + igt_ftrace.flags &= ~EXCLUDE_SET; + } + + return 0; +} + +void igt_ftrace_dump(const char *header) +{ + char *txt; + + txt = igt_sysfs_get(igt_ftrace.dir, "trace"); + if (!txt) + return; + + igt_info("%s:\n%s", header, txt); + free(txt); +} + +void igt_ftrace_close(void) +{ + if (igt_ftrace.dir < 0) + return; + + close(igt_ftrace.dir); + igt_ftrace.dir = -1; +} diff --git a/lib/igt_ftrace.h b/lib/igt_ftrace.h new file mode 100644 index 00000000..3dd67682 --- /dev/null +++ b/lib/igt_ftrace.h @@ -0,0 +1,46 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#ifndef IGT_FTRACE_H +#define IGT_FTRACE_H + +int igt_ftrace_open(void); + +struct igt_ftrace_options { + int pid; + const char *include; + const char *exclude; +}; + +int __igt_ftrace_enable(const char *mode, + const struct igt_ftrace_options *opts); +#define igt_ftrace_enable() __igt_ftrace_enable("function_graph", NULL) + +int igt_ftrace_disable(void); + +void igt_ftrace_dump(const char *header); + +void igt_ftrace_close(void); + +#endif /* IGT_FTRACE_H */