Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1123233imm; Wed, 15 Aug 2018 11:49:57 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxn1b5YWsrOyJmZE+QKa4m3b4ucIheV/7So+y/0X5SlhTvjgKPDSZ5ZnqUj65MNqMTCBUlE X-Received: by 2002:a63:1f20:: with SMTP id f32-v6mr25267418pgf.84.1534358997020; Wed, 15 Aug 2018 11:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534358996; cv=none; d=google.com; s=arc-20160816; b=UlaPuh505lo5PSO9jbdagf9Cg3YpXWuS5xUmFFBCuMEOzsa1GuHG7KCJ9Djj6O+sio VjAWlmz4vLhHLP30pQbEpCUDoKlDIeRUWZtzKLoP+iaUpF0iMObmdJbSZXIOFTddN0rz yZ/uuhI8007ybWVYkay1Su+X8jbop6z22RDpry6s+de597ebNhnpQuKlUOwC7EpzFNG6 eAFThzQQxsig6Ac7KgctWzzy4z6fXgz/TofMRo/p7VfTGmEpNhV1p1+Yj50jr9QHSCoN rVg7vmoetsZBLSK9J9VI0W2fqcbKwvgtvCy0i9+Arq6v3OmNd+8La9ivVyFOMUq9M+8W VfSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=6UlhjYOQrWNcPTR3g62lRht3/4dW6QEcuX0+gKbqcCs=; b=YPaAOKWh2aurf7MfzOaFwRv/kRNL6u1o+nUgnuKkEPySR3n5P8sVTG0vM1/oTNEMiD EMVlHySClM40TBOoUFSC7MBVDMU3dXIFTpnXL8LUm4yupT4MG4bWTYjxNMoEtO9QcFlD EmuoFCaMcDGVyKwb7uMGL55gIUUeNqLuZjubgo/xCT5O00KqN1qj5MR9PH5eQzIlWR3t 3LjzkkyJENHMRuaQ9T/ak9S3ohhNg0m6nTRyys1bYbtxG5g6Rv9ddHe+PBkMqPFFWC8r CcmT3CwQl2AxsLDv67THL2y/2yYT7nAqaGURSFPxzJwlrozsUgSoWb2tVDzxTowYB6xu 9rfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d26-v6si21162734pge.679.2018.08.15.11.49.41; Wed, 15 Aug 2018 11:49:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727407AbeHOVmK (ORCPT + 99 others); Wed, 15 Aug 2018 17:42:10 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:9227 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbeHOVmK (ORCPT ); Wed, 15 Aug 2018 17:42:10 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1, AES128-SHA) id ; Wed, 15 Aug 2018 11:48:32 -0700 Received: from HQMAIL101.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 15 Aug 2018 11:48:40 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 15 Aug 2018 11:48:40 -0700 Received: from [10.2.166.219] (172.20.13.39) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 15 Aug 2018 18:48:48 +0000 Subject: Re: [RFC PATCH] ASoC: core: Optimise suspend/resume of DAPM widgets To: Mark Brown CC: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , , , References: <1533301025-19980-1-git-send-email-jonathanh@nvidia.com> <20180803163605.GD6591@sirena.org.uk> <7ba86328-5bb6-5280-df6f-9937173fb2ab@nvidia.com> <20180814144004.GD5810@sirena.org.uk> From: Jon Hunter Message-ID: Date: Wed, 15 Aug 2018 19:48:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180814144004.GD5810@sirena.org.uk> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL101.nvidia.com (172.20.187.10) Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/08/18 15:40, Mark Brown wrote: > On Mon, Aug 13, 2018 at 07:19:16PM +0100, Jon Hunter wrote: >> >> I had taken some ftrace graphs but there was not one thing that really >> stood out. Looking again it seems that each call to >> async_schedule_domain() can take tens of uS and so it there are a lot of >> DAPM widgets (100+) this can take some time. I will dig into it a bit >> further. > > We don't call that per widget, we call that per context. We might have > a lot of contexts but it's definitely not number of widgets level. > Perhaps what we need there is something which remembers if we actually > changed anything in each context and/or there's relevant operations and > then doesn't do this if not, we're working on the basis that these > operations are fairly cheap. Yes I see that now. >>> One thing that it occurs to me might help is to start the suspend >>> process by powering down all the input and output widgets that aren't >>> ignoring suspend in one operation, that should hopefully have the effect >>> of ensuring that most of the system that's going to get powered down >>> does so on the first pass through. > >> If the async_schedule_domain() calls are the problem, then it may not >> help as we call that for all dapms apart from the card->dapm. > > No, we actually need to run the operations on all contexts - they can > all do things if they want to. We just want them all to run in parallel > so if we are doing things like waiting for capacitors to charge we don't > do it in series. So I did a bit more digging and this time on Tegra124 Jetson-TK1 (which is supported in the mainline). On Jetson-TK1 I see that dapm_power_widgets is called 4 times on entering suspend and each call then calls the dapm_pre/post_sequence_async() functions 3 times. Interestingly, at least for Jetson-TK1, it appears that the calls to dapm_pre/post_sequence_async() do not actually change the bias state because the dapm contexts are already in the desired state. Please note that at this time audio is not active and so that is probably why. Anyway, I was interested in the overhead added of calling async_schedule_domain() to schedule the dapm_pre/post_sequence_async() function calls if there is nothing to be done. This is what I see ... Times for function dapm_power_widgets() are (us): Min 23, Ave 190, Max 434, Count 39 Where 'Count' is the number of times that dapm_power_widgets() has been called (both during boot and through a few suspend iterations). So then I made the following change to avoid scheduling the function calls unnecessarily (which I think should be fine) ... diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 5ed90ea69a24..ff66a6834531 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -1955,7 +1955,7 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event) dapm_pre_sequence_async(&card->dapm, 0); /* Run other bias changes in parallel */ list_for_each_entry(d, &card->dapm_list, list) { - if (d != &card->dapm) + if (d != &card->dapm && d->bias_level != d->target_bias_level) async_schedule_domain(dapm_pre_sequence_async, d, &async_domain); } @@ -1979,7 +1979,7 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event) /* Run all the bias changes in parallel */ list_for_each_entry(d, &card->dapm_list, list) { - if (d != &card->dapm) + if (d != &card->dapm && d->bias_level != d->target_bias_level) async_schedule_domain(dapm_post_sequence_async, d, &async_domain); } And with the above change I now see ... Times for function dapm_power_widgets() are (us): Min 4, Ave 16, Max 82, Count 39 Please note that I am just using ktime_get() to log the time on entry and exit from dapm_power_widgets() and so yes the time may not be purely the time take to execute this function if we are preempted, but I am measuring in the same way in both cases and so it does seem to show some improvement. Let me know your thoughts. Cheers Jon -- nvpublic