From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 110BC3ED5DD for ; Tue, 31 Mar 2026 09:44:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774950269; cv=none; b=XivBSzP6blN+2lcbZm9HxlWlu61MxDzirRyiK1lHF1S9r1WrHVD3piYMubIQdwNRKLPkOE2XDRD0zGUMQ8IT7ej28+eMnUToKeBFDi1GSz/Simf3yPtjPI/+SnVBkSsGnDOcsm7d8VKH6SNoCRy88v0hxfPxecUf22YaK680odw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774950269; c=relaxed/simple; bh=AA5rciqA89iDBfuRYv/hgyw8rEIJWbCh3cfFTEMOSPA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tEXM4NiVyVGi/UBQ06GZI05/jJmmgzteRhJoyrG+8Yf5MHvdhe2xDoBE7H9cS2J09Gcdmhl1Tff0Q1jc6XAGfNYtwSwUdQ3R9MceMki1H2hvUZaNCEjzJWJGvPThTVVewyLt/3f4PY72VCIPIt4zS0nQHDgTKaEz+82GbgwLQCw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=wZ+u0oYa; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wZ+u0oYa" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4870206f73bso33841975e9.3 for ; Tue, 31 Mar 2026 02:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774950266; x=1775555066; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=EENVmNw5YtlVJXHsET8w6vHESlMWBJK2b8JGdfCQMgs=; b=wZ+u0oYa3ZINXjTqJdHtKnhsQme+FrRwTVpVuu74JSyTJQQgwVvVtgEP3R94QsuK1j PNDqlV9Hm+NAcTwH0GJyHWPH292XtICVAaBPIVB+QeaWZZYhDLtTb9XgkAo3ww0xqfBr 5SaZhpEe+Gz5XA6oDJQm76Xe59iNAhgZB8VZjvrrsUlrne5iWb0xpfrXRjf++frr+dBD M0q38LbbLLX1/K7kWbLWyzxO1bdX4g21GchMztU3rJP8cnsTz8mx6Fsc1IqnIMB6ELKA C0ratqiLsXaCJV2uQF83NYKP8NRfM4/Gcdt6EXwkDOp3BqV1s/g0JDeBz39GBvdiZC3z gvUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774950266; x=1775555066; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EENVmNw5YtlVJXHsET8w6vHESlMWBJK2b8JGdfCQMgs=; b=HENXgzT45PTzyuWqI6Apond5oI4k19qwJvhcLf9Aub9W1XpVMl09qWqZDhgZkmL/v7 MRryA8OvUHeNs3nSWermZ4fnIElirhsVTKGArf+JVCUSmgj98pryFzzPOiEiw1TuZ3xn 0/iLPcMV/0WwNUBWul7ZuPHszcFwmIjzMZDOOnKJKrSpXXVdubOhMl5vs+Z0+zaotB99 e5HOwcVmdSdavjgOwUnKBidC8bm5oldE8LoP+LrgFfby9jgq6qQ+PNqhtkRfle6ChNAc 3Rl+l3af9Mpgntx1AvA+mSg341d6dWvnlPLQ5WGTA9EoiSbV3tNUy+huRqTD3tQFMlJD /DMQ== X-Forwarded-Encrypted: i=1; AJvYcCXm3r/JOxFFWpB3gqQUU9KMhqctmctaFlWWfz2AH/tYr3pHPi/RcJwxkDvhBwxL8duZp8xkXi3T2qeGmp4=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ/bieZ2fNkAeJvYimrKceefg96gag7MthisDYXsldCrPiT0sc XWSdOAAkKWU7KD2tf08/RBgwNl+ebvtoyJAvtUszOcFGGvtSJ6NbKs2CH1wyF3jSgZVWIKOpffO BiUIeVFQ= X-Gm-Gg: ATEYQzxzg5lFOeeNZ2BB6193fJMYKsEKtmtqLU+4/1WIyRK/K0w4LxEXgqPCuqbf5js BZOqzRnvlrf2l436o6ABORiIEWZRPTLVtZBiRSEL6UtRs5r/SWbpwFUZMiYGIQH/4iBJUeRHwa7 Tt8bSEilYq2IS6IIWrLk5mhEGeIXh3LDFvTfXI7FwVoYTb5YeEXTNGsyATkaW6oGKuOXKrizo/r 7uSAkPVEhFa2knt+Iy7AcApdRYas2R7Sv4+u3EYeN+Ef7Ib7p8h3dX7m+78KV5ghPk94F8ZLKNh twRaU2SaeLiwPg2kTpRLjKQrOuD/qjVK5D/l9kLCAp+EtsIkEPNGDpLSKOFqjQr6iTkHKOv3s7C lBNqPLZQiIBcCsIHbZp/Lj6cdJQjNZ515ZFxoejfKI19oxQVFF6sjETWr2yuath0AIpTzaUV0PL A/dmfJS1rEPYCN+2J7ak1kgs9vHRWJ X-Received: by 2002:a05:600c:1393:b0:485:3c8f:e4d9 with SMTP id 5b1f17b1804b1-487280a09a2mr266634435e9.26.1774950265403; Tue, 31 Mar 2026 02:44:25 -0700 (PDT) Received: from [192.168.1.3] ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4887a630901sm20871675e9.0.2026.03.31.02.44.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Mar 2026 02:44:24 -0700 (PDT) Message-ID: Date: Tue, 31 Mar 2026 10:44:23 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] coresight: tpdm: add traceid_show for checking traceid To: Jie Gan , Suzuki K Poulose Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Leo Yan , Alexander Shishkin , Tingwei Zhang References: <20260325-add-traceid-show-for-tpdm-v3-1-0eb836d4ec30@oss.qualcomm.com> <95610981-ad68-4a31-a776-27894b7bca59@linaro.org> <207b78e5-ed6b-4caf-b9ce-546cf33d6dfd@oss.qualcomm.com> <7abe93fa-3748-4077-b75a-d28296862654@linaro.org> Content-Language: en-US From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 31/03/2026 10:33 am, Jie Gan wrote: > > > On 3/31/2026 5:26 PM, James Clark wrote: >> >> >> On 31/03/2026 4:18 am, Jie Gan wrote: >>> Hi James, >>> >>> On 3/31/2026 9:29 AM, Jie Gan wrote: >>>> >>>> Hi James, >>>> >>>> On 3/30/2026 10:55 PM, James Clark wrote: >>>>> >>>>> >>>>> On 25/03/2026 3:10 am, Jie Gan wrote: >>>>>> Save the trace ID in drvdata during TPDM enablement and expose it >>>>>> to userspace to support trace data parsing. >>>>>> >>>>>> The TPDM device’s trace ID corresponds to the trace ID allocated >>>>>> to the connected TPDA device. >>>>>> >>>>>> Signed-off-by: Jie Gan >>>>>> --- >>>>>> Changes in v3: >>>>>> 1. Only allow user to read the traceid while the TPDM device is >>>>>> enabled. >>>>>> - Link to v2: https://lore.kernel.org/r/20260316-add-traceid-show- >>>>>> for- tpdm-v2-1-1dec2a67e4ed@oss.qualcomm.com >>>>>> >>>>>> Changes in V2: >>>>>> 1. Use sysfs_emit instead of sprintf. >>>>>> Link to V1 - https://lore.kernel.org/all/20260306-add-traceid- >>>>>> show- for-tpdm-v1-1-0658a8edb972@oss.qualcomm.com/ >>>>>> --- >>>>>>   drivers/hwtracing/coresight/coresight-tpdm.c | 34 ++++++++++++++ >>>>>> + + + + +++++++++- >>>>>>   drivers/hwtracing/coresight/coresight-tpdm.h |  2 ++ >>>>>>   2 files changed, 35 insertions(+), 1 deletion(-) >>>>>> >>>>>> diff --git a/drivers/hwtracing/coresight/coresight-tpdm.c b/ >>>>>> drivers/ hwtracing/coresight/coresight-tpdm.c >>>>>> index da77bdaad0a4..c8339b973bfc 100644 >>>>>> --- a/drivers/hwtracing/coresight/coresight-tpdm.c >>>>>> +++ b/drivers/hwtracing/coresight/coresight-tpdm.c >>>>>> @@ -481,7 +481,7 @@ static void __tpdm_enable(struct tpdm_drvdata >>>>>> *drvdata) >>>>>>   static int tpdm_enable(struct coresight_device *csdev, struct >>>>>> perf_event *event, >>>>>>                  enum cs_mode mode, >>>>>> -               __maybe_unused struct coresight_path *path) >>>>>> +               struct coresight_path *path) >>>>>>   { >>>>>>       struct tpdm_drvdata *drvdata = dev_get_drvdata(csdev- >>>>>> >dev.parent); >>>>>> @@ -497,6 +497,7 @@ static int tpdm_enable(struct coresight_device >>>>>> *csdev, struct perf_event *event, >>>>>>       } >>>>>>       __tpdm_enable(drvdata); >>>>>> +    drvdata->traceid = path->trace_id; >>>>>>       drvdata->enable = true; >>>>>>       spin_unlock(&drvdata->spinlock); >>>>>> @@ -693,6 +694,29 @@ static struct attribute_group tpdm_attr_grp = { >>>>>>       .attrs = tpdm_attrs, >>>>>>   }; >>>>>> +static ssize_t traceid_show(struct device *dev, >>>>>> +                struct device_attribute *attr, char *buf) >>>>>> +{ >>>>>> +    unsigned long val; >>>>>> +    struct tpdm_drvdata *drvdata = dev_get_drvdata(dev->parent); >>>>>> + >>>>>> +    if (coresight_get_mode(drvdata->csdev) == CS_MODE_DISABLED) >>>>>> +        return -EINVAL; >>>>>> + >>>>>> +    val = drvdata->traceid; >>>>> >>>>> You probably need to take the coresight_mutex here otherwise you >>>>> could still return an invalid or stale value despite checking the >>>>> mode. >>>>> >>>> >>>> Acked. I have missed this potential race condition. >>>> >>>>> There might also be some value in it returning the last used trace >>>>> ID even if the mode isn't enabled anymore. Because you can still >>>>> read out of the sink after disabling, so it makes more sense for a >>>>> script to read it at that point rather than when it's enabled. >>>>> Also, you probably don't want to be doing other things in your >>>>> script in the point between enabling and disabling. >>>> >>>> That's making sense. I shouldnt add such restriction for the read >>>> process. >>>> >>> >>> I missed one point in last message. >>> >>> Is that acceptable to export the coresight_mutex from the core module? >>> Currently, the coresight_mutex is used within the module only. >>> >>> Thanks, >>> Jie >>> >> >> If the plan is to only check for non-zero trace ID and not check the >> mode any more then you don't need to lock. Maybe lets see what Suzuki >> thinks about returning the last trace ID though as it was his idea to >> add -EINVAL. >> > > Sure. The trace ID is allocated during TPDA device probe and remains > unchanged for the entire lifetime of the device. > > Thanks, > Jie > > Oh I missed that because it's assigned every time in tpdm_enable(). In that case I don't see why it can't be just: val = drvdata->traceid; if (!val) return -EINVAL; return sysfs_emit(...) >>>> Scenarios for reading: >>>> 1. device is enabled -> trace ID is valid >>>> 2. device is enabled then disabled -> trace ID is valid for the last >>>> trace event >>>> 3. device is never enabled -> invalid trace ID (value 0) >>>> >>>> we only need to check the validation of the trace ID. >>>> >>>> mutex_lock(&coresight_mutex); >>>> val = drvdata->traceid; >>>> mutex_unlock(&coresight_mutex); >>>> >>>> if (!val) >>>>      return -EINVAL; >>>> >>>> return sysfs_emit(buf, "%#lx\n", val); >>>> >>>> Thanks, >>>> Jie >>>> >>>>> >>>>>> +    return sysfs_emit(buf, "%#lx\n", val); >>>>>> +} >>>>>> +static DEVICE_ATTR_RO(traceid); >>>>>> + >>>>>> +static struct attribute *traceid_attrs[] = { >>>>>> +    &dev_attr_traceid.attr, >>>>>> +    NULL, >>>>>> +}; >>>>>> + >>>>>> +static struct attribute_group traceid_attr_grp = { >>>>>> +    .attrs = traceid_attrs, >>>>>> +}; >>>>>> + >>>>>>   static ssize_t dsb_mode_show(struct device *dev, >>>>>>                    struct device_attribute *attr, >>>>>>                    char *buf) >>>>>> @@ -1367,6 +1391,12 @@ static const struct attribute_group >>>>>> *tpdm_attr_grps[] = { >>>>>>       &tpdm_cmb_patt_grp, >>>>>>       &tpdm_cmb_msr_grp, >>>>>>       &tpdm_mcmb_attr_grp, >>>>>> +    &traceid_attr_grp, >>>>>> +    NULL, >>>>>> +}; >>>>>> + >>>>>> +static const struct attribute_group *static_tpdm_attr_grps[] = { >>>>>> +    &traceid_attr_grp, >>>>>>       NULL, >>>>>>   }; >>>>>> @@ -1425,6 +1455,8 @@ static int tpdm_probe(struct device *dev, >>>>>> struct resource *res) >>>>>>       desc.access = CSDEV_ACCESS_IOMEM(base); >>>>>>       if (res) >>>>>>           desc.groups = tpdm_attr_grps; >>>>>> +    else >>>>>> +        desc.groups = static_tpdm_attr_grps; >>>>>>       drvdata->csdev = coresight_register(&desc); >>>>>>       if (IS_ERR(drvdata->csdev)) >>>>>>           return PTR_ERR(drvdata->csdev); >>>>>> diff --git a/drivers/hwtracing/coresight/coresight-tpdm.h b/ >>>>>> drivers/ hwtracing/coresight/coresight-tpdm.h >>>>>> index 2867f3ab8186..11da64e1ade8 100644 >>>>>> --- a/drivers/hwtracing/coresight/coresight-tpdm.h >>>>>> +++ b/drivers/hwtracing/coresight/coresight-tpdm.h >>>>>> @@ -300,6 +300,7 @@ struct cmb_dataset { >>>>>>    * @cmb         Specifics associated to TPDM CMB. >>>>>>    * @dsb_msr_num Number of MSR supported by DSB TPDM >>>>>>    * @cmb_msr_num Number of MSR supported by CMB TPDM >>>>>> + * @traceid    Trace ID of the path. >>>>>>    */ >>>>>>   struct tpdm_drvdata { >>>>>> @@ -313,6 +314,7 @@ struct tpdm_drvdata { >>>>>>       struct cmb_dataset    *cmb; >>>>>>       u32            dsb_msr_num; >>>>>>       u32            cmb_msr_num; >>>>>> +    u8            traceid; >>>>>>   }; >>>>>>   /* Enumerate members of various datasets */ >>>>>> >>>>>> --- >>>>>> base-commit: b84a0ebe421ca56995ff78b66307667b62b3a900 >>>>>> change-id: 20260316-add-traceid-show-for-tpdm-88d040651f00 >>>>>> >>>>>> Best regards, >>>>> >>>> >>> >> >