From patchwork Mon Jul 23 11:46:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31B4A157A for ; Mon, 23 Jul 2018 11:47:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16FCD2863B for ; Mon, 23 Jul 2018 11:47:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08AD928669; Mon, 23 Jul 2018 11:47:07 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 8113F2863B for ; Mon, 23 Jul 2018 11:47:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCE2E6E15B; Mon, 23 Jul 2018 11:47:05 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 854E56E15B for ; Mon, 23 Jul 2018 11:47:04 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id e7-v6so380571wrs.9 for ; Mon, 23 Jul 2018 04:47:04 -0700 (PDT) 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; bh=cyGHicgZU9Rn1LYXEpzeCvbkPRI7ANCaVD3o1Y4pho8=; b=seE41LWV9URJ9qDfwswzD2e6BA9kKAg4hFcdwinNafD1NQizYz0piWkE2usYruTKlS O9zNPGSXmOqf0FNRpFv0vnXZji6D9iePtV3Otgaw/y2+wMGDYxxLbKbyPis7Wk4MSPLC 7hGIuJqr1fS60XCf+3TpQKKsl9hpO2ey9t/m8INf2IjzoitWf0zEHyzmRCNGU9A9XXI+ lWd/YR9FjTIOfb1FCUBn41h7BpO2ijVaRC1S6ePBm9OtdfbGfIEA7W6ydAqC/gj5m0Vl hnElJXTqkiIGqDdutuh4erF4szXmaB/nRCqjSPN4uPhiLoWT7pG0hIItmiQq0URPxfsc SnMg== X-Gm-Message-State: AOUpUlF0yEi6U37UlKPyL2EUwcftiPtXuIBS7oIRaC6Wj+Lo92GtGzxs NEBmYs9k+uNmSCCKaCeOWKISHeZwBqA= X-Google-Smtp-Source: AAOMgpec3Sro6LQEt+HJxWzwfHPrI1Jij3qpP+tCLJtOK+PUc0RnaUNyqh3P4Yg8zi0MUjQIwcuV9w== X-Received: by 2002:adf:b2f4:: with SMTP id g107-v6mr8613520wrd.53.1532346423159; Mon, 23 Jul 2018 04:47:03 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l14-v6sm23658407wrw.65.2018.07.23.04.47.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:47:02 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 12:46:55 +0100 Message-Id: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 Subject: [Intel-gfx] [PATCH i-g-t 1/4] lib/igt_pm: Make exit handlers signal safe 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: intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin IGT logging helpers are not signal safe so avoid calling them from exit handlers. At the same time refactor the code a bit to enable following patches. Signed-off-by: Tvrtko Ursulin --- lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 8ac132269d79..6f3b0a2d897d 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -66,33 +66,47 @@ enum { static char __igt_pm_audio_runtime_power_save[64]; static char __igt_pm_audio_runtime_control[64]; -static void __igt_pm_audio_runtime_exit_handler(int sig) +static int __igt_pm_audio_restore_runtime_pm(void) { int fd; - igt_debug("Restoring audio power management to '%s' and '%s'\n", - __igt_pm_audio_runtime_power_save, - __igt_pm_audio_runtime_control); + if (!__igt_pm_audio_runtime_power_save[0]) + return 0; fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_audio_runtime_power_save, strlen(__igt_pm_audio_runtime_power_save)) != - strlen(__igt_pm_audio_runtime_power_save)) - igt_warn("Failed to restore audio power_save to '%s'\n", - __igt_pm_audio_runtime_power_save); + strlen(__igt_pm_audio_runtime_power_save)) { + close(fd); + return errno; + } + close(fd); fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_audio_runtime_control, strlen(__igt_pm_audio_runtime_control)) != - strlen(__igt_pm_audio_runtime_control)) - igt_warn("Failed to restore audio control to '%s'\n", - __igt_pm_audio_runtime_control); + strlen(__igt_pm_audio_runtime_control)) { + close(fd); + return errno; + } + close(fd); + + __igt_pm_audio_runtime_power_save[0] = 0; + + return 0; +} + +static void __igt_pm_audio_runtime_exit_handler(int sig) +{ + __igt_pm_audio_restore_runtime_pm(); } static void strchomp(char *str) @@ -297,33 +311,48 @@ int pm_status_fd = -1; static char __igt_pm_runtime_autosuspend[64]; static char __igt_pm_runtime_control[64]; -static void __igt_pm_runtime_exit_handler(int sig) +static int __igt_restore_runtime_pm(void) { int fd; - igt_debug("Restoring runtime management to '%s' and '%s'\n", - __igt_pm_runtime_autosuspend, - __igt_pm_runtime_control); + if (pm_status_fd < 0) + return 0; fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_runtime_autosuspend, strlen(__igt_pm_runtime_autosuspend)) != - strlen(__igt_pm_runtime_autosuspend)) - igt_warn("Failed to restore runtime pm autosuspend delay to '%s'\n", - __igt_pm_runtime_autosuspend); + strlen(__igt_pm_runtime_autosuspend)) { + close(fd); + return errno; + } + close(fd); fd = open(POWER_DIR "/control", O_WRONLY); if (fd < 0) - return; + return errno; + if (write(fd, __igt_pm_runtime_control, strlen(__igt_pm_runtime_control)) != - strlen(__igt_pm_runtime_control)) - igt_warn("Failed to restore runtime pm control to '%s'\n", - __igt_pm_runtime_control); + strlen(__igt_pm_runtime_control)) { + close(fd); + return errno; + } + close(fd); + + close(pm_status_fd); + pm_status_fd = -1; + + return 0; +} + +static void __igt_pm_runtime_exit_handler(int sig) +{ + __igt_restore_runtime_pm(); } /**