Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4270917ybz; Tue, 28 Apr 2020 08:30:43 -0700 (PDT) X-Google-Smtp-Source: APiQypIkt+1MJbZlZjONY20+BXLgtYaGYFsugplUS5gfYpsP7kYCJtRw3BXwRIY5emlE8o9Inm/j X-Received: by 2002:a17:907:4033:: with SMTP id nk3mr7842209ejb.273.1588087843557; Tue, 28 Apr 2020 08:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588087843; cv=none; d=google.com; s=arc-20160816; b=ALo8fKq5cH+CP8oormBngYtm9F1sofgaWmRascItkUp7paov1JtUHKCRj9OBv6+tF9 VxakTRUxWN6rDBJVcyxYVL5JGO/0Mr/lINQgpeHe5GRZk6Ei3tOi/k6KCnkw0tcf9GRT yltqvaLDYz71eDUKSpEr0lVIbZc+CCV6pS/mZSvOFt0Ddml+d67NHykOvY0xKRopxI2X E71sS9yshJ0fIuUW7mxvDcR+tNjAGvE3FpbWjgJAxs4o6jHa5vaxDp7os/qVAdt2QDlh RT2SRcWWbqOJYy8hsCR0A1qjIGXZi3+je0CucFXOi0eSmtfeJTCAIQTTc8dV4XFlznvg VmCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bupX4Xeuiln/DjuxcvV53YK6vLVjuUky6WkzRYhlMcY=; b=gHoH8s59wE3sKJkgPxaVg0CnyNTlAMOnWeHnWbBKyKTWimZGLz96dW7w14Xb/uKYrq PuFD6EHQtbBsmrvbBHQLp9/c9alhU/wJn80UyZjOlYDnRLiKFtKYVdNA2swReZE2I2rl o1HlgVfIinCt/cRc0uk67x0Vq0FjyLj9CUgZhG9OZCKPHdXc/1cvI0Fz57kw17ENUMdw iTIereiD96XpGCyUabOyLq5CgQMRqNK+VGgcWtsCybTZD5jtMJMIMtgIMRvmo9mCjK2w hEXYd/6jcNecIms/0aXv5vCUSyXzSf7F5Sztv28EOopOnrz2OUH2xaF48S5MncF+L23j Ieaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ls38140q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n23si1830223edt.420.2020.04.28.08.30.19; Tue, 28 Apr 2020 08:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ls38140q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727917AbgD1P2p (ORCPT + 99 others); Tue, 28 Apr 2020 11:28:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728314AbgD1P2o (ORCPT ); Tue, 28 Apr 2020 11:28:44 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C82EC03C1AC for ; Tue, 28 Apr 2020 08:28:44 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id s10so8512658plr.1 for ; Tue, 28 Apr 2020 08:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bupX4Xeuiln/DjuxcvV53YK6vLVjuUky6WkzRYhlMcY=; b=ls38140qhFqIHiH1VWhQV1JjlPCTVDhgEiCQJeqzoj10IuX4Fxh+KT8CSglGlmQZGy wFYXg9ksMB0mkoRh+tgrSf0EcKN8EuBtdqwMLali2VFuB7fAD4OWBw6PhSLEXq9trlzI zcw8B9j9FwmZWgLgIJrSDOnVQgeQVwNFWMdZc= 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=bupX4Xeuiln/DjuxcvV53YK6vLVjuUky6WkzRYhlMcY=; b=ctCTbVOqjBcOpte1VlkDDc/t4siDzRLEAow2nBbNtZ3uZMUObolKt4wZsncRhtLmlj EKlax6CSw7ftzMKrFREzGXjnjRjC6dwtgjpre5sIK2Mb3PyVrl8/hbbQn4BHCEtO6YiH Lwj22AW9pFhMDNYJLDLL4e1k/aZsdhj6K8t4wo1TrRGyUEWfMFd0sbbQZ5uQQV7QpCjL D4CVBqrjDQk46PbNY500KuhyAbDpmnHhWdD70T5Yc5AYlqn2ihNChGCZjLGS7MD5jSvy 0qdDC4qnn3+r8HB4NpgRULBVRdVR8yI0lBcAUNxxe1i+jMDBfLtK7Ft/dVj1/qtMn+dE oqYA== X-Gm-Message-State: AGi0PuaYKga3hlqH23a5zO3njDsoxPVqsN6fKgr90XTXnUSEBHAGful/ H/JIs15N27zfp+ivwAHBEQXrm0VvQKw= X-Received: by 2002:a17:902:82c6:: with SMTP id u6mr30286582plz.146.1588087723981; Tue, 28 Apr 2020 08:28:43 -0700 (PDT) Received: from localhost ([2620:15c:202:1:4fff:7a6b:a335:8fde]) by smtp.gmail.com with ESMTPSA id o1sm2387369pjs.35.2020.04.28.08.28.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Apr 2020 08:28:43 -0700 (PDT) Date: Tue, 28 Apr 2020 08:28:42 -0700 From: Matthias Kaehlcke To: Georgi Djakov Cc: linux-pm@vger.kernel.org, evgreen@chromium.org, bjorn.andersson@linaro.org, akashast@codeaurora.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] interconnect: Add helpers for enabling/disabling a path Message-ID: <20200428152842.GG4525@google.com> References: <20200428091650.27669-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200428091650.27669-1-georgi.djakov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Georgi, On Tue, Apr 28, 2020 at 12:16:50PM +0300, Georgi Djakov wrote: > There is a repeated pattern in multiple drivers where they want to switch > the bandwidth between zero and some other value. This is happening often > in the suspend/resume callbacks. Let's add helper functions to enable and > disable the path, so that callers don't have to take care of remembering > the bandwidth values and handle this in the framework instead. > > With this patch the users can call icc_disable() and icc_enable() to lower > their bandwidth request to zero and then restore it back to it's previous > value. > > Suggested-by: Evan Green > Suggested-by: Bjorn Andersson > Signed-off-by: Georgi Djakov > --- > drivers/interconnect/core.c | 50 ++++++++++++++++++++++++++++++++- > drivers/interconnect/internal.h | 2 ++ > include/linux/interconnect.h | 12 ++++++++ > 3 files changed, 63 insertions(+), 1 deletion(-) > > diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c > index 2c6515e3ecf1..6af68e506ac2 100644 > --- a/drivers/interconnect/core.c > +++ b/drivers/interconnect/core.c > @@ -158,6 +158,7 @@ static struct icc_path *path_init(struct device *dev, struct icc_node *dst, > hlist_add_head(&path->reqs[i].req_node, &node->req_list); > path->reqs[i].node = node; > path->reqs[i].dev = dev; > + path->reqs[i].enabled = true; > /* reference to previous node was saved during path traversal */ > node = node->reverse; > } > @@ -249,9 +250,12 @@ static int aggregate_requests(struct icc_node *node) > if (p->pre_aggregate) > p->pre_aggregate(node); > > - hlist_for_each_entry(r, &node->req_list, req_node) > + hlist_for_each_entry(r, &node->req_list, req_node) { > + if (!r->enabled) > + continue; > p->aggregate(node, r->tag, r->avg_bw, r->peak_bw, > &node->avg_bw, &node->peak_bw); > + } > > return 0; > } > @@ -546,6 +550,50 @@ int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw) > } > EXPORT_SYMBOL_GPL(icc_set_bw); > > +int icc_disable(struct icc_path *path) > +{ > + int i; > + > + if (!path) > + return 0; > + > + if (WARN_ON(IS_ERR(path) || !path->num_nodes)) > + return -EINVAL; > + > + mutex_lock(&icc_lock); > + > + for (i = 0; i < path->num_nodes; i++) > + path->reqs[i].enabled = false; > + > + mutex_unlock(&icc_lock); > + > + return icc_set_bw(path, path->reqs[0].avg_bw, > + path->reqs[0].peak_bw); > +} > +EXPORT_SYMBOL_GPL(icc_disable); > + > +int icc_enable(struct icc_path *path) > +{ > + int i; > + > + if (!path) > + return 0; > + > + if (WARN_ON(IS_ERR(path) || !path->num_nodes)) > + return -EINVAL; > + > + mutex_lock(&icc_lock); > + > + for (i = 0; i < path->num_nodes; i++) > + path->reqs[i].enabled = true; > + > + mutex_unlock(&icc_lock); > + > + return icc_set_bw(path, path->reqs[0].avg_bw, > + path->reqs[0].peak_bw); > +} The two functions are identical except for the assignment of the 'enabled' flags. You could add a helper _icc_enable(struct icc_path *path, bool enable) and call it from icc_enable/disable().