[PATCH 19/19] perf: cs-etm: Set watermark for AUX trace

Anshuman Khandual anshuman.khandual at arm.com
Tue Dec 9 18:22:51 PST 2025



On 09/12/25 8:24 PM, James Clark wrote:
> 
> 
> On 05/12/2025 4:48 am, Anshuman Khandual wrote:
>> On 01/12/25 4:52 PM, Leo Yan wrote:
>>> The default watermark is half of the total buffer size. In many cases,
>>> the tool can not be notified with sufficient free space, especially when
>>> profiling with small AUX buffer (e.g., 64KiB).
>>
>> Could not smaller AUX buffer be prevented for TRBE instead ?
>>
> 
> It's not really about the size of the buffer but where the wakeup points are. With only two wakeup points (middle and end) once you pass the first one you are immediately into the last chance end section.
> 
> Now the driver is writing into the end section, but Perf is still reading from the first one. Once the end one fills up, you end up with no space left without Perf having a chance to say it's finished reading.

Understood.

> 
> To guarantee free space, there needs to be at least one additional section as a buffer zone. Ideally we'd set the wakeup point at thirds so there were fewer wakeups and still have one free section, but it might not always divide by 3, so 4 is also fine.
> 
> The commit message could probably explain it a bit better though.

Agreed, the commit message should explain this problem in detail. Otherwise it appeared
as if the buffer sizing alone is impacting the perf records collection.

> 
> The reason this is different now is because we want to be able to enable wrap mode as much as possible. If you imagine the scenario where a half way watermark is hit, you can't enable wrap mode without wrapping into Perf's part of the buffer (the beginning) as it's all that's left after the second half.

Got it.

> 
>>>> Setting watermark to quarter of the buffer to notifies the tool to read
>>> data earlier and prevents the data loss.
>>>
>>> Signed-off-by: Leo Yan <leo.yan at arm.com>
>>> ---
>>>   tools/perf/arch/arm/util/cs-etm.c | 7 +++++++
>>>   1 file changed, 7 insertions(+)
>>>
>>> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
>>> index ea891d12f8f40beebf8dee1d3db71cad701f5666..649b8b0d0f92b4af45fb97db9da3c5ccf24a978b 100644
>>> --- a/tools/perf/arch/arm/util/cs-etm.c
>>> +++ b/tools/perf/arch/arm/util/cs-etm.c
>>> @@ -424,6 +424,13 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
>>>           pr_debug2("%s snapshot size: %zu\n", CORESIGHT_ETM_PMU_NAME,
>>>                 opts->auxtrace_snapshot_size);
>>>   +    if (!opts->auxtrace_snapshot_mode && !opts->auxtrace_sample_mode) {
>>> +        size_t aw = opts->auxtrace_mmap_pages * (size_t)page_size / 4;
>>> +        u32 aux_watermark = aw > UINT_MAX ? UINT_MAX : aw;
>>> +
>>> +        cs_etm_evsel->core.attr.aux_watermark = aux_watermark;
>>> +    }
>>> +
>>>       /*
>>>        * To obtain the auxtrace buffer file descriptor, the auxtrace
>>>        * event must come first.
>>>
>>
> 




More information about the linux-arm-kernel mailing list