From patchwork Thu Aug 16 18:01:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10567969 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 5A9B814E1 for ; Thu, 16 Aug 2018 18:01:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 481DC2B55B for ; Thu, 16 Aug 2018 18:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C2B52B5C2; Thu, 16 Aug 2018 18:01:54 +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 CEEFD2B55B for ; Thu, 16 Aug 2018 18:01:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3CE656E4EE; Thu, 16 Aug 2018 18:01:53 +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 6839C6E4E7; Thu, 16 Aug 2018 18:01:51 +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 12961331-1500050 for multiple; Thu, 16 Aug 2018 19:01:39 +0100 From: Chris Wilson To: igt-dev@lists.freedesktop.org Date: Thu, 16 Aug 2018 19:01:36 +0100 Message-Id: <20180816180136.9040-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.18.0 Subject: [Intel-gfx] [PATCH i-g-t] lib: Poll for snd_hda_intel discovery 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 Loading the sounds modules is asynchronous with the sysfs device hierarchy being instantiated sometime after modprobe returns. As such while we are probing for the sound device, poll a few times to accommodate the async discovery. Signed-off-by: Chris Wilson Cc: Imre Deak Cc: Tvrtko Ursulin Reviewed-by: Imre Deak --- lib/igt_pm.c | 65 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 6e96db22b..f82707231 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -138,31 +138,17 @@ static void strchomp(char *str) str[len - 1] = 0; } -/** - * igt_pm_enable_audio_runtime_pm: - * - * We know that if we don't enable audio runtime PM, snd_hda_intel will never - * release its power well refcount, and we'll never reach the LPSP state. - * There's no guarantee that it will release the power well if we enable - * runtime PM, but at least we can try. - * - * We don't have any assertions on open since the user may not even have - * snd_hda_intel loaded, which is not a problem. - */ -void igt_pm_enable_audio_runtime_pm(void) +static int __igt_pm_enable_audio_runtime_pm(void) { char *path = NULL; struct dirent *de; DIR *dir; + int err; int fd; - /* Check if already enabled. */ - if (__igt_pm_audio_runtime_power_save[0]) - return; - dir = opendir("/sys/class/sound"); if (!dir) - return; + return 0; /* Find PCI device claimed by snd_hda_intel and tied to i915. */ while ((de = readdir(dir))) { @@ -196,18 +182,17 @@ void igt_pm_enable_audio_runtime_pm(void) de->d_name)); igt_debug("Audio device path is %s\n", path); - break; } fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR); if (fd < 0) - return; + return 0; /* snd_hda_intel loaded but no path found is an error. */ if (!path) { close(fd); - errno = ESRCH; + err = -ESRCH; goto err; } @@ -219,8 +204,10 @@ void igt_pm_enable_audio_runtime_pm(void) close(fd); fd = open(path, O_RDWR); - if (fd < 0) + if (fd < 0) { + err = -errno; goto err; + } igt_assert(read(fd, __igt_pm_audio_runtime_control, sizeof(__igt_pm_audio_runtime_control)) > 0); @@ -236,12 +223,42 @@ void igt_pm_enable_audio_runtime_pm(void) /* Give some time for it to react. */ sleep(1); - - return; + return 0; err: - igt_warn("Failed to enable audio runtime PM! (%d)", errno); free(path); + return err; +} + +/** + * igt_pm_enable_audio_runtime_pm: + * + * We know that if we don't enable audio runtime PM, snd_hda_intel will never + * release its power well refcount, and we'll never reach the LPSP state. + * There's no guarantee that it will release the power well if we enable + * runtime PM, but at least we can try. + * + * We don't have any assertions on open since the user may not even have + * snd_hda_intel loaded, which is not a problem. + */ +void igt_pm_enable_audio_runtime_pm(void) +{ + int err; + + /* Check if already enabled. */ + if (__igt_pm_audio_runtime_power_save[0]) + return; + + for (int count = 0; count < 5; count++) { + err = __igt_pm_enable_audio_runtime_pm(); + if (!err) + return; + + /* modprobe(sna-hda-intel) is async so poll for sysfs */ + sleep(1); + } + + igt_warn("Failed to enable audio runtime PM! (%d)\n", -err); } /**