From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA2C0C433E1 for ; Mon, 29 Jun 2020 20:38:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 78EEB20672 for ; Mon, 29 Jun 2020 20:38:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tdht5AL/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eypUlQy4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78EEB20672 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lmXW7QOuzK/jyO3Cfb7j6qWvwi62siNAPzf9968EYz4=; b=tdht5AL/3wvxo/XK0NOqGGp32 MLtWcMIUSpn4BcCCfvtyH2kOAWDqr0unUzTIDGWuLkU3xa3L9VCL2kegFi+5i+DMkcOVT7eRhbnT4 f/HqKDACyz6Ah2QxFJCOgMxAWIhqrdvqp16nJuQAKwm5kGtUSxB3yFCO/oM/b11ZI5nX6DkP4XJx5 8aDTDlI0FrOa8ZL3hvgI1k/l0Wvpg19KsLUJR6k7bmdQcEBErSIoSwRU8Lu4CxlLCWymPzg3lJqdv 4EU1rLihUQl3acaIZ/2DG4jhIlOim9wPxbC4/TX5979bwTWW3ry0TWilPEr5vbVwDv/j+Pj/tXkcX 3grSPOQmQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jq0WQ-0008Cs-Of; Mon, 29 Jun 2020 20:36:58 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jq0WO-0008CF-PV for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 20:36:57 +0000 Received: by mail-pj1-x1042.google.com with SMTP id h22so8515469pjf.1 for ; Mon, 29 Jun 2020 13:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zYp5Tw0t/c1bQYIHL+JbsqdWWWKkqJDqaNrcV49Vw4g=; b=eypUlQy4e1ZLKAAeYjC7FOA+w2pJmOIsR1f23Xmomnr07zhzNh/BT7cKbQNorY8b2m 4XXBy3s5LyLHowatZ6GuHzhrHQhQIRf0xw2cJW+M14SX+imOdsk7remTn2P2rB2TlgOU 4CYA3hNRjiBSEW05qw1r4njFHyTmRtkDhCgvWN7QN2BD3ggGE0Q+X/6EGndE52dOxigD tgHGanrn+MbhhuIrJCp6AJKHDRsAG3FTDT+3uWqbpYs4tRi63dnkSXb2LjI5F/ETfrrx tbXeau/PWENqJa5Z5AbzYNMFQ9R00dLi23LTEectnX5QiLYOqDF9Jr1WWSGhybVJd12Y 5P1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zYp5Tw0t/c1bQYIHL+JbsqdWWWKkqJDqaNrcV49Vw4g=; b=CwXz5fXLu/WLkbeyys7e5B9C116dLsiBEVJWJc192SJiFjyL2TyOPcu5MsU0VPZQmf Rw+Ph1ihLsaeSb8/kCyU5tOfviBssjqzJcQ69enQe7Gvt6hS+NFMwpu4p8lF7UK0ZiJ0 cpvfeh11dfPLPQhTGTa+G04Wyw5arigPiImCn196aKvUAsvZADHsXChdUExGdXc9byHa pPoPVQrf8O0zr1ErwKqcjr5bI9fvXSnmF0sN/qU9AiG/6adI0AoPY91Nu7Mn67NPAkaW PjxrhNNjW0HN9/Z1y+XPNgZuoqk6yzG/TLyM8XnKTIvNVI6zb1NVWtzMtwWS0TRzcYq9 huWA== X-Gm-Message-State: AOAM533z0OPLTfn1Y798HaJF/cdj6izsHPmS07vA4ZMsSyHF35dIJrZq 4uBxqcTO71LbzSZyOiiTPLH6L/mnEA8= X-Google-Smtp-Source: ABdhPJxLJH1mq2IE8FqtNkJ50+etuVpOk1g9rwyyyPnvyjvz6cuXzrk8eb5GWl4Pl+Yoqc8d3q+Q3Q== X-Received: by 2002:a17:90b:102:: with SMTP id p2mr19514726pjz.227.1593463014303; Mon, 29 Jun 2020 13:36:54 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id l134sm569288pga.50.2020.06.29.13.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 13:36:53 -0700 (PDT) Date: Mon, 29 Jun 2020 14:36:52 -0600 From: Mathieu Poirier To: Mike Leach Subject: Re: [PATCH] coresight: etmv4: Fix CPU power management setup in probe() function. Message-ID: <20200629203652.GB3732655@xps15> References: <20200623204606.13045-1-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200623204606.13045-1-mike.leach@linaro.org> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Mike, On Tue, Jun 23, 2020 at 09:46:06PM +0100, Mike Leach wrote: > The current probe() function calls a pair of cpuhp_xxx API functions to > setup CPU hotplug handling. The hotplug lock is held for the duration of > the two calls and other CPU related code using cpus_read_lock() / > cpus_read_unlock() calls. > > The problem is that on error states, goto: statements bypass the > cpus_read_unlock() call. This code has increased in complexity as the > driver has developed. > > This patch introduces a pair of helper functions etm4_pm_setup() and > etm4_pm_clear() which correct the issues above and group the PM code a > little better. > > The two functions etm4_cpu_pm_register() and etm4_cpu_pm_unregister() are > dropped as these call cpu_pm_register_notifier() / ..unregister_notifier() > dependent on CONFIG_CPU_PM - but this define is used to nop these functions > out in the pm headers - so the wrapper functions are superfluous. > > Fixes: f188b5e76aae ("coresight: etm4x: Save/restore state across CPU low power states") > Fixes: e9f5d63f84fe ("hwtracing/coresight-etm4x: Use cpuhp_setup_state_nocalls_cpuslocked()") > Fixes: 58eb457be028 ("etm4x: Convert to hotplug state machine") > > Signed-off-by: Mike Leach > --- > drivers/hwtracing/coresight/coresight-etm4x.c | 79 ++++++++++++------- > 1 file changed, 51 insertions(+), 28 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c > index 919b76fa49c4..4dd59de440de 100644 > --- a/drivers/hwtracing/coresight/coresight-etm4x.c > +++ b/drivers/hwtracing/coresight/coresight-etm4x.c > @@ -1407,18 +1407,56 @@ static struct notifier_block etm4_cpu_pm_nb = { > .notifier_call = etm4_cpu_pm_notify, > }; > > -static int etm4_cpu_pm_register(void) > +/* Setup PM. Called with cpus locked. Deals with error conditions and counts */ > +static int etm4_pm_setup_cpuslocked(void) > { > - if (IS_ENABLED(CONFIG_CPU_PM)) > - return cpu_pm_register_notifier(&etm4_cpu_pm_nb); > + int ret; > > - return 0; > + if (etm4_count++) > + return 0; > + > + ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb); > + if (ret) > + goto reduce_count; > + > + ret = cpuhp_setup_state_nocalls_cpuslocked( > + CPUHP_AP_ARM_CORESIGHT_STARTING, "arm/coresight4:starting", > + etm4_starting_cpu, etm4_dying_cpu); The 80 character limit per line has been relaxed to 100 in the 5.8 cycle. As such you can arrange CPUHP_AP_ARM_CORESIGHT_STARTING the same way you did below with CPUHP_AP_ONLINE_DYN without getting yelled at by checkpatch. > + > + if (ret) > + goto unregister_notifier; > + > + ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN, > + "arm/coresight4:online", > + etm4_online_cpu, NULL); > + > + /* HP dyn state ID returned in ret on success */ > + if (ret > 0) { > + hp_online = ret; > + return 0; > + } > + > + /* failed dyn state - remove others */ > + cpuhp_remove_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING); > + > +unregister_notifier: > + cpu_pm_unregister_notifier(&etm4_cpu_pm_nb); > + > +reduce_count: > + --etm4_count; > + return ret; > } > > -static void etm4_cpu_pm_unregister(void) > +static void etm4_pm_clear(void) > { > - if (IS_ENABLED(CONFIG_CPU_PM)) > + if (--etm4_count == 0) { if (--etm4_count != 0) return; > cpu_pm_unregister_notifier(&etm4_cpu_pm_nb); > + cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING); > + if (hp_online) { > + cpuhp_remove_state_nocalls(hp_online); > + hp_online = 0; > + } > + } > } > > static int etm4_probe(struct amba_device *adev, const struct amba_id *id) > @@ -1475,24 +1513,15 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) > etm4_init_arch_data, drvdata, 1)) > dev_err(dev, "ETM arch init failed\n"); > > - if (!etm4_count++) { > - cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING, > - "arm/coresight4:starting", > - etm4_starting_cpu, etm4_dying_cpu); > - ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN, > - "arm/coresight4:online", > - etm4_online_cpu, NULL); > - if (ret < 0) > - goto err_arch_supported; > - hp_online = ret; > + ret = etm4_pm_setup_cpuslocked(); > + cpus_read_unlock(); > > - ret = etm4_cpu_pm_register(); > - if (ret) > - goto err_arch_supported; > + /* etm4_pm_setup does its own cleanup - just exit on error here */ s/etm4_pm_setup/etm4_pm_setup_cpuslocked() Otherwise this is a good cleanup. Thanks, Mathieu > + if (ret) { > + etmdrvdata[drvdata->cpu] = NULL; > + return ret; > } > > - cpus_read_unlock(); > - > if (etm4_arch_supported(drvdata->arch) == false) { > ret = -EINVAL; > goto err_arch_supported; > @@ -1544,13 +1573,7 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) > > err_arch_supported: > etmdrvdata[drvdata->cpu] = NULL; > - if (--etm4_count == 0) { > - etm4_cpu_pm_unregister(); > - > - cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING); > - if (hp_online) > - cpuhp_remove_state_nocalls(hp_online); > - } > + etm4_pm_clear(); > return ret; > } > > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel