Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp328946imu; Thu, 8 Nov 2018 02:39:29 -0800 (PST) X-Google-Smtp-Source: AJdET5dCObT2jc8a4PpqKydUr/AiZ9YHmP/2CZ9KFz7kISbzcBOAXNLqv0/VoYm0a2apeOh+TTJA X-Received: by 2002:a62:1a92:: with SMTP id a140-v6mr3983509pfa.219.1541673568976; Thu, 08 Nov 2018 02:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541673568; cv=none; d=google.com; s=arc-20160816; b=dVJATw4blmOZmqImrQt3IsN47DqMYaWhDyTL774uSWeGeFQYFlQZcUKHLPjID/zqUA 56faekaW3J697t+1SFUTRy6m5sdF757qUZOE+7BZxwuVP8qsr7yUZioPR12d024gFJc5 goPxDMkpbtH6EE9kd8qhOebjrMiBz6VM+mX3/Z8MX4Xi0SPGXNLlxP0eOuVbEfYTJhn2 Xd8rD9hEAgFvb49a5b65CU0N9UdXrI2sjkgfDYYTkY2pnXFN2/+/1d968zvsYwp7qH5s rGYlmiHPmLfOY7Tqh7TFTjMe1psAbgHTiW37J2IiKU5645gYD7DAPhcHHN8UXyyv796z 4e8A== 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:to:subject:dkim-signature; bh=XuDMRopSgPrsNOHjWn5CvcleVHxhfIg8XLdX4pSoK0g=; b=y0GNouk4a7P6A7Dr/iw4xVbm//2zG59ZJkgaAGTMw9CIOEJJ7X650QJrAjHCFoQVqT Uk0PWPdIrFbkj+vGcNl80zGFojwWpGwT9x+5oBnTXYq3ybkuYuTh0KezSpPKEeKT8/x/ Eh6AStNKwMdARu0GUmqqg1aJxv1/C7T3R3lSaCPKwDo/n9YBtZgyGHXyopV/E21M9ewO EfUmXQLJYG342wm/V14ysblTh2UU1YtYebp32Ej+bbDqWF1nUIDd+5xQC30knVPLLCKu SDrK5unVFE4SbEt5QSQbL8T2NAd47BYwZvHnbg7GVg08xGF0iGsnl4zNz+hJMNuOFyIK q1nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=mJrGY9Lt; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s192si3713975pgc.144.2018.11.08.02.39.12; Thu, 08 Nov 2018 02:39:28 -0800 (PST) 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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=mJrGY9Lt; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbeKHULz (ORCPT + 99 others); Thu, 8 Nov 2018 15:11:55 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:52458 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726274AbeKHULz (ORCPT ); Thu, 8 Nov 2018 15:11:55 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id wA8AagPe025320; Thu, 8 Nov 2018 04:36:42 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1541673402; bh=XuDMRopSgPrsNOHjWn5CvcleVHxhfIg8XLdX4pSoK0g=; h=Subject:To:References:From:Date:In-Reply-To; b=mJrGY9LtmPDZdREiJADKWc2oUdQfbJZEkKuZi3jMOmI1rTaqncM9TvXEBNQCzZ13C K4STfbHaQ8bUSjVlycGX+qVl6QfOPeBoJBmFf+WL99D7+SIhDRhdwz5h7YMa1wPmIA 3adHYAPQQvbcbG9Ka+rDQnflEonk9iTDWtnSMLic= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id wA8AagP2102591 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 Nov 2018 04:36:42 -0600 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 8 Nov 2018 04:36:41 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Thu, 8 Nov 2018 04:36:41 -0600 Received: from [127.0.0.1] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id wA8Aabp0028880; Thu, 8 Nov 2018 04:36:38 -0600 Subject: Re: [PATCH 1/2] clk: ti: add a usecount for autoidle To: Andreas Kemnade , , , , , , , , , References: <20181004203817.22101-1-andreas@kemnade.info> <20181004203817.22101-2-andreas@kemnade.info> From: Tero Kristo Message-ID: <23cbfc19-20d9-99f0-c086-e782cc36de34@ti.com> Date: Thu, 8 Nov 2018 12:36:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181004203817.22101-2-andreas@kemnade.info> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/10/2018 23:38, Andreas Kemnade wrote: > We have the scenario that first autoidle is disabled for all clocks, > then it is disabled for selected ones and then enabled for all. So > we should have some counting here, also according to the > comment in _setup_iclk_autoidle() > > Signed-off-by: Andreas Kemnade > --- > drivers/clk/ti/autoidle.c | 32 ++++++++++++++++++++++++-------- > include/linux/clk/ti.h | 1 + > 2 files changed, 25 insertions(+), 8 deletions(-) > > diff --git a/drivers/clk/ti/autoidle.c b/drivers/clk/ti/autoidle.c > index 7bb9afbe4058..bb6cff168e73 100644 > --- a/drivers/clk/ti/autoidle.c > +++ b/drivers/clk/ti/autoidle.c > @@ -37,6 +37,14 @@ struct clk_ti_autoidle { > static LIST_HEAD(autoidle_clks); > static LIST_HEAD(clk_hw_omap_clocks); > > +/* > + * we have some non-atomic read/write > + * operations behind it, so lets > + * take one mutex for handling autoidle > + * of all clocks > + */ > +static DEFINE_MUTEX(autoidle_mutex); Why mutex? This prevents calling the autoidle APIs from atomic context. Did you check the mutex debug kernel configs with this? This may cause problems with the runtime PM entries to the code at least. > + > /** > * omap2_clk_deny_idle - disable autoidle on an OMAP clock > * @clk: struct clk * to disable autoidle for > @@ -48,8 +56,13 @@ int omap2_clk_deny_idle(struct clk *clk) > struct clk_hw_omap *c; > > c = to_clk_hw_omap(__clk_get_hw(clk)); > - if (c->ops && c->ops->deny_idle) > - c->ops->deny_idle(c); > + if (c->ops && c->ops->deny_idle) { > + mutex_lock(&autoidle_mutex); > + c->autoidle_count--; > + if (c->autoidle_count == -1) I think you should swap the arithmetics here, all the other usecounters use positive values, here you enter deep to the negative side when autoidle is denied by multiple users, which might be confusing. -Tero > + c->ops->deny_idle(c); > + mutex_unlock(&autoidle_mutex); > + } > return 0; > } > > @@ -64,8 +77,13 @@ int omap2_clk_allow_idle(struct clk *clk) > struct clk_hw_omap *c; > > c = to_clk_hw_omap(__clk_get_hw(clk)); > - if (c->ops && c->ops->allow_idle) > - c->ops->allow_idle(c); > + if (c->ops && c->ops->allow_idle) { > + mutex_lock(&autoidle_mutex); > + c->autoidle_count++; > + if (c->autoidle_count == 0) > + c->ops->allow_idle(c); > + mutex_unlock(&autoidle_mutex); > + } > return 0; > } > > @@ -201,8 +219,7 @@ int omap2_clk_enable_autoidle_all(void) > struct clk_hw_omap *c; > > list_for_each_entry(c, &clk_hw_omap_clocks, node) > - if (c->ops && c->ops->allow_idle) > - c->ops->allow_idle(c); > + omap2_clk_allow_idle(c->hw.clk); > > _clk_generic_allow_autoidle_all(); > > @@ -223,8 +240,7 @@ int omap2_clk_disable_autoidle_all(void) > struct clk_hw_omap *c; > > list_for_each_entry(c, &clk_hw_omap_clocks, node) > - if (c->ops && c->ops->deny_idle) > - c->ops->deny_idle(c); > + omap2_clk_deny_idle(c->hw.clk); > > _clk_generic_deny_autoidle_all(); > > diff --git a/include/linux/clk/ti.h b/include/linux/clk/ti.h > index a8faa38b1ed6..c460355419c0 100644 > --- a/include/linux/clk/ti.h > +++ b/include/linux/clk/ti.h > @@ -159,6 +159,7 @@ struct clk_hw_omap { > const char *clkdm_name; > struct clockdomain *clkdm; > const struct clk_hw_omap_ops *ops; > + int autoidle_count; > }; > > /* > -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki