[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aC-nOmMADRlnqkP8@x1>
Date: Thu, 22 May 2025 19:37:46 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Gautam Menghani <gautam@...ux.ibm.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>,
Howard Chu <howardchu95@...il.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org, maddy@...ux.ibm.com
Subject: Re: [PATCH v3 4/7] perf python: Add support for perf_counts_values
to return counter data
On Thu, May 22, 2025 at 07:36:31PM -0300, Arnaldo Carvalho de Melo wrote:
> On Thu, May 22, 2025 at 03:32:44PM -0700, Ian Rogers wrote:
> > On Thu, May 22, 2025 at 3:20 PM Arnaldo Carvalho de Melo
> > <acme@...nel.org> wrote:
> > >
> > > On Mon, May 19, 2025 at 12:51:41PM -0700, Ian Rogers wrote:
> > > > From: Gautam Menghani <gautam@...ux.ibm.com>
> > > >
> > > > Add support for perf_counts_values struct to enable the python
> > > > bindings to read and return the counter data.
> > > >
> > > > Signed-off-by: Gautam Menghani <gautam@...ux.ibm.com>
> > > > ---
> > > > tools/perf/util/python.c | 92 +++++++++++++++++++++++++++++++++++++++-
> > > > 1 file changed, 91 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> > > > index ead3afd2d996..1cbddfe77c7c 100644
> > > > --- a/tools/perf/util/python.c
> > > > +++ b/tools/perf/util/python.c
> > > > @@ -626,6 +626,92 @@ static int pyrf_thread_map__setup_types(void)
> > > > return PyType_Ready(&pyrf_thread_map__type);
> > > > }
> > > >
> > > > +struct pyrf_counts_values {
> > > > + PyObject_HEAD
> > > > +
> > > > + struct perf_counts_values values;
> > > > +};
> > > > +
> > > > +static const char pyrf_counts_values__doc[] = PyDoc_STR("perf counts values object.");
> > > > +
> > > > +static void pyrf_counts_values__delete(struct pyrf_counts_values *pcounts_values)
> > > > +{
> > > > + Py_TYPE(pcounts_values)->tp_free((PyObject *)pcounts_values);
> > > > +}
> > > > +
> > > > +#define counts_values_member_def(member, ptype, help) \
> > > > + { #member, ptype, \
> > > > + offsetof(struct pyrf_counts_values, values.member), \
> > > > + 0, help }
> > > > +
> > > > +static PyMemberDef pyrf_counts_values_members[] = {
> > > > + counts_values_member_def(val, Py_T_ULONG, "Value of event"),
> > > > + counts_values_member_def(ena, Py_T_ULONG, "Time for which enabled"),
> > > > + counts_values_member_def(run, Py_T_ULONG, "Time for which running"),
> > > > + counts_values_member_def(id, Py_T_ULONG, "Unique ID for an event"),
> > > > + counts_values_member_def(lost, Py_T_ULONG, "Num of lost samples"),
> > > > + {NULL}
> > > > +};
> > >
> > > So the above is failing on a aarch64 debian (rpi5):
> > >
> > > acme@...pberrypi:~/git/perf-tools-next $ dpkg -S /usr/include/python3.11/structmember.h
> > > libpython3.11-dev:arm64: /usr/include/python3.11/structmember.h
> > > acme@...pberrypi:~/git/perf-tools-next $
> > >
> > > Where it only has:
> > >
> > > acme@...pberrypi:~/git/perf-tools-next $ grep -r Py_T_ULONG /usr/include/
> > > acme@...pberrypi:~/git/perf-tools-next $ grep -rw Py_T_ULONG /usr/include/
> > > acme@...pberrypi:~/git/perf-tools-next $ grep -rw T_ULONG /usr/include/
> > > /usr/include/python3.11/structmember.h:#define T_ULONG 12
> > > acme@...pberrypi:~/git/perf-tools-next $
> > >
> > > while on fedora 42 x86_64:
> > >
> > > ⬢ [acme@...lbx perf-tools-next]$ grep -rw Py_T_ULONG /usr/include/
> > > /usr/include/python3.13/descrobject.h:#define Py_T_ULONG 12
> > > /usr/include/python3.13/structmember.h:#define T_ULONG Py_T_ULONG
> > > ⬢ [acme@...lbx perf-tools-next]$
> > >
> > > So I'm making it use the T_ULONG and others as all the other PyMemberDef
> > > arrays in tools/perf/util/python.c, ok?
> >
> > The fix makes sense to me. Checking the documentation it seems
> > Py_T_ULONG is preferred:
> > https://docs.python.org/3/c-api/structures.html#member-types
> > perhaps we can add:
> > ```
> > #ifndef Py_T_ULONG
> > #define Py_T_ULONG T_ULONG
> > #endif
> > ```
> > so that we use the approach matching the documentation while fixing
> > the RaspberryPi issue.
>
> That can be done as a followup, as there are lots of preexisting usage
> for struct method definitions.
And there is one other issue:
LINK /tmp/build/perf/perf
GEN /tmp/build/perf/python/perf.cpython-36m-x86_64-linux-gnu.so
/git/perf-6.15.0-rc7/tools/perf/util/python.c:653:7: error: missing field 'type' initializer [-Werror,-Wmissing-field-initializers]
653 | {NULL}
| ^
/git/perf-6.15.0-rc7/tools/perf/util/python.c:695:7: error: missing field 'get' initializer [-Werror,-Wmissing-field-initializers]
695 | {NULL}
| ^
2 errors generated.
error: command 'clang' failed with exit status 1
cp: cannot stat '/tmp/build/perf/python_ext_build/lib/perf*.so': No such file or directory
I'll look at this after dinner.
- Arnaldo
Powered by blists - more mailing lists