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=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 1DF05C433E1 for ; Thu, 20 Aug 2020 17:04:33 +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 D1A6C208A9 for ; Thu, 20 Aug 2020 17:04:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jqGNr82G"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Lnvj8Kcx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1A6C208A9 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=kzIpJS8jyLBqKzE0MD/tzh3fvvTBc4Fw9qAWW1blwXI=; b=jqGNr82G8qYDFkIl15LQovmPB 7GI1PYFIPD1raTmlk37ce94A4MvQ0YHCadsVfHNyJJ7yiv7uPDQGEIA0tDNLdNkO7qf5PWlJ3XyOD n21O8evqU6t+374VWqwdqmPAC2teZY3f8paMv3MYWhhEo8IO7Pepd8020mIhytZSTvAdV6LP1Vhy3 srMC8ifafIdEbTGWbU8B0r2eV27s3Z6CQ9c5U0anOTqxNAR6v6MH4sV/mlEgeYs6JTYxYGKYGHa62 bFwvJI43QbjO2i6sjmxa33Bwvpvm/vk/4w1nHPORKNs6K5pfpx+c6P5B1/rPi7Rh8uxRrmsL1Xj6e WDiNRvzAw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8nxy-0005GY-WF; Thu, 20 Aug 2020 17:03:07 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8nxw-0005FQ-4N for linux-arm-kernel@lists.infradead.org; Thu, 20 Aug 2020 17:03:05 +0000 Received: by mail-pg1-x543.google.com with SMTP id g33so1435119pgb.4 for ; Thu, 20 Aug 2020 10:03:03 -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=g1ufgcFk9HXhxui0cMSOEE4axI7wl1DdrnwmvBDs2Cs=; b=Lnvj8KcxRvVdiVKJAuhzJDQxYVI5aB67Jgy+LOsylRTKZlstzBRXmzSfhjrSC6XSZ2 rXdbgDRHuiV5oo4LZu9kt0H//p93XFQWfKGzjGkHIfiXOUDx/blVhoJeqH7HqynhA9Rn 0y0HMM+RGOHT7KE6fZP0t4nVVtmUZf6v8kUEHg2Z1y9KblYAJcsguXDLpZYWhMSBcYNA oO3IHManCzHwuB9V+/EJCmkb7PXa5sNVl9YzQXspeZtrib/6jI4WNa4cXH7/rsPP5eP5 QTV4rbdI5zpZlPUIfLmuLN9a/R7dhstTT2BWWhxCcTnLJqk/HvKBcWB4GhrYbVQkQBfd 2sHw== 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=g1ufgcFk9HXhxui0cMSOEE4axI7wl1DdrnwmvBDs2Cs=; b=JEG3Ly2OYR8YY1hPen18im8CKWkBYf4KEdGKEDy6Ov9MsGaEvzVRSarGwH2RBjmrPV HcNwfOlOLpbfJK4TmD3WdJ/hzFNYI6/kKInAGv6IDK3yGf/SKjP1EG4ad3252mFjnENU 6/cW6V//HZHYqZAtv7t77d1n3m7WF0iATEPeYkOu+h5YCdYrLFpAS9rb3RP0tI7kn2Av /Z784mGPC5U9mT//4m1hOGm5lK5rfJ7AH8KiFgHGSgUq1H5C2aiJwL4Ilw7/sVo1Ani+ wutQ3zl3ZhKQ6bgyvpk79DmZ8BpIIvZUsOkXZYjBNsX6tmiL61EtfgzwDWo0NBQyJx8K iRFg== X-Gm-Message-State: AOAM5336KtsHGhbISe0xYRaUuOJsOlrJYGzoMkwSNVF4bNuaSOlkUcZc WrdS5TNhA2jCo+MdcpeCoizmAA== X-Google-Smtp-Source: ABdhPJxDflfEQyQ0pyoJRyz06O7Kng1qg0ilGykk3jz3w4VE+IwxBQQJLUTXqFIDGHoPpZjZ1/LhnA== X-Received: by 2002:a63:cd54:: with SMTP id a20mr3008557pgj.228.1597942981376; Thu, 20 Aug 2020 10:03:01 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id d23sm3142953pgm.11.2020.08.20.10.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 10:03:00 -0700 (PDT) Date: Thu, 20 Aug 2020 11:02:59 -0600 From: Mathieu Poirier To: Linu Cherian Subject: Re: [PATCH V3] coresight: Make sysFS functional on topologies with per core sink Message-ID: <20200820170259.GA3933623@xps15> References: <20200811022842.20129-1-lcherian@marvell.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200811022842.20129-1-lcherian@marvell.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200820_130304_491336_984B920F X-CRM114-Status: GOOD ( 39.93 ) 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, mike.leach@linaro.org, linuc.decode@gmail.com, 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 Linu, On Tue, Aug 11, 2020 at 07:58:42AM +0530, Linu Cherian wrote: > Coresight driver assumes sink is common across all the ETMs, > and tries to build a path between ETM and the first enabled > sink found using bus based search. This breaks sysFS usage > on implementations that has multiple per core sinks in > enabled state. > > For this, > - coresight_find_sink API is updated with an additional flag > so that it is able to return an enabled sink > - coresight_get_enabled_sink API is updated to do a > connection based search, when a source reference is given. > > Signed-off-by: Linu Cherian > --- > Applies on https://git.linaro.org/kernel/coresight.git/log/?h=next > > Changes in V3: > Fixed checkpatch issue. > > .../hwtracing/coresight/coresight-etm-perf.c | 2 +- > drivers/hwtracing/coresight/coresight-priv.h | 5 +- > drivers/hwtracing/coresight/coresight.c | 51 +++++++++++++++++-- > 3 files changed, 51 insertions(+), 7 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c > index 1a3169e69bb1..25041d2654e3 100644 > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c > @@ -223,7 +223,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, > id = (u32)event->attr.config2; > sink = coresight_get_sink_by_id(id); > } else { > - sink = coresight_get_enabled_sink(true); > + sink = coresight_get_enabled_sink(NULL, true); It is time for this subsystem to move out of the prehistoric age. Please remove the call to coresight_get_enabled_sink() entirely. In the change log you can write that selecting a sink from sysfs is deprecated when using the perf interface. I will personally refactor the code if someone complains that it broke their user space. > } > > mask = &event_data->mask; > diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h > index f2dc625ea585..010ed26db340 100644 > --- a/drivers/hwtracing/coresight/coresight-priv.h > +++ b/drivers/hwtracing/coresight/coresight-priv.h > @@ -148,10 +148,13 @@ static inline void coresight_write_reg_pair(void __iomem *addr, u64 val, > void coresight_disable_path(struct list_head *path); > int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data); > struct coresight_device *coresight_get_sink(struct list_head *path); > -struct coresight_device *coresight_get_enabled_sink(bool reset); > +struct coresight_device * > +coresight_get_enabled_sink(struct coresight_device *source, bool reset); > struct coresight_device *coresight_get_sink_by_id(u32 id); > struct coresight_device * > coresight_find_default_sink(struct coresight_device *csdev); > +struct coresight_device * > +coresight_find_enabled_sink(struct coresight_device *csdev); > struct list_head *coresight_build_path(struct coresight_device *csdev, > struct coresight_device *sink); > void coresight_release_path(struct list_head *path); > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c > index e9c90f2de34a..ae69169c58d3 100644 > --- a/drivers/hwtracing/coresight/coresight.c > +++ b/drivers/hwtracing/coresight/coresight.c > @@ -566,6 +566,10 @@ static int coresight_enabled_sink(struct device *dev, const void *data) > > /** > * coresight_get_enabled_sink - returns the first enabled sink found on the bus > + * When a source reference is given, enabled sink is found using connection based > + * search. > + * > + * @source: Coresight source device reference > * @deactivate: Whether the 'enable_sink' flag should be reset > * > * When operated from perf the deactivate parameter should be set to 'true'. > @@ -576,10 +580,21 @@ static int coresight_enabled_sink(struct device *dev, const void *data) > * parameter should be set to 'false', hence mandating users to explicitly > * clear the flag. > */ > -struct coresight_device *coresight_get_enabled_sink(bool deactivate) > +struct coresight_device * > +coresight_get_enabled_sink(struct coresight_device *source, bool deactivate) This code was written during a time when all sources were able to reach a sink, something that is no longer the case. Starting from a source is the right way to go. > { > struct device *dev = NULL; > + struct coresight_device *sink; > + > + if (!source) > + goto bus_search; Return NULL if a source was not given. > + sink = coresight_find_enabled_sink(source); > + if (sink && deactivate) > + sink->activated = false; > + > + return sink; You get credits for trying to re-use code but in this case I would like to avoid modifying coresight_find_sink() to keep it as simple as possible. I suggest to copy the for() loop in coresight_find_sink() and stop the search when the first activated sink is found. It will introduce a little bit of code duplication but I think we will gain a lot in maintainability. > > +bus_search: > dev = bus_find_device(&coresight_bustype, NULL, &deactivate, > coresight_enabled_sink); Get rid of this. You can also get rid of the 'deactivate' parameter since it won't be used anymore. Let me know if you have questions. Thanks, Mathieu > > @@ -828,6 +843,7 @@ coresight_select_best_sink(struct coresight_device *sink, int *depth, > * > * @csdev: source / current device to check. > * @depth: [in] search depth of calling dev, [out] depth of found sink. > + * @enabled: flag to search only enabled sinks > * > * This will walk the connection path from a source (ETM) till a suitable > * sink is encountered and return that sink to the original caller. > @@ -839,7 +855,7 @@ coresight_select_best_sink(struct coresight_device *sink, int *depth, > * return best sink found, or NULL if not found at this node or child nodes. > */ > static struct coresight_device * > -coresight_find_sink(struct coresight_device *csdev, int *depth) > +coresight_find_sink(struct coresight_device *csdev, int *depth, bool enabled) > { > int i, curr_depth = *depth + 1, found_depth = 0; > struct coresight_device *found_sink = NULL; > @@ -862,7 +878,8 @@ coresight_find_sink(struct coresight_device *csdev, int *depth) > > child_dev = csdev->pdata->conns[i].child_dev; > if (child_dev) > - sink = coresight_find_sink(child_dev, &child_depth); > + sink = coresight_find_sink(child_dev, &child_depth, > + enabled); > > if (sink) > found_sink = coresight_select_best_sink(found_sink, > @@ -872,6 +889,10 @@ coresight_find_sink(struct coresight_device *csdev, int *depth) > } > > return_def_sink: > + /* Check if we need to return an enabled sink */ > + if (enabled && found_sink) > + if (!found_sink->activated) > + found_sink = NULL; > /* return found sink and depth */ > if (found_sink) > *depth = found_depth; > @@ -901,10 +922,30 @@ coresight_find_default_sink(struct coresight_device *csdev) > > /* look for a default sink if we have not found for this device */ > if (!csdev->def_sink) > - csdev->def_sink = coresight_find_sink(csdev, &depth); > + csdev->def_sink = coresight_find_sink(csdev, &depth, false); > return csdev->def_sink; > } > > +/** > + * coresight_find_enabled_sink: Find the suitable enabled sink > + * > + * @csdev: starting source to find a connected sink. > + * > + * Walks connections graph looking for a suitable sink to enable for the > + * supplied source. Uses CoreSight device subtypes and distance from source > + * to select the best sink. > + * > + * Used in cases where the CoreSight user (sysfs) has selected a sink. > + */ > +struct coresight_device * > +coresight_find_enabled_sink(struct coresight_device *csdev) > +{ > + int depth = 0; > + > + /* look for the enabled sink */ > + return coresight_find_sink(csdev, &depth, true); > +} > + > static int coresight_remove_sink_ref(struct device *dev, void *data) > { > struct coresight_device *sink = data; > @@ -992,7 +1033,7 @@ int coresight_enable(struct coresight_device *csdev) > * Search for a valid sink for this session but don't reset the > * "enable_sink" flag in sysFS. Users get to do that explicitly. > */ > - sink = coresight_get_enabled_sink(false); > + sink = coresight_get_enabled_sink(csdev, false); > if (!sink) { > ret = -EINVAL; > goto out; > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel