[PATCH v8 09/58] perf evlist: Add reference count

Namhyung Kim namhyung at kernel.org
Wed Apr 29 00:25:22 PDT 2026


On Tue, Apr 28, 2026 at 12:18:14AM -0700, Ian Rogers wrote:
> This a no-op for most of the perf tool. The reference count is set to
> 1 at allocation, the put will see the 1, decrement it and perform the
> delete. The purpose for adding the reference count is for the python
> code. Prior to this change the python code would clone evlists, but
> this has issues if events are opened, etc. This change adds a
> reference count for the evlists and a later change will add it to
> evsels. The combination is needed for the python code to operate
> correctly (not hit asserts in the evsel clone), but the changes are
> broken apart for the sake of smaller patches.

Can we keep the existing evlist__delete() code?  IIUC most parts of the
code don't need to worry about python.  Then do we really need to
convert them all?  Maybe we can convert only the relevant codes.

Also I think it's better to split evlist__put() conversion and python
code changes.

Thanks,
Namhyung

> 
> Assisted-by: Gemini:gemini-3.1-pro-preview
> Signed-off-by: Ian Rogers <irogers at google.com>
> ---
> v2: Added evlist__put to pyrf_evlist__init in case init is called more
>     than once.
> 
>     I double-checked trace__replay() and confirmed that trace->evlist
>     is not assigned to session->evlist in that function.
>     trace__replay creates a new session and uses its own evlist for
>     processing file events, leaving trace->evlist pointing to the
>     empty list created at startup. Therefore, the
>     evlist__put(trace->evlist) call in trace__exit() is safe and
>     correct to avoid leaking that empty list.
> 
> v7:
> - Added pyrf_evlist__new to zero-initialize pevlist->evlist to fix
>   crash on re-initialization.



More information about the linux-arm-kernel mailing list