From patchwork Tue May 5 12:13:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11528897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B83F092A for ; Tue, 5 May 2020 12:14:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FF43206B8 for ; Tue, 5 May 2020 12:14:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FF43206B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 95AE589F53; Tue, 5 May 2020 12:14:26 +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 38D5489F53; Tue, 5 May 2020 12:14:25 +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 21117928-1500050 for multiple; Tue, 05 May 2020 13:13:22 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 5 May 2020 13:13:18 +0100 Message-Id: <20200505121318.2816478-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] lib/i915: Reset all engine properties to defaults prior to the start of a test X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, Chris Wilson Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" We need each test in an isolated context, so that bad results from one test do not interfere with the next. In particular, we want to clean up the device and reset it to the defaults so that they are known for the next test, and the test can focus on behaviour it wants to control. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: Joonas Lahtinen --- lib/i915/gem.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/lib/i915/gem.c b/lib/i915/gem.c index b2717ba6a..6fa8abf21 100644 --- a/lib/i915/gem.c +++ b/lib/i915/gem.c @@ -22,6 +22,7 @@ * */ +#include #include #include @@ -30,6 +31,87 @@ #include "igt_debugfs.h" #include "igt_sysfs.h" +static void __restore_defaults(int engine) +{ + struct dirent *de; + int defaults; + DIR *dir; + + defaults = openat(engine, ".defaults", O_RDONLY); + if (defaults < 0) + return; + + dir = fdopendir(defaults); + if (!dir) { + close(defaults); + return; + } + + while ((de = readdir(dir))) { + char buf[256]; + int fd, len; + + if (*de->d_name == '.') + continue; + + fd = openat(defaults, de->d_name, O_RDONLY); + if (fd < 0) + continue; + + len = read(fd, buf, sizeof(buf)); + close(fd); + + fd = openat(engine, de->d_name, O_WRONLY); + if (fd < 0) + continue; + + write(fd, buf, len); + close(fd); + } + + closedir(dir); +} + +static void restore_defaults(int i915) +{ + struct dirent *de; + int engines; + DIR *dir; + int sys; + + sys = igt_sysfs_open(i915); + if (sys < 0) + return; + + engines = openat(sys, "engine", O_RDONLY); + if (engines < 0) + goto close_sys; + + dir = fdopendir(engines); + if (!dir) { + close(engines); + goto close_sys; + } + + while ((de = readdir(dir))) { + int engine; + + if (*de->d_name == '.') + continue; + + engine = openat(engines, de->d_name, O_RDONLY); + if (engine < 0) + continue; + + __restore_defaults(engine); + close(engine); + } + + closedir(dir); +close_sys: + close(sys); +} + static void reset_device(int i915) { int dir; @@ -66,6 +148,7 @@ void igt_require_gem(int i915) * sequences of batches. */ reset_device(i915); + restore_defaults(i915); err = 0; if (ioctl(i915, DRM_IOCTL_I915_GEM_THROTTLE)) {