All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Kaehlcke <mka@chromium.org>
To: Evan Green <evgreen@chromium.org>
Cc: georgi.djakov@linaro.org, linux-pm@vger.kernel.org,
	gregkh@linuxfoundation.org, rjw@rjwysocki.net,
	robh+dt@kernel.org, Michael Turquette <mturquette@baylibre.com>,
	khilman@baylibre.com,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Saravana Kannan <skannan@codeaurora.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	amit.kucheria@linaro.org, seansw@qti.qualcomm.com,
	daidavid1@codeaurora.org, mark.rutland@arm.com,
	lorenzo.pieralisi@arm.com, abailon@baylibre.com,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v5 1/8] interconnect: Add generic on-chip interconnect API
Date: Tue, 26 Jun 2018 14:58:16 -0700	[thread overview]
Message-ID: <20180626215816.GQ129942@google.com> (raw)
In-Reply-To: <CAE=gft4sSdFL7J27WdTuYCtfLPAyv8xOAizYhmtfK5UkTbP5-A@mail.gmail.com>

On Tue, Jun 26, 2018 at 01:57:21PM -0700, Evan Green wrote:
> Hi Georgi. Thanks for the new spin of this.
> 
> On Wed, Jun 20, 2018 at 5:11 AM Georgi Djakov <georgi.djakov@linaro.org> wrote:
> >
> > This patch introduce a new API to get requirements and configure the
> > interconnect buses across the entire chipset to fit with the current
> > demand.
> >
> > The API is using a consumer/provider-based model, where the providers are
> > the interconnect buses and the consumers could be various drivers.
> > The consumers request interconnect resources (path) between endpoints and
> > set the desired constraints on this data flow path. The providers receive
> > requests from consumers and aggregate these requests for all master-slave
> > pairs on that path. Then the providers configure each participating in the
> > topology node according to the requested data flow path, physical links and
> > constraints. The topology could be complicated and multi-tiered and is SoC
> > specific.
> >
> > Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
> > ---
> >  Documentation/interconnect/interconnect.rst |  96 ++++
> >  drivers/Kconfig                             |   2 +
> >  drivers/Makefile                            |   1 +
> >  drivers/interconnect/Kconfig                |  10 +
> >  drivers/interconnect/Makefile               |   2 +
> >  drivers/interconnect/core.c                 | 586 ++++++++++++++++++++
> >  include/linux/interconnect-provider.h       | 127 +++++
> >  include/linux/interconnect.h                |  42 ++
> >  8 files changed, 866 insertions(+)
> >  create mode 100644 Documentation/interconnect/interconnect.rst
> >  create mode 100644 drivers/interconnect/Kconfig
> >  create mode 100644 drivers/interconnect/Makefile
> >  create mode 100644 drivers/interconnect/core.c
> >  create mode 100644 include/linux/interconnect-provider.h
> >  create mode 100644 include/linux/interconnect.h
> >
> > ...
> >
> > diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c
> > new file mode 100644
> > index 000000000000..e7f96fc6722e
> > --- /dev/null
> > +++ b/drivers/interconnect/core.c
> > @@ -0,0 +1,586 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Interconnect framework core driver
> > + *
> > + * Copyright (c) 2018, Linaro Ltd.
> > + * Author: Georgi Djakov <georgi.djakov@linaro.org>
> > + */
> > +
> > +#include <linux/device.h>
> > +#include <linux/idr.h>
> > +#include <linux/init.h>
> > +#include <linux/interconnect.h>
> > +#include <linux/interconnect-provider.h>
> > +#include <linux/list.h>
> > +#include <linux/module.h>
> > +#include <linux/mutex.h>
> > +#include <linux/slab.h>
> > +
> > +static DEFINE_IDR(icc_idr);
> > +static LIST_HEAD(icc_provider_list);
> > +static DEFINE_MUTEX(icc_lock);
> > +
> > +/**
> > + * struct icc_req - constraints that are attached to each node
> > + *
> > + * @req_node: entry in list of requests for the particular @node
> > + * @node: the interconnect node to which this constraint applies
> > + * @dev: reference to the device that sets the constraints
> > + * @avg_bw: an integer describing the average bandwidth in kbps
> > + * @peak_bw: an integer describing the peak bandwidth in kbps
> > + */
> > +struct icc_req {
> > +       struct hlist_node req_node;
> > +       struct icc_node *node;
> > +       struct device *dev;
> > +       u32 avg_bw;
> > +       u32 peak_bw;
> > +};
> > +
> > +/**
> > + * struct icc_path - interconnect path structure
> > + * @num_nodes: number of hops (nodes)
> > + * @reqs: array of the requests applicable to this path of nodes
> > + */
> > +struct icc_path {
> > +       size_t num_nodes;
> > +       struct icc_req reqs[0];
> > +};
> > +
> > +static struct icc_node *node_find(const int id)
> > +{
> > +       struct icc_node *node;
> > +
> > +       mutex_lock(&icc_lock);
> > +       node = idr_find(&icc_idr, id);
> > +       mutex_unlock(&icc_lock);
> 
> I wonder if this is too low of a level to be dealing with the lock. I
> notice that everywhere you use this function, you afterwards
> immediately grab the lock and do more stuff. Maybe this function
> should have a comment saying it assumes the lock is already held, and
> then you can grab the lock in the callers, since you're doing that
> anyway.

I think the canonical way to document the expectation would be:

WARN_ON(!mutex_is_locked(&icc_lock));

> > +
> > +       return node;
> > +}
> > +
> > +static struct icc_path *path_allocate(struct icc_node *dst, ssize_t num_nodes)
> > +{
> > +       struct icc_node *node = dst;
> > +       struct icc_path *path;
> > +       size_t i;
> > +
> > +       path = kzalloc(sizeof(*path) + num_nodes * sizeof(*path->reqs),
> > +                      GFP_KERNEL);
> > +       if (!path)
> > +               return ERR_PTR(-ENOMEM);
> > +
> > +       path->num_nodes = num_nodes;
> > +
> > +       for (i = 0; i < num_nodes; i++) {
> > +               hlist_add_head(&path->reqs[i].req_node, &node->req_list);
> > +
> > +               path->reqs[i].node = node;
> > +               /* reference to previous node was saved during path traversal */
> > +               node = node->reverse;
> > +       }
> > +
> > +       return path;
> > +}
> > +
> > +static struct icc_path *path_find(struct device *dev, struct icc_node *src,
> > +                                 struct icc_node *dst)
> > +{
> 
> I personally prefer a comment somewhere indicating that this function
> assumes icc_lock is already held. Not sure if that's conventional or
> not.

Same as above.

WARNING: multiple messages have this Message-ID (diff)
From: mka@chromium.org (Matthias Kaehlcke)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 1/8] interconnect: Add generic on-chip interconnect API
Date: Tue, 26 Jun 2018 14:58:16 -0700	[thread overview]
Message-ID: <20180626215816.GQ129942@google.com> (raw)
In-Reply-To: <CAE=gft4sSdFL7J27WdTuYCtfLPAyv8xOAizYhmtfK5UkTbP5-A@mail.gmail.com>

On Tue, Jun 26, 2018 at 01:57:21PM -0700, Evan Green wrote:
> Hi Georgi. Thanks for the new spin of this.
> 
> On Wed, Jun 20, 2018 at 5:11 AM Georgi Djakov <georgi.djakov@linaro.org> wrote:
> >
> > This patch introduce a new API to get requirements and configure the
> > interconnect buses across the entire chipset to fit with the current
> > demand.
> >
> > The API is using a consumer/provider-based model, where the providers are
> > the interconnect buses and the consumers could be various drivers.
> > The consumers request interconnect resources (path) between endpoints and
> > set the desired constraints on this data flow path. The providers receive
> > requests from consumers and aggregate these requests for all master-slave
> > pairs on that path. Then the providers configure each participating in the
> > topology node according to the requested data flow path, physical links and
> > constraints. The topology could be complicated and multi-tiered and is SoC
> > specific.
> >
> > Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
> > ---
> >  Documentation/interconnect/interconnect.rst |  96 ++++
> >  drivers/Kconfig                             |   2 +
> >  drivers/Makefile                            |   1 +
> >  drivers/interconnect/Kconfig                |  10 +
> >  drivers/interconnect/Makefile               |   2 +
> >  drivers/interconnect/core.c                 | 586 ++++++++++++++++++++
> >  include/linux/interconnect-provider.h       | 127 +++++
> >  include/linux/interconnect.h                |  42 ++
> >  8 files changed, 866 insertions(+)
> >  create mode 100644 Documentation/interconnect/interconnect.rst
> >  create mode 100644 drivers/interconnect/Kconfig
> >  create mode 100644 drivers/interconnect/Makefile
> >  create mode 100644 drivers/interconnect/core.c
> >  create mode 100644 include/linux/interconnect-provider.h
> >  create mode 100644 include/linux/interconnect.h
> >
> > ...
> >
> > diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c
> > new file mode 100644
> > index 000000000000..e7f96fc6722e
> > --- /dev/null
> > +++ b/drivers/interconnect/core.c
> > @@ -0,0 +1,586 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Interconnect framework core driver
> > + *
> > + * Copyright (c) 2018, Linaro Ltd.
> > + * Author: Georgi Djakov <georgi.djakov@linaro.org>
> > + */
> > +
> > +#include <linux/device.h>
> > +#include <linux/idr.h>
> > +#include <linux/init.h>
> > +#include <linux/interconnect.h>
> > +#include <linux/interconnect-provider.h>
> > +#include <linux/list.h>
> > +#include <linux/module.h>
> > +#include <linux/mutex.h>
> > +#include <linux/slab.h>
> > +
> > +static DEFINE_IDR(icc_idr);
> > +static LIST_HEAD(icc_provider_list);
> > +static DEFINE_MUTEX(icc_lock);
> > +
> > +/**
> > + * struct icc_req - constraints that are attached to each node
> > + *
> > + * @req_node: entry in list of requests for the particular @node
> > + * @node: the interconnect node to which this constraint applies
> > + * @dev: reference to the device that sets the constraints
> > + * @avg_bw: an integer describing the average bandwidth in kbps
> > + * @peak_bw: an integer describing the peak bandwidth in kbps
> > + */
> > +struct icc_req {
> > +       struct hlist_node req_node;
> > +       struct icc_node *node;
> > +       struct device *dev;
> > +       u32 avg_bw;
> > +       u32 peak_bw;
> > +};
> > +
> > +/**
> > + * struct icc_path - interconnect path structure
> > + * @num_nodes: number of hops (nodes)
> > + * @reqs: array of the requests applicable to this path of nodes
> > + */
> > +struct icc_path {
> > +       size_t num_nodes;
> > +       struct icc_req reqs[0];
> > +};
> > +
> > +static struct icc_node *node_find(const int id)
> > +{
> > +       struct icc_node *node;
> > +
> > +       mutex_lock(&icc_lock);
> > +       node = idr_find(&icc_idr, id);
> > +       mutex_unlock(&icc_lock);
> 
> I wonder if this is too low of a level to be dealing with the lock. I
> notice that everywhere you use this function, you afterwards
> immediately grab the lock and do more stuff. Maybe this function
> should have a comment saying it assumes the lock is already held, and
> then you can grab the lock in the callers, since you're doing that
> anyway.

I think the canonical way to document the expectation would be:

WARN_ON(!mutex_is_locked(&icc_lock));

> > +
> > +       return node;
> > +}
> > +
> > +static struct icc_path *path_allocate(struct icc_node *dst, ssize_t num_nodes)
> > +{
> > +       struct icc_node *node = dst;
> > +       struct icc_path *path;
> > +       size_t i;
> > +
> > +       path = kzalloc(sizeof(*path) + num_nodes * sizeof(*path->reqs),
> > +                      GFP_KERNEL);
> > +       if (!path)
> > +               return ERR_PTR(-ENOMEM);
> > +
> > +       path->num_nodes = num_nodes;
> > +
> > +       for (i = 0; i < num_nodes; i++) {
> > +               hlist_add_head(&path->reqs[i].req_node, &node->req_list);
> > +
> > +               path->reqs[i].node = node;
> > +               /* reference to previous node was saved during path traversal */
> > +               node = node->reverse;
> > +       }
> > +
> > +       return path;
> > +}
> > +
> > +static struct icc_path *path_find(struct device *dev, struct icc_node *src,
> > +                                 struct icc_node *dst)
> > +{
> 
> I personally prefer a comment somewhere indicating that this function
> assumes icc_lock is already held. Not sure if that's conventional or
> not.

Same as above.

  reply	other threads:[~2018-06-26 21:58 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20 12:11 [PATCH v5 0/8] Introduce on-chip interconnect API Georgi Djakov
2018-06-20 12:11 ` Georgi Djakov
2018-06-20 12:11 ` [PATCH v5 1/8] interconnect: Add generic " Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-26 20:57   ` Evan Green
2018-06-26 20:57     ` Evan Green
2018-06-26 20:57     ` Evan Green
2018-06-26 21:58     ` Matthias Kaehlcke [this message]
2018-06-26 21:58       ` Matthias Kaehlcke
2018-06-27  0:54     ` Rob Clark
2018-06-27  0:54       ` Rob Clark
2018-07-01 11:03     ` Georgi Djakov
2018-07-01 11:03       ` Georgi Djakov
2018-07-01 11:03       ` Georgi Djakov
2018-06-26 23:34   ` Matthias Kaehlcke
2018-06-26 23:34     ` Matthias Kaehlcke
2018-07-01 11:06     ` Georgi Djakov
2018-07-01 11:06       ` Georgi Djakov
2018-06-27  6:19   ` Vincent Guittot
2018-06-27  6:19     ` Vincent Guittot
2018-07-01 11:09     ` Georgi Djakov
2018-07-01 11:09       ` Georgi Djakov
2018-07-02  7:23       ` Vincent Guittot
2018-07-02  7:23         ` Vincent Guittot
2018-06-20 12:11 ` [PATCH v5 2/8] dt-bindings: Introduce interconnect provider bindings Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-20 12:11 ` [PATCH v5 3/8] interconnect: Add debugfs support Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-20 12:11 ` [PATCH v5 4/8] interconnect: qcom: Add RPM communication Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-26 20:47   ` Evan Green
2018-06-26 20:47     ` Evan Green
2018-07-01 11:16     ` Georgi Djakov
2018-07-01 11:16       ` Georgi Djakov
2018-06-27  0:55   ` Matthias Kaehlcke
2018-06-27  0:55     ` Matthias Kaehlcke
2018-07-01 11:18     ` Georgi Djakov
2018-07-01 11:18       ` Georgi Djakov
2018-06-20 12:11 ` [PATCH v5 5/8] dt-bindings: interconnect: Document qcom,msm8916 NoC bindings Georgi Djakov
2018-06-20 12:11   ` [PATCH v5 5/8] dt-bindings: interconnect: Document qcom, msm8916 " Georgi Djakov
2018-06-20 12:11 ` [PATCH v5 6/8] interconnect: qcom: Add msm8916 interconnect provider driver Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-26 20:48   ` Evan Green
2018-06-26 20:48     ` Evan Green
2018-07-01 12:12     ` Georgi Djakov
2018-07-01 12:12       ` Georgi Djakov
2018-07-02 17:08       ` Evan Green
2018-07-02 17:08         ` Evan Green
2018-07-02 17:08         ` Evan Green
2018-06-20 12:11 ` [PATCH v5 7/8] dt-bindings: Introduce interconnect consumers bindings Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov
2018-06-20 12:11 ` [PATCH v5 8/8] interconnect: Allow endpoints translation via DT Georgi Djakov
2018-06-20 12:11   ` Georgi Djakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180626215816.GQ129942@google.com \
    --to=mka@chromium.org \
    --cc=abailon@baylibre.com \
    --cc=amit.kucheria@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=daidavid1@codeaurora.org \
    --cc=evgreen@chromium.org \
    --cc=georgi.djakov@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=khilman@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=mturquette@baylibre.com \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=seansw@qti.qualcomm.com \
    --cc=skannan@codeaurora.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.