Currently, cs-etm passes the tid value for both tid and pid parameters
when calling machine__set_current_tid(), this can lead to confusion for
thread handling. E.g. we arbitrarily pass the same value for pid and
tid, perf tool will be misled to consider it is a main thread (see
thread__main_thread()).
On the other hand, Perf tool only can retrieve tid from Arm CoreSight
context packet, and we have no chance to know pid (it maps to kernel's
task_struct::tgid) from hardware tracing data. For this reason, this
patch passes -1 as pid for function machine__set_current_tid().
Signed-off-by: Leo Yan <leo.yan(a)linaro.org>
---
tools/perf/util/cs-etm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index f323adb1af85..eed1a5930072 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1118,7 +1118,7 @@ int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq,
if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0)
return err;
- err = machine__set_current_tid(etm->machine, cpu, tid, tid);
+ err = machine__set_current_tid(etm->machine, cpu, -1, tid);
if (err)
return err;
--
2.25.1
Fix the description of the directories and attributes used
in cs_etm as used by perf.
Drop the references to the 'configurations' sub-directory which
had been removed in an earlier version of the patchset.
Fixes: f71cd93d5ea4 ("Documentation: coresight: Add documentation for CoreSight config")
Reported-by: German Gomex <german.gomez(a)arm.com>
Signed-off-by: Mike Leach <mike.leach(a)linaro.org>
---
.../trace/coresight/coresight-config.rst | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/Documentation/trace/coresight/coresight-config.rst b/Documentation/trace/coresight/coresight-config.rst
index a4e3ef295240..6ed13398ca2c 100644
--- a/Documentation/trace/coresight/coresight-config.rst
+++ b/Documentation/trace/coresight/coresight-config.rst
@@ -211,19 +211,13 @@ also declared in the perf 'cs_etm' event infrastructure so that they can
be selected when running trace under perf::
$ ls /sys/devices/cs_etm
- configurations format perf_event_mux_interval_ms sinks type
- events nr_addr_filters power
+ cpu0 cpu2 events nr_addr_filters power subsystem uevent
+ cpu1 cpu3 format perf_event_mux_interval_ms sinks type
-Key directories here are 'configurations' - which lists the loaded
-configurations, and 'events' - a generic perf directory which allows
-selection on the perf command line.::
+The key directory here is 'events' - a generic perf directory which allows
+selection on the perf command line. As with the sinks entries, this provides
+a hash of the configuration name.
- $ ls configurations/
- autofdo
- $ cat configurations/autofdo
- 0xa7c3dddd
-
-As with the sinks entries, this provides a hash of the configuration name.
The entry in the 'events' directory uses perfs built in syntax generator
to substitute the syntax for the name when evaluating the command::
--
2.17.1
On Mon, Nov 22, 2021 at 11:12:03PM +0800, Jinlong Mao wrote:
> Hi Mathieu,
>
> Thanks for the comments.
>
> I double checked the code. Please see my comments below.
>
>
> On 10/29/2021 2:06 AM, Mathieu Poirier wrote:
> > On Thu, Oct 21, 2021 at 03:38:47PM +0800, Tao Zhang wrote:
> > > Current coresight implementation only supports enabling source
> > > ETMs or STM. This patch adds support to enable more kinds of
> > > coresight source to sink paths. We build a path from source to
> > > sink when any source is enabled and store it in a list. When the
> > > source is disabled, we fetch the corresponding path from the list
> > > and decrement the refcount on each device in the path. The device
> > > is disabled if the refcount reaches zero. Don't store path to
> > > coresight data structure of source to avoid unnecessary change to
> > > ABI.
> > > Since some targets may have coresight sources other than STM and
> > > ETMs, we need to add this change to support these coresight
> > > devices.
> > >
> > > Signed-off-by: Tingwei Zhang <tingwei(a)codeaurora.org>
> > > Signed-off-by: Tao Zhang <quic_taozha(a)quicinc.com>
> > > ---
> > > drivers/hwtracing/coresight/coresight-core.c | 100 +++++++++++--------
> > > 1 file changed, 56 insertions(+), 44 deletions(-)
> > >
> > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
> > > index 8a18c71df37a..1e621d61307a 100644
> > > --- a/drivers/hwtracing/coresight/coresight-core.c
> > > +++ b/drivers/hwtracing/coresight/coresight-core.c
> > > @@ -37,18 +37,16 @@ struct coresight_node {
> > > };
> > > /*
> > > - * When operating Coresight drivers from the sysFS interface, only a single
> > > - * path can exist from a tracer (associated to a CPU) to a sink.
> > > + * struct coresight_path - path from source to sink
> > > + * @path: Address of path list.
> > > + * @link: hook to the list.
> > > */
> > > -static DEFINE_PER_CPU(struct list_head *, tracer_path);
> > > +struct coresight_path {
> > > + struct list_head *path;
> > > + struct list_head link;
> > > +};
> > For sources associated with a CPU, like ETMs, having a per-cpu way of storing
> > paths is a definite advantage and should be kept that way.
>
> Hi Mathieu,
>
> Could you please share what is the advantage to handle the sources
> associated with a CPU separatly ?
>
It is a question of efficiency. There is no point iterating through all the
sources if we don't have to.
> From the code, cpu id is only used to get the path of the ETM source.
>
> As there will be many tpdm sources, I think it will be easier to only
> maintain one list for all the sources.
>
So many TPDM and many ETMs... That is definitely a reason to do better than a
sequential search.
> > > -/*
> > > - * 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;
> > > +static LIST_HEAD(cs_active_paths);
> > Then there are sources that aren't associated with a CPU like STMs and TPDMs.
> > Perhaps using an IDR or the hash of the device name as a key to a hashing
> > vector would be better than doing a sequential search, especially as the
> > list of devices is bound to increase over time.
>
> Agree with you. I will try to use IDR or the hash of the device name as a
> key to a hashing vector.
>
If an IDR (or some other kind of mechanism) is used then we can use that to
store paths associated with ETMs as well. That way everything works the same
way and access time is constant for any kind of source.
> >
> > > /*
> > > * When losing synchronisation a new barrier packet needs to be inserted at the
> > > @@ -354,6 +352,7 @@ static void coresight_disable_sink(struct coresight_device *csdev)
> > > if (ret)
> > > return;
> > > coresight_control_assoc_ectdev(csdev, false);
> > > + csdev->activated = false;
> > I don't see why this is needed and without proper documentation there is no way
> > for me to guess the logic behind the change. The ->activated flag should be
> > manipulated from the command line interface only.
>
> When source is disabled, but sink is still actived. It will be confused for
> end users.
>
That is how it has been working for years now. It was done this way to give as
much flexibility to users and keep kernel intelligence to a minimum.
> >
> > > csdev->enable = false;
> > > }
> > > @@ -590,6 +589,20 @@ int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data)
> > > goto out;
> > > }
> > > +static struct coresight_device *coresight_get_source(struct list_head *path)
> > > +{
> > > + struct coresight_device *csdev;
> > > +
> > > + if (!path)
> > > + return NULL;
> > > +
> > > + csdev = list_first_entry(path, struct coresight_node, link)->csdev;
> > > + if (csdev->type != CORESIGHT_DEV_TYPE_SOURCE)
> > > + return NULL;
> > > +
> > > + return csdev;
> > > +}
> > > +
> > > struct coresight_device *coresight_get_sink(struct list_head *path)
> > > {
> > > struct coresight_device *csdev;
> > > @@ -1086,9 +1099,23 @@ static int coresight_validate_source(struct coresight_device *csdev,
> > > return 0;
> > > }
> > > +static int coresight_store_path(struct list_head *path)
> > > +{
> > > + struct coresight_path *node;
> > > +
> > > + node = kzalloc(sizeof(struct coresight_path), GFP_KERNEL);
> > > + if (!node)
> > > + return -ENOMEM;
> > > +
> > > + node->path = path;
> > > + list_add(&node->link, &cs_active_paths);
> > > +
> > > + return 0;
> > > +}
> > > +
> > > 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;
> > > @@ -1133,25 +1160,9 @@ 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;
> > > - }
> > > + ret = coresight_store_path(path);
> > > + if (ret)
> > > + goto err_source;
> > > out:
> > > mutex_unlock(&coresight_mutex);
> > > @@ -1168,8 +1179,11 @@ EXPORT_SYMBOL_GPL(coresight_enable);
> > > void coresight_disable(struct coresight_device *csdev)
> > > {
> > > - int cpu, ret;
> > > + int ret;
> > > struct list_head *path = NULL;
> > > + struct coresight_path *cspath = NULL;
> > > + struct coresight_path *cspath_next = NULL;
> > > + struct coresight_device *src_csdev = NULL;
> > > mutex_lock(&coresight_mutex);
> > > @@ -1180,20 +1194,18 @@ 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;
> > > + list_for_each_entry_safe(cspath, cspath_next, &cs_active_paths, link) {
> > > + src_csdev = coresight_get_source(cspath->path);
> > > + if (!src_csdev)
> > > + continue;
> > > + if (src_csdev == csdev) {
> > > + path = cspath->path;
> > > + list_del(&cspath->link);
> > > + kfree(cspath);
> > See my comment above - I agree that sources _not_ associated with a CPU should
> > be handled differently. CPU bound sources should be kept untouched.
> >
> > That is all the time I had for today, I will continue tomorrow.
> >
> > Thanks,
> > Mathieu
> >
> > > + }
> > > }
> > > + if (path == NULL)
> > > + goto out;
> > > coresight_disable_path(path);
> > > coresight_release_path(path);
> > > --
> > > 2.17.1
> > >
The patch removing the feature-sync-compare-and-swap feature detection
didn't remove the call to main_test_sync_compare_and_swap(), making the
'test-all' case fail an all the feature tests to be performed
individually:
$ cat /tmp/build/perf/feature/test-all.make.output
In file included from test-all.c:18:
test-libpython-version.c:5:10: error: #error
5 | #error
| ^~~~~
test-all.c: In function ‘main’:
test-all.c:203:9: error: implicit declaration of function ‘main_test_sync_compare_and_swap’ [-Werror=implicit-function-declaration]
203 | main_test_sync_compare_and_swap(argc, argv);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$
Fix it, now to figure out what is that test-libpython-version.c
problem...
Fixes: 60fa754b2a5a4e0c ("tools: Remove feature-sync-compare-and-swap feature detection")
Cc: Jiri Olsa <jolsa(a)redhat.com>
Cc: Leo Yan <leo.yan(a)linaro.org>
Cc: Mark Rutland <mark.rutland(a)arm.com>
Cc: Mathieu Poirier <mathieu.poirier(a)linaro.org>
Cc: Mike Leach <mike.leach(a)linaro.org>
Cc: Namhyung Kim <namhyung(a)kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme(a)redhat.com>
---
tools/build/feature/test-all.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index 9204395272912c13..0b243ce842be3383 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -200,7 +200,6 @@ int main(int argc, char *argv[])
main_test_timerfd();
main_test_stackprotector_all();
main_test_libdw_dwarf_unwind();
- main_test_sync_compare_and_swap(argc, argv);
main_test_zlib();
main_test_pthread_attr_setaffinity_np();
main_test_pthread_barrier();
--
2.31.1
1) API updated to allow dynamic load and unload of configurations and
features. Dependency management between loaded sets is added.
2) New configuration and feature sets can be added using a loadable module.
An example in /samples/coresight is provided to demonstrate this.
3) configfs can be used to activate a configuration which will then be used
when controlling tracing using sysfs.
Applies and tested on coresight/next - which is 5.15-rc1
Changes since v1:
a) Original set split to divide related changes into smaller sets.
Removed RFC flag.
b) Revised config activation for sysfs to simplify common function.
(patch 4).
c) Minor changes requested by Mathieu added.
Mike Leach (5):
coresight: syscfg: Update API to allow dynamic load and unload
coresight: syscfg: Update load API for config loadable modules
coresight: syscfg: Example CoreSight configuration loadable module
coresight: configfs: Allow configfs to activate configuration
Documentation: coresight: Update coresight configuration docs
.../trace/coresight/coresight-config.rst | 19 ++
MAINTAINERS | 1 +
.../coresight/coresight-cfg-preload.c | 9 +-
.../hwtracing/coresight/coresight-config.h | 9 +-
.../coresight/coresight-etm4x-core.c | 11 +-
.../coresight/coresight-syscfg-configfs.c | 87 +++++
.../coresight/coresight-syscfg-configfs.h | 4 +
.../hwtracing/coresight/coresight-syscfg.c | 315 ++++++++++++++++--
.../hwtracing/coresight/coresight-syscfg.h | 39 ++-
samples/Kconfig | 9 +
samples/Makefile | 1 +
samples/coresight/Makefile | 4 +
samples/coresight/coresight-cfg-sample.c | 73 ++++
13 files changed, 546 insertions(+), 35 deletions(-)
create mode 100644 samples/coresight/Makefile
create mode 100644 samples/coresight/coresight-cfg-sample.c
--
2.17.1
If a profiling program runs in a non-root PID namespace, if CoreSight
driver enables contextID tracing, it can lead to mismatching issue
between the context ID in hardware trace data and the allocated PID in
the non-root namespace.
CoreSight driver has tried to address this issue for the contextID
related interfaces under sysfs, but it misses other parts: it doesn't
prevent user to set VMID (virtual contextID) for kernel runs in EL2 with
VHE, and furthermore, it misses to handle the perf mode when the
profiling tool (e.g. perf) doesn't run in root PID namespace.
For this reason, this patch series is to correct contextID tracing for
non-root namespace.
Patch 01 is to use spinlock to protect reading virtual context ID
comparator.
Patch 02 corrects the virtual contextID tracing for non-root PID
namespace.
Patch 03/04 are used to fix the contextID tracing for perf mode.
I only verified this patch series on Juno board in the root PID
namespace and confirmed the patches don't introduce any regression for
root PID namespace.
Leo Yan (4):
coresight: etm4x: Add lock for reading virtual context ID comparator
coresight: etm4x: Don't use virtual contextID for non-root PID
namespace
coresight: etm4x: Don't trace contextID for non-root namespace in perf
mode
coresight: etm3x: Don't trace contextID for non-root namespace in perf
mode
.../coresight/coresight-etm3x-core.c | 4 +++
.../coresight/coresight-etm4x-core.c | 10 +++++--
.../coresight/coresight-etm4x-sysfs.c | 30 +++++++++++++++++++
3 files changed, 42 insertions(+), 2 deletions(-)
--
2.25.1