From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B02F9347C7 for ; Thu, 31 Oct 2024 01:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339005; cv=none; b=Oia0f/VOBfi/CjkZKaVbJM63idfWvuouYUAiLsMP/9elPEtnaPK/Jqbx7upookao8ZABbTYCd6ZzcrxAiZxTldakVfur6kkxT61vhC50OXvjocUmuEWwvYRJ2XQh606VDgI6egBzjOzOFUYeDi5qtbhmTs9FSntClZnGmfXf2nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339005; c=relaxed/simple; bh=06rUym8mEKwnrNebRhLzrvBcLI6yg+52u2nqnHXOz4k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=K7pmQRb2d9nXHn1PRnAdeTjSSBE11PGLBp0wVQm37y/72R6z9bHGvuncNiNo+kdoQvX2N62pJxbT5jJw6UcYbGAnEXNk+9zriMhWELdQ9bFCxl2LaS9SmuVASiERXgb3eJzqO6vThPnm+kex7m7wxEnNZQ9BnvfRYn0OIN/ZeDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YhmocM1I; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YhmocM1I" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30b8fd4ca1so940466276.3 for ; Wed, 30 Oct 2024 18:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339001; x=1730943801; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=xl5YYT6/j2snqAzcSfRTiY37ktA1YE2VwqMAMMgNcVo=; b=YhmocM1IvSp8FhhefMS9WMqo4eZjg1daKzO9db/1eG2sQZiTr9mD8GdXXS2EwmtxbR 0AhhRwkaldWPibDX50YCIY4zVpab6+Ue2LxpuXq5hKeBxLF4zt/6enc0G1NbyxZ80d45 zCpIlaTbduotk1i4Wl3IY3Bbe0jtKsdw3ZEdrlao8sblKZyGLA4UCjknUCdnKDS4rt9H R1V1zx7LEQGjgMSzyGymYvc5ipfwvJqqSyw9Jqt44jXxKz320vvhxX1yYBkACH9pgFKp 9XD6O+asqWuBtxVu0cfyWWxRwqBGqRm/59EIlkZ09He/p36OjS7eDIipe9zq8bH70zEJ z74w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339001; x=1730943801; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xl5YYT6/j2snqAzcSfRTiY37ktA1YE2VwqMAMMgNcVo=; b=GvSaZYAX+3eJP/EUNeFzzyjhJ4BKZWBenxRSYHNcHXxH7RrBpv5eFuWnKHyhjyAXB0 wtNl+6qlbhHAcy2b3PPsf0u/AKY5qh+Gq8V4VS+LtsoUQqUPKMlC53k5cjtwShyU3yPZ w/RpM8o+fGipD32NlGjwFBstH9zwuEJN8Bm1uOnax0fFV13lJfXOqRsMSSJBvSDLYa96 1bXa9jx446GQ0CSCW4Sh9H8S/VMFxv+goFIajfpowTa1favqIccJ08GGrb9PWpL7TryA VONLDr3nNwIM0nvtYUi84ltf0kpjCLn0yfl6XR20ZHqvhTTi6zCa89JwmSB0LjgJKzQl b6bA== X-Forwarded-Encrypted: i=1; AJvYcCUxnghN0j1RCWwrppWZPoj/8bsoPhUfBS8tgGOvPg87yLZrJNiwYznglQUnxANFk8X06xRSPYCubBt+wG8=@vger.kernel.org X-Gm-Message-State: AOJu0YzzTqxJTEyHJ+/05cPwhM+oFWIXPfObP06+edqaA4BOf3hhRg+B VWs2CseZwLoqbDGp0xTGHVhQGgzG8kpvCcZoItWHJ/IXVTHG6cWhihIqeRR5P+G8IlNd1XFuNwl 8qRov1Q== X-Google-Smtp-Source: AGHT+IHxzI6JqY6DFUSa9U4BkLnn0HNVUkF4luAUVdlH1zuSlXQhCe3P1dIsbxWxok9ixWm1zO9ItoBBiKMt X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:9012:0:b0:e2e:44ae:111a with SMTP id 3f1490d57ef6-e30cf4c9ffamr3762276.8.1730339000801; Wed, 30 Oct 2024 18:43:20 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:32 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 01/21] perf python: Remove python 2 scripting support From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Python2 was deprecated 4 years ago, remove support and workarounds. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- .../scripts/python/Perf-Trace-Util/Context.c | 18 ----- tools/perf/util/python.c | 73 +++---------------- .../scripting-engines/trace-event-python.c | 63 +--------------- 3 files changed, 15 insertions(+), 139 deletions(-) diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index 01f54d6724a5..d742daaa5d5a 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -24,16 +24,6 @@ #include "../../../util/srcline.h" #include "../../../util/srccode.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyCapsule_GetPointer(arg1, arg2) \ - PyCObject_AsVoidPtr(arg1) -#define _PyBytes_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyUnicode_AsUTF8(arg) \ - PyString_AsString(arg) - -PyMODINIT_FUNC initperf_trace_context(void); -#else #define _PyCapsule_GetPointer(arg1, arg2) \ PyCapsule_GetPointer((arg1), (arg2)) #define _PyBytes_FromStringAndSize(arg1, arg2) \ @@ -42,7 +32,6 @@ PyMODINIT_FUNC initperf_trace_context(void); PyUnicode_AsUTF8(arg) =20 PyMODINIT_FUNC PyInit_perf_trace_context(void); -#endif =20 static struct scripting_context *get_args(PyObject *args, const char *name= , PyObject **arg2) { @@ -213,12 +202,6 @@ static PyMethodDef ContextMethods[] =3D { { NULL, NULL, 0, NULL} }; =20 -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf_trace_context(void) -{ - (void) Py_InitModule("perf_trace_context", ContextMethods); -} -#else PyMODINIT_FUNC PyInit_perf_trace_context(void) { static struct PyModuleDef moduledef =3D { @@ -240,4 +223,3 @@ PyMODINIT_FUNC PyInit_perf_trace_context(void) =20 return mod; } -#endif diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 31a223eaf8e6..02279ab4967c 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -25,40 +25,14 @@ #include #include "../builtin.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyUnicode_FromString(arg) \ - PyString_FromString(arg) -#define _PyUnicode_AsString(arg) \ - PyString_AsString(arg) -#define _PyUnicode_FromFormat(...) \ - PyString_FromFormat(__VA_ARGS__) -#define _PyLong_FromLong(arg) \ - PyInt_FromLong(arg) - -#else - #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) #define _PyUnicode_FromFormat(...) \ PyUnicode_FromFormat(__VA_ARGS__) #define _PyLong_FromLong(arg) \ PyLong_FromLong(arg) -#endif =20 -#ifndef Py_TYPE -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#endif - -/* Define PyVarObject_HEAD_INIT for python 2.5 */ -#ifndef PyVarObject_HEAD_INIT -# define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, -#endif - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf(void); -#else PyMODINIT_FUNC PyInit_perf(void); -#endif =20 #define member_def(type, member, ptype, help) \ { #member, ptype, \ @@ -116,7 +90,7 @@ static PyObject *pyrf_mmap_event__repr(struct pyrf_event= *pevent) pevent->event.mmap.pgoff, pevent->event.mmap.filename) < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -147,7 +121,7 @@ static PyMemberDef pyrf_task_event__members[] =3D { =20 static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) { - return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " + return PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " "ptid: %u, time: %" PRI_lu64 "}", pevent->event.header.type =3D=3D PERF_RECORD_FORK ? "fork" : "exit", pevent->event.fork.pid, @@ -180,7 +154,7 @@ static PyMemberDef pyrf_comm_event__members[] =3D { =20 static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent) { - return _PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", + return PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", pevent->event.comm.pid, pevent->event.comm.tid, pevent->event.comm.comm); @@ -211,7 +185,7 @@ static PyObject *pyrf_throttle_event__repr(struct pyrf_= event *pevent) { struct perf_record_throttle *te =3D (struct perf_record_throttle *)(&peve= nt->event.header + 1); =20 - return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id= : %" PRI_lu64 + return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id:= %" PRI_lu64 ", stream_id: %" PRI_lu64 " }", pevent->event.header.type =3D=3D PERF_RECORD_THROTTLE ? "" : "un", te->time, te->id, te->stream_id); @@ -246,7 +220,7 @@ static PyObject *pyrf_lost_event__repr(struct pyrf_even= t *pevent) pevent->event.lost.id, pevent->event.lost.lost) < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -273,7 +247,7 @@ static PyMemberDef pyrf_read_event__members[] =3D { =20 static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent) { - return _PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", + return PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", pevent->event.read.pid, pevent->event.read.tid); /* @@ -308,7 +282,7 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_ev= ent *pevent) if (asprintf(&s, "{ type: sample }") < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -342,7 +316,7 @@ tracepoint_field(struct pyrf_event *pe, struct tep_form= at_field *field) } if (field->flags & TEP_FIELD_IS_STRING && is_printable_array(data + offset, len)) { - ret =3D _PyUnicode_FromString((char *)data + offset); + ret =3D PyUnicode_FromString((char *)data + offset); } else { ret =3D PyByteArray_FromStringAndSize((const char *) data + offset, len= ); field->flags &=3D ~TEP_FIELD_IS_STRING; @@ -431,7 +405,7 @@ static PyObject *pyrf_context_switch_event__repr(struct= pyrf_event *pevent) !!(pevent->event.header.misc & PERF_RECORD_MISC_SWITCH_OUT)) < 0) { ret =3D PyErr_NoMemory(); } else { - ret =3D _PyUnicode_FromString(s); + ret =3D PyUnicode_FromString(s); free(s); } return ret; @@ -917,17 +891,8 @@ static PyObject *pyrf_evlist__get_pollfd(struct pyrf_e= vlist *pevlist, =20 for (i =3D 0; i < evlist->core.pollfd.nr; ++i) { PyObject *file; -#if PY_MAJOR_VERSION < 3 - FILE *fp =3D fdopen(evlist->core.pollfd.entries[i].fd, "r"); - - if (fp =3D=3D NULL) - goto free_list; - - file =3D PyFile_FromFile(fp, "perf", "r", NULL); -#else file =3D PyFile_FromFd(evlist->core.pollfd.entries[i].fd, "perf", "r", -= 1, NULL, NULL, NULL, 0); -#endif if (file =3D=3D NULL) goto free_list; =20 @@ -1233,9 +1198,9 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel *= pevsel, =20 tp_format =3D trace_event__tp_format(sys, name); if (IS_ERR(tp_format)) - return _PyLong_FromLong(-1); + return PyLong_FromLong(-1); =20 - return _PyLong_FromLong(tp_format->id); + return PyLong_FromLong(tp_format->id); #endif // HAVE_LIBTRACEEVENT } =20 @@ -1249,18 +1214,11 @@ static PyMethodDef perf__methods[] =3D { { .ml_name =3D NULL, } }; =20 -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initperf(void) -#else PyMODINIT_FUNC PyInit_perf(void) -#endif { PyObject *obj; int i; PyObject *dict; -#if PY_MAJOR_VERSION < 3 - PyObject *module =3D Py_InitModule("perf", perf__methods); -#else static struct PyModuleDef moduledef =3D { PyModuleDef_HEAD_INIT, "perf", /* m_name */ @@ -1273,7 +1231,6 @@ PyMODINIT_FUNC PyInit_perf(void) NULL, /* m_free */ }; PyObject *module =3D PyModule_Create(&moduledef); -#endif =20 if (module =3D=3D NULL || pyrf_event__setup_types() < 0 || @@ -1281,11 +1238,7 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || pyrf_cpu_map__setup_types() < 0) -#if PY_MAJOR_VERSION < 3 - return; -#else return module; -#endif =20 /* The page_size is placed in util object. */ page_size =3D sysconf(_SC_PAGE_SIZE); @@ -1334,7 +1287,7 @@ PyMODINIT_FUNC PyInit_perf(void) goto error; =20 for (i =3D 0; perf__constants[i].name !=3D NULL; i++) { - obj =3D _PyLong_FromLong(perf__constants[i].value); + obj =3D PyLong_FromLong(perf__constants[i].value); if (obj =3D=3D NULL) goto error; PyDict_SetItemString(dict, perf__constants[i].name, obj); @@ -1344,9 +1297,7 @@ PyMODINIT_FUNC PyInit_perf(void) error: if (PyErr_Occurred()) PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); -#if PY_MAJOR_VERSION >=3D 3 return module; -#endif } =20 =20 diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index d7183134b669..f1d461d47d73 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -58,22 +58,6 @@ #include "mem-events.h" #include "util/perf_regs.h" =20 -#if PY_MAJOR_VERSION < 3 -#define _PyUnicode_FromString(arg) \ - PyString_FromString(arg) -#define _PyUnicode_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyBytes_FromStringAndSize(arg1, arg2) \ - PyString_FromStringAndSize((arg1), (arg2)) -#define _PyLong_FromLong(arg) \ - PyInt_FromLong(arg) -#define _PyLong_AsLong(arg) \ - PyInt_AsLong(arg) -#define _PyCapsule_New(arg1, arg2, arg3) \ - PyCObject_FromVoidPtr((arg1), (arg2)) - -PyMODINIT_FUNC initperf_trace_context(void); -#else #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) #define _PyUnicode_FromStringAndSize(arg1, arg2) \ @@ -88,7 +72,6 @@ PyMODINIT_FUNC initperf_trace_context(void); PyCapsule_New((arg1), (arg2), (arg3)) =20 PyMODINIT_FUNC PyInit_perf_trace_context(void); -#endif =20 #ifdef HAVE_LIBTRACEEVENT #define TRACE_EVENT_TYPE_MAX \ @@ -181,17 +164,7 @@ static int get_argument_count(PyObject *handler) { int arg_count =3D 0; =20 - /* - * The attribute for the code object is func_code in Python 2, - * whereas it is __code__ in Python 3.0+. - */ - PyObject *code_obj =3D PyObject_GetAttrString(handler, - "func_code"); - if (PyErr_Occurred()) { - PyErr_Clear(); - code_obj =3D PyObject_GetAttrString(handler, - "__code__"); - } + PyObject *code_obj =3D code_obj =3D PyObject_GetAttrString(handler, "__co= de__"); PyErr_Clear(); if (code_obj) { PyObject *arg_count_obj =3D PyObject_GetAttrString(code_obj, @@ -1899,12 +1872,6 @@ static void set_table_handlers(struct tables *tables) tables->synth_handler =3D get_handler("synth_data"); } =20 -#if PY_MAJOR_VERSION < 3 -static void _free_command_line(const char **command_line, int num) -{ - free(command_line); -} -#else static void _free_command_line(wchar_t **command_line, int num) { int i; @@ -1912,7 +1879,6 @@ static void _free_command_line(wchar_t **command_line= , int num) PyMem_RawFree(command_line[i]); free(command_line); } -#endif =20 =20 /* @@ -1922,30 +1888,12 @@ static int python_start_script(const char *script, = int argc, const char **argv, struct perf_session *session) { struct tables *tables =3D &tables_global; -#if PY_MAJOR_VERSION < 3 - const char **command_line; -#else wchar_t **command_line; -#endif - /* - * Use a non-const name variable to cope with python 2.6's - * PyImport_AppendInittab prototype - */ - char buf[PATH_MAX], name[19] =3D "perf_trace_context"; + char buf[PATH_MAX]; int i, err =3D 0; FILE *fp; =20 scripting_context->session =3D session; -#if PY_MAJOR_VERSION < 3 - command_line =3D malloc((argc + 1) * sizeof(const char *)); - if (!command_line) - return -1; - - command_line[0] =3D script; - for (i =3D 1; i < argc + 1; i++) - command_line[i] =3D argv[i - 1]; - PyImport_AppendInittab(name, initperf_trace_context); -#else command_line =3D malloc((argc + 1) * sizeof(wchar_t *)); if (!command_line) return -1; @@ -1953,15 +1901,10 @@ static int python_start_script(const char *script, = int argc, const char **argv, command_line[0] =3D Py_DecodeLocale(script, NULL); for (i =3D 1; i < argc + 1; i++) command_line[i] =3D Py_DecodeLocale(argv[i - 1], NULL); - PyImport_AppendInittab(name, PyInit_perf_trace_context); -#endif + PyImport_AppendInittab("perf_trace_context", PyInit_perf_trace_context); Py_Initialize(); =20 -#if PY_MAJOR_VERSION < 3 - PySys_SetArgv(argc + 1, (char **)command_line); -#else PySys_SetArgv(argc + 1, command_line); -#endif =20 fp =3D fopen(script, "r"); if (!fp) { --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 112C18121F for ; Thu, 31 Oct 2024 01:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339006; cv=none; b=us/1lmMIG+JNYj9VE+xY6C/YCvGGzDQGeItOoBvafj6Pegah3bCKJcfYKCoMfsgYqT+jUSAB9cenvsIEGqwKYo/jlECDaeZniEZV+VcyNf4sEGS9tx4KK7K6OtOOR807aZWmAHA90MWNSFoZJ+Oi1i57bHvWyXAVN+VPogoKKy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339006; c=relaxed/simple; bh=CiUzxYw0RBvkytit97TqdNjM6aeeFRoA/HnhpHqF9To=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LK2+W9yeKFpZIvppxVR+R8pQykCSIIKeWELvLVpGWCoOFV8TPyaxo21ZpCtwJkN0kNvbctVUlUEPJacoUuyMWfnjy37OHXZrAbasanAAqWlfg+GC9Ltp2zQbPoMgWJu0y6ZW4oRucJ/Ct9MDhL2vafzTILnKyKtr9WaciXXYTAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=b1ITmQph; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="b1ITmQph" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e28ef71f0d8so1016477276.0 for ; Wed, 30 Oct 2024 18:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339003; x=1730943803; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=H603DVgWa6efETS0jocUXZJdUuhFvKOBL+70ertaUeY=; b=b1ITmQphzyo0NWIYiHMCP3Zzg/1nJ8qD1fb81tb8b4t2KoeWdPsMEKowhR8mum6PBs 3yRaBLrqK5QP13nU1j0D+1joT/HHDdtYIJQvw78HlEjjKKByde5tv2vJwhX4W4+X5fU4 HNu+NeHhOXjOFoBnepnoHJAHu1nhLuOKOTVzxBIWV9jkJ2MVZeDNyaN7LDNwHSO/QB2L wRmHuvu9igjs60vCM//+0UE6OdItA8gLHLnwWsCULrwVo+1nmVD9b/WHHmqyQwqQa+rj sOZKmglIBv+YThtKU4gUHmc26TrgR6PH8Gq9sBUvJc+fBWwVFyKYbyKxYf32QwopeOuc OWbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339003; x=1730943803; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H603DVgWa6efETS0jocUXZJdUuhFvKOBL+70ertaUeY=; b=lijn1zfXo65NtDND+jsV9Ka8QvxGKL4SHJMS2CpzPXXx4cktAyBkt4fb+mXcskXPiU PSASGPr4oiQw4i7LbwvcrOnx4iDMMgJ8/gpZ8cz2FjGJ4xadi/0AXJZ6szQwLvOgxk6v Mm3OPiX/7WHN4YfCv5Dsnl9CXKdkycsTKDhXdBJLpVGk2URC7PnOuHI1yU+JlbftX8dg 1GZ7NMcIEdjtjhQ2QAdDhhTHS2acDGmMWdaibCkvElxYmPLo41qv74KyjtruY3E+IgYr oK1BHD6Qs9NF5ZNpKa4hS4AkOtl2E3u1sjnoHIg7+iZ2/H18nH38SYpwaabflr/p2HPx cnFg== X-Forwarded-Encrypted: i=1; AJvYcCXubmdCTs5oboFDxUbxkX3mA5PUfZomEi+RnnIRrMCzvC8xCobojCmCujkilyHYBocUV9nXDWJ8gJDjs3U=@vger.kernel.org X-Gm-Message-State: AOJu0YyAAQLErOqm3zj7YSp1ss5jqvgedmap27n6eRYmtrNpx4M7CtSm YL/99vYlUVd1HTyEwOGSGBJW6mlfCFoDDMjJJ4hyRUxy7fEyRwBwFo475LfngtwZcxnoJ25xUmc iouvs4g== X-Google-Smtp-Source: AGHT+IERr2h5rI0Yp0296WNZHggnGMCv8xggBo62YaI3NX5rYRlIStfpNu+t5hy24D65mXLs/Z42vu/beuTi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a5b:2ca:0:b0:e30:bf92:7a64 with SMTP id 3f1490d57ef6-e30bf927b96mr5303276.2.1730339002925; Wed, 30 Oct 2024 18:43:22 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:33 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 02/21] perf python: Constify variables and parameters From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Opportunistically constify variables and parameters when possible. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 02279ab4967c..13dad27169a0 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -62,7 +62,7 @@ struct pyrf_event { sample_member_def(sample_period, period, T_ULONGLONG, "event period"), \ sample_member_def(sample_cpu, cpu, T_UINT, "event cpu"), =20 -static char pyrf_mmap_event__doc[] =3D PyDoc_STR("perf mmap event object."= ); +static const char pyrf_mmap_event__doc[] =3D PyDoc_STR("perf mmap event ob= ject."); =20 static PyMemberDef pyrf_mmap_event__members[] =3D { sample_members @@ -77,7 +77,7 @@ static PyMemberDef pyrf_mmap_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_mmap_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_mmap_event__repr(const struct pyrf_event *pevent) { PyObject *ret; char *s; @@ -106,7 +106,7 @@ static PyTypeObject pyrf_mmap_event__type =3D { .tp_repr =3D (reprfunc)pyrf_mmap_event__repr, }; =20 -static char pyrf_task_event__doc[] =3D PyDoc_STR("perf task (fork/exit) ev= ent object."); +static const char pyrf_task_event__doc[] =3D PyDoc_STR("perf task (fork/ex= it) event object."); =20 static PyMemberDef pyrf_task_event__members[] =3D { sample_members @@ -119,7 +119,7 @@ static PyMemberDef pyrf_task_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_task_event__repr(const struct pyrf_event *pevent) { return PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " "ptid: %u, time: %" PRI_lu64 "}", @@ -141,7 +141,7 @@ static PyTypeObject pyrf_task_event__type =3D { .tp_repr =3D (reprfunc)pyrf_task_event__repr, }; =20 -static char pyrf_comm_event__doc[] =3D PyDoc_STR("perf comm event object."= ); +static const char pyrf_comm_event__doc[] =3D PyDoc_STR("perf comm event ob= ject."); =20 static PyMemberDef pyrf_comm_event__members[] =3D { sample_members @@ -152,7 +152,7 @@ static PyMemberDef pyrf_comm_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_comm_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_comm_event__repr(const struct pyrf_event *pevent) { return PyUnicode_FromFormat("{ type: comm, pid: %u, tid: %u, comm: %s }", pevent->event.comm.pid, @@ -170,7 +170,7 @@ static PyTypeObject pyrf_comm_event__type =3D { .tp_repr =3D (reprfunc)pyrf_comm_event__repr, }; =20 -static char pyrf_throttle_event__doc[] =3D PyDoc_STR("perf throttle event = object."); +static const char pyrf_throttle_event__doc[] =3D PyDoc_STR("perf throttle = event object."); =20 static PyMemberDef pyrf_throttle_event__members[] =3D { sample_members @@ -181,9 +181,10 @@ static PyMemberDef pyrf_throttle_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_throttle_event__repr(const struct pyrf_event *pevent) { - struct perf_record_throttle *te =3D (struct perf_record_throttle *)(&peve= nt->event.header + 1); + const struct perf_record_throttle *te =3D (const struct perf_record_throt= tle *) + (&pevent->event.header + 1); =20 return PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id:= %" PRI_lu64 ", stream_id: %" PRI_lu64 " }", @@ -201,7 +202,7 @@ static PyTypeObject pyrf_throttle_event__type =3D { .tp_repr =3D (reprfunc)pyrf_throttle_event__repr, }; =20 -static char pyrf_lost_event__doc[] =3D PyDoc_STR("perf lost event object."= ); +static const char pyrf_lost_event__doc[] =3D PyDoc_STR("perf lost event ob= ject."); =20 static PyMemberDef pyrf_lost_event__members[] =3D { sample_members @@ -210,7 +211,7 @@ static PyMemberDef pyrf_lost_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_lost_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_lost_event__repr(const struct pyrf_event *pevent) { PyObject *ret; char *s; @@ -236,7 +237,7 @@ static PyTypeObject pyrf_lost_event__type =3D { .tp_repr =3D (reprfunc)pyrf_lost_event__repr, }; =20 -static char pyrf_read_event__doc[] =3D PyDoc_STR("perf read event object."= ); +static const char pyrf_read_event__doc[] =3D PyDoc_STR("perf read event ob= ject."); =20 static PyMemberDef pyrf_read_event__members[] =3D { sample_members @@ -245,7 +246,7 @@ static PyMemberDef pyrf_read_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_read_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_read_event__repr(const struct pyrf_event *pevent) { return PyUnicode_FromFormat("{ type: read, pid: %u, tid: %u }", pevent->event.read.pid, @@ -266,7 +267,7 @@ static PyTypeObject pyrf_read_event__type =3D { .tp_repr =3D (reprfunc)pyrf_read_event__repr, }; =20 -static char pyrf_sample_event__doc[] =3D PyDoc_STR("perf sample event obje= ct."); +static const char pyrf_sample_event__doc[] =3D PyDoc_STR("perf sample even= t object."); =20 static PyMemberDef pyrf_sample_event__members[] =3D { sample_members @@ -274,7 +275,7 @@ static PyMemberDef pyrf_sample_event__members[] =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_sample_event__repr(const struct pyrf_event *pevent) { PyObject *ret; char *s; @@ -289,13 +290,13 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_= event *pevent) } =20 #ifdef HAVE_LIBTRACEEVENT -static bool is_tracepoint(struct pyrf_event *pevent) +static bool is_tracepoint(const struct pyrf_event *pevent) { return pevent->evsel->core.attr.type =3D=3D PERF_TYPE_TRACEPOINT; } =20 static PyObject* -tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field) +tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *fie= ld) { struct tep_handle *pevent =3D field->event->tep; void *data =3D pe->sample.raw_data; @@ -384,7 +385,7 @@ static PyTypeObject pyrf_sample_event__type =3D { .tp_getattro =3D (getattrofunc) pyrf_sample_event__getattro, }; =20 -static char pyrf_context_switch_event__doc[] =3D PyDoc_STR("perf context_s= witch event object."); +static const char pyrf_context_switch_event__doc[] =3D PyDoc_STR("perf con= text_switch event object."); =20 static PyMemberDef pyrf_context_switch_event__members[] =3D { sample_members @@ -394,7 +395,7 @@ static PyMemberDef pyrf_context_switch_event__members[]= =3D { { .name =3D NULL, }, }; =20 -static PyObject *pyrf_context_switch_event__repr(struct pyrf_event *pevent) +static PyObject *pyrf_context_switch_event__repr(const struct pyrf_event *= pevent) { PyObject *ret; char *s; @@ -474,7 +475,7 @@ static PyTypeObject *pyrf_event__type[] =3D { [PERF_RECORD_SWITCH_CPU_WIDE] =3D &pyrf_context_switch_event__type, }; =20 -static PyObject *pyrf_event__new(union perf_event *event) +static PyObject *pyrf_event__new(const union perf_event *event) { struct pyrf_event *pevent; PyTypeObject *ptype; @@ -542,7 +543,7 @@ static PySequenceMethods pyrf_cpu_map__sequence_methods= =3D { .sq_item =3D pyrf_cpu_map__item, }; =20 -static char pyrf_cpu_map__doc[] =3D PyDoc_STR("cpu map object."); +static const char pyrf_cpu_map__doc[] =3D PyDoc_STR("cpu map object."); =20 static PyTypeObject pyrf_cpu_map__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -611,7 +612,7 @@ static PySequenceMethods pyrf_thread_map__sequence_meth= ods =3D { .sq_item =3D pyrf_thread_map__item, }; =20 -static char pyrf_thread_map__doc[] =3D PyDoc_STR("thread map object."); +static const char pyrf_thread_map__doc[] =3D PyDoc_STR("thread map object.= "); =20 static PyTypeObject pyrf_thread_map__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -795,7 +796,7 @@ static PyMethodDef pyrf_evsel__methods[] =3D { { .ml_name =3D NULL, } }; =20 -static char pyrf_evsel__doc[] =3D PyDoc_STR("perf event selector list obje= ct."); +static const char pyrf_evsel__doc[] =3D PyDoc_STR("perf event selector lis= t object."); =20 static PyTypeObject pyrf_evsel__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -1078,7 +1079,7 @@ static PySequenceMethods pyrf_evlist__sequence_method= s =3D { .sq_item =3D pyrf_evlist__item, }; =20 -static char pyrf_evlist__doc[] =3D PyDoc_STR("perf event selector list obj= ect."); +static const char pyrf_evlist__doc[] =3D PyDoc_STR("perf event selector li= st object."); =20 static PyTypeObject pyrf_evlist__type =3D { PyVarObject_HEAD_INIT(NULL, 0) @@ -1100,10 +1101,12 @@ static int pyrf_evlist__setup_types(void) =20 #define PERF_CONST(name) { #name, PERF_##name } =20 -static struct { +struct perf_constant { const char *name; int value; -} perf__constants[] =3D { +}; + +static const struct perf_constant perf__constants[] =3D { PERF_CONST(TYPE_HARDWARE), PERF_CONST(TYPE_SOFTWARE), PERF_CONST(TYPE_TRACEPOINT), --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAD6684D12 for ; Thu, 31 Oct 2024 01:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339008; cv=none; b=UhWJsqz7dv613M8kPyjiBlLTghB25UKf5LsH3GtDZPvR0wRdTU0aKDh0SagmMueJrPfTjAAf4zy4xLFnezTFF+F+qjtbsT99rZgmPDW/VLNVaw9JHetUpwV/XbZF3VXc86ckRfs/S8ybFP8VIN+Dy6wMA9AKZD7sA4KJmXSW/5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339008; c=relaxed/simple; bh=GYxmpcXArXMONJWsRe5WPl7DZqsyI1iL6F7x/lVFYsI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=l4spAPF6IDSHKrhfGhRuWf1Y+8KzXEDydhk/meJ22XxWt1LOJYej4WVGxOs68vR0j/7BSO5tP9Nh43RnLT8rvc+KAT9MbilW+TZsB8an/9UWNBaDxYlndR3sEtvOJj9+sBSnrroaBgbTAYITpca6ho1QQRXNf8WYg+0tWf4kkt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=i8dSVfJL; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i8dSVfJL" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3497c8eb0so6019147b3.0 for ; Wed, 30 Oct 2024 18:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339005; x=1730943805; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=HNJdU7+o4d1QH5mPoNKTab3DA0/sS4GdEQIezl8TuMU=; b=i8dSVfJLwAEC3Yc3iBSmdXJa2a1NKEQl0pe29oKpmV9UfR2G3iEHDnHTEfkiXW+Gp1 xECSB6NxeLVsNj1m4TG8XoSpFduYKvxNk0EvpSCSjAqWARTSRL2tV3IMCgN1NVa2duBc Th18HNhxGQhsehqllG+QCBu91ckdXLkxD8PgTpdARw6M/0svOHOyPTF+U+dLyzJbA/vr misp0UXr5z3s8qTBFS7lFf9xupKLKIlcBE4sEzS2DV+OACoBKJRae8V8VoF64Uxqz0wB R86ql7ANYS7OvRNNJK+HtSCFUJ3TqjkeB8SgDizXLBLhSkPJmVOI+p9y/PnxGDF2tUfv s4+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339005; x=1730943805; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HNJdU7+o4d1QH5mPoNKTab3DA0/sS4GdEQIezl8TuMU=; b=IXJ7hu42lJVe8gz4ulTJK/vCqpWWwCxKq3PDD//fTmApsxLL3P7HU+dCHAgHiA32wL teS14nA52Lf06Q5akVMBqDi7pbs286Ovwz5ZEMxePeFl3xS1TxjR+oaryETZlEZYFMRF Zqcg6sIl+FNMcxJn4IVL0RMVecbc7Ke1EE1zkUe4GfwaY3/GlcOc9WVRMgsWmZ9arKyT njk8J6haERcWXVrakBRBlGxKKVobvIaXd92xFntZCjVEfI/u7aDUpDvbU1Rx4eXuDSd8 EDFqK2h9KDks8GMZJGH3KU0ubLBLW5lO2LISdMXQe6OVwCv1yIUk/y6rB/dumnlE3lZM r7Vg== X-Forwarded-Encrypted: i=1; AJvYcCUisCyWp2rX+A6Ak05BuMS5qbOth3T5VNMbtUOBEFBF0MsMbXSKAERqmIGPqy/4iLZ1mWTfCZOdv3sh/Y0=@vger.kernel.org X-Gm-Message-State: AOJu0YyqYnicI5Mcb0dZBLgEvUKhm7en0RkVZsBsrPZnNx01/9BsblDZ vNDrWzquQxUM2SstXsx7xLa+KYWIAcn8cKAfxiXhrbTXceM2UC7YUPOr3spiJxYWMSJiNH75exK HSEme9Q== X-Google-Smtp-Source: AGHT+IFR9rK/aQ9amJdpd1t/y1Cad1qqJ3/zdCMOUezpWk9aRtk00B9mU2U04VpxVeYw1eEz90LsxD3W/WdV X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a05:690c:7004:b0:620:32ea:e1d4 with SMTP id 00721157ae682-6ea554802ffmr68657b3.0.1730339005014; Wed, 30 Oct 2024 18:43:25 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:34 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 03/21] perf python: Remove unused #include From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove unused #include of bpf-filter.h. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 13dad27169a0..974578a04099 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/bpf-filter.h" #include "util/env.h" #include "util/kvm-stat.h" #include "util/kwork.h" --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B194126BEF for ; Thu, 31 Oct 2024 01:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339010; cv=none; b=cepUFhYFPOvb8Sx2JJfR2vJQ7hNPIfyrH6I8uCwUwBzXz3f+P44BFl9Nh1Oo5jOg2nGslyXPFFURC1hpuN9vQLJNy/jtzKfymH4n7p9FTwOtuCAYEzSywDjXuH3xBPDsbl3H5aUdHZSWfL41riNx3jR5p9XX+VW/bSSWf4PE1ZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339010; c=relaxed/simple; bh=yvPuFAfJaNIVJqiiJainkQUGB6s3nnX48VfIsgR6iK4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ohRQVLAOVgWTr6UpTCgXL8/7ioatfV3zwfEahAYWadp7xiw/IXtyaixnt3wwwNpWmTB565T2eASM8lrkZLdD2xzH1pzX1hu6TT2XjP9JpqMKG4iyBS4RqC4CjwQxinGznQxTkvgmcxMpr+x1LaCm4lU1KpTn4O10EP7sVQc7844= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zL2CAq25; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zL2CAq25" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea527764c3so11160347b3.0 for ; Wed, 30 Oct 2024 18:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339007; x=1730943807; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=8V2yhtENQ8jLHM+jOYAUxP+5ml2lCB5CR/T0xGeIOrc=; b=zL2CAq25NX05mv9plYTW1rXFjy9pxRscrqtj3TPQ4MSBbZ0JVkLjHysVdB+n8XomhZ DSxR0c80xKd4gjmZmJlXGl8wvs884p16VEuKKo+g9Ue0bIMaA3gTja4JdRdZ+yOsuNeT i9L1jlLqDmQqJRZft47sfIzOZyT7QRbFT9CoNKbcq0t42u80pIUJ45z99iGlEF0RgCiK FGAlYlkJoSMxRT1ml6x/rxUXGBagUIXHkS/tn5VhrQEPsi9j70vt5ytvUj1J0FynROzr +4twEk1kHspvbUsG6aOnrJ5uElYXzWbiJ4g15Fiw0Ves3gGmXrN+N5ZcfqdfACp1cI7K ZHHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339007; x=1730943807; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8V2yhtENQ8jLHM+jOYAUxP+5ml2lCB5CR/T0xGeIOrc=; b=Yf18EqhC/RBPgqbimqUcY8nEia76YX1eGCyjnb2sQXbF+btxm3+YCkXkmAkwxfBfUG 4iK6pAH5BcvjcRXl7RF36z6VaxmmLMnGN/L+drcn7zXsj/oxeZsUnv0tt/B9q2DEcac5 9NtQFijGIZPk/0wArlKoBxTyqLUJCszH1VrudEbUONTCVFEwqy8+193ZaMGtFt3kBrT4 YXtuQDweq/DCo1ApYj/TliQuqFxsFaJhjNOe4tyxh9aVV6PP0ucexDM1h8disxG7fqAW bWiajirwHBGhxWXHvuYqL3NejJ9BzVahRtP/MHSw93TfvVNA+ehcUsZI+OLyUNtDBRWD Lozw== X-Forwarded-Encrypted: i=1; AJvYcCU7SJhAQQXpN6jRWmaQHmFld/IqXErm8gaVRAMMUaDvTPwpxvru+xYDAkfWM3Dns+ZdqNSzd3QgGWazbPk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy50Pt26YgA5g75bCjU/o4cUfKN5MzLVrzjtbf+Z4lGIX7cXp3j d44fnNQUv1E6SJBf1TlO3s8eS5GcD1F8i/vj8jHpC4Z6rxEMIKLzqO+W2s/vq+1MbB793QbS5r7 NqYWpVg== X-Google-Smtp-Source: AGHT+IEMd9R2AtMT95ukzXCTLbKL2p5xzh40NAoOkgE2zBkm/4QxHvXtyWzIOxcjRsyYO+fDNfVRcxPlBGLM X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a81:be02:0:b0:6a9:3d52:79e9 with SMTP id 00721157ae682-6ea3b94f7famr1085127b3.4.1730339007150; Wed, 30 Oct 2024 18:43:27 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:35 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 04/21] perf script: Move scripting_max_stack out of builtin From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" scripting_max_stack is used in util code which is linked into the python module. Move the variable declaration to util/trace-event-scripting.c to avoid conditional compilation. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 2 -- tools/perf/util/python.c | 2 -- tools/perf/util/trace-event-scripting.c | 3 +++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 6b6d4472db6e..5d5a1a06d8c6 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -92,8 +92,6 @@ static struct dlfilter *dlfilter; static int dlargc; static char **dlargv; =20 -unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; - enum perf_output_field { PERF_OUTPUT_COMM =3D 1ULL << 0, PERF_OUTPUT_TID =3D 1ULL << 1, diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 974578a04099..298f43981fc5 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1306,8 +1306,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; - bool kvm_entry_event(struct evsel *evsel __maybe_unused) { return false; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index bd0000300c77..8abb7a7b6888 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -16,9 +16,12 @@ #include "debug.h" #include "trace-event.h" #include "evsel.h" +#include #include #include "util/sample.h" =20 +unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPTH; + struct scripting_context *scripting_context; =20 void scripting_context__update(struct scripting_context *c, --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E10EC12C478 for ; Thu, 31 Oct 2024 01:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339012; cv=none; b=pXAVVlrqiCWE5J8jyZBjxkdi7LtfJYOQZbfxlE5mLH2MwvML9zuxtCS0BMJtV6WwuL+u+x+X0wqOww01GYN9W3PGYZn1/qfGi288c1cARrbfdhqCqWPciwbm1CGCLMttvjz+bvneoTBGRZU4xvPos3aCI75b3ZumV+BWS5dQ5xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339012; c=relaxed/simple; bh=aVce+4MfNDpZ0CbKS/Y3lxpj+YoiC94qhm+g5EWIpQE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dh7fiVTsRv/YMMaYAnX7G7DWHfcHMmLzOPn6/hR2hvGGqQ9d5JiQeGf+au05rJMo7n40dlpnRfgeLBzRVuaYyQLvw0k5pEjsTsAc/C5wx1yaZ3+3UG4YMlqqK9KSbjij9u8C1ngyovhlKBUg5tjGi73OIlZK0flnYud3pGcpgac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Vl9dlF2w; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Vl9dlF2w" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3d660a1afso9702757b3.0 for ; Wed, 30 Oct 2024 18:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339009; x=1730943809; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PeOJZ1eHy/s5KnsoiJfHZk8rV3gYmSD8emrvfidGiQI=; b=Vl9dlF2wXPbIsRplxA4jQtQV1Hu6jq8HHXKh7UVo1SolRDe6KMNZP6vbFNQHJvB2BS RdU1gMx8Gw8pZj6tPy9OwmAYPgaMpWVXinV9XxeCNu2z5njfcZ4N7ENsg7ez/jPTfLWI bzIBmLo/36oF6LzLzE3Ab1AwR8ZGNC7aoSrShysQjWzNLL18Q+nHR4Cx/cO3+2vhC5u/ XhRCwCI2ZGByFXYOvJYArzD0/y2sJ2zAulnRUBCL7AYMqKN5q1gWf+1JxRcD3iQeYrzD NfiZOubVfEnHjSov4EyjPyukz5cu1R55uwuTHNoBmP98xKaA31I+dre3+ih4KQPK5T6C Hcog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339009; x=1730943809; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PeOJZ1eHy/s5KnsoiJfHZk8rV3gYmSD8emrvfidGiQI=; b=avAimf4mptnit0A+2/FMmkqT1U5du6uEJwF9ByaMtxdnUrTlRQC+MB+rDTYa2+NvEG RQzZj8TGKaeiCDTtaxBiQxU64Ie4fFRm12NQquYMbTtgemwGoAQVSlZWILiRZBidsY06 /DIuBYaH0ptJWMeFDormRY2IQhr7U5pNelmDaDWUcaQp5Q7knavL9nwlvHczIPnlALPn r8ouEPQec4KVq9UAZ2F4Y2OSUcbtCGqtjSrJiAGCkHZS5xCZeaNiGmISck7qYwHWLiL6 bXNjulF1XUxOkvSgFr/UMiHbXDfJrSZZAvSgBpU30zkzi8Jy7YnmZkp9x+9zcMWb2EKm /U6Q== X-Forwarded-Encrypted: i=1; AJvYcCUZLZumgzh1ohoqbY4R3YIX1shcAMjeAAPPQCYZYGN6y3NSdDfYlI+XeDPPaAb38TvxRUeaZodNoK2w1nA=@vger.kernel.org X-Gm-Message-State: AOJu0YyUQ0xErgDVSk2RSmyXFlOYLDFTDu5qkO21YdTlY9/qo/tamhP9 NRPryXEg6hSu//Os1BuSDY4ShksKbTPmYqZMqIIKby63XVQ8uy4yEnfztfW4DvKVQQH8LCUagX5 irRoILA== X-Google-Smtp-Source: AGHT+IEYrO5boaRHSPgvVCktZKiN82j8q9zAe1ZfPnp6qu7vg6BvMGUGufYOxZDbNRbFSXCkEyFDlTlPV1KW X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a05:690c:c01:b0:6ea:fa4:a365 with SMTP id 00721157ae682-6ea0fa4bd2amr5241897b3.8.1730339009135; Wed, 30 Oct 2024 18:43:29 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:36 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 05/21] perf kvm: Move functions used in util out of builtin From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The util library code is used by the python module but doesn't have access to the builtin files. Make a util/kvm-stat.c to match the kvm-stat.h file that declares the functions and move the functions there. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-kvm.c | 61 --------------------------------- tools/perf/util/Build | 1 + tools/perf/util/kvm-stat.c | 70 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/kvm-stat.h | 3 ++ tools/perf/util/python.c | 30 ---------------- 5 files changed, 74 insertions(+), 91 deletions(-) create mode 100644 tools/perf/util/kvm-stat.c diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 099ce3ebf67c..e50cd04e3725 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -615,67 +615,6 @@ static const char *get_filename_for_perf_kvm(void) =20 #if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) =20 -void exit_event_get_key(struct evsel *evsel, - struct perf_sample *sample, - struct event_key *key) -{ - key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason); -} - -bool kvm_exit_event(struct evsel *evsel) -{ - return evsel__name_is(evsel, kvm_exit_trace); -} - -bool exit_event_begin(struct evsel *evsel, - struct perf_sample *sample, struct event_key *key) -{ - if (kvm_exit_event(evsel)) { - exit_event_get_key(evsel, sample, key); - return true; - } - - return false; -} - -bool kvm_entry_event(struct evsel *evsel) -{ - return evsel__name_is(evsel, kvm_entry_trace); -} - -bool exit_event_end(struct evsel *evsel, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return kvm_entry_event(evsel); -} - -static const char *get_exit_reason(struct perf_kvm_stat *kvm, - struct exit_reasons_table *tbl, - u64 exit_code) -{ - while (tbl->reason !=3D NULL) { - if (tbl->exit_code =3D=3D exit_code) - return tbl->reason; - tbl++; - } - - pr_err("unknown kvm exit code:%lld on %s\n", - (unsigned long long)exit_code, kvm->exit_reasons_isa); - return "UNKNOWN"; -} - -void exit_event_decode_key(struct perf_kvm_stat *kvm, - struct event_key *key, - char *decode) -{ - const char *exit_reason =3D get_exit_reason(kvm, key->exit_reasons, - key->key); - - scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); -} - static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) { struct kvm_reg_events_ops *events_ops =3D kvm_reg_events_ops; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 1eedead5f2f2..650974413849 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -120,6 +120,7 @@ perf-util-y +=3D spark.o perf-util-y +=3D topdown.o perf-util-y +=3D iostat.o perf-util-y +=3D stream.o +perf-util-y +=3D kvm-stat.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c new file mode 100644 index 000000000000..38ace736db5c --- /dev/null +++ b/tools/perf/util/kvm-stat.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "evsel.h" +#include "kvm-stat.h" + +#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) + +bool kvm_exit_event(struct evsel *evsel) +{ + return evsel__name_is(evsel, kvm_exit_trace); +} + +void exit_event_get_key(struct evsel *evsel, + struct perf_sample *sample, + struct event_key *key) +{ + key->info =3D 0; + key->key =3D evsel__intval(evsel, sample, kvm_exit_reason); +} + + +bool exit_event_begin(struct evsel *evsel, + struct perf_sample *sample, struct event_key *key) +{ + if (kvm_exit_event(evsel)) { + exit_event_get_key(evsel, sample, key); + return true; + } + + return false; +} + +bool kvm_entry_event(struct evsel *evsel) +{ + return evsel__name_is(evsel, kvm_entry_trace); +} + +bool exit_event_end(struct evsel *evsel, + struct perf_sample *sample __maybe_unused, + struct event_key *key __maybe_unused) +{ + return kvm_entry_event(evsel); +} + +static const char *get_exit_reason(struct perf_kvm_stat *kvm, + struct exit_reasons_table *tbl, + u64 exit_code) +{ + while (tbl->reason !=3D NULL) { + if (tbl->exit_code =3D=3D exit_code) + return tbl->reason; + tbl++; + } + + pr_err("unknown kvm exit code:%lld on %s\n", + (unsigned long long)exit_code, kvm->exit_reasons_isa); + return "UNKNOWN"; +} + +void exit_event_decode_key(struct perf_kvm_stat *kvm, + struct event_key *key, + char *decode) +{ + const char *exit_reason =3D get_exit_reason(kvm, key->exit_reasons, + key->key); + + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); +} + +#endif diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 3e9ac754c3d1..4249542544bb 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -115,6 +115,8 @@ struct kvm_reg_events_ops { struct kvm_events_ops *ops; }; =20 +#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT) + void exit_event_get_key(struct evsel *evsel, struct perf_sample *sample, struct event_key *key); @@ -127,6 +129,7 @@ bool exit_event_end(struct evsel *evsel, void exit_event_decode_key(struct perf_kvm_stat *kvm, struct event_key *key, char *decode); +#endif =20 bool kvm_exit_event(struct evsel *evsel); bool kvm_entry_event(struct evsel *evsel); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 298f43981fc5..ab67abf3b607 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1306,36 +1306,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -bool kvm_entry_event(struct evsel *evsel __maybe_unused) -{ - return false; -} - -bool kvm_exit_event(struct evsel *evsel __maybe_unused) -{ - return false; -} - -bool exit_event_begin(struct evsel *evsel __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return false; -} - -bool exit_event_end(struct evsel *evsel __maybe_unused, - struct perf_sample *sample __maybe_unused, - struct event_key *key __maybe_unused) -{ - return false; -} - -void exit_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, - struct event_key *key __maybe_unused, - char *decode __maybe_unused) -{ -} - int find_scripts(char **scripts_array __maybe_unused, char **scripts_path= _array __maybe_unused, int num __maybe_unused, int pathlen __maybe_unused) { --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29219135A63 for ; Thu, 31 Oct 2024 01:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339014; cv=none; b=IZjh4CFugUQ3AywyR1+KWC06TcOAhbM82ACZvhwHUn3oCSbsTs+wfsZnM+vV+rbrs+OLf0jPHpBw9yjlybzCyKFPalpZzU2F+HOb5GExe5RrVDlR/j/vN4JX3FY4YjZp2jTKkFqaj15B0xV49k8GDT03emi3yIr4frLZ6PIyawo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339014; c=relaxed/simple; bh=j3zx3+RMUuwoG2j9m2zcYqP3xxAWJ5nOngPUL6avzO4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JX9uwfYtF6wEYKmQmXqLupe0Esc3Ab9to3e9FTJm+TlyGHiFsr/phijieoJbvatfIJrrvGlF2T2GVbjwk1/KgrNouS9TZds9vvvxn0v4VlFZVn7dUHY1sq17C8OPJdqw9VmC5EJV/BN6tn4KkrFpilpZrTE0lz1NaCyCGAbkLpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=A/Lx0GSw; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A/Lx0GSw" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e29205f6063so743747276.1 for ; Wed, 30 Oct 2024 18:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339011; x=1730943811; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=pYvGkK59Z6miGuboUup6skSYtdnkz5NEtw08MfrBQsY=; b=A/Lx0GSwCU9xW3bzWo2MZ6v461q02GZ7KzAwj8CGR6enSZmZARK4iD/exZrZhHtZNX 8DW5WAFJNk6VcvxgzBgvvO/YpNSx4PJSLkO3O0DS3kx9W2XaAS0SiT170eIxPn649JyW QApyeoK2b84TRn5BmaIGChx4tSWkKqGUmTE30mNF19fJGf3QKLT09/yCl7hL7vRfZHex GfAWkylItSNdiC4BrL8CVEAFX2fCDYhxkudvcENpNMeQ1hKspHVwNY5klTpnyAtYSSry t0ktL2V/ekjNmwiLiJPDblFCGXPpctwgqm5OinLjqQ0PkwcXYF1kT71wolsqebMS9Urf 8M1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339011; x=1730943811; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pYvGkK59Z6miGuboUup6skSYtdnkz5NEtw08MfrBQsY=; b=mX0nWSiI5IH71zvQBcaNJPKRpQq69wbuge692LAOxD04v3FDXyKAgIaxqzr8sSsBlU TCzEVakPbVI201LgNZvc0rE74jGzN4ZcY9Rv0a+5bXzbYzaJXb3yK+/7MeBg4qOCpBiW 3UdKZ/O4jxAxJDzv/QqTez+822NHVrUgzIcM0eegLUHD5Ewi0m3TNcU3WSZKOlO0BmMr Z3FDDZb7b7zyYp/cCtWVhRMYzBhGVzGfJvt9qG9UPZRv0KYyJq/4cQRquodwmH1Qogzz hydRIVNmnM9aiuIcTN71n0dlVqh0dqBXBP2zdjiF/3MaPNFySWvE/W5ZcKlDRMOVcVgt GXVA== X-Forwarded-Encrypted: i=1; AJvYcCWYHqzch113kwqFl1ZP4rgsKBRLN5YwFfKsbBeWBailr8Ec2V6QiWPlVzKB5OYjrmgyfU6WFCmv0T5zmOE=@vger.kernel.org X-Gm-Message-State: AOJu0YxKHkuDC+PaHCB+rAJpaOKeWcb3w5fvVuDxkIta8hfJXPrbrCMT pK3FEH/EBqFqIVL2624Cjh0qjoxUTVtCF3gTBOD4h1vao5O7Om/AbQxqyIgKVO2FfXGOrRD31dE wUwodDw== X-Google-Smtp-Source: AGHT+IERyHC+D+v45j3FhQdchZZrI684i84H+7DZRgxEKBBkhSFK6a2LiQYfe6TabLcXwUSeH3SGS2aBBhdA X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:26cc:0:b0:e25:5cb1:77cd with SMTP id 3f1490d57ef6-e3087c2d76fmr65003276.10.1730339011118; Wed, 30 Oct 2024 18:43:31 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:37 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 06/21] perf script: Move find_scripts to browser/scripts.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The only use of find_scripts is in browser/scripts.c but the definition in builtin causes linking problems requiring a stub in python.c. Move the function to allow the stub to be removed. Rewrite the directory iteration to use openat so that large character arrays aren't needed. The arrays are warned about potential buffer overflows by GCC now that all the code exists in a single C file. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 138 ------------------------ tools/perf/builtin.h | 6 -- tools/perf/ui/browsers/scripts.c | 177 ++++++++++++++++++++++++++++++- tools/perf/util/path.c | 10 ++ tools/perf/util/path.h | 1 + tools/perf/util/python.c | 6 -- 6 files changed, 186 insertions(+), 152 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 5d5a1a06d8c6..e9ec74056f71 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3521,144 +3521,6 @@ static void free_dlarg(void) free(dlargv); } =20 -/* - * Some scripts specify the required events in their "xxx-record" file, - * this function will check if the events in perf.data match those - * mentioned in the "xxx-record". - * - * Fixme: All existing "xxx-record" are all in good formats "-e event ", - * which is covered well now. And new parsing code should be added to - * cover the future complex formats like event groups etc. - */ -static int check_ev_match(char *dir_name, char *scriptname, - struct perf_session *session) -{ - char filename[MAXPATHLEN], evname[128]; - char line[BUFSIZ], *p; - struct evsel *pos; - int match, len; - FILE *fp; - - scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname); - - fp =3D fopen(filename, "r"); - if (!fp) - return -1; - - while (fgets(line, sizeof(line), fp)) { - p =3D skip_spaces(line); - if (*p =3D=3D '#') - continue; - - while (strlen(p)) { - p =3D strstr(p, "-e"); - if (!p) - break; - - p +=3D 2; - p =3D skip_spaces(p); - len =3D strcspn(p, " \t"); - if (!len) - break; - - snprintf(evname, len + 1, "%s", p); - - match =3D 0; - evlist__for_each_entry(session->evlist, pos) { - if (evsel__name_is(pos, evname)) { - match =3D 1; - break; - } - } - - if (!match) { - fclose(fp); - return -1; - } - } - } - - fclose(fp); - return 0; -} - -/* - * Return -1 if none is found, otherwise the actual scripts number. - * - * Currently the only user of this function is the script browser, which - * will list all statically runnable scripts, select one, execute it and - * show the output in a perf browser. - */ -int find_scripts(char **scripts_array, char **scripts_path_array, int num, - int pathlen) -{ - struct dirent *script_dirent, *lang_dirent; - char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; - DIR *scripts_dir, *lang_dir; - struct perf_session *session; - struct perf_data data =3D { - .path =3D input_name, - .mode =3D PERF_DATA_MODE_READ, - }; - char *temp; - int i =3D 0; - - session =3D perf_session__new(&data, NULL); - if (IS_ERR(session)) - return PTR_ERR(session); - - snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); - - scripts_dir =3D opendir(scripts_path); - if (!scripts_dir) { - perf_session__delete(session); - return -1; - } - - for_each_lang(scripts_path, scripts_dir, lang_dirent) { - scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, - lang_dirent->d_name); -#ifndef HAVE_LIBPERL_SUPPORT - if (strstr(lang_path, "perl")) - continue; -#endif -#ifndef HAVE_LIBPYTHON_SUPPORT - if (strstr(lang_path, "python")) - continue; -#endif - - lang_dir =3D opendir(lang_path); - if (!lang_dir) - continue; - - for_each_script(lang_path, lang_dir, script_dirent) { - /* Skip those real time scripts: xxxtop.p[yl] */ - if (strstr(script_dirent->d_name, "top.")) - continue; - if (i >=3D num) - break; - snprintf(scripts_path_array[i], pathlen, "%s/%s", - lang_path, - script_dirent->d_name); - temp =3D strchr(script_dirent->d_name, '.'); - snprintf(scripts_array[i], - (temp - script_dirent->d_name) + 1, - "%s", script_dirent->d_name); - - if (check_ev_match(lang_path, - scripts_array[i], session)) - continue; - - i++; - } - closedir(lang_dir); - } - - closedir(scripts_dir); - perf_session__delete(session); - return i; -} - static char *get_script_path(const char *script_root, const char *suffix) { struct dirent *script_dirent, *lang_dirent; diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 94f4b3769bf7..a07e93c53848 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h @@ -2,10 +2,6 @@ #ifndef BUILTIN_H #define BUILTIN_H =20 -#include -#include -#include - struct feature_status { const char *name; const char *macro; @@ -56,6 +52,4 @@ int cmd_ftrace(int argc, const char **argv); int cmd_daemon(int argc, const char **argv); int cmd_kwork(int argc, const char **argv); =20 -int find_scripts(char **scripts_array, char **scripts_path_array, int num, - int pathlen); #endif diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scri= pts.c index e437d7889de6..2d04ece833aa 100644 --- a/tools/perf/ui/browsers/scripts.c +++ b/tools/perf/ui/browsers/scripts.c @@ -1,16 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 -#include "../../builtin.h" -#include "../../perf.h" #include "../../util/util.h" // perf_exe() #include "../util.h" +#include "../../util/evlist.h" #include "../../util/hist.h" #include "../../util/debug.h" +#include "../../util/session.h" #include "../../util/symbol.h" #include "../browser.h" #include "../libslang.h" #include "config.h" +#include #include #include +#include #include =20 #define SCRIPT_NAMELEN 128 @@ -77,6 +79,177 @@ static int scripts_config(const char *var, const char *= value, void *data) return 0; } =20 +/* + * Some scripts specify the required events in their "xxx-record" file, + * this function will check if the events in perf.data match those + * mentioned in the "xxx-record". + * + * Fixme: All existing "xxx-record" are all in good formats "-e event ", + * which is covered well now. And new parsing code should be added to + * cover the future complex formats like event groups etc. + */ +static int check_ev_match(int dir_fd, const char *scriptname, struct perf_= session *session) +{ + char line[BUFSIZ]; + FILE *fp; + + { + char filename[FILENAME_MAX + 5]; + int fd; + + scnprintf(filename, sizeof(filename), "bin/%s-record", scriptname); + fd =3D openat(dir_fd, filename, O_RDONLY); + if (fd =3D=3D -1) + return -1; + fp =3D fdopen(fd, "r"); + if (!fp) + return -1; + } + + while (fgets(line, sizeof(line), fp)) { + char *p =3D skip_spaces(line); + + if (*p =3D=3D '#') + continue; + + while (strlen(p)) { + int match, len; + struct evsel *pos; + char evname[128]; + + p =3D strstr(p, "-e"); + if (!p) + break; + + p +=3D 2; + p =3D skip_spaces(p); + len =3D strcspn(p, " \t"); + if (!len) + break; + + snprintf(evname, len + 1, "%s", p); + + match =3D 0; + evlist__for_each_entry(session->evlist, pos) { + if (evsel__name_is(pos, evname)) { + match =3D 1; + break; + } + } + + if (!match) { + fclose(fp); + return -1; + } + } + } + + fclose(fp); + return 0; +} + +/* + * Return -1 if none is found, otherwise the actual scripts number. + * + * Currently the only user of this function is the script browser, which + * will list all statically runnable scripts, select one, execute it and + * show the output in a perf browser. + */ +static int find_scripts(char **scripts_array, char **scripts_path_array, i= nt num, + int pathlen) +{ + struct dirent *script_dirent, *lang_dirent; + int scripts_dir_fd, lang_dir_fd; + DIR *scripts_dir, *lang_dir; + struct perf_session *session; + struct perf_data data =3D { + .path =3D input_name, + .mode =3D PERF_DATA_MODE_READ, + }; + char *temp; + int i =3D 0; + const char *exec_path =3D get_argv_exec_path(); + + session =3D perf_session__new(&data, NULL); + if (IS_ERR(session)) + return PTR_ERR(session); + + { + char scripts_path[PATH_MAX]; + + snprintf(scripts_path, sizeof(scripts_path), "%s/scripts", exec_path); + scripts_dir_fd =3D open(scripts_path, O_DIRECTORY); + pr_err("Failed to open directory '%s'", scripts_path); + if (scripts_dir_fd =3D=3D -1) { + perf_session__delete(session); + return -1; + } + } + scripts_dir =3D fdopendir(scripts_dir_fd); + if (!scripts_dir) { + close(scripts_dir_fd); + perf_session__delete(session); + return -1; + } + + while ((lang_dirent =3D readdir(scripts_dir)) !=3D NULL) { + if (lang_dirent->d_type !=3D DT_DIR && + (lang_dirent->d_type =3D=3D DT_UNKNOWN && + !is_directory_at(scripts_dir_fd, lang_dirent->d_name))) + continue; + if (!strcmp(lang_dirent->d_name, ".") || !strcmp(lang_dirent->d_name, ".= .")) + continue; + +#ifndef HAVE_LIBPERL_SUPPORT + if (strstr(lang_dirent->d_name, "perl")) + continue; +#endif +#ifndef HAVE_LIBPYTHON_SUPPORT + if (strstr(lang_dirent->d_name, "python")) + continue; +#endif + + lang_dir_fd =3D openat(scripts_dir_fd, lang_dirent->d_name, O_DIRECTORY); + if (lang_dir_fd =3D=3D -1) + continue; + lang_dir =3D fdopendir(lang_dir_fd); + if (!lang_dir) { + close(lang_dir_fd); + continue; + } + while ((script_dirent =3D readdir(lang_dir)) !=3D NULL) { + if (script_dirent->d_type =3D=3D DT_DIR) + continue; + if (script_dirent->d_type =3D=3D DT_UNKNOWN && + is_directory_at(lang_dir_fd, script_dirent->d_name)) + continue; + /* Skip those real time scripts: xxxtop.p[yl] */ + if (strstr(script_dirent->d_name, "top.")) + continue; + if (i >=3D num) + break; + scnprintf(scripts_path_array[i], pathlen, "%s/scripts/%s/%s", + exec_path, + lang_dirent->d_name, + script_dirent->d_name); + temp =3D strchr(script_dirent->d_name, '.'); + snprintf(scripts_array[i], + (temp - script_dirent->d_name) + 1, + "%s", script_dirent->d_name); + + if (check_ev_match(lang_dir_fd, scripts_array[i], session)) + continue; + + i++; + } + closedir(lang_dir); + } + + closedir(scripts_dir); + perf_session__delete(session); + return i; +} + /* * When success, will copy the full path of the selected script * into the buffer pointed by script_name, and return 0. diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 00adf872bf00..9712466c51e2 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c @@ -68,6 +68,16 @@ bool is_directory(const char *base_path, const struct di= rent *dent) return S_ISDIR(st.st_mode); } =20 +bool is_directory_at(int dir_fd, const char *path) +{ + struct stat st; + + if (fstatat(dir_fd, path, &st, /*flags=3D*/0)) + return false; + + return S_ISDIR(st.st_mode); +} + bool is_executable_file(const char *base_path, const struct dirent *dent) { char path[PATH_MAX]; diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h index d94902c22222..fbafbe7015dd 100644 --- a/tools/perf/util/path.h +++ b/tools/perf/util/path.h @@ -12,6 +12,7 @@ int path__join3(char *bf, size_t size, const char *path1,= const char *path2, con =20 bool is_regular_file(const char *file); bool is_directory(const char *base_path, const struct dirent *dent); +bool is_directory_at(int dir_fd, const char *path); bool is_executable_file(const char *base_path, const struct dirent *dent); =20 #endif /* _PERF_PATH_H */ diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index ab67abf3b607..5f11ae88943d 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1306,12 +1306,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -int find_scripts(char **scripts_array __maybe_unused, char **scripts_path= _array __maybe_unused, - int num __maybe_unused, int pathlen __maybe_unused) -{ - return -1; -} - void perf_stat__set_no_csv_summary(int set __maybe_unused) { } --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB9213957C for ; Thu, 31 Oct 2024 01:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339016; cv=none; b=YKAgKoFqRNA3Exs5aynejcgxir9HhF/R1jxzuFcO0XmipccKtXs6YzF2VvrteNaODPTPhX4rZX1gVfUaE5n5qGeOxLtjjs2vEUZcDmPL8Sk1wjZTWQPlfPi8RPI2zKdN07fn4X/ZON16ewWq8G8AO0Nffp9xbaVSRNh5gBDBNrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339016; c=relaxed/simple; bh=OkgfakVEBzNhVQvYPoWUWgsb9ea6uiwfv7CjO2/5vxs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=deFakQX3fi9w6yqx+ymYwJaUEkjqfTeXt+8uX+JqCTIuewrd76eefJwDC3gsxQfPlizffsheQcfdaT5IyVzuIdf/uach19qKWRYisRVipLMj8iChRrM+SXezZ54xXNOQs1RuoUsh61P34cCKrExg4Rn2wKDda0FJ2EvOYZS4mcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fBiGvLyM; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fBiGvLyM" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e24a31ad88aso750751276.1 for ; Wed, 30 Oct 2024 18:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339013; x=1730943813; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=zVk767eKKMka2fJeUsflenyL0QHm0J7Og37hcfkqc+Q=; b=fBiGvLyMq42/oAsJG5k/cqpY+JGLqjgeSUtNLy3Bu4ya4bNDFMkgqgBu++mAxghhdX JnETCbuO53ZbNfnUjd3xSf/9UcT72mvViU7cUFPdwvzF3NqXHg00Lz5tNlttsFKX2Jrd lmSO/vWuaB56UKnyebSj525XlXEso1GTsB9xykk1zLXSoSf5q9qK4I23KEXwEfE37eCI 1jPyR2oUOh28fvFxc4mdjEYoofC7w4oW7AhsiHFlVA8wwWK4bGFDFdfn3qukWFh08kZW TUYRDWas4npBpA34inscwMA//cibAY6A4x3nJyQxgSvFmgYRAElM30M7WcXNqVL+5zIx zIYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339013; x=1730943813; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zVk767eKKMka2fJeUsflenyL0QHm0J7Og37hcfkqc+Q=; b=MSh8M3ZY6X0v3doQxl6IYye6WIY0tt9QoOFiZy1jfTLNqB6MBgVST7BTVy5NlqW9Mu tYp9iIcAAknTxYKuI4GGYLhOMHWVvnVnYIcEizjT1u/3Dn7kk5mXgQ8vYxLk3p3u7q3x zim7mqIlc0PnjtUK/RJxFw1CvnsoEUe8T7Pwo/2m9CqtaB6wfOrASVUyr7Szk/HNuiz9 dFRzmUaGHGnCAOsvtmhSZ6ESICj3Aph41M9eWE26O+G4vWCbXhZ8v7qmM3y6b8n8BKu0 qdrCurBR8h8HdyCj7NhJWZQwtU+8ZBa9l1+Zc/wekGtumdAVMZGG7mo378Hl0mjaNXw0 6eaA== X-Forwarded-Encrypted: i=1; AJvYcCVyQoaVJ5/AR3fPi5E3X4NATWiu3Y8ijoN1+QpkWmIPGigjvy4lzA7xA/WePfpgJRfc0cC3BvQQBouNyIA=@vger.kernel.org X-Gm-Message-State: AOJu0YyYs9LLnf5hktBquMhJHRhQvOjYHBOiDoPte4hWqdg60ROMH2pe svsIvFK7N99DTmRSee58aY2YcnFRW3QHJJKxCizETjQ4SoX3vucAUkRvyXEQpX0kT8O+UZ5nQFU jy8grPA== X-Google-Smtp-Source: AGHT+IGpHHG8N7FxAL6vCvTXmjIng8pUhJCdXh7OTikcvfaqC5gJYr1V+cxcaRgy8j8lsb6l5WCpw3LtqDl5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:9086:0:b0:e29:74e3:616c with SMTP id 3f1490d57ef6-e3087a4f19cmr12068276.3.1730339013331; Wed, 30 Oct 2024 18:43:33 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:38 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 07/21] perf stat: Move stat_config into config.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" stat_config is accessed by config.c via helper functions, but declared in builtin-stat. Move to util/config.c so that stub functions aren't needed in python.c which doesn't link against the builtin files. To avoid name conflicts change builtin-script to use the same stat_config as builtin-stat. Rename local variables in tests to avoid shadow declaration warnings. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 1 - tools/perf/builtin-stat.c | 27 --------------------------- tools/perf/tests/stat.c | 16 +++++++++------- tools/perf/util/config.c | 27 +++++++++++++++++++++++++++ tools/perf/util/python.c | 9 --------- tools/perf/util/stat.h | 3 ++- 6 files changed, 38 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index e9ec74056f71..62e851fdf5ca 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -85,7 +85,6 @@ static bool system_wide; static bool print_flags; static const char *cpu_list; static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); -static struct perf_stat_config stat_config; static int max_blocks; static bool native_arch; static struct dlfilter *dlfilter; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c12158d99353..a1625443e5a5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -112,8 +112,6 @@ static struct target target =3D { .uid =3D UINT_MAX, }; =20 -#define METRIC_ONLY_LEN 20 - static volatile sig_atomic_t child_pid =3D -1; static int detailed_run =3D 0; static bool transaction_run; @@ -151,21 +149,6 @@ static struct perf_stat perf_stat; =20 static volatile sig_atomic_t done =3D 0; =20 -static struct perf_stat_config stat_config =3D { - .aggr_mode =3D AGGR_GLOBAL, - .aggr_level =3D MAX_CACHE_LVL + 1, - .scale =3D true, - .unit_width =3D 4, /* strlen("unit") */ - .run_count =3D 1, - .metric_only_len =3D METRIC_ONLY_LEN, - .walltime_nsecs_stats =3D &walltime_nsecs_stats, - .ru_stats =3D &ru_stats, - .big_num =3D true, - .ctl_fd =3D -1, - .ctl_fd_ack =3D -1, - .iostat_run =3D false, -}; - /* Options set from the command line. */ struct opt_aggr_mode { bool node, socket, die, cluster, cache, core, thread, no_aggr; @@ -1071,16 +1054,6 @@ static void sig_atexit(void) kill(getpid(), signr); } =20 -void perf_stat__set_big_num(int set) -{ - stat_config.big_num =3D (set !=3D 0); -} - -void perf_stat__set_no_csv_summary(int set) -{ - stat_config.no_csv_summary =3D (set !=3D 0); -} - static int stat__set_big_num(const struct option *opt __maybe_unused, const char *s __maybe_unused, int unset) { diff --git a/tools/perf/tests/stat.c b/tools/perf/tests/stat.c index 6468cc0d0204..d60983657bad 100644 --- a/tools/perf/tests/stat.c +++ b/tools/perf/tests/stat.c @@ -27,7 +27,7 @@ static int process_stat_config_event(const struct perf_to= ol *tool __maybe_unused struct machine *machine __maybe_unused) { struct perf_record_stat_config *config =3D &event->stat_config; - struct perf_stat_config stat_config =3D {}; + struct perf_stat_config test_stat_config =3D {}; =20 #define HAS(term, val) \ has_term(config, PERF_STAT_CONFIG_TERM__##term, val) @@ -39,25 +39,27 @@ static int process_stat_config_event(const struct perf_= tool *tool __maybe_unused =20 #undef HAS =20 - perf_event__read_stat_config(&stat_config, config); + perf_event__read_stat_config(&test_stat_config, config); =20 - TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode =3D=3D AGGR_CORE= ); - TEST_ASSERT_VAL("wrong scale", stat_config.scale =3D=3D 1); - TEST_ASSERT_VAL("wrong interval", stat_config.interval =3D=3D 1); + TEST_ASSERT_VAL("wrong aggr_mode", test_stat_config.aggr_mode =3D=3D AGGR= _CORE); + TEST_ASSERT_VAL("wrong scale", test_stat_config.scale =3D=3D 1); + TEST_ASSERT_VAL("wrong interval", test_stat_config.interval =3D=3D 1); return 0; } =20 static int test__synthesize_stat_config(struct test_suite *test __maybe_un= used, int subtest __maybe_unused) { - struct perf_stat_config stat_config =3D { + struct perf_stat_config test_stat_config =3D { .aggr_mode =3D AGGR_CORE, .scale =3D 1, .interval =3D 1, }; =20 TEST_ASSERT_VAL("failed to synthesize stat_config", - !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_con= fig_event, NULL)); + !perf_event__synthesize_stat_config(NULL, &test_stat_config, + process_stat_config_event, + NULL)); =20 return 0; } diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 68f9407ca74b..2d07c9257a1a 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -13,6 +13,7 @@ #include #include "cache.h" #include "callchain.h" +#include "header.h" #include #include "util/event.h" /* proc_map_timeout */ #include "util/hist.h" /* perf_hist_config */ @@ -34,6 +35,22 @@ =20 #define DEBUG_CACHE_DIR ".debug" =20 +#define METRIC_ONLY_LEN 20 + +struct perf_stat_config stat_config =3D { + .aggr_mode =3D AGGR_GLOBAL, + .aggr_level =3D MAX_CACHE_LVL + 1, + .scale =3D true, + .unit_width =3D 4, /* strlen("unit") */ + .run_count =3D 1, + .metric_only_len =3D METRIC_ONLY_LEN, + .walltime_nsecs_stats =3D &walltime_nsecs_stats, + .ru_stats =3D &ru_stats, + .big_num =3D true, + .ctl_fd =3D -1, + .ctl_fd_ack =3D -1, + .iostat_run =3D false, +}; =20 char buildid_dir[MAXPATHLEN]; /* root dir for buildid, binary cache */ =20 @@ -455,6 +472,16 @@ static int perf_ui_config(const char *var, const char = *value) return 0; } =20 +void perf_stat__set_big_num(int set) +{ + stat_config.big_num =3D (set !=3D 0); +} + +static void perf_stat__set_no_csv_summary(int set) +{ + stat_config.no_csv_summary =3D (set !=3D 0); +} + static int perf_stat_config(const char *var, const char *value) { if (!strcmp(var, "stat.big-num")) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 5f11ae88943d..0fa8e27769be 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -17,7 +17,6 @@ #include "trace-event.h" #include "mmap.h" #include "util/env.h" -#include "util/kvm-stat.h" #include "util/kwork.h" #include "util/sample.h" #include "util/lock-contention.h" @@ -1306,14 +1305,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -void perf_stat__set_no_csv_summary(int set __maybe_unused) -{ -} - -void perf_stat__set_big_num(int set __maybe_unused) -{ -} - int script_spec_register(const char *spec __maybe_unused, struct scripting= _ops *ops __maybe_unused) { return -1; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 6f8cff3cd39a..2fda9acd7374 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -117,8 +117,9 @@ struct perf_stat_config { unsigned int topdown_level; }; =20 +extern struct perf_stat_config stat_config; + void perf_stat__set_big_num(int set); -void perf_stat__set_no_csv_summary(int set); =20 void update_stats(struct stats *stats, u64 val); double avg_stats(struct stats *stats); --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D199213AA41 for ; Thu, 31 Oct 2024 01:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339019; cv=none; b=YV75ROKazl7BGez3hPVOZ8i+WxxDyQKJq5/Vk4VJVVR+LqQotyGXj4swfyhlfWpsUc2c+1OexH+44GjfV/G4/ugHaG/ld5GkuGSi3m2Gv3VNiNnIF+Daf9bLSi3bPKy3dY/DJasMS7NI2SAzsWM6pQGSf7a+Pg0wDQE+bfk0wiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339019; c=relaxed/simple; bh=qKQOsPnZUvFJyIQxLl3j+FlzyZDOhBy3IVqiYH6w9gc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=tVDPamqV1o2mHYxA/l4gGUCAWQmVzKsj2Lkf0XqwsxPC23jIzUc1qrfw5sqv6kfdL5YWayG48gBa0Ly/1kt8Tx9yUXEam2VZM7jgDGyZM+eBFYWWfYgAjwF2CNfKqCS8vENRSulCi3632NlwK8Ks0FaTR61d/tgmCEuTJ5qYHvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OeazsVk5; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OeazsVk5" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30daaf5928so914181276.1 for ; Wed, 30 Oct 2024 18:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339016; x=1730943816; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6uiHAaKIX2yVkUStL8pjT7UngaZd5XqJSnRpP3LDu9o=; b=OeazsVk5jyYpSMIKFio1cE88jSGj3g3EzvrjzIGGLEzLHUqE9RkbjwTajJ+l178Tou kFRRjSKGsQTvLkzOz44o9NvjXRkIa/oTfx9LG8Agr8SPB9Hwch3z01SgAMV5JCOleCIC 6LtLYIPe+izW+ikG8gSOWZcu0VPjwczxJgbTQ/JjmdLSw1ISJQJCTJRo8JrMYdz5JUD4 OuUoALx8l1gzcTxjoveTLooNpeFK6BTBQKBhAn56lmbGgL1Xz0EhjhCyaLNtgnUR3H5Z CSMqCexaFDW7Z/lBO6VGcM7fkrea29WAlXCcaGeA8okoOEs90j4C0pj5R0Rkq4kBdVXm U+NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339016; x=1730943816; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6uiHAaKIX2yVkUStL8pjT7UngaZd5XqJSnRpP3LDu9o=; b=kIWhu4FzoHfXQCjVXymAwwed/XEYc4UldShfZvxbhys16KdDW19vcPtRb3AuJcc+CO bple0cGywcca8G52n6kOSwuDth6u90o09HsPIr+umf5OY5VD9acJ+LtcIJBKok6McTES XQeNHM76qUolvYh9LDhACNxJmcZLg9/COL1GzAWpTAAqNawvp/Vt5cyfbbrsMKjvci1C k7Y0WducDEqgwrqGYSmyk7ms9iJ6SJWTYoPaJ8tCNAz4Y+kpo5xjQWGIDaQK79J0/Gl1 dsiG9jZ+/fah5TYirCMBm8qFhe0cy6O7hVHKmYPgF45ehJpsKDF6Tbxk0LIvjK0ouFts OMpg== X-Forwarded-Encrypted: i=1; AJvYcCXv8NzqbwPqxApm0vsg9VIVtPqKbozIeTJTeDsSqgLd+gv/ybHeRGAHJolAJw9UdufGUfftmNw0QXqAQ+8=@vger.kernel.org X-Gm-Message-State: AOJu0YwcdpTpPg5aMNVW8MIfXMTN1Dks3tSDSDsVCsezIy67Ct9zu4N2 LGqRCFMdHglWA5d9hn0mDKQssvDRjGW6AgDUDGd+/5bL4pEiYs1Fnpre/n2ZXqzrDEtU5MO0cdh i/wBfxQ== X-Google-Smtp-Source: AGHT+IGtW8phYXnOQvoQ0KuBpkZCVibLaAtDznaAlEOwKPQIEuGdac2PNuOtYTpak5scuI/HZig8HpOMqpeg X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a5b:bcd:0:b0:e29:b6d7:20e2 with SMTP id 3f1490d57ef6-e3087736bf6mr95579276.0.1730339015284; Wed, 30 Oct 2024 18:43:35 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:39 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 08/21] perf script: Move script_spec code to trace-event-scripting.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The script_spec code is referenced in util/trace-event-scripting but the list was in builtin-script, accessed via a function that required a stub function in python.c. Move all the logic to trace-event-scripting, with lookup and foreach functions exposed for builtin-script's benefit. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 67 +--------------------- tools/perf/util/python.c | 5 -- tools/perf/util/trace-event-scripting.c | 75 +++++++++++++++++++++++++ tools/perf/util/trace-event.h | 3 +- 4 files changed, 80 insertions(+), 70 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 62e851fdf5ca..11c0ee8c1afc 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2956,79 +2956,18 @@ static int __cmd_script(struct perf_script *script) return ret; } =20 -struct script_spec { - struct list_head node; - struct scripting_ops *ops; - char spec[]; -}; - -static LIST_HEAD(script_specs); - -static struct script_spec *script_spec__new(const char *spec, - struct scripting_ops *ops) +static int list_available_languages_cb(struct scripting_ops *ops, const ch= ar *spec) { - struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); - - if (s !=3D NULL) { - strcpy(s->spec, spec); - s->ops =3D ops; - } - - return s; -} - -static void script_spec__add(struct script_spec *s) -{ - list_add_tail(&s->node, &script_specs); -} - -static struct script_spec *script_spec__find(const char *spec) -{ - struct script_spec *s; - - list_for_each_entry(s, &script_specs, node) - if (strcasecmp(s->spec, spec) =3D=3D 0) - return s; - return NULL; -} - -int script_spec_register(const char *spec, struct scripting_ops *ops) -{ - struct script_spec *s; - - s =3D script_spec__find(spec); - if (s) - return -1; - - s =3D script_spec__new(spec, ops); - if (!s) - return -1; - else - script_spec__add(s); - + fprintf(stderr, " %-42s [%s]\n", spec, ops->name); return 0; } =20 -static struct scripting_ops *script_spec__lookup(const char *spec) -{ - struct script_spec *s =3D script_spec__find(spec); - if (!s) - return NULL; - - return s->ops; -} - static void list_available_languages(void) { - struct script_spec *s; - fprintf(stderr, "\n"); fprintf(stderr, "Scripting language extensions (used in " "perf script -s [spec:]script.[spec]):\n\n"); - - list_for_each_entry(s, &script_specs, node) - fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name); - + script_spec__for_each(&list_available_languages_cb); fprintf(stderr, "\n"); } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0fa8e27769be..3d938fe2de6a 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1305,11 +1305,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -int script_spec_register(const char *spec __maybe_unused, struct scripting= _ops *ops __maybe_unused) -{ - return -1; -} - arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) { return NULL; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 8abb7a7b6888..ad62d8e5a368 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -24,6 +24,81 @@ unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPT= H; =20 struct scripting_context *scripting_context; =20 +struct script_spec { + struct list_head node; + struct scripting_ops *ops; + char spec[]; +}; + +static LIST_HEAD(script_specs); + +static struct script_spec *script_spec__new(const char *spec, + struct scripting_ops *ops) +{ + struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); + + if (s !=3D NULL) { + strcpy(s->spec, spec); + s->ops =3D ops; + } + + return s; +} + +static void script_spec__add(struct script_spec *s) +{ + list_add_tail(&s->node, &script_specs); +} + +static struct script_spec *script_spec__find(const char *spec) +{ + struct script_spec *s; + + list_for_each_entry(s, &script_specs, node) + if (strcasecmp(s->spec, spec) =3D=3D 0) + return s; + return NULL; +} + +static int script_spec_register(const char *spec, struct scripting_ops *op= s) +{ + struct script_spec *s; + + s =3D script_spec__find(spec); + if (s) + return -1; + + s =3D script_spec__new(spec, ops); + if (!s) + return -1; + + script_spec__add(s); + return 0; +} + +struct scripting_ops *script_spec__lookup(const char *spec) +{ + struct script_spec *s =3D script_spec__find(spec); + + if (!s) + return NULL; + + return s->ops; +} + +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)) +{ + struct script_spec *s; + int ret =3D 0; + + list_for_each_entry(s, &script_specs, node) { + ret =3D cb(s->ops, s->spec); + if (ret) + break; + } + return ret; +} + void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index bbf8b26bc8da..81fceaf297ba 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -116,7 +116,8 @@ struct scripting_ops { =20 extern unsigned int scripting_max_stack; =20 -int script_spec_register(const char *spec, struct scripting_ops *ops); +struct scripting_ops *script_spec__lookup(const char *spec); +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)); =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, struct machine *machine); --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C164213B590 for ; Thu, 31 Oct 2024 01:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339021; cv=none; b=l7o+LgeFS15AOf4NcBYFhrOHQUoYgb/FcuBDRvp+Eo1w4WXYDYdUaoELtVqm74E8OSP5SfgGDLc8BmGY67jHbKyMhtAUCvdm2iaIbcBwew5QCRtNAlNc4nFnGl+YwzG1pEIJlfuq/zzEp/uPZFDaBd9Mtn6P+Snh3gLC9SJi4Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339021; c=relaxed/simple; bh=K8MBywRM9VYie83K/Ge+IX+DJ5KQde66JpktMNcoH1U=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ewyr6jr96b8aS2Brl8JmvfSEutIglwrA/kYqOKr1hpGi0zweizLElqMlc/YMSWIzNRvyUXCHmNOTUVp+0EKB66zADCXrdpd1BJLxwKf0vdbbNKtVbgPyJXw4jJobBbapP+5pU8SGIhmiThtBLOAHercQ0iBokmDJs5NmovdfyrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YiKwCkra; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YiKwCkra" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea258fe4b6so9127887b3.1 for ; Wed, 30 Oct 2024 18:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339018; x=1730943818; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=R0Dg3ZC4eOFcXD0FKfDkQR9jWSBdCYfi1JBGipnV6Sk=; b=YiKwCkrazEkPHk8+2C4h6asLcccUCivPoTiT5guHdGMPfZNIWLgnVJEBAGxtbin1Vo qdAbKFE6bziR1umpvfJQOwkSZjd0ICnfTvkrcfRxeBnUv65gPqPMOOEeMS8zy5Oh7dBh nxK309cRnlc/9wdvJaadrlEkQRDpTKS4X7dCdLH0ZTjM0tZRzeog5r5+d7zlp15AiBZ4 R7zQdLGfJ+X84ap608R11WPYoV+maBoPsC7qNB4JoL8jABCx9hhKecgRlX6p/iDJlui5 RBhQ3I/QCErnHXTwVUqCnaUojtMJPETcIReuz+xarqo2c5GGNy640gz1+/5v3DtewJK9 fkyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339018; x=1730943818; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R0Dg3ZC4eOFcXD0FKfDkQR9jWSBdCYfi1JBGipnV6Sk=; b=WUyroWCUvWjtdW86CZ+JB2nHQQL5Gknua6AXrsFlRCjqBTUjpGHTArbRr73j9hACm9 5vHXyHa8TFN2FxyNbWSkhnGrI1wqoG1COR39sVHXHATF28tCrwVddb/m2BjoJnu/ZuX2 end5EHKxeyumoVJSs1Y7PLzqe06vmZub2GuO0KlIV3iaaAs+WupP66UfnaElR9hOuZhq rV8CR+phG7Ry+05Z/i40TVZlmWG1+AP5MoYWMXwaABtLgjarELK0OJ1hsFZJgYvLOSRf 1gjWyA4yQerk344ydxPeJpviSaLqxG9wbJRwSo5a72sCPZJG5yPvqTGgryvMe9ovRgDR 2NMQ== X-Forwarded-Encrypted: i=1; AJvYcCWlbmHTJx93731qUmFROntkmLQkZRih7jXiyXml+gTPEzCe44ZlBo6rLV0ZFR2VWtxamCq7JBTzRIi4xiI=@vger.kernel.org X-Gm-Message-State: AOJu0YxAACqsABviHvDTMwoyWpK+IpZe/4pMBoD3/YnSGwwP2d2WNWXO oDUv+aSPkHhcS/T+Qun2vtb2Nrzy9bm0jkysRitA9+OkWTDeVGCjbHPruhPN908nPECgddUww8S fOUYKRg== X-Google-Smtp-Source: AGHT+IF1rP5Msd1P6O0UYnEIUmpAMH6Jbste9JWLyi8Wl1w59KncQO0H7ERpr3LZu+N//L79UZ/6voNz4uwo X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:4b85:0:b0:e29:68a9:8612 with SMTP id 3f1490d57ef6-e3087a54ccemr76572276.4.1730339017743; Wed, 30 Oct 2024 18:43:37 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:40 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 09/21] perf script: Move script_fetch_insn to trace-event-scripting.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add native_arch as a parameter to script_fetch_insn rather than relying on the builtin-script value that won't be initialized for the dlfilter and python Context use cases. Assume both of those cases are running natively. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 15 +-------------- .../perf/scripts/python/Perf-Trace-Util/Context.c | 2 +- tools/perf/util/dlfilter.c | 3 ++- tools/perf/util/python.c | 6 ------ tools/perf/util/trace-event-scripting.c | 14 ++++++++++++++ tools/perf/util/trace-event.h | 2 +- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 11c0ee8c1afc..22d78a9d8f27 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1586,19 +1586,6 @@ static int perf_sample__fprintf_callindent(struct pe= rf_sample *sample, return len + dlen; } =20 -__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - -void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine) -{ - if (sample->insn_len =3D=3D 0 && native_arch) - arch_fetch_insn(sample, thread, machine); -} - static int perf_sample__fprintf_insn(struct perf_sample *sample, struct evsel *evsel, struct perf_event_attr *attr, @@ -1608,7 +1595,7 @@ static int perf_sample__fprintf_insn(struct perf_samp= le *sample, { int printed =3D 0; =20 - script_fetch_insn(sample, thread, machine); + script_fetch_insn(sample, thread, machine, native_arch); =20 if (PRINT_FIELD(INSNLEN)) printed +=3D fprintf(fp, " ilen: %d", sample->insn_len); diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index d742daaa5d5a..60dcfe56d4d9 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -93,7 +93,7 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject= *args) if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread))= { struct machine *machine =3D maps__machine(thread__maps(c->al->thread)); =20 - script_fetch_insn(c->sample, c->al->thread, machine); + script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=3D*/t= rue); } if (!c->sample->insn_len) Py_RETURN_NONE; /* N.B. This is a return statement */ diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index 7d180bdaedbc..ddacef881af2 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -234,7 +234,8 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len) struct machine *machine =3D maps__machine(thread__maps(al->thread)); =20 if (machine) - script_fetch_insn(d->sample, al->thread, machine); + script_fetch_insn(d->sample, al->thread, machine, + /*native_arch=3D*/true); } } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3d938fe2de6a..22edadd64e5f 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -void script_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, size_t sz __maybe_unused) { diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index ad62d8e5a368..beac456260ae 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -13,6 +13,7 @@ #include #endif =20 +#include "archinsn.h" #include "debug.h" #include "trace-event.h" #include "evsel.h" @@ -269,3 +270,16 @@ void setup_perl_scripting(void) } #endif #endif + +__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, + struct thread *thread __maybe_unused, + struct machine *machine __maybe_unused) +{ +} + +void script_fetch_insn(struct perf_sample *sample, struct thread *thread, + struct machine *machine, bool native_arch) +{ + if (sample->insn_len =3D=3D 0 && native_arch) + arch_fetch_insn(sample, thread, machine); +} diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 81fceaf297ba..e0bb42e6509e 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -120,7 +120,7 @@ struct scripting_ops *script_spec__lookup(const char *s= pec); int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)); =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine); + struct machine *machine, bool native_arch); =20 void setup_perl_scripting(void); void setup_python_scripting(void); --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B18813D245 for ; Thu, 31 Oct 2024 01:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339023; cv=none; b=gSW0v9sPmnXqv3EgmH6Llq1Qx0c1UDqsSm6oDfLmU8MRdmpURJRP4U2hUD5foXm05qU+CaiZw0G5z93uD/PudAd3BqtPZ3f4lgyPyq3Dx/F9XJnU5fILV/RXyvrUOeBbyg8hpU25kXrrCzCW1GtTIrxHJVS2RwraksCcOMtkuCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339023; c=relaxed/simple; bh=zMeecy7/smWWbX5JVxugJXTBkHPzGUQGmIH9BZfWEU8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=J9l5uH1hKNZ8dDN+uAlbrlrjxU4uqool6+6ycoW27/xkYcqZ0i65zfdxLV9kTGc4TOpt4HB0B5V+GKuLRbCOhGwbpASjDe3+JtoiT1oSbvFzUoEpIagO8itkiiYbepGnOuNGQ8Uqn44ynTyFzJ8hBvLGgLgkP8hYsPfBfm5Bnc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NQtgxhYr; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NQtgxhYr" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e30cd709b40so807362276.1 for ; Wed, 30 Oct 2024 18:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339020; x=1730943820; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=aIG2rq27RxuU3SrtyLvz5J2CM3te2VzhilM3WPSQ4As=; b=NQtgxhYr55hiXMyx+CSdDiD4nBa+y4ersLtGDxd25pgIfl2Zw3g556kgrKwv2JuTu6 dl4RZ9OQXDgXwmQJ8MQs9Y7oRlJ0wZMWF/FU6h+wG7VBhYH9SbDyTEunXXh5ANNcrK0T RHrWjNaTN1Qq5ftcyEsXl9nZqiIYD0GJYILtJdEtry9miPrl+5gdXB/FAks6sukIgjsA TfRPf8drh5RT8SeJN0IlKOZ2Y3aAlBQxZAzpvh5J1SPyNkCkesR3cOh4bK2VGwSRO5Mw wRUkM2jXnaahGiEVef7DT8RR8rlmGEiV8zdaofKL5FXLS5TY0AmlIvvSRJ0NCzukpvcu LiyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339020; x=1730943820; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aIG2rq27RxuU3SrtyLvz5J2CM3te2VzhilM3WPSQ4As=; b=iKw3Hmnc0Xb3GzcScY/r9gpYPkd+JyqcY6IbqfR7vfH+UiXIXrwVR4vY9Jkk3xHwmq OCAbb4WM6l5Ychbacx+pGlCfE3akP8zN9Ei74YUzChqm5Yp/wBvVZv1SRBbX5bzalorb BjVMODGM/v/Ya6TX91of0aLG0TelImvd2ujY9Wl1Cu0wY9T3mYS6k9C/RMdU7K3311NZ KsueGLFMcF5s/QEOE56g1k17UxcAFkLtRWp6dPn6UWT5xG1+F+90jOg/Wbcc4GRkhFJY g/lh6iiefg9zTpb8sbaGdP/5I1A0wx3b1S5hHxkVEtXgtAE6RPORynlgoSQ0Dj6o4t3e zNQQ== X-Forwarded-Encrypted: i=1; AJvYcCWCse5Fph9cm1V1u+s45aG9wMVu0BoR9JsZOb7BC0TxDtDomYtho0O+UDbEgfUStp0bpFscdX8+xRvar34=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Mp8sL3aL94lIKr2cjZa2vV1R/ehu7P15YUhkTm3BJ3KrTMz5 elBF0dWmi/pAG/EAR9BsoighRRBrIWp2urIU9aX+bKdf4z9W4gp8WEXTyd+tCMjfdhbctXjojrN wEi25cQ== X-Google-Smtp-Source: AGHT+IHzA+wOxNKEWWHOYzf5aDHV9IRu8jnhkG9ujTbzcDUuPo4sTsvFQ39Gyr+/Aekz2wO12kQ1Bx6+U4P+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:aace:0:b0:e28:f35b:c719 with SMTP id 3f1490d57ef6-e3087bd6066mr51467276.6.1730339019914; Wed, 30 Oct 2024 18:43:39 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:41 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 10/21] perf script: Move perf_sample__sprintf_flags to trace-event-scripting.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_sample__sprintf_flags is used in the python C code and so needs to be in the util library rather than a builtin. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 81 ------------------------ tools/perf/util/python.c | 6 -- tools/perf/util/trace-event-scripting.c | 83 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 87 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 22d78a9d8f27..1eda065dcb2b 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1693,87 +1693,6 @@ static int perf_sample__fprintf_bts(struct perf_samp= le *sample, return printed; } =20 -static struct { - u32 flags; - const char *name; -} sample_flags[] =3D { - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, - {PERF_IP_FLAG_BRANCH, "jmp"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, "hw int"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, - {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, - {0, NULL} -}; - -static const char *sample_flags_to_name(u32 flags) -{ - int i; - - for (i =3D 0; sample_flags[i].name ; i++) { - if (sample_flags[i].flags =3D=3D flags) - return sample_flags[i].name; - } - - return NULL; -} - -int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) -{ - u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | - PERF_IP_FLAG_INTR_TOGGLE; - const char *chars =3D PERF_IP_FLAG_CHARS; - const size_t n =3D strlen(PERF_IP_FLAG_CHARS); - const char *name =3D NULL; - size_t i, pos =3D 0; - char xs[16] =3D {0}; - - if (flags & xf) - snprintf(xs, sizeof(xs), "(%s%s%s)", - flags & PERF_IP_FLAG_IN_TX ? "x" : "", - flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", - flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); - - name =3D sample_flags_to_name(flags & ~xf); - if (name) - return snprintf(str, sz, "%-15s%6s", name, xs); - - if (flags & PERF_IP_FLAG_TRACE_BEGIN) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); - if (name) - return snprintf(str, sz, "tr strt %-7s%6s", name, xs); - } - - if (flags & PERF_IP_FLAG_TRACE_END) { - name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); - if (name) - return snprintf(str, sz, "tr end %-7s%6s", name, xs); - } - - for (i =3D 0; i < n; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D chars[i]; - } - for (; i < 32; i++, flags >>=3D 1) { - if ((flags & 1) && pos < sz) - str[pos++] =3D '?'; - } - if (pos < sz) - str[pos] =3D 0; - - return pos; -} - static int perf_sample__fprintf_flags(u32 flags, FILE *fp) { char str[SAMPLE_FLAGS_BUF_SIZE]; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 22edadd64e5f..77e02fcc51dd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, - size_t sz __maybe_unused) -{ - return -1; -} - bool match_callstack_filter(struct machine *machine __maybe_unused, u64 *c= allstack __maybe_unused) { return false; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index beac456260ae..2e9da0b089ef 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -15,6 +15,7 @@ =20 #include "archinsn.h" #include "debug.h" +#include "event.h" #include "trace-event.h" #include "evsel.h" #include @@ -283,3 +284,85 @@ void script_fetch_insn(struct perf_sample *sample, str= uct thread *thread, if (sample->insn_len =3D=3D 0 && native_arch) arch_fetch_insn(sample, thread, machine); } + +static const struct { + u32 flags; + const char *name; +} sample_flags[] =3D { + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, + {PERF_IP_FLAG_BRANCH, "jmp"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "ire= t"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "sysc= all"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sy= sret"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_F= LAG_INTERRUPT, + "hw int"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMENTRY, "vmentry= "}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_VMEXIT, "vmexit"}, + {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_BRANCH_MISS, "br miss"}, + {0, NULL} +}; + +static const char *sample_flags_to_name(u32 flags) +{ + int i; + + for (i =3D 0; sample_flags[i].name ; i++) { + if (sample_flags[i].flags =3D=3D flags) + return sample_flags[i].name; + } + + return NULL; +} + +int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) +{ + u32 xf =3D PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE | + PERF_IP_FLAG_INTR_TOGGLE; + const char *chars =3D PERF_IP_FLAG_CHARS; + const size_t n =3D strlen(PERF_IP_FLAG_CHARS); + const char *name =3D NULL; + size_t i, pos =3D 0; + char xs[16] =3D {0}; + + if (flags & xf) + snprintf(xs, sizeof(xs), "(%s%s%s)", + flags & PERF_IP_FLAG_IN_TX ? "x" : "", + flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "", + flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : ""); + + name =3D sample_flags_to_name(flags & ~xf); + if (name) + return snprintf(str, sz, "%-15s%6s", name, xs); + + if (flags & PERF_IP_FLAG_TRACE_BEGIN) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN)); + if (name) + return snprintf(str, sz, "tr strt %-7s%6s", name, xs); + } + + if (flags & PERF_IP_FLAG_TRACE_END) { + name =3D sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END)); + if (name) + return snprintf(str, sz, "tr end %-7s%6s", name, xs); + } + + for (i =3D 0; i < n; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D chars[i]; + } + for (; i < 32; i++, flags >>=3D 1) { + if ((flags & 1) && pos < sz) + str[pos++] =3D '?'; + } + if (pos < sz) + str[pos] =3D 0; + + return pos; +} --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F13913DDA7 for ; Thu, 31 Oct 2024 01:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339025; cv=none; b=LOMUHbWoRGm+elqq5OLcK/0BGx3mnIw7YMcgfDvi2zAXkij/9IYKWE/hE0QrNFNofQHcGu57iA71vmFQdWjrsuc8ieJChEQ/moszTQkD05tdD6t/l53rvbeKf+PJmG0uehS0I4BByXGrgzLB9gs8zE1ZjLTuM5U6DEBDIeGmLgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339025; c=relaxed/simple; bh=82bijJeRZvQKffUYSp6pgeymdNvCFHYsEPeLvVMlPr4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DwwV7UlwAIs/0UxxjeA+tNGtq4KCQsiNVnrar/MSl9iQyBpoYlfPGBLxTjWh6CF59wHLXku0q0qlGN1z5zQlscnJvqZX8Khgi/4fCbssveNMHFFBVptpHR9AdrWXOnKi4xQa8UaLBDFoW/P+tqMlsFTYm8MM4ayHIZtMzmTZAzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eonBIH3z; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eonBIH3z" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3497c8eb0so6020717b3.0 for ; Wed, 30 Oct 2024 18:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339022; x=1730943822; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ZD7VBq2UGR6iF+9N7VjgPo1K8yaYKmQwzvOlxr3CE1U=; b=eonBIH3zCzg8KRJaTDSDHr9rkgvGAszuxrCer46Fm8KbzCsDqLRL0fxvy+NjO2Nf3k H1/+tVhvsIvtv6yj5LnQD2QUxZ/xR1ouPh6eoFhTPx2Ca3fKmoQLQ8UmvyKr56Qkea1d iG7Y9IUZW21KA/sItudj4lQSY3zVL6NoDcp//zLVl25JtfQPnYWrVn/sWX3uZqnawSWS /c+118dg10aKeEJCilSQgievuD9vcbQ4kWkJ3LLstqJP1JH16rS26z8FUt7aLBlgmj49 zdrPuwjlfyenBd2HejP7YXPMNiknziQIzqYZCZZcmRa+u7jqmptGXs8FEfAMzhDKfG1P +7nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339022; x=1730943822; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZD7VBq2UGR6iF+9N7VjgPo1K8yaYKmQwzvOlxr3CE1U=; b=dT6+NmJqkAn4KecAFBJWLsM7+hLiIoi5S8FX7KYe1in+J78yivYo96HC7wA8d0ijR7 GUISBtRn1IyqY7Ubsey8d2f72/ILOZaJBYtHSfyqm96hYWWl8LV2MI88ozmtHKJBEmxg O0eHrVuGDWtCdzWV/LNVNH6JNAPjfBRdiioZ8NPte3wq1Ps7FsFDvk5reEGL3OzFhiVh 85Ilsba/7CIGlOn8AC4jmyv3zVflRBzRcZA1RJkgwHsncU/8vTkpZIFquxxTIRkBDStt KH+pRhmNIrpXzBaCwi2t6zPg2h7Toa/Qp8gUr44GE/x73MfWc1IYLTJhdxvSu15Zo0Oo c5iw== X-Forwarded-Encrypted: i=1; AJvYcCWfXqo5zOIpS5xbVCK88W3lqEGhbpp0DBLb9+DsNglg8L4lb0aJhZj+CVpkztoAOEOaIaSugxhBG9AXF8A=@vger.kernel.org X-Gm-Message-State: AOJu0Ywsg7g4u3jrt2w5HXPMF/fs0+9rF1KcZe/5MiJqY+D7VuxtZkgW Uz0GPvhiuoDdEPzsx6dAbwYpRYFcPAMLQZ5QGJ2b8LIMsH5K5PVzAP1cvgW/8R5MJ1/24IgY9UP D71cCIw== X-Google-Smtp-Source: AGHT+IGD2zl5CoM1dn1fd62QFAfNFk6dQhVlQX2zqIA8JQBYZtzbSCfBNBohWHmQXmShCDO3HgNQb3NdUTNe X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a0d:d1c3:0:b0:6d9:d865:46c7 with SMTP id 00721157ae682-6ea5576f128mr31617b3.2.1730339022068; Wed, 30 Oct 2024 18:43:42 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:42 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 11/21] perf x86: Define arch_fetch_insn in NO_AUXTRACE builds From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" archinsn.c containing arch_fetch_insn was only enabled with CONFIG_AUXTRACE, but this meant that a NO_AUXTRACE build on x86 would use the empty weak version of arch_fetch_insn - weak symbols are a frequent source of errors like this and are outside of the C specification. Change it so that archinsn.c is always built on x86 and make the weak symbol empty version of arch_fetch_insn a strong one guarded by ifdefs. arch_fetch_insn on x86 depends on insn_decode which is a function included then built into intel-pt-insn-decoder.c. intel-pt-insn-decoder.c isn't built in a NO_AUXTRACE=3D1 build. Separate the insn_decode function from intel-pt-insn-decoder.c by just directly compiling the relevant file. Guard this compilation to be for either always on x86 (because of the use in arch_fetch_insn) or when auxtrace is enabled. Apply the CFLAGS overrides as necessary, reducing the amount of code where warnings are disabled. Signed-off-by: Ian Rogers Tested-by: Adrian Hunter Tested-by: Arnaldo Carvalho de Melo --- tools/perf/arch/x86/util/Build | 2 +- tools/perf/util/Build | 2 +- tools/perf/util/intel-pt-decoder/Build | 18 ++++++++++++++---- .../intel-pt-decoder/intel-pt-insn-decoder.c | 3 --- tools/perf/util/trace-event-scripting.c | 4 +++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index bc56a8e70f34..c5df4a2cf180 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -18,6 +18,6 @@ perf-util-$(CONFIG_LOCAL_LIBUNWIND) +=3D unwind-libunw= ind.o perf-util-$(CONFIG_LIBDW_DWARF_UNWIND) +=3D unwind-libdw.o =20 perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o -perf-util-$(CONFIG_AUXTRACE) +=3D archinsn.o +perf-util-y +=3D archinsn.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-bts.o diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 650974413849..340544a6f5ec 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -122,7 +122,7 @@ perf-util-y +=3D iostat.o perf-util-y +=3D stream.o perf-util-y +=3D kvm-stat.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o -perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt-decoder/ +perf-util-y +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o perf-util-$(CONFIG_AUXTRACE) +=3D intel-bts.o perf-util-$(CONFIG_AUXTRACE) +=3D arm-spe.o diff --git a/tools/perf/util/intel-pt-decoder/Build b/tools/perf/util/intel= -pt-decoder/Build index 30793d08c6d4..f99d150059b9 100644 --- a/tools/perf/util/intel-pt-decoder/Build +++ b/tools/perf/util/intel-pt-decoder/Build @@ -9,14 +9,24 @@ $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tabl= es_script) $(inat_table =20 # Busybox's diff doesn't have -I, avoid warning in the case =20 -$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-deco= der/intel-pt-insn-decoder.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c +ifeq ($(SRCARCH),x86) + perf-util-y +=3D inat.o insn.o +else + perf-util-$(CONFIG_AUXTRACE) +=3D inat.o insn.o +endif + +$(OUTPUT)util/intel-pt-decoder/inat.o: $(srctree)/tools/arch/x86/lib/inat.= c $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(call rule_mkdir) $(call if_changed_dep,cc_o_c) =20 -CFLAGS_intel-pt-insn-decoder.o +=3D -I$(OUTPUT)util/intel-pt-decoder +CFLAGS_inat.o +=3D -I$(OUTPUT)util/intel-pt-decoder + +$(OUTPUT)util/intel-pt-decoder/insn.o: $(srctree)/tools/arch/x86/lib/insn.c + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) =20 ifeq ($(CC_NO_CLANG), 1) - CFLAGS_intel-pt-insn-decoder.o +=3D -Wno-override-init + CFLAGS_insn.o +=3D -Wno-override-init endif =20 -CFLAGS_intel-pt-insn-decoder.o +=3D -Wno-packed +CFLAGS_insn.o +=3D -Wno-packed diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/too= ls/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c index 47cf35799a4d..8fabddc1c0da 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c @@ -11,9 +11,6 @@ #include #include "../../../arch/x86/include/asm/insn.h" =20 -#include "../../../arch/x86/lib/inat.c" -#include "../../../arch/x86/lib/insn.c" - #include "event.h" =20 #include "intel-pt-insn-decoder.h" diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 2e9da0b089ef..8d71998a9ecd 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -272,11 +272,13 @@ void setup_perl_scripting(void) #endif #endif =20 -__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, +#if !defined(__i386__) && !defined(__x86_64__) +void arch_fetch_insn(struct perf_sample *sample __maybe_unused, struct thread *thread __maybe_unused, struct machine *machine __maybe_unused) { } +#endif =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, struct machine *machine, bool native_arch) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07155142E67 for ; Thu, 31 Oct 2024 01:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339026; cv=none; b=dfCKy5mkQCuwK6fCUu6/+4xWHBJSYmPtxXzqk7rS9FQTlQvoGGtplvYAXBh0QMfY2epbJv8unLsHAJdvImj+C9Y/f8XYkqNoIkiWbY3FE8+AFRO/VSgPYkCnz3P8HteAKz2VSKYYuw/1IYd7SxCbxO1wrAEYatbtleglD/m3Ysk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339026; c=relaxed/simple; bh=DLQSr6SnK+8kn/RmCu+SnzxGcgCWeuDWyrx6+bcBl+s=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LA1c0jGjAJxBZvH8dnAqpXQvn7Gu0yk3B/2+vV0CZXJs8o1jvSqnMvswKhhp14cUEHJJ3jdR/DAnxOgbLBR4AWkokqja9Z2A+3QceWNTvr3pDVgtmZ8bi0LdM3mNeOZNVyMYSbz9UApfF4OWR0Rl20LpCjENLAPFfhArn3P+erM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uZalzd1W; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uZalzd1W" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e9e897852fso8707637b3.3 for ; Wed, 30 Oct 2024 18:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339024; x=1730943824; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5AVgUHfJDItQA9RxyoIMfq8JR0bFjxdZgjCoy85Lj8s=; b=uZalzd1WLyPminW80awrnT6fZCE4DZhhU2wg03xE4GF4iBpHQ6xADO6gg2nQKU1fZO /iDcP9mxiGegnuL1nRf/KH/VQf6z7lVIx8PMspV2qsFnmXjszzIFShQ8cnrF27P/fy8s XfNnAMg3k6FkW7MYdWf/jyvzd5sFcNRudzotcVUim2L+95vM/IlAgoEeUNTsPd5C4L6Q Zg5SQXwt5u2UnkqYeJsCQ3DFBvenbkSq8HGM2E/IDzHXHdebdssuCHJ2MNSTwlnLEVrr GjRy6QKn/5qBr4eUKyLSP6YTFCwq0OJRgzddJXrWaDlyFeD5lRbrnvctfNs2VL2Ytr9Y k+ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339024; x=1730943824; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5AVgUHfJDItQA9RxyoIMfq8JR0bFjxdZgjCoy85Lj8s=; b=EGe9ktQl265DSMmg9TLKugYCBI+9gliLwn6mDopcIkUThDnkjGUxzHqfzkOTNE/a5Z zSPory039Gf+nY4O/DG2PeQZcRgnORA1dF4+Iu76aVDc4x5fCSQGFiZztH4/b8lhNeij e48j6p2AWeh8lhP1yxdQL3c4M7Acsp4me5yf/uZVieRtySAxsYWdU1kt9Wgln62RVFVO aSbBQIWZrUirt//7CO2im5niWiD4qTFAmyusntnBRF6F0pzE5dEItUB602Y6PRIVLy7y 8o0/Tpvjwr8P4zq5pZuqhlK+/8zy80wr3l2Q0uvvmuxAIu8XpNnthMwurmiuKpNxEnJV bALg== X-Forwarded-Encrypted: i=1; AJvYcCXJGaJdyCcf+lG4H7J5KNOoDnM3RZmw7Q26acRO9tppyPN8SsxNT5lZd7wU6WGPm7wXSAjBoNqrprDhWU4=@vger.kernel.org X-Gm-Message-State: AOJu0YwUhOCiVk9w8S833M9zFyQbbFFm277rAXXu0/CaPvR+jt0Hs+t6 dvHzpBECK/5yXkDQTuqJ+yfUjKxdBwWiAPdrLO4Zrh+uEHxhTlFI7rK1Knw8XL7nNVNVR+53cVl J/YCjmw== X-Google-Smtp-Source: AGHT+IGWaNJtf4/sIlqPPGJnBicFjuTejugTBGvCf+W6KOXLnebs9Hw1u+rJ+APnqGqmZvtWD0iNxWHEowVb X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a05:690c:f:b0:6e3:6414:80c5 with SMTP id 00721157ae682-6e9d87b4522mr7889527b3.0.1730339024226; Wed, 30 Oct 2024 18:43:44 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:43 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 12/21] perf intel-pt: Remove stale build comment From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 00a263902ac3 ("perf intel-pt: Use shared x86 insn decoder") removed the use of diff, so remove stale busybox comment. Signed-off-by: Ian Rogers Acked-by: Adrian Hunter Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/intel-pt-decoder/Build | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/Build b/tools/perf/util/intel= -pt-decoder/Build index f99d150059b9..5b8f0149167d 100644 --- a/tools/perf/util/intel-pt-decoder/Build +++ b/tools/perf/util/intel-pt-decoder/Build @@ -7,8 +7,6 @@ $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tables= _script) $(inat_table $(call rule_mkdir) @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) = > $@ || rm -f $@ =20 -# Busybox's diff doesn't have -I, avoid warning in the case - ifeq ($(SRCARCH),x86) perf-util-y +=3D inat.o insn.o else --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C4AD142E9F for ; Thu, 31 Oct 2024 01:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339029; cv=none; b=hw3B/dp1jvoVk8zsAApuIDel39asKZUZttYDVVcxFuNNYHHi2KobTmilB50HHhxAQRgRWhMbdiaOze287W0wNlRKrIRfxUlD8yRiMxi9eGMMHGFcX2XCEMbLPC/y5rJQdhA9UVZuiCq3uhOoV7SZqrWNytRPpyzS4bO7Cv3Y7gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339029; c=relaxed/simple; bh=Y7k15MkT30/A8lyrkiuyGM2T9Ad6ytcpFrWreD4e5Yc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KEbZb81La+kDdNNMBz5iOzzxlnCLyG/Txg26lxMOr12vH8ipz8WQCV9CRgqPBQZ0aQb4G0L5W8fEtPz2d84mPeWnF1DulwKYnlBeoSQXWLaN5Oej6qNchWO/dDXjFd4ggl+vh9+ogtaJLQgs7U7HHw5Nw1zV0aF4QN+zU1hSt6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZXrYtOr2; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZXrYtOr2" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e7fb84f99cso8862267b3.1 for ; Wed, 30 Oct 2024 18:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339026; x=1730943826; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Bgmf/JpaloLQYHqwCvUuDV8PrkKL2cewLYYHkwF5BH4=; b=ZXrYtOr2BfISzNN+dFvLdv2h0EBVztVo/9K09ZQLbGBWct5fHEvwQ9ANMYfuszjBme lp91dtEb3JmQo0p1sCDyIVm+NZm5aBBmIKsaDgc8frT/FQ97inM3nptDvHOBY3unnKyv CWUnUrq8BqcbdNa/qswjAULnvUvwzY7EUWG90OVZ+gXNK6Z3Q5NZLZFReWEGtvw/hjLL suEgNYl36dtmDdwraMyU3aigE+lCRX42xoW4PSmZHgMhFTWjnYaFrbzgpiA+DbcZIt2o 3nNSpWi2/jqv4P66m6K5ml7LoGBrSE0yC+xxxPqPiM6HlwnuGt5J8ME+WBD+GMKkdzym Cw5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339026; x=1730943826; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bgmf/JpaloLQYHqwCvUuDV8PrkKL2cewLYYHkwF5BH4=; b=oafovBwCvhwdSzDZlyZm0yUvjqPtWO7lzHOnWEcSkgPA1gVymvO5IXUeEJfmuf5JW0 zvbmrEG0NerSQex3svnCPHKFr5DoWjufeE8C7Gyx44EO7cp3l4liM7MkZU1/2BH/nJlB 3yTPkjwXiVaIFlse9wMLlBRUE9zNER/PbRrMBym+4tY6aGi6hn9QHyuhEeFZQiMD5qou ivMNT2RE9f/yPZ14GZyVLhdFIKjM/+Kx9+n46eNR1FqaCbx3pDZ9SheyzJ3ylAP3hID7 +J8wZysDEdLZiPZYHvSCNfgi+WF+ADCwl5moOKWU62igVLybAtoFh6rqwLiIr1MQKeNo wQBQ== X-Forwarded-Encrypted: i=1; AJvYcCWag5Zs6e2z7rfOfn7eCwm7J2fwhn26J8ZbveBDhjAbcztNs1Ws5EMEJvW/YBhUQ0EVBOULl1RndI/gyDA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywa9T5aJgYkm4I+LVn8brr+9PEveSSEFvVZ02YQOxXxwHuG6Suj l8GCPQ7I1S7fXBbaoO4m/vnfTvC22uoCOcCYv79VY+mABetgWJxjekpUcgFg5i9rZUztoVppob5 /N1yvbg== X-Google-Smtp-Source: AGHT+IEndKaU9Rg6Vbq1IfTDr5MuubT+9yr9iLYbMbcYGark7QvH+rUTuEDXrJ85fBxDVmbmN1K9W9CyRsAE X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:2d28:0:b0:e2b:d0e9:1cdc with SMTP id 3f1490d57ef6-e3087c2be5emr93866276.10.1730339026305; Wed, 30 Oct 2024 18:43:46 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:44 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-14-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 13/21] perf env: Move arch errno function to only use in env From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move arch_syscalls__strerrno_function out of builtin-trace.c to env.c so that there isn't a util to builtin function call. This allows the python.c stub to be removed. Also, remove declaration/prototype from env.h and make static to reduce scope. The include is moved inside ifdefs to avoid, "defined but unused warnings". Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 1 - tools/perf/trace/beauty/arch_errno_names.sh | 3 ++- tools/perf/util/env.c | 4 ++++ tools/perf/util/env.h | 2 -- tools/perf/util/python.c | 6 ------ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 748b061f8678..5d0345480140 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1108,7 +1108,6 @@ static bool syscall_arg__strtoul_btf_type(char *bf __= maybe_unused, size_t size _ .strtoul =3D STUL_STRARRAY_FLAGS, \ .parm =3D &strarray__##array, } =20 -#include "trace/beauty/arch_errno_names.c" #include "trace/beauty/eventfd.c" #include "trace/beauty/futex_op.c" #include "trace/beauty/futex_val3.c" diff --git a/tools/perf/trace/beauty/arch_errno_names.sh b/tools/perf/trace= /beauty/arch_errno_names.sh index 30d3889b2957..b22890b8d272 100755 --- a/tools/perf/trace/beauty/arch_errno_names.sh +++ b/tools/perf/trace/beauty/arch_errno_names.sh @@ -57,7 +57,8 @@ create_arch_errno_table_func() archlist=3D"$1" default=3D"$2" =20 - printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const= char *arch)\n' + printf 'static arch_syscalls__strerrno_t *\n' + printf 'arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do arch_str=3D$(arch_string "$arch") diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ccb464026642..e58f56412fbb 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -470,6 +470,10 @@ const char *perf_env__arch(struct perf_env *env) return normalize_arch(arch_name); } =20 +#if defined(HAVE_SYSCALL_TABLE_SUPPORT) && defined(HAVE_LIBTRACEEVENT) +#include "trace/beauty/arch_errno_names.c" +#endif + const char *perf_env__arch_strerrno(struct perf_env *env __maybe_unused, i= nt err __maybe_unused) { #if defined(HAVE_SYSCALL_TABLE_SUPPORT) && defined(HAVE_LIBTRACEEVENT) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index ae604c4edbb7..e9db89395dab 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -56,8 +56,6 @@ struct pmu_caps { =20 typedef const char *(arch_syscalls__strerrno_t)(int err); =20 -arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch); - struct perf_env { char *hostname; char *os_release; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 77e02fcc51dd..35d84a96dbec 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/env.h" #include "util/kwork.h" #include "util/sample.h" #include "util/lock-contention.h" @@ -1305,11 +1304,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) -{ - return NULL; -} - struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_un= used, struct kwork_class *class __maybe_unused, struct kwork_work *key __maybe_unused) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D1991482ED for ; Thu, 31 Oct 2024 01:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339033; cv=none; b=ax0Nw7Hun844jBDoIM6nMaewKO2iqSlhOj50skY9BnmkDnB4ATl3/IuuV9TDL6se7DPNYwpSpym0nvkixxB11SnYFmCczBvwhAVNLVA8f+1mFOMsl5FS/kkVQ+eJy8SU3gT13rOIOa+JpaBhTSTZJMpl0cUKt4fFXJ9onFIaB5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339033; c=relaxed/simple; bh=iHOKIdkJKn5OohvH2Y5eDxRnBsLlbcQV9FkSQyGhP0Y=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=oC3ZSNNOR4DRqzTnti6zFjTOPHK9pBcjkjMPadzi8AazQdZ6b9WyLJarp53xIlCC0hvwuNUZkpCO9zg+8MIWziyiKrQx7unz2QzutEX63gdPz59YWST0VmvEwdXwhXs9pty5F3p9w6eIdH+MSnHCDPp3sXt6zeF38CBW60lOvfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EoE3pB2A; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EoE3pB2A" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e38562155bso10227317b3.1 for ; Wed, 30 Oct 2024 18:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339029; x=1730943829; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=QgKZjzUuV/L3+to29vj/idvGzpfhLPLw+vFOZgW77l8=; b=EoE3pB2Ab5OnowVUL+P5OmOJmDUz2OoeNTIU1HTWx1v14MjRPCVXOroubh8SX03Vas HZZBo+lt+nQ6sDxFu4S68mwf91u48FfIUrJ0F+lVSFc3rKBpQTSXONt63MaQqIqI4nZn vogQNbUUAuDEHJVBDM2dE8+DJVoECfxUo9L8XUSF3VvAJ9Uaia/Z37+l7xIQhDSLc3Cj 3c7Rx3x70m7TsXvt6VAtIKPBWvHZvslhO2i0N8WVQFHNk/fQbHCgpIT9KzFquHjt107+ 9TMQJAwsZIOx96RHzApD8uLSReOa4BV/0zg+27Yn5hDTiYnopWbLPXey3rHie0UIOwaa 8qSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339029; x=1730943829; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QgKZjzUuV/L3+to29vj/idvGzpfhLPLw+vFOZgW77l8=; b=wW3sEMnGZZJmMTbILrIo1JXdRaUhcWV+B8TI38e8M8exUSE+pmlbMjpf1pLFdb4pSN p2VK25d6cO2nK1oaorKEOnir4crQEEOySJUnaN9nmXKy2TvJQ/JaLEim11GTZdmkXYci tjKtGEj4bd4/7BeqX+BYNl0tFXvdb8/ghjmQ0szqvLUfXwOPiAUgUysizUR3NUVMAALs ziGh5HVOjAbxa3Jd/bELFTLFzD4eQ95KucViA0RP4mWNFuF7z43p/iftG8SXW5I4BgNk t2JADMzjqp7mkNNXc6omVMt+D7uAXlsoIA2TZ4KBVbQrZ8bqDaCypdr7bMu8PvDtpbW9 VA8w== X-Forwarded-Encrypted: i=1; AJvYcCX7pK6QWqzx/Q2OlYZ80YCM1J/HxXs5icHQNy8Po2X3zSZtaunTBck+QihCZFSq/sNiVCuEfAuXGUwpSm0=@vger.kernel.org X-Gm-Message-State: AOJu0YxxRDYhUMGCfGkh+F63CZwifkHqZkdcOcyZcPp3csJyMbima21v dIrYd7NLXtmEhEJ3QE3ccV68S9EMEb4ryPTda2CyUtvyE1FES4aIs6YpnS4LI8gfG+IlsFzI1Mk 4XpyTOg== X-Google-Smtp-Source: AGHT+IESYhHH0YHqZZP/CUDn21hDBb+ojNf+QFDtv5NrSAaC4jOualWN+74xgiHkIoPV01shsDPUjpoJfyzW X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a05:690c:6383:b0:6e2:ad08:4924 with SMTP id 00721157ae682-6e9d8aacb2dmr10893567b3.4.1730339028213; Wed, 30 Oct 2024 18:43:48 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:45 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-15-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 14/21] perf lock: Move common lock contention code to new file From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid references from util code to builtin-lock that require python stubs. Move the functions and related variables to util/lock-contention.c. Add max_stack_depth parameter to match_callstack_filter to avoid sharing a global variable. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-lock.c | 137 +-------------------- tools/perf/util/Build | 1 + tools/perf/util/bpf_lock_contention.c | 2 +- tools/perf/util/lock-contention.c | 170 ++++++++++++++++++++++++++ tools/perf/util/lock-contention.h | 37 ++---- tools/perf/util/python.c | 17 --- 6 files changed, 185 insertions(+), 179 deletions(-) create mode 100644 tools/perf/util/lock-contention.c diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 062e2b56a2ab..f66948b1fbed 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -46,15 +46,6 @@ static struct perf_session *session; static struct target target; =20 -/* based on kernel/lockdep.c */ -#define LOCKHASH_BITS 12 -#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) - -static struct hlist_head *lockhash_table; - -#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) -#define lockhashentry(key) (lockhash_table + __lockhashfn((key))) - static struct rb_root thread_stats; =20 static bool combine_locks; @@ -67,24 +58,13 @@ static unsigned long bpf_map_entries =3D MAX_ENTRIES; static int max_stack_depth =3D CONTENTION_STACK_DEPTH; static int stack_skip =3D CONTENTION_STACK_SKIP; static int print_nr_entries =3D INT_MAX / 2; -static LIST_HEAD(callstack_filters); static const char *output_name =3D NULL; static FILE *lock_output; =20 -struct callstack_filter { - struct list_head list; - char name[]; -}; - static struct lock_filter filters; =20 static enum lock_aggr_mode aggr_mode =3D LOCK_AGGR_ADDR; =20 -static bool needs_callstack(void) -{ - return !list_empty(&callstack_filters); -} - static struct thread_stat *thread_stat_find(u32 tid) { struct rb_node *node; @@ -477,93 +457,6 @@ static struct lock_stat *pop_from_result(void) return container_of(node, struct lock_stat, rb); } =20 -struct lock_stat *lock_stat_find(u64 addr) -{ - struct hlist_head *entry =3D lockhashentry(addr); - struct lock_stat *ret; - - hlist_for_each_entry(ret, entry, hash_entry) { - if (ret->addr =3D=3D addr) - return ret; - } - return NULL; -} - -struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags) -{ - struct hlist_head *entry =3D lockhashentry(addr); - struct lock_stat *ret, *new; - - hlist_for_each_entry(ret, entry, hash_entry) { - if (ret->addr =3D=3D addr) - return ret; - } - - new =3D zalloc(sizeof(struct lock_stat)); - if (!new) - goto alloc_failed; - - new->addr =3D addr; - new->name =3D strdup(name); - if (!new->name) { - free(new); - goto alloc_failed; - } - - new->flags =3D flags; - new->wait_time_min =3D ULLONG_MAX; - - hlist_add_head(&new->hash_entry, entry); - return new; - -alloc_failed: - pr_err("memory allocation failed\n"); - return NULL; -} - -bool match_callstack_filter(struct machine *machine, u64 *callstack) -{ - struct map *kmap; - struct symbol *sym; - u64 ip; - const char *arch =3D perf_env__arch(machine->env); - - if (list_empty(&callstack_filters)) - return true; - - for (int i =3D 0; i < max_stack_depth; i++) { - struct callstack_filter *filter; - - /* - * In powerpc, the callchain saved by kernel always includes - * first three entries as the NIP (next instruction pointer), - * LR (link register), and the contents of LR save area in the - * second stack frame. In certain scenarios its possible to have - * invalid kernel instruction addresses in either LR or the second - * stack frame's LR. In that case, kernel will store that address as - * zero. - * - * The below check will continue to look into callstack, - * incase first or second callstack index entry has 0 - * address for powerpc. - */ - if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || - (i !=3D 1 && i !=3D 2)))) - break; - - ip =3D callstack[i]; - sym =3D machine__find_kernel_symbol(machine, ip, &kmap); - if (sym =3D=3D NULL) - continue; - - list_for_each_entry(filter, &callstack_filters, list) { - if (strstr(sym->name, filter->name)) - return true; - } - } - return false; -} - struct trace_lock_handler { /* it's used on CONFIG_LOCKDEP */ int (*acquire_event)(struct evsel *evsel, @@ -1165,7 +1058,7 @@ static int report_lock_contention_begin_event(struct = evsel *evsel, if (callstack =3D=3D NULL) return -ENOMEM; =20 - if (!match_callstack_filter(machine, callstack)) { + if (!match_callstack_filter(machine, callstack, max_stack_depth)) { free(callstack); return 0; } @@ -2449,34 +2342,6 @@ static int parse_lock_addr(const struct option *opt = __maybe_unused, const char * return ret; } =20 -static int parse_call_stack(const struct option *opt __maybe_unused, const= char *str, - int unset __maybe_unused) -{ - char *s, *tmp, *tok; - int ret =3D 0; - - s =3D strdup(str); - if (s =3D=3D NULL) - return -1; - - for (tok =3D strtok_r(s, ", ", &tmp); tok; tok =3D strtok_r(NULL, ", ", &= tmp)) { - struct callstack_filter *entry; - - entry =3D malloc(sizeof(*entry) + strlen(tok) + 1); - if (entry =3D=3D NULL) { - pr_err("Memory allocation failure\n"); - free(s); - return -1; - } - - strcpy(entry->name, tok); - list_add_tail(&entry->list, &callstack_filters); - } - - free(s); - return ret; -} - static int parse_output(const struct option *opt __maybe_unused, const cha= r *str, int unset __maybe_unused) { diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 340544a6f5ec..3c6cd8d81d88 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -121,6 +121,7 @@ perf-util-y +=3D topdown.o perf-util-y +=3D iostat.o perf-util-y +=3D stream.o perf-util-y +=3D kvm-stat.o +perf-util-y +=3D lock-contention.o perf-util-$(CONFIG_AUXTRACE) +=3D auxtrace.o perf-util-y +=3D intel-pt-decoder/ perf-util-$(CONFIG_AUXTRACE) +=3D intel-pt.o diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index 41a1ad087895..37e17c56f106 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -458,7 +458,7 @@ int lock_contention_read(struct lock_contention *con) if (con->save_callstack) { bpf_map_lookup_elem(stack, &key.stack_id, stack_trace); =20 - if (!match_callstack_filter(machine, stack_trace)) { + if (!match_callstack_filter(machine, stack_trace, con->max_stack)) { con->nr_filtered +=3D data.count; goto next; } diff --git a/tools/perf/util/lock-contention.c b/tools/perf/util/lock-conte= ntion.c new file mode 100644 index 000000000000..841bb18b1f06 --- /dev/null +++ b/tools/perf/util/lock-contention.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "env.h" +#include "lock-contention.h" +#include "machine.h" +#include "symbol.h" + +#include +#include + +#include +#include + +#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) +#define lockhashentry(key) (lockhash_table + __lockhashfn((key))) + +struct callstack_filter { + struct list_head list; + char name[]; +}; + +static LIST_HEAD(callstack_filters); +struct hlist_head *lockhash_table; + +int parse_call_stack(const struct option *opt __maybe_unused, const char *= str, + int unset __maybe_unused) +{ + char *s, *tmp, *tok; + int ret =3D 0; + + s =3D strdup(str); + if (s =3D=3D NULL) + return -1; + + for (tok =3D strtok_r(s, ", ", &tmp); tok; tok =3D strtok_r(NULL, ", ", &= tmp)) { + struct callstack_filter *entry; + + entry =3D malloc(sizeof(*entry) + strlen(tok) + 1); + if (entry =3D=3D NULL) { + pr_err("Memory allocation failure\n"); + free(s); + return -1; + } + + strcpy(entry->name, tok); + list_add_tail(&entry->list, &callstack_filters); + } + + free(s); + return ret; +} + +bool needs_callstack(void) +{ + return !list_empty(&callstack_filters); +} + +struct lock_stat *lock_stat_find(u64 addr) +{ + struct hlist_head *entry =3D lockhashentry(addr); + struct lock_stat *ret; + + hlist_for_each_entry(ret, entry, hash_entry) { + if (ret->addr =3D=3D addr) + return ret; + } + return NULL; +} + +struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags) +{ + struct hlist_head *entry =3D lockhashentry(addr); + struct lock_stat *ret, *new; + + hlist_for_each_entry(ret, entry, hash_entry) { + if (ret->addr =3D=3D addr) + return ret; + } + + new =3D zalloc(sizeof(struct lock_stat)); + if (!new) + goto alloc_failed; + + new->addr =3D addr; + new->name =3D strdup(name); + if (!new->name) { + free(new); + goto alloc_failed; + } + + new->flags =3D flags; + new->wait_time_min =3D ULLONG_MAX; + + hlist_add_head(&new->hash_entry, entry); + return new; + +alloc_failed: + pr_err("memory allocation failed\n"); + return NULL; +} + +bool match_callstack_filter(struct machine *machine, u64 *callstack, int m= ax_stack_depth) +{ + struct map *kmap; + struct symbol *sym; + u64 ip; + const char *arch =3D perf_env__arch(machine->env); + + if (list_empty(&callstack_filters)) + return true; + + for (int i =3D 0; i < max_stack_depth; i++) { + struct callstack_filter *filter; + + /* + * In powerpc, the callchain saved by kernel always includes + * first three entries as the NIP (next instruction pointer), + * LR (link register), and the contents of LR save area in the + * second stack frame. In certain scenarios its possible to have + * invalid kernel instruction addresses in either LR or the second + * stack frame's LR. In that case, kernel will store that address as + * zero. + * + * The below check will continue to look into callstack, + * incase first or second callstack index entry has 0 + * address for powerpc. + */ + if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") || + (i !=3D 1 && i !=3D 2)))) + break; + + ip =3D callstack[i]; + sym =3D machine__find_kernel_symbol(machine, ip, &kmap); + if (sym =3D=3D NULL) + continue; + + list_for_each_entry(filter, &callstack_filters, list) { + if (strstr(sym->name, filter->name)) + return true; + } + } + return false; +} + +#ifndef HAVE_BPF_SKEL +int lock_contention_prepare(struct lock_contention *con __maybe_unused) +{ + return 0; +} + +int lock_contention_start(void) +{ + return 0; +} + +int lock_contention_stop(void) +{ + return 0; +} + +int lock_contention_finish(struct lock_contention *con __maybe_unused) +{ + return 0; +} + +int lock_contention_read(struct lock_contention *con __maybe_unused) +{ + return 0; +} +#endif /* !HAVE_BPF_SKEL */ diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-conte= ntion.h index 1a7248ff3889..bfa5c7db0a5d 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -67,10 +67,11 @@ struct lock_stat { */ #define MAX_LOCK_DEPTH 48 =20 -struct lock_stat *lock_stat_find(u64 addr); -struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags); +/* based on kernel/lockdep.c */ +#define LOCKHASH_BITS 12 +#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) =20 -bool match_callstack_filter(struct machine *machine, u64 *callstack); +extern struct hlist_head *lockhash_table; =20 /* * struct lock_seq_stat: @@ -148,7 +149,14 @@ struct lock_contention { bool save_callstack; }; =20 -#ifdef HAVE_BPF_SKEL +struct option; +int parse_call_stack(const struct option *opt, const char *str, int unset); +bool needs_callstack(void); + +struct lock_stat *lock_stat_find(u64 addr); +struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags); + +bool match_callstack_filter(struct machine *machine, u64 *callstack, int m= ax_stack_depth); =20 int lock_contention_prepare(struct lock_contention *con); int lock_contention_start(void); @@ -156,25 +164,4 @@ int lock_contention_stop(void); int lock_contention_read(struct lock_contention *con); int lock_contention_finish(struct lock_contention *con); =20 -#else /* !HAVE_BPF_SKEL */ - -static inline int lock_contention_prepare(struct lock_contention *con __ma= ybe_unused) -{ - return 0; -} - -static inline int lock_contention_start(void) { return 0; } -static inline int lock_contention_stop(void) { return 0; } -static inline int lock_contention_finish(struct lock_contention *con __may= be_unused) -{ - return 0; -} - -static inline int lock_contention_read(struct lock_contention *con __maybe= _unused) -{ - return 0; -} - -#endif /* HAVE_BPF_SKEL */ - #endif /* PERF_LOCK_CONTENTION_H */ diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 35d84a96dbec..91fd444615cd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -18,7 +18,6 @@ #include "mmap.h" #include "util/kwork.h" #include "util/sample.h" -#include "util/lock-contention.h" #include #include "../builtin.h" =20 @@ -1311,22 +1310,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -bool match_callstack_filter(struct machine *machine __maybe_unused, u64 *c= allstack __maybe_unused) -{ - return false; -} - -struct lock_stat *lock_stat_find(u64 addr __maybe_unused) -{ - return NULL; -} - -struct lock_stat *lock_stat_findnew(u64 addr __maybe_unused, const char *n= ame __maybe_unused, - int flags __maybe_unused) -{ - return NULL; -} - int cmd_inject(int argc __maybe_unused, const char *argv[] __maybe_unused) { return -1; --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35356148314 for ; Thu, 31 Oct 2024 01:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339034; cv=none; b=GKuJLUYXFQwFkaf0bEpTMX59lRBnNVcjG3s+KUBdIHGyQU+Uc7jkFEsVjon2GjvvtgGvXdmiCNxyxUqXn++NcZVFX2Ffj1Vx/62cmnioC0oQXmsSaxGGM5Moop8ntslmFJ5W5KaTxcHwyZdSpLVoEHLIPl4JB+6s6IgQcV82qWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339034; c=relaxed/simple; bh=wvbasbr/bHT6byIIBcUUP6y+LhSLf7VNj3pt+3TFKi0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XoD6FvclXWUpCtfkcCdAMhUP4nV5Hw3ASxXvZQkFjTe6wle2Yhg+c5GN6syokSRbiYmtkCEDUr9lNvFCSoUg1+moab7i4T+g1WVIuh/7UKx4v9wsXXdmRhYI8kFIpLXeghkj/AQpZ6dQN/NgGjaQ7SXmRYitM1Z8YntChgJ4IzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qK7LzFQh; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qK7LzFQh" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e291ac8dcf3so725617276.3 for ; Wed, 30 Oct 2024 18:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339031; x=1730943831; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=R2ba9KAPKd1ye/yPm45C2inPyTurG9rFVVaZ7EYtd/Q=; b=qK7LzFQhqbtd1mAGVjNW0NKFUFYvsI2Z9f9aVeybYXqugWRlp6bx9xD0SY+mAYLmU9 qiUD8CfhKOiIj4Gh0/uAMoNr34hhctNvCjl0PHnx+tgJTbhIN+qKhngQ9TJDm2EgyUv4 FCJIPXBh8CeP+xDccyefgYcSRW2P1ioXvd3nCmQEirn/wuTw8PmoJaYOtzjHVMLplH2c fZha4eUWD6jqpNJ4TRi5mwa6u4WdBUPgpfX5PNUz8UdFMCDXjV6vFt7ybOSFWVDx5TGv yS61V2Ik+FvoFSmhyzYIoNGig3QfCEy3Fd8/sckUiiQ3DAqT4W9tSj3RDDXKeLXQWvbv AnIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339031; x=1730943831; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R2ba9KAPKd1ye/yPm45C2inPyTurG9rFVVaZ7EYtd/Q=; b=aBqQla+BsHZ5B9lU+a9Sj/HQu0KdGlsHp/keRxRc60Ez4dmBz/aLV1EW8/1YDL7iXQ 9zwwgb7ls8OijJa0cmmWc34Zp+yIEWTtuIikCTeAg6cdvJEdMNpqT/qEtdvJV9yxC6tZ 7ENPS2TkQaWXrwkKpNh5d1xp8AumOgS4Loatq1cfvP2cYYS1MlaI3PfFlmAHx3Uw9Gln i9Y0Z39Mw5znJ6LJwL6eykhQbIM8TSf+CvE2HlxSAafAnSLxs8VXEWdFhYsYzNL7Kr5p 5Fg/WqqVrVXJjRs46QuSmwhZulmV1Yb1e2HkdL59ipeb9ovHlxzgzOFKUxTWVCPWzk8N Kypw== X-Forwarded-Encrypted: i=1; AJvYcCVLaxhJSp3EAIduklwQlFGbMI1B6wq7R0yDqCF+ChYV/hia1BYcLTcbuX68SVklbRiZN+Mjltiw1xsF1fM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/TKnysGKqHVvjQ+aNXxYe3I7wI0FBLMLpl9i0rCn09N4GQw6Y wyCdvj3s0y2PaZrcCle84AASfNsOYglvP3f2KGCk6gqJRM8z21egq/iz/eY21FeNTGds/i3O247 BlxQ8Cg== X-Google-Smtp-Source: AGHT+IE6z5vPED/uLJOGmFJYAUbGjMLVAz6keaBEJdHcoHVGklglOAt/IvD+PSSVPz37oh93JhJrnTW5NGaS X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:ae64:0:b0:e20:2db0:932e with SMTP id 3f1490d57ef6-e3087bceae0mr63811276.6.1730339031301; Wed, 30 Oct 2024 18:43:51 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:46 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-16-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 15/21] perf bench: Remove reference to cmd_inject From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid `perf bench internals inject-build-id` referencing the cmd_inject sub-command that requires perf-bench to backward reference internals of builtins. Replace the reference to cmd_inject with a call to main. To avoid python.c needing to link with something providing main, drop the libperf-bench library from the python shared object. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile.perf | 7 +++++-- tools/perf/bench/inject-buildid.c | 13 +++++++------ tools/perf/util/python.c | 6 ------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index b4dee7c20ed1..ef1b39b5042d 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -487,6 +487,9 @@ endif EXTLIBS :=3D $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS)) LIBS =3D -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-= archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group =20 +PERFLIBS_PY :=3D $(call filter-out,$(LIBPERF_BENCH),$(PERFLIBS)) +LIBS_PY =3D -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-= whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group + export INSTALL SHELL_PATH =20 ### Build rules @@ -735,9 +738,9 @@ all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BI= NDINGS) $(OTHER_PROGRAMS) # Create python binding output directory if not already present $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python') =20 -$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.p= y $(PERFLIBS) +$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.p= y $(PERFLIBS_PY) $(QUIET_GEN)LDSHARED=3D"$(CC) -pthread -shared" \ - CFLAGS=3D'$(CFLAGS)' LDFLAGS=3D'$(LDFLAGS) $(LIBS)' \ + CFLAGS=3D'$(CFLAGS)' LDFLAGS=3D'$(LDFLAGS) $(LIBS_PY)' \ $(PYTHON_WORD) util/setup.py \ --quiet build_ext; \ cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/ diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-bu= ildid.c index a759eb2328be..f55c07e4be94 100644 --- a/tools/perf/bench/inject-buildid.c +++ b/tools/perf/bench/inject-buildid.c @@ -52,7 +52,7 @@ struct bench_dso { static int nr_dsos; static struct bench_dso *dsos; =20 -extern int cmd_inject(int argc, const char *argv[]); +extern int main(int argc, const char **argv); =20 static const struct option options[] =3D { OPT_UINTEGER('i', "iterations", &iterations, @@ -294,7 +294,7 @@ static int setup_injection(struct bench_data *data, boo= l build_id_all) =20 if (data->pid =3D=3D 0) { const char **inject_argv; - int inject_argc =3D 2; + int inject_argc =3D 3; =20 close(data->input_pipe[1]); close(data->output_pipe[0]); @@ -318,15 +318,16 @@ static int setup_injection(struct bench_data *data, b= ool build_id_all) if (inject_argv =3D=3D NULL) exit(1); =20 - inject_argv[0] =3D strdup("inject"); - inject_argv[1] =3D strdup("-b"); + inject_argv[0] =3D strdup("perf"); + inject_argv[1] =3D strdup("inject"); + inject_argv[2] =3D strdup("-b"); if (build_id_all) - inject_argv[2] =3D strdup("--buildid-all"); + inject_argv[3] =3D strdup("--buildid-all"); =20 /* signal that we're ready to go */ close(ready_pipe[1]); =20 - cmd_inject(inject_argc, inject_argv); + main(inject_argc, inject_argv); =20 exit(0); } diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 91fd444615cd..c52da509ae58 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -19,7 +19,6 @@ #include "util/kwork.h" #include "util/sample.h" #include -#include "../builtin.h" =20 #define _PyUnicode_FromString(arg) \ PyUnicode_FromString(arg) @@ -1309,8 +1308,3 @@ struct kwork_work *perf_kwork_add_work(struct perf_kw= ork *kwork __maybe_unused, { return NULL; } - -int cmd_inject(int argc __maybe_unused, const char *argv[] __maybe_unused) -{ - return -1; -} --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84C92148855 for ; Thu, 31 Oct 2024 01:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339036; cv=none; b=GB5bhRzE8kf8EZC4/7IwENiYH3cnUbSbnRwVKHo4bR94O4KknA1eoyr8sBzD1PHZ3Ac345TEja1Qbj2SYmT35fqdE97iiWlAQAzNVV1QXgXs/t4FpPuBdTvCEYlbAGcO2D4iYfrQSQCz/zDWDpc5HyG+bO1jBUqkC9C2Hc76AbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339036; c=relaxed/simple; bh=lW07OjyjtiP7BSeHvWrJwzhwe6xJuxZ4Ci6QSD1wU8E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=R5B2JDzxv7WnDi/1X3LdxQzlQzD01+sGK+DQ1n46fB/pYQkk6lgLl9kwTtGZtHIp23HYIcQKvGnojPTS2LLFmtqOBAezmi0qlAlr0hyJK3Ay3eLDLW7aVfRk+BCcqsDru7CniRSsffRXN0wRzkjDbBLJwU9XRj2uuvcaO/kh3Lw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3oit4txH; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3oit4txH" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2904d0cad0so867369276.1 for ; Wed, 30 Oct 2024 18:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339033; x=1730943833; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=t8Sn8jdbA+NjEGCeG6Gm1wYYNvd28v2iQntXlq3XUm8=; b=3oit4txHj0gb3ZzEWB7LaF7L6IQCTaQP3zQwF0oeuDl8H2aDd3DmRTVnCQAXWPlefd CPggBErzmmxzfh9Bm++ErqJE4wXtmWuyLo7AJMcTPusPL05KVi/jr5mv/EFPY8tG50ZT RmxWrVA0/i/+rRgPOHxcKgwvJLdEzZkGSMzZUOBjA+s9Hkh2ZI/AQEnw/qubxA9Swayo 0w0s5tGoWvJemhZDhOuLdrp3wy8UNNPv22AbL/3o2suxI+lRUVMLye0lhyxYXs4UUNfz lypU6Y+v4wTyUR4sgwSse+XOnpdWccgaNhS/2gP4GQ1NENWMb/HlOOYF7c7SIboz7xHX uY2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339033; x=1730943833; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t8Sn8jdbA+NjEGCeG6Gm1wYYNvd28v2iQntXlq3XUm8=; b=qkPqyQzVooifrttsuxSlKJg/j3gDNKSPKxguHKbns4Mf8WH0KWjiyYzctA1W5WqI4v gfDj0vgEnjLTJ9NxMPicBnhlt3d6MIYiAJyAipxLHZ0O1Edq8xLAxqGkuCb5Vbx0JF3J GX7h5iEOuQ8DC+8jySULiEJ/podilHNzXGOibQmJlwyU/5zdOMlVAMdxu51RIM/xAnAQ svVX/QlUzgMWvdKbzDdih77uobNMhMeXSwEzdAEHfEMkhAnH+mFQxfz/wMzemwiLsK3a 276ZpbqICyMKH30HFdEghZYZHMpNPqlTjVBYTcOs852qd4focHfDynXLbgO/GeZXcCLl aQMA== X-Forwarded-Encrypted: i=1; AJvYcCX9VDxCQ9O0ITim680dz5xm7DzyL0pEJ/3vWBCLT4oKnR2O+0w8xorF/HXexL5YvR6diPQDz5NltscpVVo=@vger.kernel.org X-Gm-Message-State: AOJu0YzpqVXBXHAhZRmSlxw9Bn86+gqC43AtXVat4NlByOJSoFJqw235 0T0lqc6G0/o5h2YIem9E2rYOGHWfiC5R5toVkoaggxaUeahqBPMq0U8iSVHd908vmYAzDEJEbwB Ch2p/Xg== X-Google-Smtp-Source: AGHT+IENQAr4DyjJzfVoLdavjhPbpIIWA4h+VHZAUWU69OewcS/tSnsHo7O4wYPUpEXhUAU71z/C/JUuheGY X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:ae64:0:b0:e20:2db0:932e with SMTP id 3f1490d57ef6-e3087bceae0mr63813276.6.1730339033538; Wed, 30 Oct 2024 18:43:53 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:47 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-17-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 16/21] perf kwork: Make perf_kwork_add_work a callback From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_kwork_add_work is declared in builtin-kwork, whereas much kwork code is in util. To avoid needing to stub perf_kwork_add_work in python.c, add a callback to struct perf_kwork and initialize it in builtin-kwork to perf_kwork_add_work - this is the only struct perf_kwork. This removes the need for the stub in python.c. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-kwork.c | 3 ++- tools/perf/util/bpf_kwork.c | 2 +- tools/perf/util/bpf_kwork_top.c | 2 +- tools/perf/util/kwork.h | 6 ++++-- tools/perf/util/python.c | 12 ------------ 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index c1daf82c9b92..fabfcb74800b 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1846,7 +1846,7 @@ static void process_skipped_events(struct perf_kwork = *kwork, } } =20 -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, +static struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *key) { @@ -2344,6 +2344,7 @@ int cmd_kwork(int argc, const char **argv) .all_runtime =3D 0, .all_count =3D 0, .nr_skipped_events =3D { 0 }, + .add_work =3D perf_kwork_add_work, }; static const char default_report_sort_order[] =3D "runtime, max, count"; static const char default_latency_sort_order[] =3D "avg, max, count"; diff --git a/tools/perf/util/bpf_kwork.c b/tools/perf/util/bpf_kwork.c index 6c7126b7670d..5cff755c71fa 100644 --- a/tools/perf/util/bpf_kwork.c +++ b/tools/perf/util/bpf_kwork.c @@ -285,7 +285,7 @@ static int add_work(struct perf_kwork *kwork, (bpf_trace->get_work_name(key, &tmp.name))) return -1; =20 - work =3D perf_kwork_add_work(kwork, tmp.class, &tmp); + work =3D kwork->add_work(kwork, tmp.class, &tmp); if (work =3D=3D NULL) return -1; =20 diff --git a/tools/perf/util/bpf_kwork_top.c b/tools/perf/util/bpf_kwork_to= p.c index 7261cad43468..b6f187dd9136 100644 --- a/tools/perf/util/bpf_kwork_top.c +++ b/tools/perf/util/bpf_kwork_top.c @@ -255,7 +255,7 @@ static int add_work(struct perf_kwork *kwork, struct wo= rk_key *key, bpf_trace =3D kwork_class_bpf_supported_list[type]; tmp.class =3D bpf_trace->class; =20 - work =3D perf_kwork_add_work(kwork, tmp.class, &tmp); + work =3D kwork->add_work(kwork, tmp.class, &tmp); if (!work) return -1; =20 diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index 76fe2a821bcf..29352ca1d497 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -251,12 +251,14 @@ struct perf_kwork { * perf kwork top data */ struct kwork_top_stat top_stat; -}; =20 -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork, + /* Add work callback. */ + struct kwork_work *(*add_work)(struct perf_kwork *kwork, struct kwork_class *class, struct kwork_work *key); =20 +}; + #ifdef HAVE_BPF_SKEL =20 int perf_kwork__trace_prepare_bpf(struct perf_kwork *kwork); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index c52da509ae58..6e2ff0076daa 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -16,7 +16,6 @@ #include "thread_map.h" #include "trace-event.h" #include "mmap.h" -#include "util/kwork.h" #include "util/sample.h" #include =20 @@ -1297,14 +1296,3 @@ PyMODINIT_FUNC PyInit_perf(void) PyErr_SetString(PyExc_ImportError, "perf: Init failed!"); return module; } - - -/* The following are stubs to avoid dragging in builtin-* objects. */ -/* TODO: move the code out of the builtin-* file into util. */ - -struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_un= used, - struct kwork_class *class __maybe_unused, - struct kwork_work *key __maybe_unused) -{ - return NULL; -} --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE2D1811E2 for ; Thu, 31 Oct 2024 01:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339038; cv=none; b=h99EZh2hhjoioW3W6V+GYtroLI9tvPANtTvWXof7bUH+QBPgfqKB1f1eKz6Qc7pJtYCvzNNPoNqRYqmk/qmcN/JbW5cK/fbk0CS9DTGgv1eOjTlKA+K7t9d1mnoblT1PzGqQ4ZlZJ5li6dnSWcPMU205tWmDgtUSKmLWc3dOI+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339038; c=relaxed/simple; bh=iNS6gSj7D1lsvc1g5KMcNyPf5WgHbLQ5ta+6ZtnweO0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Gu2anBOhLnt5nzjq5k4wz4nDuuobWzXgsdAqfW/Q/+eUeHPCkOZzxI/SfNRTUicmKF7B9pc90iHRlDoFF3fdbmdpce/sWn0uA+/tY2mgpY/09KfJtHOvzzH9KM9nVChEMpogd2UAdQD4qTfiF89yb8NrWaKtRT8eSz5S6QcB4pk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DSp2Neo+; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DSp2Neo+" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e321d26b38so8923517b3.2 for ; Wed, 30 Oct 2024 18:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339036; x=1730943836; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=T1shwZLFPVJttCYQn91hD7eEDXA/86MDDB/52gfDhUo=; b=DSp2Neo+xiRs/wFkiWZcJixKMwL1LxRUr6m+pCnnOrUwPbHOSr5CRrFc0bamSuLWMn dEvVxlUFOPiJCEUDq7/8sRD3CQG2lQfhtcMw7rB6e4Ntx18NomM4ZqTaCi3N1ucy7xEG ws1S0h1aXajA+X0dFxRyPuy2Zra6Vb041LYH6aulnMwJpMswEuVuwXQg4HnEz0EFdMnV 5Tf+xt7GUanxF7Baz4MM0LY23+8IVqEriJLEwTgDsEyr0L1Xc7Z7446z7afbsZ7kW+hu rbWMXVxaKRpl7BeQyXenzf0VUhF0IObRyDoH1ug1PprFEQuHOUtkXgeT94LOi6r8WQ55 G7HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339036; x=1730943836; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T1shwZLFPVJttCYQn91hD7eEDXA/86MDDB/52gfDhUo=; b=JMjGv041auoFZgqUpVJ7igCRipjaCv4dLHUwAtxLiS7enkG3zV0NmSlJXJd1c7dWJa 3yEb0SQbtVoPVt9VPsDmmKpg1DWEPtaPt58hOM8NT7+oD1kSQuFmBjbWb0cuOkoDOx80 M1j/DXvGWaNRgiEwBPeaW4P+JC0z+z5vPPaY8FHy3nd0G4a8tyvY8wgV114zhYEJJJr5 bNj24om2+hIO6MwqHULaXSTVNOpI2MtRMWIBAV+Po3BHOw8tA9dSOAl20xcIl0N6UnX8 /1sFxzqq1+f77IKeG4BVh1qbuROFf3HsXU6kylOe3zuY1pMimHf/Wh638NO+xOOz4mL5 4c/g== X-Forwarded-Encrypted: i=1; AJvYcCVioXpufnoeHuVXmucwjzpbCiBwAqVa7HrHnXrx+cFGDeIITSYQkW6J/jLVzNBMDYxlHuezkXwJ7RdoSr8=@vger.kernel.org X-Gm-Message-State: AOJu0YwGvBMz9lrYrXLp9I91no9tpFma4oW2kZBbKQQjJV+mTwxGWv7q M0xOrS7FSRkuQwBxzuwGa06BNGDp1wLc74gYlJKu2fidnYxTTEUyR1a3OvOPxNoamqYQ7SCsIvu bvlNUQQ== X-Google-Smtp-Source: AGHT+IGu87SVB/Gw+solzkrJxkcfsXWl4gq0Heu8eKvryWBGXThh2EwRPmXV+WR3Z9DmPGB5Ok76MC+czjoK X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a05:690c:4c09:b0:6db:b2ed:7625 with SMTP id 00721157ae682-6ea521c92b4mr45007b3.0.1730339035759; Wed, 30 Oct 2024 18:43:55 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:48 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-18-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 17/21] perf build: Remove test library from python shared object From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With the attr.c code moved to a shell test, there is no need to link the test code into the python dso to avoid a missing reference to test_attr__open. Drop the test code from the python library. With the bench and test code removed from the python library on my x86 debian derived laptop the python library is reduced in size by 508,712 bytes or nearly 5%. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index ef1b39b5042d..2059f1c4b78d 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -487,7 +487,7 @@ endif EXTLIBS :=3D $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS)) LIBS =3D -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-= archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group =20 -PERFLIBS_PY :=3D $(call filter-out,$(LIBPERF_BENCH),$(PERFLIBS)) +PERFLIBS_PY :=3D $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERF= LIBS)) LIBS_PY =3D -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-= whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group =20 export INSTALL SHELL_PATH --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F277414B092 for ; Thu, 31 Oct 2024 01:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339041; cv=none; b=XO/9d9s/M/hv0BLr0ZSjNGUlfP4r3Wc0Tkfyu4Y1yBraKLdivHc9DOiuj0EvQ/F+pTOh2zMInkCjb0RrrZ3osVn7FOfEmDKACpqxbPDVQjsrkoxk88M+X8FtQ11vwbykku/zwFl8ntJMfylZLfWscoj1WBE/Zwt50ARVjD1gz4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339041; c=relaxed/simple; bh=wFg8rXKhwSk+/WnE2Ybco7HPsV496JVgIBfe+G5oj+I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=CHNUUWdHItSFwnSNS2DNAoJwOZg5t6F2ubdRfaHC1xPbekRvGj8eZLvTeXwFacvCk2gVvlRrKf61T29GOEmUq2hLfD/fhh1LNIOiPNQyZEu5OXLMnysVvI+0QlDs01CimtfCVZRJlok3K4rKZkJDgequeBFHaViDhSSCkRBWCNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=V7KvGWlU; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="V7KvGWlU" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e31e5d1739so8342537b3.1 for ; Wed, 30 Oct 2024 18:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339038; x=1730943838; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ACBWh/O4/X4qiB3oXOqHhx7Z60zaZQtrFXt6UTS1Yas=; b=V7KvGWlUOgO3XuIJiy5vYNCJfyuWJhGuyhvZ7EuEcuLmLixdt8+oBiUhA3HFLSrfD/ 1OXgPD84gJ8m9OwAwscVycMX5r/23Z7fdVhkmOCW+nrdLm2As9f5cSV/4zB8voWz/+Lt 54f/KyrJyrArDXS4FR3RdJpzQf3L6qeEaIhBB9ILOyk35BqxZWNoGKLojqXEf7paD7K2 SNhU8xZaIGWvlJfsDUGSnJcqsqN4Xpdmj3G9c4PwsgDMPausmMZXzdH04vcSFFn/yacf qXnlSXcZpAaD/adcCtYbOrlckcs7w38RddifCss/A3raGXIYedyUWVSzYqm90WpgXJGI 1chQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339038; x=1730943838; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ACBWh/O4/X4qiB3oXOqHhx7Z60zaZQtrFXt6UTS1Yas=; b=klLDNNluH03ViYyb1mUU7tT7WL6o/hmuAY9oqeUOpPAsL1BJcWG9MgFM5pnfOQuDdu 4k1BdQA2Wktkc1l3JewC4Gg9fhcVUknkdvXC0HWLbIla+Wpka2/fa5wGAyr+wI01CS1Q HoIdeFTN9nRzA2h9H+ZpnWHyoW7tG5Hm9xPdfK9/blIwDg1pPWvr8SkAWlvMF3AY3caK 6lxV7h0sxltLxAzm3S7DquEWT0DqgXGb59UGX8lZxpEdYxzFQpuHg4oYLMxXm+j6B2Wt KkWlx8VfpSAzkygjMhc7izdsUcDwm/MgMX8aauNSjRSbfC3EsDjLHgspE9z9VyO8huxm 4WZQ== X-Forwarded-Encrypted: i=1; AJvYcCWqdKv4A7jcgPQjABJlTnK9UuQ67m/tjdeWwsZNLxacsescwOnt7NpqVQL46OKQNguBpTUHMArwddwl1Rw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8qfjs2EwbYgUp7M/DyhQNhD042biH8+yTID55+hRH64f3Q7wQ xkfZCzTBRUtQnlEDzqX+PurlL/haFGCsW62bmm7kSD5GL63Lc7DA24FvY6JndQ3Mo//kH8XnmT+ On6i+wg== X-Google-Smtp-Source: AGHT+IEqaz7ycUlhAWtRd1uPjKDmpfP1/3VQIxzcug2wLaT0TrrwpCVBkUafJHmQLBHVodYIBtZod9ELpHSN X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a81:a844:0:b0:62c:f976:a763 with SMTP id 00721157ae682-6e9d892d6cemr5326627b3.1.1730339037973; Wed, 30 Oct 2024 18:43:57 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:49 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-19-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 18/21] perf python: Add parse_events function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic parse_events function that takes a string and returns an evlist. As the python evlist is embedded in a pyrf_evlist, and the evsels are embedded in pyrf_evsels, copy the parsed data into those structs and update evsel__clone to enable this. Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/cgroup.c | 2 +- tools/perf/util/evsel.c | 19 ++++++++----- tools/perf/util/evsel.h | 2 +- tools/perf/util/python.c | 61 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 0f759dd96db7..fbcc0626f9ce 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -473,7 +473,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const = char *str, =20 leader =3D NULL; evlist__for_each_entry(orig_list, pos) { - evsel =3D evsel__clone(pos); + evsel =3D evsel__clone(/*dest=3D*/NULL, pos); if (evsel =3D=3D NULL) goto out_err; =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f780e30aa259..4213ffacdc3c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -453,7 +453,7 @@ static int evsel__copy_config_terms(struct evsel *dst, = struct evsel *src) * The assumption is that @orig is not configured nor opened yet. * So we only care about the attributes that can be set while it's parsed. */ -struct evsel *evsel__clone(struct evsel *orig) +struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig) { struct evsel *evsel; =20 @@ -466,7 +466,11 @@ struct evsel *evsel__clone(struct evsel *orig) if (orig->bpf_obj) return NULL; =20 - evsel =3D evsel__new(&orig->core.attr); + if (dest) + evsel =3D dest; + else + evsel =3D evsel__new(&orig->core.attr); + if (evsel =3D=3D NULL) return NULL; =20 @@ -511,11 +515,12 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->core.leader =3D orig->core.leader; =20 evsel->max_events =3D orig->max_events; - free((char *)evsel->unit); - evsel->unit =3D strdup(orig->unit); - if (evsel->unit =3D=3D NULL) - goto out_err; - + zfree(&evsel->unit); + if (orig->unit) { + evsel->unit =3D strdup(orig->unit); + if (evsel->unit =3D=3D NULL) + goto out_err; + } evsel->scale =3D orig->scale; evsel->snapshot =3D orig->snapshot; evsel->per_pkg =3D orig->per_pkg; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 04934a7af174..7f41d6f8cf6f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -241,7 +241,7 @@ static inline struct evsel *evsel__new(struct perf_even= t_attr *attr) return evsel__new_idx(attr, 0); } =20 -struct evsel *evsel__clone(struct evsel *orig); +struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig); =20 int copy_config_terms(struct list_head *dst, struct list_head *src); void free_config_terms(struct list_head *config_terms); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 6e2ff0076daa..1a53a97c513d 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -13,6 +13,7 @@ #include "evsel.h" #include "event.h" #include "print_binary.h" +#include "strbuf.h" #include "thread_map.h" #include "trace-event.h" #include "mmap.h" @@ -1201,6 +1202,60 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel = *pevsel, #endif // HAVE_LIBTRACEEVENT } =20 +static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) +{ + struct pyrf_evsel *pevsel =3D PyObject_New(struct pyrf_evsel, &pyrf_evsel= __type); + + if (!pevsel) + return NULL; + + memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); + evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); + + evsel__clone(&pevsel->evsel, evsel); + return (PyObject *)pevsel; +} + +static PyObject *pyrf_evlist__from_evlist(struct evlist *evlist) +{ + struct pyrf_evlist *pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_ev= list__type); + struct evsel *pos; + + if (!pevlist) + return NULL; + + memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); + evlist__init(&pevlist->evlist, evlist->core.all_cpus, evlist->core.thread= s); + evlist__for_each_entry(evlist, pos) { + struct pyrf_evsel *pevsel =3D (void *)pyrf_evsel__from_evsel(pos); + + evlist__add(&pevlist->evlist, &pevsel->evsel); + } + return (PyObject *)pevlist; +} + +static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) +{ + const char *input; + struct evlist evlist =3D {}; + struct parse_events_error err; + PyObject *result; + + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + parse_events_error__init(&err); + evlist__init(&evlist, NULL, NULL); + if (parse_events(&evlist, input, &err)) { + parse_events_error__print(&err, input); + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + result =3D pyrf_evlist__from_evlist(&evlist); + evlist__exit(&evlist); + return result; +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "tracepoint", @@ -1208,6 +1263,12 @@ static PyMethodDef perf__methods[] =3D { .ml_flags =3D METH_VARARGS | METH_KEYWORDS, .ml_doc =3D PyDoc_STR("Get tracepoint config.") }, + { + .ml_name =3D "parse_events", + .ml_meth =3D (PyCFunction) pyrf__parse_events, + .ml_flags =3D METH_VARARGS, + .ml_doc =3D PyDoc_STR("Parse a string of events and return an evlist.") + }, { .ml_name =3D NULL, } }; =20 --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDBA014EC5B for ; Thu, 31 Oct 2024 01:44:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339044; cv=none; b=PnHRCV+AkWTKNcTUkpzEsLLRQw2oNq/ycHYe8EFhCBzCc8p0Kopx4V7Fety5DHG9ROyWpEeXG25t8ZlpDx8y5ok7HyxT/1pZbDBtMEBEJLfrtJ5nPtgRLJtyHsKvyh0Z4EZTtiBjrcHh2X+7qOYXt9rXwIMntHdH47pZSZ0ohuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339044; c=relaxed/simple; bh=8nfaXceOAmgiqk2t3wMeEWNA4KSjqafBiascjUECmpw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Ei7IBzk/oygk04lKNGoTbHzdCiexmXoQgnEa2gq7n2DbRCXcIF9LzQxfDREv2PKPPGjKYZmJns7Bd5Z3FloTL7WyJndr0OuLn12JqUvLx+gIbzUx9TwvabTaMc6Zgy9SMVI8ZL4eNJR7XTrERhNSkKILhiJhAQ6parW87G3hmKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=h5tP0Zmh; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h5tP0Zmh" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e36cfed818so6637517b3.3 for ; Wed, 30 Oct 2024 18:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339040; x=1730943840; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=dis7RmFKQzQzt6CCLpk0OQW/Lncdns24hHlJR2bLa6w=; b=h5tP0Zmhb4G/H07PxlHisuQxnQwgsBWqC3lgs0LEDkQljmGclh36pMKM5NlLoBBfX7 k58QbPEdwHxzqubjNNuUY9L2SXVKvurcr/gQxNOhgFxFSfmUU+V35IOvWT1jYe6LwOrr YoJcbGL/f9PrEbiIoKwhDJz0+nBsv7QQ1eLW3MhUZjlZ2DsRQMXYoDKTXnDCA+1V6sQw lBm5Z/Iuzs6YCiU6Tfmcb6Rk+uBQv88jF/7QNaM0Xn0GWC+KqJOjTsAviaAZowrMY0dO /tBlI/YntEJsHDpV6A7/qHcd0uHGHqqbmHwTNMIKA/3Ks4UIVQBQL3cCRe9YP1oJ13NZ uQNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339040; x=1730943840; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dis7RmFKQzQzt6CCLpk0OQW/Lncdns24hHlJR2bLa6w=; b=b3SZP7tp9ajzk6Lx1o6k9odJ2vwyZ/tiEa10nojzHBZpYp3q4RPE2qjS9TFqRvRxYa fU38AVZVHOGcmFb2Re49XEKsTjdnlAr0JjOHUYkCJ6zn+J8vOsLLyvZ7ObpPMbPv966B FnG6FZby4qTQK+7eE17WwKjRyNWOlId8LI1NXbA7VQ0Zg14+Fmdp5u30Upok+7VUjs2H OVtfiBVVaQbNhOEC0kxRCHBeesURcHNWgxCJNMh1Ep0pe/wSr+ZV1ALAICohQGVnaQVR m+07KwQ6kuOIrCYhx7nOuts/6NqzfBQdYse2qN5EeDZWNWfpeJAogzV/q2OCqlXRhy+r cCZQ== X-Forwarded-Encrypted: i=1; AJvYcCWAet1obKN5NZfC14ZbfVoAyXjs7rAWJcuxgYPrGkhpTsPXg4OOckH5Q84f6fh2GnyWmHNsRjaaHigTQhE=@vger.kernel.org X-Gm-Message-State: AOJu0YykNK5kKbfvR1FFiRYrIBK3JL3qxz+Z+epnscHnw08wOzeO1S0y vqiFB/XPCEk2VFCQH3TcKGR29fPct5G2vqi/yJhAFHgjEyu2dF9XFeMC5VokDtr5SvwS3WbuNfU 3GVIHIA== X-Google-Smtp-Source: AGHT+IGQq3M4vfXsHI+Az7Xvrx0IFPhm3BfRkVi7rYd6AuYsG0RdG+quXrCLKrsw0ORuUqiPHTLwAqWA0VT3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a5b:18f:0:b0:e25:d46a:a6b6 with SMTP id 3f1490d57ef6-e3087c07f8emr54926276.8.1730339039890; Wed, 30 Oct 2024 18:43:59 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:50 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-20-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 19/21] perf python: Add __str__ and __repr__ functions to evlist From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This allows the values in the evlist to be shown in the REPL like: ``` Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0,'/tmp/perf/python') >>> import perf >>> perf.parse_events('cycles,data_read') evlist([cycles,uncore_imc_free_running_0/data_read/,uncore_imc_free_running= _1/data_read/]) ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 1a53a97c513d..a71bad3418da 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1069,6 +1069,30 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py= _ssize_t i) return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); } =20 +static PyObject *pyrf_evlist__str(PyObject *self) +{ + struct pyrf_evlist *pevlist =3D (void *)self; + struct evsel *pos; + struct strbuf sb =3D STRBUF_INIT; + bool first =3D true; + PyObject *result; + + strbuf_addstr(&sb, "evlist(["); + evlist__for_each_entry(&pevlist->evlist, pos) { + if (!first) + strbuf_addch(&sb, ','); + if (!pos->pmu) + strbuf_addstr(&sb, evsel__name(pos)); + else + strbuf_addf(&sb, "%s/%s/", pos->pmu->name, evsel__name(pos)); + first =3D false; + } + strbuf_addstr(&sb, "])"); + result =3D PyUnicode_FromString(sb.buf); + strbuf_release(&sb); + return result; +} + static PySequenceMethods pyrf_evlist__sequence_methods =3D { .sq_length =3D pyrf_evlist__length, .sq_item =3D pyrf_evlist__item, @@ -1086,6 +1110,8 @@ static PyTypeObject pyrf_evlist__type =3D { .tp_doc =3D pyrf_evlist__doc, .tp_methods =3D pyrf_evlist__methods, .tp_init =3D (initproc)pyrf_evlist__init, + .tp_repr =3D pyrf_evlist__str, + .tp_str =3D pyrf_evlist__str, }; =20 static int pyrf_evlist__setup_types(void) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC6941531C0 for ; Thu, 31 Oct 2024 01:44:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339044; cv=none; b=RzGRvBjCeMuNocpsfexiEEcU7W0txkM2dmlASLF9O4VSE3m2vNQ5QfcaLYlJE0d1wmxuNQs9A/CGFQ8IbK39u4VUDeD5GFA5XT5yeaZFIwAclT1ymiXagrHjg/cIoWfrsXegWk3k0bv3OuR/JfG15zU9by7C2x5DuioKWXEzj3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339044; c=relaxed/simple; bh=/jY2Cqs+V3l7u/rQt+XOfsCTPd6q/qZBAn7EK80i8Ms=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=i3tNvPRJ8z8e4qd+0cDFXIc9vaDxzvzbrWHyWhGufJnIOCrOIOiWJo1xWVZovI2k5e5Mw4Ufh1bPQsblCM1FWEY+IQzFS/kuUsdr0Vy+GBv+dXsa5qOZVcqi4UQkMeDXbZ55B61UWJtfcm7m1pTQFR+JgfyGjAGSwutY6DHj9V4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uFWuYjKi; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uFWuYjKi" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30ceaa5feeso810340276.2 for ; Wed, 30 Oct 2024 18:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339042; x=1730943842; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=IhmE2mCwcXnI6RxZJjd/8LP8gD2HSvEYfpFi71K4cps=; b=uFWuYjKi+9TY6reK+N2hr8K688jrrr3aEacNcGGTYY6KCqqvJ2pq9EBje6j4sxS2S5 DPTTlZv7BgHNjMe5RwVh+mZrU6BGdTV9vCLuRfhvDp4ZvcGSG595k4uJWsCDcLwbaZ1f vYyYBnDNUYsi9f8Z661HGGQsLYrENyu8bdYF5TloqdcM1YVpAkQIXdV1HVqSwmb/mRmQ rLK/wNDm5/6224DtdNXoxk2uQkNvbkq1aMTWBXUCOHDxIDCXepoIwGgMRrb8c8iHeAl4 9G0N6boWxBxZKxp4R7P/U2dzgcFKi8mppTnJwzDRHnh6qrao9f/jeyOhRyifWdAPH4fr xhFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339042; x=1730943842; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IhmE2mCwcXnI6RxZJjd/8LP8gD2HSvEYfpFi71K4cps=; b=IvMPItRPgMgp7j5bBu8Ku1uOZLBmLXrVKKbuenKmijGi8g2l5GfMB9L/biSAv5ViLx CrqiQSR6AYBwB1NH/frAdHEMWwHizQzg6m4F+cqSRhSLfIrhZGxNDqtE12K02RqwbluR xPxzBBf9b8fcKBYuyEY1ZycqtStlsau5NuvO2BgvO2K0v882pNAEosHrCBCL7yOzIGSe pkVZiljrnat64+zZ26vxOfiIaOWG9MhHvnHvf08uPuPNCXieAurhS5zKI518ckjZ8EnG PzECnc++pvpyoZSZbo3g+7OdWSI67qPMYn/NEz0HzudFKq5+7154Yeu7So426q4nOU1c p7aw== X-Forwarded-Encrypted: i=1; AJvYcCWqlFABbwEKos+yfnDrR54Wu03t1Qwu+hT1fp7OgOqj655P+rHhdENzrCAn1qSL1WqSq4vTaj/m00vRizQ=@vger.kernel.org X-Gm-Message-State: AOJu0YweK7wZsMfwa4wCTo7xYlF62UFAcPPIdDpdltkQC8YM/U4ECps7 vHF3IWt9I3idB1EDcxHE22hsTXIAyq+Npnkbl0pAjW1VBh4zXuByguj2IA7VwcpwuTGRJRaF5lv 6I/24JQ== X-Google-Smtp-Source: AGHT+IF2Wm48yp/1f9MpiKy0f92BjyDlsHyY5mBiiVL4GOvoDikO9Kah6FK8W1kPcElcsptW0C0VK9sCKWiY X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a05:6902:531:b0:e22:3aea:6eb5 with SMTP id 3f1490d57ef6-e3087be9610mr62129276.7.1730339042077; Wed, 30 Oct 2024 18:44:02 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:51 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-21-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 20/21] perf python: Add __str__ and __repr__ functions to evsel From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This allows evsel to be shown in the REPL like: ``` Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, '/tmp/perf/python') >>> import perf >>> x=3Dperf.parse_events('cycles,data_read') >>> print(x) evlist([cycles,uncore_imc_free_running_0/data_read/,uncore_imc_free_running= _1/data_read/]) >>> x[0] evsel(cycles) >>> x[1] evsel(uncore_imc_free_running_0/data_read/) >>> x[2] evsel(uncore_imc_free_running_1/data_read/) ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index a71bad3418da..0d71ec673aa3 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -781,6 +781,17 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *p= evsel, return Py_None; } =20 +static PyObject *pyrf_evsel__str(PyObject *self) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + struct evsel *evsel =3D &pevsel->evsel; + + if (!evsel->pmu) + return PyUnicode_FromFormat("evsel(%s)", evsel__name(evsel)); + + return PyUnicode_FromFormat("evsel(%s/%s/)", evsel->pmu->name, evsel__nam= e(evsel)); +} + static PyMethodDef pyrf_evsel__methods[] =3D { { .ml_name =3D "open", @@ -802,6 +813,8 @@ static PyTypeObject pyrf_evsel__type =3D { .tp_doc =3D pyrf_evsel__doc, .tp_methods =3D pyrf_evsel__methods, .tp_init =3D (initproc)pyrf_evsel__init, + .tp_str =3D pyrf_evsel__str, + .tp_repr =3D pyrf_evsel__str, }; =20 static int pyrf_evsel__setup_types(void) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 02:11:23 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 513251547E3 for ; Thu, 31 Oct 2024 01:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339047; cv=none; b=XF8KlVX/UfAR1AwtWpenWv6EH+i98Z8UQx+1FuSFLFq8pHqrUh+Os707HKzbsg03mi1hOrqNaaZNmK7Iz51Lc92VOD9LuIYac8elG8nDoR3ppiqe3lot16kdUpyCscof2UX43F9+Cz1252r9prJ08vNjoWuAXyVF7RJLJX4M8Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730339047; c=relaxed/simple; bh=RYBqniKAr0HDr9QavuDpVba3HWcJbNfezQsIwVzha5U=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZVm9mD4Hhf9W7MVKVYUBVKUCX0p1yEsz+vffYnxniIQLfG+hELNXX6eksvJ0sv8zvvNh3r+CHU/KK81/woR5DirqKveF5ZV6BVxy3EAF23i5Dg53gW5fvfV1CCzInSWiZBS8Hy7NFWFeeLLXFRXRLdntYqRPtXNw76Lt+O3/UgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tl3VYr0V; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tl3VYr0V" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e28ef71f0d8so1017177276.0 for ; Wed, 30 Oct 2024 18:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730339044; x=1730943844; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=XAPItomQeEHLPhkkwn1yLotANahBFAs02uwcMpYu9h4=; b=tl3VYr0VG/z41np86ByXhPDaDNrJDPucKRf1t3DWIePa5TRdoidlpmMvanCKZ46Zmu Ibd3NK5u24IJ3LyHQU3t2h13DivgdANPjzPwON0i5W+08Vr6zddoV9JmHr8K10FDns5r 27Z+u0oB4i0RguEjNwlU7pPRZceYcvftfGisVcaJwT1BrUk+sFkOxOJVhnp1NCyXtAam EgtS79ctM8kfA4SLIS301zoz7NiYoiCb7JdcMcfXKhpr9PLOFzPQXQ5g9cV2kQ7+0pU0 lxCjtlPzpxb1oEnOmkzhqO2F5QDLyCGEsddyxZNLw+AbwnBQHfXCCN3pbbgzrQGjXum3 7VLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730339044; x=1730943844; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XAPItomQeEHLPhkkwn1yLotANahBFAs02uwcMpYu9h4=; b=rPFCNzMuVz0EwRrw+GIGdHHyaLq37LRERsGlBzMkaS8TMtqFxtAC4/LTZqFIfhv04r 5lpJM+5t7kELqbjUVdPxyCgTnEKa+P34PE+guioVGgKgs0VZGWpJMEXJWVN2lk5R7NNd d917uDm3SUSY2JoDtYKhJAiWB+wWvFCp6DpQo3cTgerLDdRNs9M0R5VnaTbf2QZKTN36 HbblXwMpmapE7EOxXo960XAERnH5+dvqWUtCGubIEKp9DhLXKLawvIL/ZnCmMhSoiz9p 7IH8cr+clPpugVIm3qX2eLNOzgBmKr66w1y3oxMSAfGE5A0On9Xp3crU8GnlISdK6hfG b0kA== X-Forwarded-Encrypted: i=1; AJvYcCXECYhdBKwjSioWzdg1PuIZdCJaCYRKsYxtTgM9ourraYb6+Y3fp//WrMymg8RMvbnlzu3ATmeyupC0SaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwWpAtOCfYrC1jXSoLdzsI4yfpEkXP0Qzo8zIarEMxcGWMCPljt /dTrHs8IqznwpOpCHkxnQds2sqfVxJWSl5Z+xT54R709ooEtaNbosTw5uJ0YQGDRln2kHjizopH MbPGP0w== X-Google-Smtp-Source: AGHT+IEkY0kwA61fgb8QWJVjudJLWMNOihPx9Kn6+kS+DP+smb+Lv/r7Eh0Y0JtgYpuC8tIFBhpKYAanEiLV X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ad0f:67e7:f1a6:84c4]) (user=irogers job=sendgmr) by 2002:a25:308a:0:b0:e16:68fb:f261 with SMTP id 3f1490d57ef6-e3087a704f3mr11572276.5.1730339044365; Wed, 30 Oct 2024 18:44:04 -0700 (PDT) Date: Wed, 30 Oct 2024 18:42:52 -0700 In-Reply-To: <20241031014252.753588-1-irogers@google.com> Message-Id: <20241031014252.753588-22-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241031014252.753588-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v5 21/21] perf python: Correctly throw IndexError From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Correctly throw IndexError for out-of-bound accesses to evlist: ``` Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, '/tmp/perf/python') >>> import perf >>> x=3Dperf.parse_events('cycles') >>> print(x) evlist([cycles]) >>> x[2] Traceback (most recent call last): File "", line 1, in IndexError: Index out of range ``` Signed-off-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0d71ec673aa3..25114dcadd21 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1071,8 +1071,10 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py= _ssize_t i) struct pyrf_evlist *pevlist =3D (void *)obj; struct evsel *pos; =20 - if (i >=3D pevlist->evlist.core.nr_entries) + if (i >=3D pevlist->evlist.core.nr_entries) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } =20 evlist__for_each_entry(&pevlist->evlist, pos) { if (i-- =3D=3D 0) --=20 2.47.0.163.g1226f6d8fa-goog