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

From: Namhyung Kim <[email-masked]>
Date: Wed, 29 Apr 2026 00:25:22 -0700

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 <[email-masked]>
> ---
> 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.