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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C73CAC433F5 for ; Wed, 9 Feb 2022 15:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235903AbiBIPel (ORCPT ); Wed, 9 Feb 2022 10:34:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231876AbiBIPek (ORCPT ); Wed, 9 Feb 2022 10:34:40 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F56C0613CA for ; Wed, 9 Feb 2022 07:34:43 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id m126-20020a1ca384000000b0037bb8e379feso3410992wme.5 for ; Wed, 09 Feb 2022 07:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6X/EAW4PGBx6CDB8KQmDtTWJkXrlZ6dQ+0Rs2M/cTuA=; b=nOrDAITSH7wzDvkmTQ+WxdJJ5LiypiQw8gyR5ZzYHI/ZxB6y4Vo5zdc2h4eVX9iuI3 ckWEaTq8exA0XoNJ38vd7iuNuswyTgbDLt8X3JXbgbUOKciOr39qWtDNN1LdeQ42OuEM fF8T7oVHa1ew+OGdcRor3ZwDqdYE8s+R714wkGPFt9DP7kHplDSfD79FJ0HKcWyF17tg HjzwFETNEk40GIDISpiKX+lhlCcT1cyjr2nts+wOYJjGSo43l7jyc+9zR9UO7m+qP+oJ ZV1cSoyPlleHVR98rVHP1ff0Lw/9so2YyGXrKyLigCBioqdYVx4EknqE8e7uR61mb8G+ bknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6X/EAW4PGBx6CDB8KQmDtTWJkXrlZ6dQ+0Rs2M/cTuA=; b=b0CpKURuB81iCVgKiw3QwvqONFbYVwbhlFWrdzJRpY6gxJ0qING7joNa7WAdoR/Rtq QL6z8ohIHFsfNBKDvJCXMbp38NwYHxo18YiLyfrgKTkYeljnUZHRCWb8wAZ2q9O0sBWs C89NYIUefTptIUNCLnfFSSNxJt784lCqF3bFgXcHT+of9UGB53X8spC2YR01ovygyAEC L8OTK+hUSdedLQf1YPerhaGj5kyDjGs7AHQQXsRqfT+HwF1WL1FKTHO6S68JE2oWiY5k yw9WZFlL7JDTJ6W9IT9RnPaGbHTKdvQ0sE3lTLODMgf8qINtg4XH6fQ+tR7/Afk9IjFK PWHg== X-Gm-Message-State: AOAM533GvaDu6pNurD6X+HYpsN9SOC1IVg2F+HD0EtNMrxhMbP/lUy9v h1NeZwZvpfH8gHkrXYUOF3zW8TFamU4OZy8uaVDaHA== X-Google-Smtp-Source: ABdhPJxNv6jCZcI+iE2gzUBh5OZQiKto84KWQlOAB2YrLoAHr4oY6Zt2iCCYuiqnYpC4U4lH6Y+894SHzGcLDZoOC4s= X-Received: by 2002:a05:600c:3846:: with SMTP id s6mr3103500wmr.26.1644420881817; Wed, 09 Feb 2022 07:34:41 -0800 (PST) MIME-Version: 1.0 References: <20220209105706.18852-1-quic_jinlmao@quicinc.com> <20220209105706.18852-2-quic_jinlmao@quicinc.com> In-Reply-To: <20220209105706.18852-2-quic_jinlmao@quicinc.com> From: Mike Leach Date: Wed, 9 Feb 2022 15:34:30 +0000 Message-ID: Subject: Re: [PATCH v3 01/10] Use IDR to maintain all the enabled sources' paths. To: Mao Jinlong Cc: Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Leo Yan , Greg Kroah-Hartman , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Tingwei Zhang , Yuanfang Zhang , Tao Zhang , Trilok Soni , Hao Zhang , linux-arm-msm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Hi, On Wed, 9 Feb 2022 at 10:57, Mao Jinlong wrote: > > Use hash length of the source's device name to map to the pointer > of the enabled path. Using IDR will be more efficient than using > the list. And there could be other sources except STM and CPU etms > in the new HWs. It is better to maintain all the paths together. > > Signed-off-by: Mao Jinlong > --- > drivers/hwtracing/coresight/coresight-core.c | 76 +++++++------------- > 1 file changed, 27 insertions(+), 49 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index 88653d1c06a4..a90097f88425 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -26,6 +27,12 @@ > static DEFINE_MUTEX(coresight_mutex); > static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); > > +/* > + * Use IDR to map the hash length of the source's device name > + * to the pointer of path for the source > + */ > +static DEFINE_IDR(path_idr); > + > /** > * struct coresight_node - elements of a path, from source to sink > * @csdev: Address of an element. > @@ -36,20 +43,6 @@ struct coresight_node { > struct list_head link; > }; > > -/* > - * When operating Coresight drivers from the sysFS interface, only a single > - * path can exist from a tracer (associated to a CPU) to a sink. > - */ > -static DEFINE_PER_CPU(struct list_head *, tracer_path); > - > -/* > - * As of this writing only a single STM can be found in CS topologies. Since > - * there is no way to know if we'll ever see more and what kind of > - * configuration they will enact, for the time being only define a single path > - * for STM. > - */ > -static struct list_head *stm_path; > - > /* > * When losing synchronisation a new barrier packet needs to be inserted at the > * beginning of the data collected in a buffer. That way the decoder knows that > @@ -1088,10 +1081,11 @@ static int coresight_validate_source(struct coresight_device *csdev, > > int coresight_enable(struct coresight_device *csdev) > { > - int cpu, ret = 0; > + int ret = 0; > struct coresight_device *sink; > struct list_head *path; > enum coresight_dev_subtype_source subtype; > + u32 hash; > > subtype = csdev->subtype.source_subtype; > > @@ -1133,26 +1127,14 @@ int coresight_enable(struct coresight_device *csdev) > if (ret) > goto err_source; > > - switch (subtype) { > - case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: > - /* > - * When working from sysFS it is important to keep track > - * of the paths that were created so that they can be > - * undone in 'coresight_disable()'. Since there can only > - * be a single session per tracer (when working from sysFS) > - * a per-cpu variable will do just fine. > - */ > - cpu = source_ops(csdev)->cpu_id(csdev); > - per_cpu(tracer_path, cpu) = path; > - break; > - case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: > - stm_path = path; > - break; > - default: > - /* We can't be here */ > - break; > - } > - > + /* > + * Use the hash length of source's device name as ID Slightly confusing comment: hashlen_string creates a hash and a length for the string. We are using the hash here so comment should be: "Use the hash of source's device name as ID" > + * and map the ID to the pointer of the path. > + */ > + hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev))); > + ret = idr_alloc_u32(&path_idr, path, &hash, hash, GFP_KERNEL); > + if (ret) > + goto err_source; > out: > mutex_unlock(&coresight_mutex); > return ret; > @@ -1168,8 +1150,9 @@ EXPORT_SYMBOL_GPL(coresight_enable); > > void coresight_disable(struct coresight_device *csdev) > { > - int cpu, ret; > + int ret; > struct list_head *path = NULL; > + u32 hash; > > mutex_lock(&coresight_mutex); > > @@ -1180,21 +1163,16 @@ void coresight_disable(struct coresight_device *csdev) > if (!csdev->enable || !coresight_disable_source(csdev)) > goto out; > > - switch (csdev->subtype.source_subtype) { > - case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: > - cpu = source_ops(csdev)->cpu_id(csdev); > - path = per_cpu(tracer_path, cpu); > - per_cpu(tracer_path, cpu) = NULL; > - break; > - case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: > - path = stm_path; > - stm_path = NULL; > - break; > - default: > - /* We can't be here */ > - break; > + hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev))); > + /* Find the path by the hash length. */ same comment as above re hash / hash length > + path = idr_find(&path_idr, hash); > + if (path == NULL) { > + dev_info(&csdev->dev, "Path is not found for %s\n", > + dev_name(&csdev->dev)); pr_err() is used in other parts of this file to print error messages. > + return; this skips the mutex_unlock(). use goto out; > } > > + idr_remove(&path_idr, hash); > coresight_disable_path(path); > coresight_release_path(path); > > -- > 2.17.1 > Regards Mike -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20B6DC433EF for ; Wed, 9 Feb 2022 15:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yZgQBTFHV1sm/CkyaI1y/Ol9Dwys55jHngRZ5/CzZF4=; b=N2fSyKSU7lpdMc m+I//yN8bdd8RIiBP8TEMWFUZ7EhQHM1ECMJt/BDB02h+orqENZa7Wackm8CkCR8s+K06NVLNdm9h Qj6s7FKofgpAk+ioGoj6odFjTHim+nB/Nolusu7LYXvdlpZdp1eJj/eAuAjW0SOfGh3xSDrGLzjST PLx8AdhLhKGiDLv2K0ANs1iIL0XNnHy3c83NjTLN5Hcf0O1U+kNyAj/AKUu8S5970qLxLbaRndASb 3gfUerfjZVfSQvPZnyTWqJn/PMU+TF/zJ3/ezJqu5mOGC4DAeoyueVL0EE0xQ0Xmmr3FWPeuP4J5j ENuGnAt882PtMM3hFDzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHozY-000bRb-NJ; Wed, 09 Feb 2022 15:34:48 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHozU-000bQ3-5z for linux-arm-kernel@lists.infradead.org; Wed, 09 Feb 2022 15:34:45 +0000 Received: by mail-wm1-x32f.google.com with SMTP id j5-20020a05600c1c0500b0034d2e956aadso1865730wms.4 for ; Wed, 09 Feb 2022 07:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6X/EAW4PGBx6CDB8KQmDtTWJkXrlZ6dQ+0Rs2M/cTuA=; b=nOrDAITSH7wzDvkmTQ+WxdJJ5LiypiQw8gyR5ZzYHI/ZxB6y4Vo5zdc2h4eVX9iuI3 ckWEaTq8exA0XoNJ38vd7iuNuswyTgbDLt8X3JXbgbUOKciOr39qWtDNN1LdeQ42OuEM fF8T7oVHa1ew+OGdcRor3ZwDqdYE8s+R714wkGPFt9DP7kHplDSfD79FJ0HKcWyF17tg HjzwFETNEk40GIDISpiKX+lhlCcT1cyjr2nts+wOYJjGSo43l7jyc+9zR9UO7m+qP+oJ ZV1cSoyPlleHVR98rVHP1ff0Lw/9so2YyGXrKyLigCBioqdYVx4EknqE8e7uR61mb8G+ bknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6X/EAW4PGBx6CDB8KQmDtTWJkXrlZ6dQ+0Rs2M/cTuA=; b=MVBP3+Kb4SWPVfeLMTWRqgffqGyHfXoS9uMjx3rr+QDv/fD3vAXh/6eF3G8e9yfI9n GXj/1ff8uAk7n0PSbQDnC06RFBWDFT9Oh95CtvhGyFP66CLNcAPjTnMiec3EEuF9sYMu 7QQfIDk77Z/0geeSEzS7HVk/8yt3nEfcfK4CN+ISJlC6tW53X0+TvM3XbSmyE3mSlQF+ CMxzuDdqX/GRNfGah0DNRmJ78GCuqK25rkYkekyIrVKd4CP27lXlpem2+4exIZC6P/oI e3Caij7+n72s08I9UWanioHXVMNaIBogprJBnQPZg5L5gaoDJXMt0Sm4UuGT2zkUbwoG 9/Mg== X-Gm-Message-State: AOAM531MISVuvdmYKD43vg/yKlGMYpuI2ZQWX6hoLhqdRzcLCYGndgFb oivst6vmBHp2HNlOLDLOVvUk4odPg8NITNz69zsMNw== X-Google-Smtp-Source: ABdhPJxNv6jCZcI+iE2gzUBh5OZQiKto84KWQlOAB2YrLoAHr4oY6Zt2iCCYuiqnYpC4U4lH6Y+894SHzGcLDZoOC4s= X-Received: by 2002:a05:600c:3846:: with SMTP id s6mr3103500wmr.26.1644420881817; Wed, 09 Feb 2022 07:34:41 -0800 (PST) MIME-Version: 1.0 References: <20220209105706.18852-1-quic_jinlmao@quicinc.com> <20220209105706.18852-2-quic_jinlmao@quicinc.com> In-Reply-To: <20220209105706.18852-2-quic_jinlmao@quicinc.com> From: Mike Leach Date: Wed, 9 Feb 2022 15:34:30 +0000 Message-ID: Subject: Re: [PATCH v3 01/10] Use IDR to maintain all the enabled sources' paths. To: Mao Jinlong Cc: Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Leo Yan , Greg Kroah-Hartman , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Tingwei Zhang , Yuanfang Zhang , Tao Zhang , Trilok Soni , Hao Zhang , linux-arm-msm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220209_073444_259187_FF87B2A9 X-CRM114-Status: GOOD ( 35.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, On Wed, 9 Feb 2022 at 10:57, Mao Jinlong wrote: > > Use hash length of the source's device name to map to the pointer > of the enabled path. Using IDR will be more efficient than using > the list. And there could be other sources except STM and CPU etms > in the new HWs. It is better to maintain all the paths together. > > Signed-off-by: Mao Jinlong > --- > drivers/hwtracing/coresight/coresight-core.c | 76 +++++++------------- > 1 file changed, 27 insertions(+), 49 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index 88653d1c06a4..a90097f88425 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -26,6 +27,12 @@ > static DEFINE_MUTEX(coresight_mutex); > static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); > > +/* > + * Use IDR to map the hash length of the source's device name > + * to the pointer of path for the source > + */ > +static DEFINE_IDR(path_idr); > + > /** > * struct coresight_node - elements of a path, from source to sink > * @csdev: Address of an element. > @@ -36,20 +43,6 @@ struct coresight_node { > struct list_head link; > }; > > -/* > - * When operating Coresight drivers from the sysFS interface, only a single > - * path can exist from a tracer (associated to a CPU) to a sink. > - */ > -static DEFINE_PER_CPU(struct list_head *, tracer_path); > - > -/* > - * As of this writing only a single STM can be found in CS topologies. Since > - * there is no way to know if we'll ever see more and what kind of > - * configuration they will enact, for the time being only define a single path > - * for STM. > - */ > -static struct list_head *stm_path; > - > /* > * When losing synchronisation a new barrier packet needs to be inserted at the > * beginning of the data collected in a buffer. That way the decoder knows that > @@ -1088,10 +1081,11 @@ static int coresight_validate_source(struct coresight_device *csdev, > > int coresight_enable(struct coresight_device *csdev) > { > - int cpu, ret = 0; > + int ret = 0; > struct coresight_device *sink; > struct list_head *path; > enum coresight_dev_subtype_source subtype; > + u32 hash; > > subtype = csdev->subtype.source_subtype; > > @@ -1133,26 +1127,14 @@ int coresight_enable(struct coresight_device *csdev) > if (ret) > goto err_source; > > - switch (subtype) { > - case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: > - /* > - * When working from sysFS it is important to keep track > - * of the paths that were created so that they can be > - * undone in 'coresight_disable()'. Since there can only > - * be a single session per tracer (when working from sysFS) > - * a per-cpu variable will do just fine. > - */ > - cpu = source_ops(csdev)->cpu_id(csdev); > - per_cpu(tracer_path, cpu) = path; > - break; > - case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: > - stm_path = path; > - break; > - default: > - /* We can't be here */ > - break; > - } > - > + /* > + * Use the hash length of source's device name as ID Slightly confusing comment: hashlen_string creates a hash and a length for the string. We are using the hash here so comment should be: "Use the hash of source's device name as ID" > + * and map the ID to the pointer of the path. > + */ > + hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev))); > + ret = idr_alloc_u32(&path_idr, path, &hash, hash, GFP_KERNEL); > + if (ret) > + goto err_source; > out: > mutex_unlock(&coresight_mutex); > return ret; > @@ -1168,8 +1150,9 @@ EXPORT_SYMBOL_GPL(coresight_enable); > > void coresight_disable(struct coresight_device *csdev) > { > - int cpu, ret; > + int ret; > struct list_head *path = NULL; > + u32 hash; > > mutex_lock(&coresight_mutex); > > @@ -1180,21 +1163,16 @@ void coresight_disable(struct coresight_device *csdev) > if (!csdev->enable || !coresight_disable_source(csdev)) > goto out; > > - switch (csdev->subtype.source_subtype) { > - case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: > - cpu = source_ops(csdev)->cpu_id(csdev); > - path = per_cpu(tracer_path, cpu); > - per_cpu(tracer_path, cpu) = NULL; > - break; > - case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE: > - path = stm_path; > - stm_path = NULL; > - break; > - default: > - /* We can't be here */ > - break; > + hash = hashlen_hash(hashlen_string(NULL, dev_name(&csdev->dev))); > + /* Find the path by the hash length. */ same comment as above re hash / hash length > + path = idr_find(&path_idr, hash); > + if (path == NULL) { > + dev_info(&csdev->dev, "Path is not found for %s\n", > + dev_name(&csdev->dev)); pr_err() is used in other parts of this file to print error messages. > + return; this skips the mutex_unlock(). use goto out; > } > > + idr_remove(&path_idr, hash); > coresight_disable_path(path); > coresight_release_path(path); > > -- > 2.17.1 > Regards Mike -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel