From patchwork Fri Mar 2 11:55:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10254487 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 8182F60211 for ; Fri, 2 Mar 2018 11:55:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D7F82896D for ; Fri, 2 Mar 2018 11:55:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 623A12896F; Fri, 2 Mar 2018 11:55:49 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 C73BC2896D for ; Fri, 2 Mar 2018 11:55:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D0876EE35; Fri, 2 Mar 2018 11:55:48 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3D5236EE2D for ; Fri, 2 Mar 2018 11:55:46 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id w77so9825098wrc.6 for ; Fri, 02 Mar 2018 03:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nNGLxxPksqvpraQmWcFItRvcMY/lEMW5OX9+hVgeb80=; b=i+L3LiCSsVjYIT9zdC07KEvHOClN3jMn4A0pMFbtyPlsO6/ye3s1FNTy2c+3enOYe7 ZmrxoTSqvqDXOEaj349h5T0cdNjTG49Qib3buK3IsJJWCKlOn+PMTl/Qx0WaaVjk17+P /ZrlKq3P61jN85IWzBm1naTZFrGMs0fMR6vDRAfLT9Fnx4X2T5JOGbC+cju2DWcNWmDy ewiFAppcqazDOuPldEThXrmkAiFV9qYTWfzspLuM1PXrz3A1pTfyZQL4dVZ3C0XfBtLV 76EDK4do+pVKSoj+s/toBn3SQ5AE53x5jcsNV2mJAmCRjTLhT7HWOjPupZQXjhCqwWAX hBow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nNGLxxPksqvpraQmWcFItRvcMY/lEMW5OX9+hVgeb80=; b=VVebO8AFYeGg1UjiL6mTFLBAH7imfCxK+gHDzI8IzgRA/3ulWFvog5uEU+FsDJNBKh aVBriLtGM6hYmE+QjGC18mQ/912zf3JMmiyNCx0YkAqOS79hWg3rWzuZiRykstw0Yyrv P/v8L8PiwqMKCluvW1ugjy2Ng8jonyH+gv2IxsQ+jyyj7EpbBPJ8xVg1HWzcnQobIWhe 1ZDVJvyAsC5eNZ/g6TyaFtDcrzeinarsff6OU0JUPdk3kF3Zq3iKQwBMULuZfLml4tQ9 z8UnzgvXIKVoDx4t0VlFCPxjnydjobkl7MlVP+Xppd/ZAcYFmL4lLifH0xBI/6U8EBeM Jjeg== X-Gm-Message-State: APf1xPAm4lrS2PTHMfNmRiQOF+1pV3RWtTncb1JVbG90DH0C0k9+xpq6 CowemnEW9Ug5LIcZMU1nLRzMcRbL X-Google-Smtp-Source: AG47ELsHyi6+aM0mME6VZfITOkYXzZ99pE0uLSgHMweVFHCd5I2Eoc1EGwcSuaiR+Gu6btDcg78bwg== X-Received: by 10.223.142.5 with SMTP id n5mr5100821wrb.28.1519991744722; Fri, 02 Mar 2018 03:55:44 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id o16sm1506348wmi.38.2018.03.02.03.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 03:55:44 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Fri, 2 Mar 2018 11:55:36 +0000 Message-Id: <20180302115536.5411-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <151999096825.32001.14419167403718865731@mail.alporthouse.com> References: <151999096825.32001.14419167403718865731@mail.alporthouse.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v5] tests/perf_pmu: Handle CPU hotplug failures better X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomi Sarvela , Intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Wilson CPU hotplug, especially CPU0, can be flaky on commodity hardware. To improve test reliability and reponse times when testing larger runs we need to handle those cases better. Handle failures to off-line a CPU by immediately skipping the test, and failures to on-line a CPU by immediately rebooting the machine. This patch includes igt_sysrq_reboot implementation from Chris Wilson. v2: Halt by default, reboot if env variable IGT_REBOOT_ON_FATAL_ERROR is set. (Petri Latvala) v3: Add missign docs and update stale comment. (Petri Latvala) v4: Use pause instead of sleep. (Chris Wilson) v5: Newlines! (Chris Wilson) Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson Cc: Petri Latvala Cc: Tomi Sarvela Reviewed-by: Petri Latvala --- lib/Makefile.sources | 2 ++ lib/igt_core.c | 23 +++++++++++++++++++++++ lib/igt_core.h | 1 + lib/igt_sysrq.c | 27 +++++++++++++++++++++++++++ lib/igt_sysrq.h | 30 ++++++++++++++++++++++++++++++ lib/meson.build | 1 + tests/perf_pmu.c | 38 +++++++++++++++++++++++++++++++------- 7 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 lib/igt_sysrq.c create mode 100644 lib/igt_sysrq.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index 5b13ef8896c0..3d37ef1d1984 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -35,6 +35,8 @@ lib_source_list = \ igt_stats.h \ igt_sysfs.c \ igt_sysfs.h \ + igt_sysrq.c \ + igt_sysrq.h \ igt_x86.h \ igt_x86.c \ igt_vgem.c \ diff --git a/lib/igt_core.c b/lib/igt_core.c index c292343de09e..e52b806bdb01 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -70,6 +70,7 @@ #include "igt_core.h" #include "igt_aux.h" #include "igt_sysfs.h" +#include "igt_sysrq.h" #include "igt_rc.h" #define UNW_LOCAL_ONLY @@ -1136,6 +1137,28 @@ void igt_fail(int exitcode) } } +/** + * igt_fatal_error: Stop test execution on fatal errors + * + * Stop test execution or optionally, if the IGT_REBOOT_ON_FATAL_ERROR + * environment variable is set, reboot the machine. + * + * Since out test runner (piglit) does support fatal test exit codes, we + * implement the default behaviour by waiting endlessly. + */ +void __attribute__((noreturn)) igt_fatal_error(void) +{ + if (igt_check_boolean_env_var("IGT_REBOOT_ON_FATAL_ERROR", false)) { + igt_warn("FATAL ERROR - REBOOTING\n"); + igt_sysrq_reboot(); + } else { + igt_warn("FATAL ERROR\n"); + for (;;) + pause(); + } +} + + /** * igt_can_fail: * diff --git a/lib/igt_core.h b/lib/igt_core.h index 7af2b4c109fe..66523a208c31 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -311,6 +311,7 @@ void __igt_fail_assert(const char *domain, const char *file, const char *format, ...) __attribute__((noreturn)); void igt_exit(void) __attribute__((noreturn)); +void igt_fatal_error(void) __attribute__((noreturn)); /** * igt_ignore_warn: diff --git a/lib/igt_sysrq.c b/lib/igt_sysrq.c new file mode 100644 index 000000000000..3bda321f7c5b --- /dev/null +++ b/lib/igt_sysrq.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include "igt_core.h" + +#include "igt_sysrq.h" + +/** + * igt_sysrq_reboot: Reboots the machine + * + * Syncs filesystems and immediately reboots the machine. + */ +void igt_sysrq_reboot(void) +{ + sync(); + + /* Try to be nice at first, and if that fails pull the trigger */ + if (reboot(RB_AUTOBOOT)) { + int fd = open("/proc/sysrq-trigger", O_WRONLY); + igt_ignore_warn(write(fd, "b", 2)); + close(fd); + } + + abort(); +} diff --git a/lib/igt_sysrq.h b/lib/igt_sysrq.h new file mode 100644 index 000000000000..422473d2a480 --- /dev/null +++ b/lib/igt_sysrq.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2018 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_SYSRQ_H__ +#define __IGT_SYSRQ_H__ + +void igt_sysrq_reboot(void) __attribute__((noreturn)); + +#endif /* __IGT_SYSRQ_H__ */ diff --git a/lib/meson.build b/lib/meson.build index a9e53689b35d..b3b8b14a3f01 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -14,6 +14,7 @@ lib_sources = [ 'igt_stats.c', 'igt_syncobj.c', 'igt_sysfs.c', + 'igt_sysrq.c', 'igt_vgem.c', 'igt_x86.c', 'instdone.c', diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c index 3bbb18d2f216..87e7e782d05e 100644 --- a/tests/perf_pmu.c +++ b/tests/perf_pmu.c @@ -965,6 +965,7 @@ static void cpu_hotplug(int gem_fd) int link[2]; int fd, ret; int cur = 0; + char buf; igt_skip_on(IS_BROXTON(intel_get_drm_devid(gem_fd))); igt_require(cpu0_hotplug_support()); @@ -1011,9 +1012,32 @@ static void cpu_hotplug(int gem_fd) } /* Offline followed by online a CPU. */ - igt_assert_eq(write(cpufd, "0", 2), 2); + + ret = write(cpufd, "0", 2); + if (ret < 0) { + /* + * If we failed to offline a CPU we don't want + * to proceed. + */ + igt_warn("Failed to offline cpu%u! (%d)\n", + cpu, errno); + igt_assert_eq(write(link[1], "s", 1), 1); + break; + } + usleep(1e6); - igt_assert_eq(write(cpufd, "1", 2), 2); + + ret = write(cpufd, "1", 2); + if (ret < 0) { + /* + * Failed to bring a CPU back online is fatal + * for the sanity of a test run so stop further + * testing. + */ + igt_warn("Failed to online cpu%u! (%d)\n", + cpu, errno); + igt_fatal_error(); + } close(cpufd); cpu++; @@ -1027,15 +1051,12 @@ static void cpu_hotplug(int gem_fd) * until the CPU core shuffler finishes one loop. */ for (;;) { - char buf; - int ret2; - usleep(500e3); end_spin(gem_fd, spin[cur], 0); /* Check if the child is signaling completion. */ - ret2 = read(link[0], &buf, 1); - if ( ret2 == 1 || (ret2 < 0 && errno != EAGAIN)) + ret = read(link[0], &buf, 1); + if ( ret == 1 || (ret < 0 && errno != EAGAIN)) break; igt_spin_batch_free(gem_fd, spin[cur]); @@ -1054,6 +1075,9 @@ static void cpu_hotplug(int gem_fd) close(fd); close(link[0]); + /* Skip if child signals a problem with offlining a CPU. */ + igt_skip_on(buf == 's'); + assert_within_epsilon(val, ts[1] - ts[0], tolerance); }