On Tue, Jul 23, 2024 at 05:05:09PM +0100, Leo Yan wrote:
> On 7/23/2024 2:28 PM, James Clark wrote:
> >
> > The linked commit moved the early return on the first sample to before
> > the verbose log, so move the log earlier too. Now the first sample is
> > also logged and not skipped.
> >
> > Fixes: 2d98dbb4c9c5 ("perf scripts python arm-cs-trace-disasm.py: Do not ignore disam first sample")
> > Signed-off-by: James Clark <james.clark(a)linaro.org>
>
> Reviewed-by: Leo Yan <leo.yan(a)arm.com>
Thanks, applied to tmp.perf-tools-next,
- Arnaldo
> > ---
> > tools/perf/scripts/python/arm-cs-trace-disasm.py | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> > index d973c2baed1c..7aff02d84ffb 100755
> > --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
> > +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> > @@ -192,17 +192,16 @@ def process_event(param_dict):
> > ip = sample["ip"]
> > addr = sample["addr"]
> >
> > + if (options.verbose == True):
> > + print("Event type: %s" % name)
> > + print_sample(sample)
> > +
> > # Initialize CPU data if it's empty, and directly return back
> > # if this is the first tracing event for this CPU.
> > if (cpu_data.get(str(cpu) + 'addr') == None):
> > cpu_data[str(cpu) + 'addr'] = addr
> > return
> >
> > -
> > - if (options.verbose == True):
> > - print("Event type: %s" % name)
> > - print_sample(sample)
> > -
> > # If cannot find dso so cannot dump assembler, bail out
> > if (dso == '[unknown]'):
> > return
> > --
> > 2.34.1
> >
I noticed this when looking into Ganapat's fix to arm-cs-trace-disasm.py.
I assumed that seeing this in the output was a bug and went to
investigate why it happened in some cases and not others.
It turned out to not actually be a bug, but I think it doesn't look right.
In the end this change doesn't really accomplish anything and I'm not
sure if it's worth putting it in or not?
Maybe it will save someone doing the same thing as me, or maybe it will
actually break something if someones script is looking for 0xdeadbeef?
James Clark (1):
perf cs-etm: Output 0 instead of 0xdeadbeef when exception packets are
flushed
tools/perf/util/cs-etm.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--
2.34.1
On 24/07/2024 4:00 pm, Leo Yan wrote:
> On 7/24/2024 3:33 PM, James Clark wrote:
>>
>> The example shows the vmlinux path being given to the script, but this
>> only works when running on the target. If the script is run off the
>> target, then confusingly the vmlinux argument also needs to be given to
>> Perf as well.
>>
>> Without going into too much detail in the example about when it is or
>> isn't required, just include it. It doesn't do any harm even when
>> running on the target. Now the example command works in both places.
>>
>> Signed-off-by: James Clark <james.clark(a)linaro.org>
>
> The change makes senses to me. Just check a bit, does it need to add the same
> option for the command "only source line and symbols"?
>
> Thanks,
> Leo
>
I assumed that because that one didn't have vmlinux at all then it's
just for userspace tracing. I think it's good to have an example without
vmlinux to show that it's not a strict requirement.
>> ---
>> tools/perf/scripts/python/arm-cs-trace-disasm.py | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
>> index 7aff02d84ffb..4aeb9b497f7a 100755
>> --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
>> +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
>> @@ -19,10 +19,10 @@ from perf_trace_context import perf_set_itrace_options, \
>> # Below are some example commands for using this script.
>> #
>> # Output disassembly with objdump:
>> -# perf script -s scripts/python/arm-cs-trace-disasm.py \
>> +# perf script -k path/to/vmlinux -s scripts/python/arm-cs-trace-disasm.py \
>> # -- -d objdump -k path/to/vmlinux
>> # Output disassembly with llvm-objdump:
>> -# perf script -s scripts/python/arm-cs-trace-disasm.py \
>> +# perf script -k path/to/vmlinux -s scripts/python/arm-cs-trace-disasm.py \
>> # -- -d llvm-objdump-11 -k path/to/vmlinux
>> # Output only source line and symbols:
>> # perf script -s scripts/python/arm-cs-trace-disasm.py
>> --
>> 2.34.1
>>
The example shows the vmlinux path being given to the script, but this
only works when running on the target. If the script is run off the
target, then confusingly the vmlinux argument also needs to be given to
Perf as well.
Without going into too much detail in the example about when it is or
isn't required, just include it. It doesn't do any harm even when
running on the target. Now the example command works in both places.
Signed-off-by: James Clark <james.clark(a)linaro.org>
---
tools/perf/scripts/python/arm-cs-trace-disasm.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
index 7aff02d84ffb..4aeb9b497f7a 100755
--- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
+++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
@@ -19,10 +19,10 @@ from perf_trace_context import perf_set_itrace_options, \
# Below are some example commands for using this script.
#
# Output disassembly with objdump:
-# perf script -s scripts/python/arm-cs-trace-disasm.py \
+# perf script -k path/to/vmlinux -s scripts/python/arm-cs-trace-disasm.py \
# -- -d objdump -k path/to/vmlinux
# Output disassembly with llvm-objdump:
-# perf script -s scripts/python/arm-cs-trace-disasm.py \
+# perf script -k path/to/vmlinux -s scripts/python/arm-cs-trace-disasm.py \
# -- -d llvm-objdump-11 -k path/to/vmlinux
# Output only source line and symbols:
# perf script -s scripts/python/arm-cs-trace-disasm.py
--
2.34.1
The linked commit moved the early return on the first sample to before
the verbose log, so move the log earlier too. Now the first sample is
also logged and not skipped.
Fixes: 2d98dbb4c9c5 ("perf scripts python arm-cs-trace-disasm.py: Do not ignore disam first sample")
Signed-off-by: James Clark <james.clark(a)linaro.org>
---
tools/perf/scripts/python/arm-cs-trace-disasm.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
index d973c2baed1c..7aff02d84ffb 100755
--- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
+++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
@@ -192,17 +192,16 @@ def process_event(param_dict):
ip = sample["ip"]
addr = sample["addr"]
+ if (options.verbose == True):
+ print("Event type: %s" % name)
+ print_sample(sample)
+
# Initialize CPU data if it's empty, and directly return back
# if this is the first tracing event for this CPU.
if (cpu_data.get(str(cpu) + 'addr') == None):
cpu_data[str(cpu) + 'addr'] = addr
return
-
- if (options.verbose == True):
- print("Event type: %s" % name)
- print_sample(sample)
-
# If cannot find dso so cannot dump assembler, bail out
if (dso == '[unknown]'):
return
--
2.34.1
On 22/07/2024 11:02 am, Ganapatrao Kulkarni wrote:
>
> Hi James,
>
> On 19-07-2024 08:09 pm, James Clark wrote:
>>
>>
>> On 19/07/2024 10:26 am, Ganapatrao Kulkarni wrote:
>>> To generate the instruction tracing, script uses 2 contiguous packets
>>> address range. If there a continuity brake due to discontiguous branch
>>> address, it is required to reset the tracing and start tracing with the
>>> new set of contiguous packets.
>>>
>>> Adding change to identify the break and complete the remaining tracing
>>> of current packets and restart tracing from new set of packets, if
>>> continuity is established.
>>>
>>
>> Hi Ganapatrao,
>>
>> Can you add a before and after example of what's changed to the commit
>> message? It wasn't immediately obvious to me if this is adding missing
>> output, or it was correcting the tail end of the output that was
>> previously wrong.
>
> It is adding tail end of the trace as well avoiding the segfault of the
> perf application. With out this change the perf segfaults with as below log
>
>
> ./perf script --script=python:./scripts/python/arm-cs-trace-disasm.py --
> -d objdump -k ../../vmlinux -v $* > dump
> objdump: error: the stop address should be after the start address
> Traceback (most recent call last):
> File "./scripts/python/arm-cs-trace-disasm.py", line 271, in
> process_event
> print_disam(dso_fname, dso_vm_start, start_addr, stop_addr)
> File "./scripts/python/arm-cs-trace-disasm.py", line 105, in print_disam
> for line in read_disam(dso_fname, dso_start, start_addr, stop_addr):
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "./scripts/python/arm-cs-trace-disasm.py", line 99, in read_disam
> disasm_output = check_output(disasm).decode('utf-8').split('\n')
> ^^^^^^^^^^^^^^^^^^^^
> File "/usr/lib64/python3.12/subprocess.py", line 466, in check_output
> return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/usr/lib64/python3.12/subprocess.py", line 571, in run
> raise CalledProcessError(retcode, process.args,
> subprocess.CalledProcessError: Command '['objdump', '-d', '-z',
> '--start-address=0xffff80008125b758',
> '--stop-address=0xffff80008125a934', '../../vmlinux']' returned non-zero
> exit status 1.
> Fatal Python error: handler_call_die: problem in Python trace event handler
> Python runtime state: initialized
>
> Current thread 0x0000ffffb05054e0 (most recent call first):
> <no Python frame>
>
> Extension modules: perf_trace_context, systemd._journal,
> systemd._reader, systemd.id128, report._py3report, _dbus_bindings,
> problem._py3abrt (total: 7)
> Aborted (core dumped)
>
>>
>>> Signed-off-by: Ganapatrao Kulkarni <gankulkarni(a)os.amperecomputing.com>
>>> ---
>>> tools/perf/scripts/python/arm-cs-trace-disasm.py | 10 ++++++++++
>>> 1 file changed, 10 insertions(+)
>>>
>>> diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py
>>> b/tools/perf/scripts/python/arm-cs-trace-disasm.py
>>> index d973c2baed1c..ad10cee2c35e 100755
>>> --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
>>> +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
>>> @@ -198,6 +198,10 @@ def process_event(param_dict):
>>> cpu_data[str(cpu) + 'addr'] = addr
>>> return
>>> + if (cpu_data.get(str(cpu) + 'ip') == None):
>>> + cpu_data[str(cpu) + 'ip'] = ip
>>> +
>>
>> Do you need to write into the global cpu_data here? Doesn't it get
>> overwritten after you load it back into 'prev_ip'
>
> No, the logic is same as holding the addr of previous packet.
> Saving the previous packet saved ip in to prev_ip before overwriting
> with the current packet.
It's not exactly the same logic as holding the addr of the previous
sample. For addr, we return on the first None, with your change we now
"pretend" that the second one is also the previous one:
if (cpu_data.get(str(cpu) + 'addr') == None):
cpu_data[str(cpu) + 'addr'] = addr
return <----------------------------sample 0 return
if (cpu_data.get(str(cpu) + 'ip') == None):
cpu_data[str(cpu) + 'ip'] = ip <---- sample 1 save but no return
Then for sample 1 'prev_ip' is actually now the 'current' IP:
prev_ip = cpu_data[str(cpu) + 'ip']
This means that prev_ip is sometimes the previous sample's IP only
sometimes (samples following 1), otherwise it's the current IP. Does
your fix actually require this bit? Because we already save the 'real'
previous one:
cpu_data[str(cpu) + 'ip'] = stop_addr
Also normally we save ip + 4 (stop_addr), where as you save ip. It's not
clear why there is no need to add the 4?
>>
>> prev_ip = cpu_data[str(cpu) + 'ip']
>>
>> ... then ...
>>
>> # Record for previous sample packet
>> cpu_data[str(cpu) + 'addr'] = addr
>> cpu_data[str(cpu) + 'ip'] = stop_addr
>>
>> Would a local variable not accomplish the same thing?
>
> No, We need global to hold the ip of previous packet.
>>
>>> + prev_ip = cpu_data[str(cpu) + 'ip']
>>> if (options.verbose == True):
>>> print("Event type: %s" % name)
>>> @@ -243,12 +247,18 @@ def process_event(param_dict):
>>> # Record for previous sample packet
>>> cpu_data[str(cpu) + 'addr'] = addr
>>> + cpu_data[str(cpu) + 'ip'] = stop_addr
>>> # Handle CS_ETM_TRACE_ON packet if start_addr=0 and stop_addr=4
>>> if (start_addr == 0 and stop_addr == 4):
>>> print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
>>> return
>>> + if (stop_addr < start_addr):
>>> + # Continuity of the Packets broken, set start_addr to previous
>>> + # packet ip to complete the remaining tracing of the address
>>> range.
After looking a bit more I'm also not sure why stop_addr < start_addr
signifies a discontinuity. What if the discontinuity ends up with
stop_addr > start_addr? There's no reason it can't jump forwards as well
as backwards.
Can you share the 3 samples from the --verbose output to the script that
cause the issue?
I see discontinuities as having the branch source (ip) set to 0 which is
what we do at the start:
Sample = { cpu: 0000 addr: 0x0000ffffb807adac phys_addr:
0x0000000000000000 ip: 0x0000000000000000 pid: 28388 }
Then the ending one has the branch target (addr) set to 0:
Sample = { cpu: 0000 addr: 0x0000000000000000 phys_addr:
0x0000000000000000 ip: 0x0000ffffb7eee168 pid: 28388 }
And it doesn't hit objdump because of the range check:
Start address 0x0 is out of range ...
So I don't see any missing disassembly or crashes for this.
>>> + start_addr = prev_ip
>>> +
>>> if (start_addr < int(dso_start) or start_addr > int(dso_end)):
>>> print("Start address 0x%x is out of range [ 0x%x .. 0x%x ]
>>> for dso %s" % (start_addr, int(dso_start), int(dso_end), dso))
>>> return
>
> Thanks,
> Ganapat
Some HW has static trace id which cannot be changed via
software programming. For this case, configure the trace id
in device tree with "arm,trace-id = <xxx>", and
call coresight_trace_id_get_system_id with the trace id value
in device probe function. The id will be reserved for the HW
all the time if the device is probed.
Changes since V2:
1. Change "trace-id" to "arm,trace-id".
2. Add trace id flag for getting preferred id or ODD id.
Changes since V1:
1. Add argument to coresight_trace_id_get_system_id for preferred id
instead of adding new function coresight_trace_id_reserve_system_id.
2. Add constraint to trace-id in dt-binding file.
Mao Jinlong (3):
dt-bindings: arm: Add arm,trace-id for coresight dummy source
coresight: Add support to get preferred id for system trace sources
coresight: dummy: Add reserve atid support for dummy source
.../sysfs-bus-coresight-devices-dummy-source | 15 +++++
.../arm/arm,coresight-dummy-source.yaml | 6 ++
drivers/hwtracing/coresight/coresight-dummy.c | 59 +++++++++++++++++--
.../hwtracing/coresight/coresight-platform.c | 25 ++++++++
drivers/hwtracing/coresight/coresight-stm.c | 2 +-
drivers/hwtracing/coresight/coresight-tpda.c | 2 +-
.../hwtracing/coresight/coresight-trace-id.c | 35 +++++++----
.../hwtracing/coresight/coresight-trace-id.h | 11 +++-
include/linux/coresight.h | 1 +
9 files changed, 137 insertions(+), 19 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-bus-coresight-devices-dummy-source
--
2.41.0
On 19/07/2024 10:26 am, Ganapatrao Kulkarni wrote:
> To generate the instruction tracing, script uses 2 contiguous packets
> address range. If there a continuity brake due to discontiguous branch
> address, it is required to reset the tracing and start tracing with the
> new set of contiguous packets.
>
> Adding change to identify the break and complete the remaining tracing
> of current packets and restart tracing from new set of packets, if
> continuity is established.
>
Hi Ganapatrao,
Can you add a before and after example of what's changed to the commit
message? It wasn't immediately obvious to me if this is adding missing
output, or it was correcting the tail end of the output that was
previously wrong.
> Signed-off-by: Ganapatrao Kulkarni <gankulkarni(a)os.amperecomputing.com>
> ---
> tools/perf/scripts/python/arm-cs-trace-disasm.py | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> index d973c2baed1c..ad10cee2c35e 100755
> --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
> +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> @@ -198,6 +198,10 @@ def process_event(param_dict):
> cpu_data[str(cpu) + 'addr'] = addr
> return
>
> + if (cpu_data.get(str(cpu) + 'ip') == None):
> + cpu_data[str(cpu) + 'ip'] = ip
> +
Do you need to write into the global cpu_data here? Doesn't it get
overwritten after you load it back into 'prev_ip'
prev_ip = cpu_data[str(cpu) + 'ip']
... then ...
# Record for previous sample packet
cpu_data[str(cpu) + 'addr'] = addr
cpu_data[str(cpu) + 'ip'] = stop_addr
Would a local variable not accomplish the same thing?
> + prev_ip = cpu_data[str(cpu) + 'ip']
>
> if (options.verbose == True):
> print("Event type: %s" % name)
> @@ -243,12 +247,18 @@ def process_event(param_dict):
>
> # Record for previous sample packet
> cpu_data[str(cpu) + 'addr'] = addr
> + cpu_data[str(cpu) + 'ip'] = stop_addr
>
> # Handle CS_ETM_TRACE_ON packet if start_addr=0 and stop_addr=4
> if (start_addr == 0 and stop_addr == 4):
> print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
> return
>
> + if (stop_addr < start_addr):
> + # Continuity of the Packets broken, set start_addr to previous
> + # packet ip to complete the remaining tracing of the address range.
> + start_addr = prev_ip
> +
> if (start_addr < int(dso_start) or start_addr > int(dso_end)):
> print("Start address 0x%x is out of range [ 0x%x .. 0x%x ] for dso %s" % (start_addr, int(dso_start), int(dso_end), dso))
> return