From nobody Tue Nov 26 02:04:39 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 75DEF1BE85C for ; Tue, 22 Oct 2024 17:30:52 +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=1729618254; cv=none; b=H3cRRgPQlxcPNDJl6BvMkCokeMUC97Mx9ehSGL2m3TlEf/+2ZcU24CRoDi2dptaERu1G36TnKE2UmSJVpvEsxOGiPQMLhzHHxfEjXA7Yz7negj9vNLffXG0AC4ueVEhoEBVD+qQbMxiqihEvHjqmIiOzGg8BNCcQhpO21CqqTGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618254; c=relaxed/simple; bh=06rUym8mEKwnrNebRhLzrvBcLI6yg+52u2nqnHXOz4k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=tRkthc6EgXcHkWaqeO4kaXSPZLuFZyoGMUDa0p+YpMGOicU74abwLo2o8S094jjJ1PxMnAY4emXOV2SbmjZ+mwSy8VrRckoxaw5jcQJtEU/gicdwslrVru/5xGRD8O3PlwriyNEtJ96/U2ugzXQnmUMDlZj5zdwJtq4YXpcXTjo= 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=pjFxM0+a; 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="pjFxM0+a" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32e8436adso84542587b3.0 for ; Tue, 22 Oct 2024 10:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618251; x=1730223051; 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=pjFxM0+a2qLeYZY/aREHB+oVIS+w1/6jZYLvH6crUtqXNKA/vYf74sISEtgN1aHbmY hH4kCkC1QKb/vZYnNxvy/jytu2OmV/WF0XeAWcE5O+3Hee0KGOT3qi69gJh/8QlQstYA 9Dgb/i6sS0mK+v0y6nu0220vxhwzCQwawOVwEgEXe5wS2AS26O0YzVSME2UkAriPPioM Y8YxplkLuxhTgXgxPL9RoelagkMpGj7+FQ1z+zNE25dxkXT5YGJrwn04x5zCzqZ8aOV6 iXvoPg8YGr9UUPY2IvtvPOj5iuw41Rn5z34dh7dnxpEVA8tHz+N9NS4z8Fu0gV2wt8+U LRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618251; x=1730223051; 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=dTER+7MNLedqG9zM0Yf/A4WlwdtY8PyrLQVI6K/aW94+nq3eZ2UHNmLDyypvG6E7lC uVoykLgbjBmCNh66bZEddfpNtWIHmKYo0qPA2h61MKwO9+hsYI99gXc7S6K1ftkNw0j1 CElGy8TaFYltLbGdr6GVG6jMnA9vFhRFULhdkjfRcQOBVXdWyt25YEscS7XY+IQUQCmL Yg+yR29+BrjfDVvOi/ER5gEprNlv2odI2CHyFqW//ZyBd/IWc0wzLhrkvBY5ej/j1HvR rPlAEVqkfhZnw6TY6ym5XN3Uqro6KGnHZkJaNWpadg/C3b41QwD3wTlv8l2PaFlItRP4 pmuQ== X-Forwarded-Encrypted: i=1; AJvYcCXSIuD2ghvkAXuUdUE4JsLqnRQmjps+r+qDTsTMZn6uvbcxguOjVGKTFMokgXtaZ7I1MjNUhfzCoNutGbM=@vger.kernel.org X-Gm-Message-State: AOJu0YyNhqBSG8tJ2juPvGSvM5aKMi/NMO8NPkAxVP2wqKEyCWlo9G4e a585S2Uq4v2dvG1V3CHwQe2PcRc5A19M9UMGoxy2X2NGaR6LtEJbecsFyZZRk2Ct32h7yzA4hd8 8NT3IqQ== X-Google-Smtp-Source: AGHT+IHu23lfa777lZDghM4tj+r8X+0qvHQd456fRs1Z7PJFRRiVSqxKSVDvOU44o+EjZAZ1tu3L57z0R9D2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a05:6902:248b:b0:e2e:2fe8:2d0b with SMTP id 3f1490d57ef6-e2e2fe833e0mr6954276.5.1729618251184; Tue, 22 Oct 2024 10:30:51 -0700 (PDT) Date: Tue, 22 Oct 2024 10:29:59 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 01/16] 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 , 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 --- .../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 Tue Nov 26 02:04:39 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 784291BF335 for ; Tue, 22 Oct 2024 17:30:54 +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=1729618256; cv=none; b=IOqGngqJXEfPUDP1xrxp7cVcPzQfn1WSk7PiqSaygN9HxkpYLx+nOj9+qh1b1BY/qvHRqK56oXOsy6WlRLaWdlNSgggv5Oem5snl75oxdyTRG/f2+9GmR0pw6SjltPTFwsQr00qJlo+6qljgywL8SutE19eKnlOrQijHTFlP3D0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618256; c=relaxed/simple; bh=CiUzxYw0RBvkytit97TqdNjM6aeeFRoA/HnhpHqF9To=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZN1qdp3jcQwXhhnxhA9c0UBawASUaR+SN0tTtiKeRHe7nVD30bWngJu+Gk0+wJwJZbKfIZgcBpc9EoTdSkOOV0dDJZpbNP/PebPRpnFwC9kbVQylRd1pKRLA60tmqy+A6n1N4X2/VRSvwBy+/Ur5nUNftVogs26e6T7kpL1gcDU= 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=Dbjvra5B; 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="Dbjvra5B" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2974759f5fso98604276.0 for ; Tue, 22 Oct 2024 10:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618253; x=1730223053; 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=Dbjvra5BSnvEBhUc89WPulije4bndlVU/0dIsfgdeCL/4NKSkCWUxxspOk0+hDeIam Hrexvbd9jIQ9aoBR5j7xYMjRHyVbhTSXaVU1EHCW3EjxCfUleuhnbhQVNpCssjq6FI0T HoPdI5AOU0PryC/qtOt8awHu9UTKf34y7gvT6xbP6EQg9VImxShORNRSz2oeFRSP966O aXwiEZ86Lqr49OnY/C2NCCNZ52aGrZ4L1+cJatbaFyl4d/CmcJxxpIC3wxr0k8N7ZzVc ChHy4ZJSfFGtxosvjFTI6Gqfm73t6BNirLpXufXyZPKRkX/oz2aW1ts0/TswOBLVwMxh r/Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618253; x=1730223053; 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=RHO7/+nocZ19H/Ef5g4RviTpBAMmf/3bfZsb5D9Xff4WX0R/v+/lQkYIzsqsUO5cjr BJNM/iZ2woi6Gyy5NkcaCrHlUtp0FA0bunSjNHxVmN5gOAYnQSqEt1fHnO7b9SRLFvE9 GFydWJeKk8/8CesQNynxAENPEQWaKFHoN3zBcv3WHssfhXxtKPbGeyUuSRyA1eXx1hDC YFQMvyGUf9kMzTm+sUi2ugMvOQnAllsoKjaIVV4WCDa+ukLCXATo7QvE1oCgkaMyLLx8 V+gdJCg4efVMkyopd3ENvLIZ8LLvqVM9C2eMPCCNoyGU8Dc5Dtqh6dfdG4OlHlYCv4Nr Lw0w== X-Forwarded-Encrypted: i=1; AJvYcCVBwm1m2Jwdz6+8pxbi5hmqY6cQ3zluTNjmI+r5SY8FukNhoB5RYUAs66Ze68inv13Uq8pN6o4ncvxbFRc=@vger.kernel.org X-Gm-Message-State: AOJu0YzrDf7A88YoF+A7uA6pFwKV5BoEbjsWLpfUxp7z1nwxRBh0+5nD /5hMPbz6PKBPwSt3kzpecs7g8xHlb7wefnmYQuav8u2bSJgv9TstifgOtni08n+LfPq3qTis4LY hL7nj3w== X-Google-Smtp-Source: AGHT+IEsWlyYqo1tRYkC64jh1T7l6up59x5SKUADAkoq0NWCxwQTJQ9OMj7EOOKwBuXSEguq9eFMyQIb1Dg/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:c586:0:b0:e26:3788:9ea2 with SMTP id 3f1490d57ef6-e2e242a6517mr14690276.0.1729618253389; Tue, 22 Oct 2024 10:30:53 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:00 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 02/16] 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 , 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 --- 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 Tue Nov 26 02:04:39 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 C8D201BF7FA for ; Tue, 22 Oct 2024 17:30:56 +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=1729618258; cv=none; b=BUahoZOFjPOX9FhfIVWjIUKneOc1GrtIkvByokHoA6x8LVk/6iqAf71zqDlaAYC/2JON0VfoR9TWhqEXFeVN1/LYefHMildRAVvTTu7YFGH0GV+ctF5ToHjgdLYEXHgKJXxcYbn0ZBDt4tErzg0jS2ox5wwZiOcaVOJwYNNR0FQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618258; c=relaxed/simple; bh=GYxmpcXArXMONJWsRe5WPl7DZqsyI1iL6F7x/lVFYsI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Ja1vR4zKrq29bqMrz5vA4whqsekPhTL7OgLOuFuVfW3E2+eamC0lD8wp7WDKC6thg7dIAu7IsH+uRKZlvQCTkfP6wtFqqJ42zUVPlY7zjea64NIQpnR1V0Hwba26A+oYTQIZ8DC9BlUkrmdhnThyZia/tDpfEMLciJJcEGX7ShI= 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=gnhyOn2a; 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="gnhyOn2a" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e28fc8902e6so10291322276.0 for ; Tue, 22 Oct 2024 10:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618256; x=1730223056; 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=gnhyOn2azr4kRVP169J0IKEj9kxRbxU71BVnPd3XFaS/ZDv4QcdTe3qreIy3a2zUUt M1Lqr2GBGhUjbcD8c/yDQnLE1qgRHrmBLMU+XNRI0ZKJdMa+XEjmZ49nZKsnW/W6SdvF LwZr3Np+br7++FL/8PHQuzRd5b103AXzmZOYtpI+zFxqkDYIkQiwOVP2Qg0WJ+rXiqht lsU/WM0YOsIC9pqqBBt2dxdE2hFe25432l7PQfZAvoeLQ9smDz3gQpvQe+xNWgE4pA+B +HCrtGDLhveRNTG6X2fuOH2rorC2pxUlSSxaAFvCepFv4QdIDEmYrK6cYEzUqX3aQaRZ j+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618256; x=1730223056; 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=K+M6je+HooWwqkWUAlGeLMokzikDdS0Q0Au9Am3I+cpxlVnl4VgpR+PvLjV85txqPr P3WhZQZBAJfqkN+zcik+/Bs8xFilVqPlF7MKztcgOsJc5HyaKNGIA0Ts2JK4Mur9sNt4 lyTooL3Bh/RoLxCmk2tQZKniE/kr2RV/kcsS36mJAA2/MuR9vM1JjaxUBiAJv5JQQjPD bG+OOvfosIfsQsHpySGYNSHONMTHEdWaTM2BRmbimdZCLJvIoOsHbMdjpoTG4CDB7/gM pdBWi76jEkNu3kyq+GR84cfI5woHzwJHmgFd1PnNFyH/OaBWRcivdxJYp+AhR9JVPnXv 8ubA== X-Forwarded-Encrypted: i=1; AJvYcCWIw88KSZ+Zp7UuoD76PaOBldTd749PdsdFDM+LzpnrtqVHiaayyOWTBsVhE5u9gVYvoE1WhRvKQMEZmPs=@vger.kernel.org X-Gm-Message-State: AOJu0YyeFhhmjfmIkQGWyUd+zPua6po4AUS/hy+Kv6zsZZEIb5Vq96sr 5WXtRY+B/LUldmu7AB+H5e+q52LE6GCeOM/kxqjnrylW8FtZgmN9kptd9OetWmnzGoU3TXGKEz7 gNWCEUQ== X-Google-Smtp-Source: AGHT+IHOiwWXO2ZHbTfv88EA0bDyZRXW/88QCQ9qRZQo6GdNscne5yPWZzbRQcgZmqadb3XY1CXrBgj64hyZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:360c:0:b0:e24:a393:bb8e with SMTP id 3f1490d57ef6-e2bb158ba76mr21384276.7.1729618255720; Tue, 22 Oct 2024 10:30:55 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:01 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 03/16] 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 , 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 --- 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 Tue Nov 26 02:04:39 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 7CD0C1BF7FA for ; Tue, 22 Oct 2024 17:31:01 +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=1729618263; cv=none; b=hLb2mXDdf2HXi0DiX2hCg3hoGxtP8bte8OAzVksw/8xxLLoR5cGKlK21fOPhIvhRSCXbXINQ/QtHwZSd3h6jnHFIM0srwW9ujhNIuXSZM6fJFiL6pZ/VdtlMOdwp8YRtYU3TavRu0isMq9x3LEkHOMOiHAk5z++e6B3A8tEpZF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618263; c=relaxed/simple; bh=H3R8MsSWGSQnGeDZaFT2V4GrMZxhd3Tz/afE2tKUxgo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KqNSUdwOS4DNgmAsBpSC0OA1KM3UyOAYMxp9dNTICBTa7LxfSCvjdiXAY/vp5GSFCKTjB6NpOBMpNgFGPRfmlshXEjQ6mXsj1aAZqJPXBcFi01YzjuAWh2eBfoUNP06Hp3qVfkoQxhvqQasM91hnV/NqfaE5Wm6EkCFGoSE7z5U= 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=mz3TnOc1; 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="mz3TnOc1" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e7e7568ed3so783557b3.1 for ; Tue, 22 Oct 2024 10:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618260; x=1730223060; 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=i9/j+c/KOCVX2XapkXz1QeJCdXQcJtU2BeNP+j/8p1s=; b=mz3TnOc10khTI+QcvWKvlR5R8pyeX1seg1pD32hws8maUV2QsJwGi0+4oSpJLnzig+ tHlApGtnUdHezxB8pwuVLJK+7J/UBTVZDkPFvA8IB/H3/u8SN1UbiJTHfMrm+jAqCKSx Idj99CzW6S82V74x/wRCQ7OlG1cbdn+ISWb+zd4JDX2mWFn8jI/afOAHrO92USgEbNsL xFlK1qEUx11f4MpLOKkJPYZsknVgXBthHjtdI5i5KXBReSfGO3ST2mk/XGjssJcrsR8E 9zn24PyGv4LJ/tOZe6L3SW+fyafdriCdD/YhNwBkcLzcRrOLgu/bTRkR+SmHOo4S8hqH FVCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618260; x=1730223060; 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=i9/j+c/KOCVX2XapkXz1QeJCdXQcJtU2BeNP+j/8p1s=; b=vr81UTL7tw//PJnf4j0i3cKR3VSWmfY2h4LAv70UnSPi16EDOBDD20mgkF4JurvRkN irECQnCh8TxLowY3kycEj2HOtXbyOhEIGUrLvhTqOdB7MVU0VEXD4cGswGZ4KgpYoanl EXD1Xu2ScDRiLpDHBvf8et7FceXuMu3kMRdkPd7xuF0jhRKUwXO9UJGSPGi7dXrqug+s Jex8wHp4I9aCPb7VjKN/oiooBZ/84PrS9KdZloMnIrNvhMli+B+JfU70/K1wVtl59smt w2/WURcmInVonvpBRNbpE+5ar8yddx3dIl0oRHkisVgBVM02eOCE1latlxN06TUh3uHo qmNg== X-Forwarded-Encrypted: i=1; AJvYcCVrvidkXcdf9Bn4BbX1D0qxM0uYoq4pXH3NBXg+xtTEhFDGSXDS8xGG4SARVncC+35ACsz4FvKCNEq18OU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2gHtt2rW4tZQVBWq3+Hdylvdka4E4NEFVc8UP7zi6Izgg0PRj 7pdnfZb6lscwcTXLvTvcFGWGQkXpR/zATNQ1a3SLOHC5cqPAHiNMmtHSX08dp6emCdP3l4cxVEb xyy/maA== X-Google-Smtp-Source: AGHT+IHN/IzuKCIDhR9euB0F74dwGBIUGCqlmNTqScwZ0hD19IOV4yCWNZdg8WjDV+It7qMsAqOF+V2/L3RF X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:8445:0:b0:e24:c330:f4cc with SMTP id 3f1490d57ef6-e2e24859f18mr24476276.6.1729618260257; Tue, 22 Oct 2024 10:31:00 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:02 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 04/16] 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 , 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 --- 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 a644787fa9e1..621c26c388c8 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 Tue Nov 26 02:04:39 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 82A071BE23D for ; Tue, 22 Oct 2024 17:31:03 +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=1729618265; cv=none; b=qOkbKGSYQ9TjyKUgmDApgiKQFv6MJtX/cGnDUkSyQ6SPjzfdjR50Y7y0egZ/35zo0gUmzk/l2gSQJCGDYZyeHtz2etZkYreOCP1IGxn6DiiHetsKzZz/yB6eZxb0GqQUNAoWTowhZ3cvfSFdaPR3g5IyCHNOZwNIQkwdiiSJUhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618265; c=relaxed/simple; bh=nAZ99nR+Oe5nWC38v3mC/ZyoUxWfealxv/EFhpW8Loo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=O/4a15xgUxCCzFqWCqMFfmgbaRK3Gx3+Fjs7WJf5FOUE6nbuQ0Js9zxie2LTAoEJMyPfkHhiXn9GflAYCY9tIRJG2RasEd/z7Ww3amg78fvjK8kQuC9D/jU8RGXoa1C9poaQZiUxznFtVfE6ZczTn8/ORnDm6YTCJ528GjdZY2c= 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=T8SDXWF7; 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="T8SDXWF7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3497c8eb0so1053357b3.0 for ; Tue, 22 Oct 2024 10:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618262; x=1730223062; 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=/Cw9APxZPsYeIlsd3UwqSQwdAMf/cDuC3cJ8AZxYajw=; b=T8SDXWF7gkSd/PqwvajzUwALAmVSkMHO6WjUJdMYzUyGAJ0gkIWnzf90XmWu7pzeww C+LXvq8/hb0LImoyLIBPHpnBC71D2nguv29qT7+wX49yDEGsiBLwyDGYGab8DPR+po40 6X8EsVG/S4GY4OcKiGl28FYIBlmS8C0i8HH80e9fYNSnoDuZh7jUJvC54biqd7uYwPhF PEehGeum+6DljbUzFPniBCt+BY7v8ZJa/KHOIC4QQaKxJnGzI1Ouk5pHY+DL0VCGoiik t9ootYNhID3PrvVbE2REr1TCGwDS6jw/JI1nANRpS7YdjV0lC36/AbBFCT9510O6z/Kp aG3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618262; x=1730223062; 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=/Cw9APxZPsYeIlsd3UwqSQwdAMf/cDuC3cJ8AZxYajw=; b=r1vezNfF1KbZmHz3Vaqs8Xt+L3hYKh89OzNNOufTp5McJCP8IuPOiWT/cxHyow1p0I rfMU0r/VFoV+CvSlUY/5C8EZXT9gG4c1vL8RyY7n0funWKcEbUoNsreZJB4DfROqdN90 xBaFFN4jD34Eniel3qBN4Crv9329VdrOMswLhNeYbQ5+sLClFI3MTpjCETCmoNSBo+ne YgIk8Wt2/SjcfJ0lwucKjSizwBABuBLSlWCtQPM7k7f7LE81t48dN7pjOlBiTKC7oTpn YE6TqUMURSPYy+YymxE9A+ZpFkjmlNpix1V8QShUUzCGW2dzQhzwns7QHiyp3EL5+ym4 utUg== X-Forwarded-Encrypted: i=1; AJvYcCXv6xBv1HjZhawrC6ZDJ1CfQYL2S9llnDd4OZDY9vRd8IOmFzgtV7GWrjEetJMCLf+FhX8rSaKKCtvSFiE=@vger.kernel.org X-Gm-Message-State: AOJu0YwIDktX8m0HlRjPbgc5fo9iplLv2F3sayC0yXs9OzC6N99B3XSB yQWq1dNb92Mdgy8rqmOoFP59d0JWM3UjMlJ0lZLKhPEHSWtueMmlgYRXhSgfy+c/uqR5FkKLwu7 7rW5nwA== X-Google-Smtp-Source: AGHT+IFPgBFqRdUNc0OqbYf9uzqW5Sjrj+hZeWcniqaLPsnRGHZ9VuKwKOnSdmSpIXhyc4XQq4/vyDgmH9Pw X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a05:690c:6f8d:b0:6e3:c4cb:689b with SMTP id 00721157ae682-6e7d4a02590mr1650807b3.4.1729618262496; Tue, 22 Oct 2024 10:31:02 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:03 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 05/16] 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 , 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 --- 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 55ea17c5ff02..6f34099d5fb0 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 fa508e113dd0..2a2f7780e595 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 Tue Nov 26 02:04:39 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 D330F1C2430 for ; Tue, 22 Oct 2024 17:31: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=1729618267; cv=none; b=W4Q81I6AX5Ud1pcw+mSrNq6cBC5kET5rCSjQIsAmmPNtoxjcBkmeOhG1p0IFMuLO8jsypmOrV9acRZuYl2HlkNCRZ9+1yTtY86y4erD/8TzVnPmgEmFpQXerxOBQ3YvN78qOHH7CMimwehOI9YXY34HNUp7t92xcT7YLc1n6Cnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618267; c=relaxed/simple; bh=6cttDjPsB1xs49GXiBCJ0QlBVNSiYwO7nQoWfqaKE9Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DCFfB5Ge0MFTJ69DkuotjDOJhRg9sBvr1V8qo22TDOb5Tgm8v4s2Xg1QW/DVDqwH3d0XpkhYQh+Y5C8c3Yoo7YFlq93f6H15YjVINkpmTT3SubAuhTTKxP/25Bo462lfip9gPubLN7ky+AsRZXwZnb77s/qigdEXygk73IU/n4U= 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=Na0MyMHx; 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="Na0MyMHx" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2954ada861so9468588276.3 for ; Tue, 22 Oct 2024 10:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618265; x=1730223065; 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=zon9Vw1vMszuf0NLJgkDjtpi+W/1zN2WqSe7ikjjtB8=; b=Na0MyMHxsfnW1GWoOT4lQ/7n0LLS7Zqen7kdIxKXzbgPcuopvu3m2m5QXqnYlIZSwb KdGG+kCMhbuNR6mJUt1I3Cx2KRzePXwZ7EpVg8fS+yLW9+VMvEl8GdAylMmo0Z4Rvzs3 DG+Hy5JCNCuFvWmYLiQjBA+bvTwd/iuqWOKHlDP6Z0NFxRjsjqeLn9AJnJFHZI5SqKgM 5L3NOF/j2cZWs9Ogsph2sUIHM9UO+LfKc09jMZSR5ue9x3ILPZfC/49FY19BCUr7ioIc FSKp/0osgErosLQzB4Bh2jjIKJtrAgAJcejvPtL+vjL/ToQsiYATj6qPA1edUlmxyKXQ u4UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618265; x=1730223065; 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=zon9Vw1vMszuf0NLJgkDjtpi+W/1zN2WqSe7ikjjtB8=; b=IfSPSno2UpWqLCrEx2/V6t5twgklZVfzQzvv1AuculnPo/gztpmiwyoAV/1Ag8wHEl WvdSGelx4OIUrDN2ylb2+8FBqbRbZYmLoK7lWYSWCap+srhr5OpLNmhyWGwTcdZasdcH vdXzE8GmVuTyhfrYaxwa/Lf20NyVmgw7tEoxy6XPg+GUzvvivqBr7FDOd6lgV24qWdTc MpD6HQaUMEVmfIGhQec4/e6FB8AsZLHHAs/KozcrTokZZXneoEI4PJRBLYRKezJmvQEb 8YLNIge9g2BxtTFBDzvJ6cOczIWePgSwNDicDn3ixO3iV5Jpp0R+qBGtaUu5o1ipgPj5 OmSQ== X-Forwarded-Encrypted: i=1; AJvYcCVDtOy4zBkCgw9bCCuZt50YjgWNSoth1bj60iy9Sj0kaFTWJfYm2njTby9kvUcuoNCgN9tyuKc7CCS7NBI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/ga8nZxujnXZvGCvdHmGrrEQ4c4ks+SL1WPOUb81ksZC9JWym FDy97Futio9u1qiT6N+bdMFzY7kOZpaxgmi12cu/LDtgWGaiB3NBzHC7wEU833X0GBciwdH6aSv nE7QkLQ== X-Google-Smtp-Source: AGHT+IEsf9wn4RMQX2HTLLljT8CvwysksgavxhpdoB5CfE51zXXYbhiZHmzSGrhpyGjpXqOgcOOOu970/zV7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a5b:b51:0:b0:e2e:330b:fab3 with SMTP id 3f1490d57ef6-e2e330bfc61mr12878276.11.1729618264768; Tue, 22 Oct 2024 10:31:04 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:04 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 06/16] 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 , 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 --- 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 621c26c388c8..27b2fb08ad67 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3520,144 +3520,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 Tue Nov 26 02:04:39 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 59E621BC9FB for ; Tue, 22 Oct 2024 17:31:08 +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=1729618270; cv=none; b=EavlfaUgKF1P4ViTye7qbKd7ZtOr415nVpaylygJnBl7o8O93bwjn4V/jyExYzrBJXE3yZTZf0pHb6UVwgx0wGQLPZkBoPIxtSdCpCb2TnfElr7ItnEwllKmAmtx/t0P3JtPv8CtUKk9eTvcDwv6WnBcyP/XeAIaSY018O/ici0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618270; c=relaxed/simple; bh=s31dSzgjSGas7kPllBbZiPWKWXkpL9nMCVZO/I2SOZU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=g3H5arV8mhmHXoRtVZ385RlnUaiJrdXc0sn1LTBbs69Yqmon9+HTiXZ/dpijbe5uWYDh7wJL6tihllhzZ1zXhVuzXXPg7T4swW28up3SmmipTpBd7zTbECMr4LqVsJ1w9R/2ikmzR5NbVsTOguTvVRO+qnrRW0+7EJs52MN5V6g= 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=gEHjqN+V; 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="gEHjqN+V" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2bd9b1441aso4573096276.0 for ; Tue, 22 Oct 2024 10:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618267; x=1730223067; 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=rgPxjN/5Bqvxkvpikn5AEcPP+fMC5PENxXEI6dgAv3U=; b=gEHjqN+VNbb3aun78kHSap34Iya3ftirIVkGrd1k/heB+FS3ymU+D1zCPLiGv6ovzD ORe9uwI6V/VtxDjP2VY2w+dcGonyx1UMOMdgT03yP+KVw63M4g4vdeCFyNiTK2DrsQSL p4JmadCnRDfgl+v+JmVPYMudt6sqx6p9rT6dwWRD2nW+1uYePHGLJrXqGHuEpvzJdOKS hBGqI1t1nMOG0CXkP6Gf13qYru1CfoNoEtPyA5EtE4iisDfvJl6UTXt3mIci5V7p9M26 Gom17uwWoQIrPIhuQ4oo3g4VyJHET2Af+wt5v+BbuAcNuHxxjw0ZRtJAEvSO3AtlpM+v nlPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618267; x=1730223067; 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=rgPxjN/5Bqvxkvpikn5AEcPP+fMC5PENxXEI6dgAv3U=; b=aQDDsRsM32ab3yvlmOwT1Ne8hFuVfW8KYjkyUxMNph6qvPWUAXxKiammWtsf+jqb9o yiO3LgwROWN48Kb/svB3zjBf4S9LHu00W0Gcu7uimvVgmXunQEE2glAbxs7uHJwT6Cu0 BhLn+zR5Z1WiCZf+HsyDojrL3ECSvraZzpShYxBiP7zEJuk/jf+0ZhhFx3bm/uFBblCk KXYCGmxwnRy+X0odnHtKTP+olknsENRB4XrOGa6+jhQonu3oO0ZH7tKs69KwHPeAc59o ooLvz9Marwck6jOVuxNfp3MUs23rGKer6+oiGwWTYzI7ODBPBVZ/UAuzT71m2IBKmoUL mR0Q== X-Forwarded-Encrypted: i=1; AJvYcCXlU/8AOQNa5oUjqikTyq/QRy2+9rNusv4Fhc7zzC6VJkmCh030I8+hLmBpWbxH5vXKANeQvPOpaALGjJE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw09ZMRPRvwlMT4zEW5eLWkPC9DRudB7Nvzcstetmk7WQlx8vZ8 Hp02cq+68dA0Gyv9MSCj8BLfqb0kjt+unhU51ud2VNENNEhosFoaW002CW1BgHzLWb6+IqyDvn2 jo2Lmcw== X-Google-Smtp-Source: AGHT+IHmhEj8jDmTBd5ueE3FMCFsA6yJQFA0/6n58ZO1nAwQpMjQ3hJs1pPs3ymDYl0vJHj4IRNseRMVBDOh X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:800f:0:b0:e05:6532:166 with SMTP id 3f1490d57ef6-e2bb11cccaemr28124276.1.1729618267187; Tue, 22 Oct 2024 10:31:07 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:05 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 07/16] 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 , 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 --- 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 27b2fb08ad67..1ce7b71f1f46 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 b5e18853982c..7c7424824b0e 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; @@ -1059,16 +1042,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 fd7a187551bd..78ddc14507b7 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 Tue Nov 26 02:04:39 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 3B44E1C330B for ; Tue, 22 Oct 2024 17:31:10 +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=1729618271; cv=none; b=WlP5VToGwBUwKE5bVQaaSD41AuKspRAQQrqlnmempTarUUtQH9wgut52hWzC9AeZzTSBqHMwWsUDDK9lkPdK6PTUQbitYMhggKnrX+/qKDsE3AAYsNXqkzJ6/4uby6vOG9QTZzcEi97Ttq1NeZF8u0wdbTGA4yc+aXQdfHzL6jU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618271; c=relaxed/simple; bh=3Ry2ZDeSTDeejTE5bU/QIsOgJoWOwBO05hCd6qGy+iQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=aY2xmpv0cafLddtGkqIkNsd05I4uNjkzftQNH9e4E75QwICv2DZMWWVJtk96BAZky2kZf4jgjoxANwh8cTE3WaWM8m1FrvFThPXVx4yCvMM9HItK1plfm5LmlIjZPteUd9QphDt69RX3BZNKESNsH3Xj9EiszRa9CxWYvTsGlRU= 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=vhtr1Os6; 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="vhtr1Os6" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e7e7568ed3so785057b3.1 for ; Tue, 22 Oct 2024 10:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618269; x=1730223069; 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=DPqMOcw/gz/9oB1GzsDQOCA1KyL9cUpEHgbKTJ/WmIk=; b=vhtr1Os6+WdvFNtt6SXGQ2ZqM2viw3H1ANn3vq3Yutj7NQ0AjVORQSeFqFZ2ydXlk5 xJ2kP5hH2L12JqM7KQu4rDCXoTw2SSPBlSh7cMgsl1ExUNBIIi350o1nDKbt4+zKAJnq S4jHERbTVLCh1SWqz/K6XY0hGK8rxDcKbSk8Pn7HXjeS63G4F6GomyKTLJJmgDyB2ek+ Gys7K7oRHRDHKUpE0L0o+2OOJGC6KBXZxPUaswbuRv8wkr/z5a3UW2GJEUk0fAcoqx85 eARlBRyjS8JLLp6E4wrb0mcfK3qhcffCCqIrOX5ATbA1ve9CxwszIr151Ap+Y28hTVj1 OZTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618269; x=1730223069; 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=DPqMOcw/gz/9oB1GzsDQOCA1KyL9cUpEHgbKTJ/WmIk=; b=rTyufh5zYGHP9jXgUgHK6JlScHrzK8fLBj05YKB+PuczTnojHeM+oTqB92i0YMMlm5 821aBpA3GKwUVWHqR28SGNY/+SVRxtBhgizU8vGt8BxORR4tVzVLicV27UaAXbEeJeBm Ob1fvGWqrEcWT2C3tU6bApxXb1ju1Ygg9qd0R386Fbg2LzOxK0ja8LHTdj03uHBwnpI7 H7uG/RGcJVEZ0T+/0Y7suSyX5f01l7CrXjcD7E66Ac3uzZfjArym7KvHMNvmW7X/Qpgl Re9MnU09iNmdqzyQL7fI1LLNoY2sH5ymxkZ56HS+lzcTba5V9h8iNPuK++dXjqOPMgfv DLkA== X-Forwarded-Encrypted: i=1; AJvYcCXdK9CiE9v14tFGwoqVSOtnmiQzSh0Nt+ozxtuOU+CIDSQ10w9xgZ0+yRyydCU793/w7x+csB20wesong0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0xK75L1waacIOT2SZ/C+zR/86/gyc+EdX+ubGzWw5wd9SJkV3 DjY8GQBcPAys70HRSU72W/xi/zSty7HNXTiFSFuIoBen7EGX+YrYKyDKnwsg+kROg/IBtHdDWSd BmNv+Ug== X-Google-Smtp-Source: AGHT+IHBj9SATT1LWVafd+BHC+BE7V5JcH4XBN+jmDAuOFFp3W//F6VmIEMLgXF+lrsJMgBcSKlHr93kBSWB X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:c101:0:b0:e2e:317a:d599 with SMTP id 3f1490d57ef6-e2e317ad75cmr11450276.2.1729618269206; Tue, 22 Oct 2024 10:31:09 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:06 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 08/16] 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 , 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 --- 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 1ce7b71f1f46..b838470657d4 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2955,79 +2955,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 Tue Nov 26 02:04:39 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 53F3D1C3F3C for ; Tue, 22 Oct 2024 17:31:12 +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=1729618273; cv=none; b=Lhme8MHgsJ6sucaGjGVK5RzH4ZolJEdQDdOfcy1Gt6YPcRqmvWnHmstD+3snQI+F9T0CJF2ttVVGd+olaUFmWeCi7ILC1YdkOCaqHKX6C9NAoLa9KMBM32tElaQghrl7/uaBn7iZpld0sRwJezvetVFBVsV8NHT1WnlnVOoados= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618273; c=relaxed/simple; bh=/crqTxCEFIJ8zM+Mn3jruBiNWQfecVziDkUeZ96I01M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JWoB4dWdQn8IWQPk0/ilgWxuqVs6TmbvbC2DpigQh7VnDMzNGJCGt9lKcoM2baGannqKPUUFM1WYIFfD7TSUOwwizfqFhB2WLEbYSbpfEeuq9WcRO08o6ZFokvPZPR6uTaXRGWopRzoqnOaBSgph1N1J1qWBeYiPcaQj5/De8+I= 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=X/xM0Zz2; 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="X/xM0Zz2" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e290b8b69f8so9841980276.2 for ; Tue, 22 Oct 2024 10:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618271; x=1730223071; 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=fhvpBUz7ScY2P9mICu9O6uJW+157JnJHgqfTK+JmiWc=; b=X/xM0Zz20LSfhjyoT1Mm5HLnhGBBsrMhAmY6xgCdSOjmmDRpuK4gTWQWmSr7frF1n4 /Y4uOCnDW2riR+yqmcrM7Ali/48Zi2k6wyQf6wWePP0Xw93DnSxcDuP3qhWANc0bXMB3 oCOY95Xv7ClUacw4Kw1CJiPe7yne8Nh70cG1fIjv/qTRpTCZNdHMb7LX2+Lu3Dt6lU2Z uohbBeNooOygcq1/zczIVe44uyCvhBFOONoCXuiidLaXZBzzCN2Ycw8iv7WBGfISxAuW FoamERyxX277pFchhVjDk5xgjF947dUlIbZtIERfMNDi7OPLTiall0AuS9FEhK/1Y4nA 1/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618271; x=1730223071; 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=fhvpBUz7ScY2P9mICu9O6uJW+157JnJHgqfTK+JmiWc=; b=wuYBjlzLNrJl3CJ5tHt9TXFMcpcAd/cGqFvE7CwJrnB5w6eGtUBLHiTztNmxiVV+YA pFa7BqrbutC/Gs4j8JFG63bTecSeKxiPOkZvXWEclaryQkLi/Rb1LNmWIxKTOznRfVPL JnNOud38P5V1XDvcgVqJoOGFlkcjeIcz5mEZMWCPJjwD7ukUb97Pd+ek8BH8X/780ruV gFrA8BYMF77/jYNZPhvCPcdaxUKfez/wD/XlqdmgtEJuJ9q02QB91MUDlMqU70758uQL rI7/MjenDVcCbqqk0Z1kf71xfQtf88MrIvWmkPKY48XzLoIVzZKnTCBh2+aJZMHRYm1H uz7Q== X-Forwarded-Encrypted: i=1; AJvYcCXpc7DfXGHlfpP7GqMi7hCzE1H4LBdot9/HtDOmtyMgT/sJ085KmdAJM3yL9+4v6azvFkQye6xRD4X/994=@vger.kernel.org X-Gm-Message-State: AOJu0Yzkr6Bq5R8Yx3EA+3F1hkbFKoU8UH3oLcKowv0indBooILEKbQn gZLrBBh8GUbLU8NUtqJFONgB9K/oeJWBu2KSdwL74Pn+nDtkfCDgrO6QhXpv27udT7OkynF1eYR SyrM/Kw== X-Google-Smtp-Source: AGHT+IHDnq+abCllals/kqnWsGmCM/mFjJoZMc4Oom4dfZXS3a6TCKQxUeC1YZSC/YAiejk1FxZfEJUjmYXh X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:d8c4:0:b0:e2b:d0e9:130f with SMTP id 3f1490d57ef6-e2bd0e914admr8223276.0.1729618271277; Tue, 22 Oct 2024 10:31:11 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:07 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 09/16] 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 , 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. Switch the weak arch_fetch_insn to being guarded by ifdefs as weak functions are outside of the C specification. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 15 +-------------- .../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 | 16 ++++++++++++++++ tools/perf/util/trace-event.h | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b838470657d4..63a00dad02c6 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..543e78b17e5f 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,18 @@ void setup_perl_scripting(void) } #endif #endif + +#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 + +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 Tue Nov 26 02:04:39 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 8F4991C578F for ; Tue, 22 Oct 2024 17:31:14 +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=1729618276; cv=none; b=WQKoDKYqZryEN8a6In1fXv60fntEpeC/uo6L4AJC9NJeUU5YriAq1xyX/MlXZ35+MMvR+j3703YbXc2G95bLthT6RD/ksQdlHhdE3qbjkSMGMefAB4BQrdbjr3DmjeYrGD/fdMPEvFUK994GzqH8Kix0Wsn2D7Fj7cCrtwB7Il0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618276; c=relaxed/simple; bh=6cBSvBCPWOSZF+MItRvyrCkvc/eDCuHzWE3rNUATjb4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gnkVYHRWiAQA1OU9rr9pJyjQvTexRYkdv7jDyM6jXt+3bV8/ltx5L1JrZg5kD+eGyIClTjxod64BbtKFzE4vDDdZFfY4Hh+OHiuubQnBRkAyAi74oJm3SBCeCumePpiDYSXD4M5QB+mpPRcF1nfLciSykaTO3SKVO19p4CRgkEo= 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=rRZ9OBPh; 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="rRZ9OBPh" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e35a643200so119783177b3.0 for ; Tue, 22 Oct 2024 10:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618273; x=1730223073; 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=FGGhHZMe/gCvpVhm6kMneTHlRVnqYzRTKL5fI6/PdXc=; b=rRZ9OBPhRuqP0BgYnYiB5R8EDtXyrAaqA4k+JN1AD+NpDB+D5eAQNWbdbViFXC1hpT vXBrAq8oQCl7EoOdU+D5vRut4PjwxZFp6wUKMc+rOcmrxDzVy8s8/QlBdg5ndiby15CZ 5UANxCza1TKxxDto/cnFlJ5OJ56wIWZLqGikqFKmqpUz705xxxyo33Ffht5ichAVABbg /1vXWmd1XACfWJ01WtB0zBsUv3iHccP4m6g+o9oKQIfB3S6j93BT47BG4mLyzkBmVHex T7sSUYRZPPfUH/UngMru8YSVqesV7gPQpDLO3t6QvNJp2rikDH3/MPs9M3ezjCIkHfXA KE7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618273; x=1730223073; 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=FGGhHZMe/gCvpVhm6kMneTHlRVnqYzRTKL5fI6/PdXc=; b=IHGA7lK9vIb2BpGcLJjfQEHX6Eo0ndT8FCV0eO89+RYKqvDBQjFZKfZCSq3U5tPE56 I8JMntq9kgbOvDzYHLj604HKh0sAahIr08faywRBxGbs+PeeTtLL8TRIeVU5VwU/JvXM KfLd1vhv33c/ACAetGSawCxiVmOuDUjzedZ4WALdrgQc/BEMgQeb4pU+if7RmFyFq5OX F7uFqTehDmythfCNhIuBCVa9keh4EBzldrTOidpFeVpCj7a53S0DKhEJQMSbIXZS9lqh 3OgV7A3Kb9xt8yTmxqzfYB/LrH1xr8aUKcQGdvYOD4DV5oJet7v2GEl5Eq+T+o9dBG7r bHtw== X-Forwarded-Encrypted: i=1; AJvYcCWkNsaYbkrhLXAZQ1/BbrVqzqv7Lbb+VMUnBDWLJyZXD03NIvj5eBg4AWY/3oQs6oUTncurCLVTuISqTok=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc9Z+7SXa+eCq45yhsiVYHwirS15oCnDj0F9VVNZeXMbNQKqNy kBYUPc02uYKx69L9cbEjhSoIUfq6XJfLwi8Upxf/O7rRvym9To002rVQfzXl6zVKVPEj3irvXLH RMQhicg== X-Google-Smtp-Source: AGHT+IF3S9g75sPNhGzb0F/YX/oOHI6JoHuNFLi0jjjoECv0cQRrHecZ9TUZKQkAY4FfP3Y55sqexXI6QR6w X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:868a:0:b0:e28:8f62:e735 with SMTP id 3f1490d57ef6-e2bb11aac7emr10021276.1.1729618273325; Tue, 22 Oct 2024 10:31:13 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:08 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 10/16] 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 , 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 --- tools/perf/builtin-script.c | 80 ------------------------ tools/perf/util/python.c | 6 -- tools/perf/util/trace-event-scripting.c | 82 +++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 86 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 63a00dad02c6..b5329f4b0602 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1693,86 +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"}, - {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 543e78b17e5f..1734967d7f70 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 @@ -285,3 +286,84 @@ 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"}, + {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 Tue Nov 26 02:04:39 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 D64051C57B6 for ; Tue, 22 Oct 2024 17:31:16 +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=1729618278; cv=none; b=pXqJBH2E8yhlE7vMx5K2plJ4q6uTDQk+nQ9MgDmS0LXXU9Mx2uBaLOaAdJy4SZpb7hUuduLKHdXFJ+HnPRHVsuCidfiIWoy0ntiw2mNlAgDv+7vgPPs2eTNPtOYGs45pXHFsSARD7SUKlYDjYwSKlsva2BL8yX6iF6EsRiNINaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618278; c=relaxed/simple; bh=a/SJnAfZ++cIVzZ0MOXAnphnbstLnHOB9fZ5EurCpyc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=F1Qe2MvmOzfqxLuMWXEGu3z/4SFHmm6W7yIhqf00nYFVjAafYmxsQR1KOWYFaRmihSqn++otyaYkOb2+H2m2pFEkZVVf2h7dEe8nHZ5ZeqLX77A7VGHdWCYoIqsg5eYFYOUhN1oMeJ/j225fw8XY9BT1VUOYUww1ahN3zjWb9iU= 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=H+F84tAV; 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="H+F84tAV" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2939e25402so9454176276.2 for ; Tue, 22 Oct 2024 10:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618276; x=1730223076; 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=XfPboL9tDGHiiStyDSuUXrmQVY6xilnSC3mqb44Upvg=; b=H+F84tAVydPdjGpz0hmykG5pNmhIC+25qU5uNC4FT+D/t/3hiChNHjvJ0nbYj/58ZA C+BeeKXpxB/QocLesRzZBmRw876UC88VM5viAssceJcMPjcFyvI4V7Tg4XkgtCBpa7MI KdvgwaTwiZ/KHfgsuLAMpNyQlnm7G9OQU/EG5gq1PsMLouaYRTFotRJwB7v2+M2wBByV wEq8cxlJFLmZ5w8D3b85kKtbdSCM4gpsLZZPC8LA7ik+WoVckfqbDUjTaKPwSBBm6vQy IrQV2V5ZGpmlB+iHdSjq3Uoe/UviRbiFEamZewpJkIp+br5WgVvoKUnKP4CADLhu1a/u tn2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618276; x=1730223076; 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=XfPboL9tDGHiiStyDSuUXrmQVY6xilnSC3mqb44Upvg=; b=O2RRX0q1B1zWbiEIhuv7tXS4/M8I9nokuz99WnZBRlKsMzeDGw3Cim6MnUf3eg3KQq UXraVE01ckxhCqm7IiLh+hGkF77eYHqrsa0FOxyNudELx93C9UenHQliJtd3SIjbJafu LFnuGjGbhassSmuSXPFQ1rWx3PZFQqCHBA00nFxcTHlgu3bczxN9hb6qHNS/ZJBv0wFn lfkaDao/xrYP5zWnl1GEFEtb1it4TYiDY206rv4XJuhquArKqwUzWlF5Iz7rJnmM5gGL eg3iLFo0yJLWAirZQnej5AJCCMfsQo7xZXvZPPiRTRr3heOSXn97gGGjl1zf57hSTsVe myTw== X-Forwarded-Encrypted: i=1; AJvYcCXCGPl3lRWuVsPXvWbvYW8zsnweOmZW27JHSag6S3V1hByYJAYYuGFTsuj5306GYfdBDXhnDA4lwD/mOL4=@vger.kernel.org X-Gm-Message-State: AOJu0YyMJ9phT5FNU2ucG0sCSpbLr6N+J1vsnjVlvp0ml4ZLd1Rqm3mK LdZyOPWdug4EIJVjqJJve6IllYzEfN91UrE9IzZCL0lgmbFS6Z5rT8fAy9OPex1v+hOSSkyrd6y 8/MB+PQ== X-Google-Smtp-Source: AGHT+IGCLZBFLtm70BOUOBJbP5T6K0jZmBV7v3k9f+Sgp12tlexCZccbgnAElZqFxYL3YtgPtnkCAjDHu9BF X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:ced1:0:b0:e28:ec75:75ed with SMTP id 3f1490d57ef6-e2bb1018b3emr28314276.0.1729618275780; Tue, 22 Oct 2024 10:31:15 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:09 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 11/16] 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 , 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. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 1 - tools/perf/trace/beauty/arch_errno_names.sh | 3 ++- tools/perf/util/env.c | 2 ++ tools/perf/util/env.h | 2 -- tools/perf/util/python.c | 6 ------ 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0b30297b4ecb..dbcf74a9e047 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 1edbccfc3281..a903917a09a4 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -22,6 +22,8 @@ struct perf_env perf_env; #include "bpf-utils.h" #include =20 +#include "trace/beauty/arch_errno_names.c" + void perf_env__insert_bpf_prog_info(struct perf_env *env, struct bpf_prog_info_node *info_node) { diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 51b36c36019b..6a61ceff10bc 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 Tue Nov 26 02:04:39 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 039061C6F6B for ; Tue, 22 Oct 2024 17:31:18 +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=1729618282; cv=none; b=bnKKt2jC/MJEeuOOTCAhrC/PXX5aH5rYlgUw8ugWu1Ala9r200nQvRaBCx1KBp4UNEniU6xQ+LTGI/koFpCapEl8zeK5dQpN6G4WVg3lmmUvOOwCPe47rB+bvhxl4uyeHF5h8ZF+mFP+TkhsUziVJx88HPHaxEc5pOi3NVWyzMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618282; c=relaxed/simple; bh=nzHuTvDmWygMaXjwH3QcnN5kJk52moDDMgfOxj3g/cM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Cx+tTEi4N7q+lVIc6szvDVz7cx95B9OsA4PyBOpoqSmmKORQNiQ2lMkkvf4XzRX20cM2HPFXnFPkIMXFVu3aLLX/S26Z/QMOQ6UEBwrwgge/zuR6FRD3FtCseYzpldv4QftA5JDU5kmVMG/kdicnP8mvjCiJ4X0kkoI1Y2kfsSU= 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=VqtLDWWD; 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="VqtLDWWD" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d9e31e66eeso118825047b3.1 for ; Tue, 22 Oct 2024 10:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618278; x=1730223078; 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=EAxWlDzpsO6EVzLYVc/EaqicqPV6/ujgED/chHKdAkA=; b=VqtLDWWDlWIg7206VeZT2Yic/l3wEeuSs3Mt2xLU8UPrITRo4DWA63Aah5NOdEA/GY UdSatRX9VZcEUzEo/FUvf44atXdiszra63GdoaJq0CM7SqpT8lfEAwJak97WB+n6xhxp a2LFjLC0Gi/It85AcQbsDgFw9xWsX+uGr7eVb2otwmjA4jrWIbS+UVrau9lirCuV3dEQ 6+X+15kSMAjp26q1IrzrTXtDRS8VvUF+nUEkXh24UXT4XdBKu5qqpzCjlStsHeFlxeR1 mNWBV6BiBlNw3yxZyL6BXpE9OWAc5CPtAD+3zw5EUl39J4VzCUrnMgiugK5YUtpeH+j+ 4WfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618278; x=1730223078; 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=EAxWlDzpsO6EVzLYVc/EaqicqPV6/ujgED/chHKdAkA=; b=tqLF+bUuDx/YF/IiH1MpY+EtiS815EqvtW95+y7J7xrv3KNXYXfwQhd9KUI/ae2Oem y2YrppiP2iCRPxUYkEnwwMwnGAOR784Kl7OQ+WP3VZ6ihXX4ePlEu4U+WJd262gAf3fM qk+MMBKbTG33ptQZzEwnIXUZvogoP+bRvsjB9Joe/vJBv2Vng72OinMLjyCnHW89XDQq Mr1NT+Aa+RYdux49z/5tVKSUE0nXwWbDKRBUvGn6zL2oKclLrmQm/XdEXPSifxS+LLgP F2swdONBDqR+vEPo/agnPFIZErdYXwyJ++8aDLf+gfi00c0AO3knr26KoYR6ppObYuYa dIfg== X-Forwarded-Encrypted: i=1; AJvYcCW9NJFtDbAQUxDpsSJCVO43t+Qgd7Ov4nadaEOv79D6PLikUUNBZieD0vZjlA8Ee6czlyawNcghnUyzej0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm+LYImaZvOC0SEuxdJfI3vAVWCZ09Vx1VZc+xk6QLRhIfU9iD coLiB94lfHEnT5dlGJjW9PnC+t6hfvq1TxmV57WLr2TZCkU6Amnk1QXmHRYxU+Ep25ngdL88Ww9 8/0IwkQ== X-Google-Smtp-Source: AGHT+IHoKmZxZXKoWcnKzQPXbsoKR4Y6hMAv1bquFP9rfNz7KebTHJNwy0MloiRBi4V47ViBBMyDsbxnAaAw X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a05:690c:fd2:b0:69b:c01:82a5 with SMTP id 00721157ae682-6e5bfc5d0b9mr4269907b3.7.1729618278049; Tue, 22 Oct 2024 10:31:18 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:10 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 12/16] 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 , 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 --- 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 2a2f7780e595..ea2d9eced92e 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-$(CONFIG_AUXTRACE) +=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 Tue Nov 26 02:04:39 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 286141C7B73 for ; Tue, 22 Oct 2024 17:31:21 +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=1729618283; cv=none; b=u4XvUDjNHMiwuCjNRlWFJmha2bWvBmR6GXKRWHZev94sDOg0/iwxJiTtVZt3WTuifzVgLJqCVcGTU1VoIgeNAO9ss9ue2H0ZKmD1sAiJySXhRqkOsGQPHtWzTiQW1ySqiwvAewZsvIb0d2lWHGJ25Bco7ypOg6ZzTUR5CNWh1xI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618283; c=relaxed/simple; bh=h8Ou5g5DrhLFfv50C/dN4S1HrMs3trrQOcpAWXFdCag=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OI0RmBZza+X+yYKXHDxGR0HNw7KnTcxZFx3YCyJpSro59w27ozDer6OkHfVnWnCLt5plslJy6B8IJ842PRP010Eet/DPnbSjfMROK6qxXewiw9GqGyvGO+iTHCrh2wB0UGGD3olh8OsJI45APH5dNu/uePyCBB9XdVpdfVVZE4E= 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=4CldvtaT; 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="4CldvtaT" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3231725c9so101949317b3.1 for ; Tue, 22 Oct 2024 10:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618280; x=1730223080; 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=Kd9t++03UqxW+nAg8foHREOoohXM4WxHxsh35bvMJTw=; b=4CldvtaT3VL3NM+J6R4h8a5SRnsDFWp5rrpbc7Bes+WqT5+DTJkVpjx+gvdrMAByrm xyguf+P/CurYftM8u0UW1vxioowhsvxVk4v/Ar1ASKYTDeZPzLJP6PUU/XLvfZlFKV97 ikvpv58k7ERNqXgtIwEwj1vpikIXJL0LdKl1hhcGWUQw/yV+hlqjQkBjv0IW8F0ogykp aUBGS8QcZARnoUaXn+wyvUZCOTnAqNmtFhkTLKv7q9HR5l8lHjU38sFaWMR3RmRKKLRb CYEy2QOYA/6OfBNBqjMgCvU2HYiGcbWlz5px9HaOUQgZBdiS5dOJwMtyv/0PjlpRQiNi /HXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618280; x=1730223080; 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=Kd9t++03UqxW+nAg8foHREOoohXM4WxHxsh35bvMJTw=; b=SgXJ35gKqCMW6DeVMjjQUpbH1qGg/8ysZ1u3zbM4ZfBDIlFCWfCIlrkbOAqrlWtJeK 5KVEM0WNjVGbWb2laDNHawx2/3wYyze8DEkX987ig39uIkOxCVFe8TYF94Hryhwz7RtA rkqbbbrPkB6juAzS6YWDfFeI+BmK0A62+5KAP8wWUaWix4tiFdBiKjDrvC1TY2Cy8zGE fwy9CfwlEU9KQ23vqCPZv4R2JhJ5U9O1qh0VgHM4HnFTT/vjugy6OzQw0qiumH7ejlcr q9OJHCzu51X3NG2msECIeEUcieSgDCRAds+LZBLkquWc4iZoL8UEylPusTdc57zCZ3Px lPQw== X-Forwarded-Encrypted: i=1; AJvYcCW98U/qYuEDwrlrl4OCnjTCOi2ij88T4UIpjzHVIPG1xkHhdjhSY8e7BNNM5nq02xdZZjf6V3TNMGT2kO8=@vger.kernel.org X-Gm-Message-State: AOJu0YwCJf/S/z1LrtMigHWbywwzItIveRMbSHkbVfW4ePbGPpJ6B1vH Pmqa2m9BUwDXdr5zdqpuqqu49XtGrDBhuA07sQn8Tug09e9edwy1gKHAZi9s0+kGnS4Su7maB5d EBbBHsg== X-Google-Smtp-Source: AGHT+IEPVjkVUrVyWr92okZd44uTJWhsJ7++u4e+qUxWtLRQgdL/39dFblyN0funt1fdnaaLPWEpJa2VplC3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a05:690c:6902:b0:6db:c6eb:bae9 with SMTP id 00721157ae682-6e5bfb868e1mr4151097b3.2.1729618280324; Tue, 22 Oct 2024 10:31:20 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:11 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 13/16] 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 , 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 --- 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 105f734b6820..e54c6953cf02 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 Tue Nov 26 02:04:39 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 687691C8FB0 for ; Tue, 22 Oct 2024 17:31: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=1729618285; cv=none; b=Qh/P4selEI/mx8fdJhnLjwe58w8teVV/1WmXRjWQahh4UV7/efc5K/Q4XD4p71pJdKe/0Dt/3Gn7xJULjyZvG0vGJ+B/p8MHrbj8zsEmKzrP8cgCU/SrZbikrv44oPMh0DjEnIkgXhD3jSncsQx8dT3dAQc0l78nTDkurShhat0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618285; c=relaxed/simple; bh=lW07OjyjtiP7BSeHvWrJwzhwe6xJuxZ4Ci6QSD1wU8E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JZed3b7IKEEtMTgNtie8IGnXAg1UNhmS07+KWIRszBAmPLChXgHX6ggYvPC8xo5mbJw8QRM36AY1llbba+ElZs6RmosjaP43U7Iva9MwQ+OpJk1ntWcYSYiRBr3Wi18Mvp7MliDIMcNHAA36KxmtNGCsA3hF0484B8meFySrxs4= 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=gNiUk3xM; 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="gNiUk3xM" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e292dbfd834so8933364276.3 for ; Tue, 22 Oct 2024 10:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618282; x=1730223082; 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=gNiUk3xMhmyGl/0MUuffKd9G0n4ZpHByYjGyedlmNCRYpxxVsp+BHusFqgYei3brhA +lxzkiOXfWClRrZ0oBFGbSb6HAkm01JIFVrM3IOqtEunVotlmnFFZv+rvrhzY4nDetWM mDsLI7g0a7A0jr/LNOFHez5cW4+3IJ8EqL8mp2d2sk9c1Vm7OuRPORx/8ZEGnBr1kWPe /cedoV6foI/HEVYBuavh+YWRXTjB4Fo7KjZGRO6P+7ZI/ZmL1V0soS2f+fzuljnE2p6A KgS15U0KWa2ySSgQ2dByBzxpB8adRm05qvdgahlyQL5NhMT2nJRXk2CPo/guvGN0d91R Jetw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618282; x=1730223082; 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=V4yg6a4Nya1OMNgP3wn7q9lDI6bvvcBQU+PqcTAw51MS5L6rCiKjiEB9gGpWTSF3Dd kRcujVlZMPYSR9At+EvLgziSMPd1lV3SVfRU7LQNah7AhguBbq0Tmc3iQPlmHpA+nTDG F1Rk6+0ryQK9Ee/v77jJS8WrlqiGSxIfQsVQd9/AC2b8/8UK4xhkIkfWs6FFAzA7nBLM Dkp7jfdm3rP6XLXOCBV+excB5NPUN/UM7BHFb+yX5+I3iTf2ZW4Ca6EgbwVuuLuE850S uszlUCcuZpNB/Ho+7gnHlLotvzHVIHTZ9LCGm0KTwe5tMcmweECmEX3xpsvVXICNcCwY R4Uw== X-Forwarded-Encrypted: i=1; AJvYcCVb1Zci7kWAPbiseONGxBQvb+irxurtLLsHPdrFoXEWQwNMrDA8QtrUrXYmxz+uk4xBhqdT0u2UQLhB8vg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5/rhUjR4zCnOwQ5RbWvrDZspxPSW3cDh1CAeB8nKF1YaubC/W LLBlbwjwkqofE+mc/2+AjgemV4gguPgzAuPBMId/rpCyDbdYt+r9wzJ5hQBtF5Y6u0fjjqsCi7v Po9GU3w== X-Google-Smtp-Source: AGHT+IH9/EN5Q/+v0NKTCOkVpwJedIXeesZVaCnYSA/yidNa2oMOS06NMBkkfS9kppFI17/jXw7kZB9ilOvg X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:9c82:0:b0:e28:fe07:9cc1 with SMTP id 3f1490d57ef6-e2bb11dfda8mr36214276.3.1729618282343; Tue, 22 Oct 2024 10:31:22 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:12 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 14/16] 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 , 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 --- 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 Tue Nov 26 02:04:39 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 85F5C1C9B74 for ; Tue, 22 Oct 2024 17:31: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=1729618287; cv=none; b=saQMrbQFLmw+gIWi60sVlzuFOSHEhMTQgn19vNf9gKXEQ2uVxBUELjnua6ftBddwnkHbAUuDv4effLHlyR3DW2+7AL4CXbdJjeuAQVpcH2oQg74w9JifALr0ER5JepCW1MttpuFL/V+d9wGOwnmqFYas3SxXC1R9pxK9QJKK54Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618287; c=relaxed/simple; bh=wP5xmkvAAF0cc6yxByZSQ91mHbkEonU1IDc+KMo9VIA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eY3sDi1cuD934pmVhh1Q9kW5Sn3LxgqHWyfZd1yv5Ug/OLU3puJ4lqztMLjl8hEJLOcCJi4osE05frfmeVmNuVHcpu21j5/A1d3umwV7kNgannTdeJYw8K1Umqkl3q4pYWPYWYMAAIzMqpmg3Rg/8biavpB/3JPjUIuP/7ga7ss= 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=S+cnXiMv; 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="S+cnXiMv" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e7e0093018so15527467b3.3 for ; Tue, 22 Oct 2024 10:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618284; x=1730223084; 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=q2lIQmRoJAPcxBHPZc9OawDV+vOklIH/TcpOqXgiCgo=; b=S+cnXiMvonGNZ2dW1NWAbfZPGyVUqLS+LJwN07yliAZ15SHPfGcAHzbGM+db1f4VQN YTDpheEsSNv+J+xtrR3W352yXYokN686ocW0R1900sy0h8SGOx60X4uqx7fWKFibbZeP q0BFMY4QrNRJPYwtciyoTLplR9t8ZC/38ng1cwsL0vGPpaNXEStsUneiZ+JHZY6cj8s5 RiHrqugy/5E9ytrxWxl5ie9bU27Wdqw1jzWHKUzx7ZVbEXfnYTNhljpNVphEfTl2ll7q 3Iof+oOI/4phkaUHenS9z+/bZPt1uk2Xtv38qZJ9bQLt1cpLXYbuhYsj13k4o9hnTIls aYBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618284; x=1730223084; 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=q2lIQmRoJAPcxBHPZc9OawDV+vOklIH/TcpOqXgiCgo=; b=qI/V1cDELqXnEZ9EVtgpjNTWAWjM3xoPlZP1yVNk4QyYntT3ynmKWP8UqfvifRQ9Ja x7h7+P+2uRc9HCeuW+7tu9JH5H9DOXWjLuxGI1pf95SxisQRhqUVbhhpdCX7UQbSKQmk YnvYlfY4ep/BUdGxvugy6GNLzpeU53iF23NnlK79bg7YjtX7vTRTrCfB0ci8qxPkHy94 oOJh3B228niIkfnJr+o7f/OfV7Hp1hT5ef3TIuiB7tuaj269MZGQWv6QfnLOut+gSFaC PdSObTGAo/9nAYaiGWy5dU/d0QhOr8REl0sElk6fQ1AuYtX6jZalrkRQLVa83cBg/oR6 KnoQ== X-Forwarded-Encrypted: i=1; AJvYcCXB3/FERVPuEDzVrbaxtcBN+3y9GimVT26gHhnHsdI4DrtiORJJnEsgrIyJeXJlA3hPkxsTQqxcccCCm9Q=@vger.kernel.org X-Gm-Message-State: AOJu0YwMiKHTSIDaGy4KPnPgNR/vRsJaHUjUGGxb/2NwPgMiSbULvx+7 bdZS/TyzrtwJ5/K41OZS9iD/vTgKedF97e2XBu6ZGG+vG3Fs+xjymVZpAAKi2SW+XmtiL/wmUqY w6iUGtw== X-Google-Smtp-Source: AGHT+IGzmwekM0FkphwepMJvsOqlkRGtCfnNkqk3W7pCbVKQLK6M3uitUSkN44V5hE7kzuyq8IwCiMDHpmhT X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a05:690c:4783:b0:6db:c3b8:c4ce with SMTP id 00721157ae682-6e5bfd8b0edmr535057b3.7.1729618284520; Tue, 22 Oct 2024 10:31:24 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:13 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 15/16] 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 , 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 --- 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 e54c6953cf02..957b25322786 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 Tue Nov 26 02:04:39 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 2C1761C9DEB for ; Tue, 22 Oct 2024 17:31:27 +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=1729618289; cv=none; b=J5KaKTtR6fYIdEIb/lWE7243lgslnlwK6gZh4najleWkmHGEpXePUHZpoBe1MV85Z2oGG3cWiPF4mGRnDvI6nRyt+Pq4g5Rl0rHMyn6Wf7Rj/DR+a6arZSyvySCnsAkneC8SpuWkre1zCJuXhlRpm7K9KDdZciD5/j6WmM4hEbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618289; c=relaxed/simple; bh=uf+pqZIq59zWUrhBXlbY8/wph3KVNlWL4TVWGoXzUW4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=knS6i3MS9/dxbPGUaowPguGQWnl2yWRVTdAFXUHIqLWkgstUzjRMEz4ZUB/5PrbvAYFI+KXfM06uKSG1ih8g5jilhjlbbfw1OH14qZBtaaspHkexZvXV2vsxuMMZggubFQpfxaSwYPnQ1I28EOhu+rfFZV8yzz8DfbI2b1VYkCQ= 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=wkATsuC4; 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="wkATsuC4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e7e0093018so15528987b3.3 for ; Tue, 22 Oct 2024 10:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618287; x=1730223087; 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=4RCKTfa55Bgazupu7nQwlQJBbYx0nTCBpL94lBi/7F4=; b=wkATsuC4dwNJxwGu0MHucKw42b6iqQ+QYNdG0nVfmsI2ZowDc9+1JK2MhqHQtBH+NP 9+p+gPl03ngmSjW0b9rJXgFk67JGUcWkDvJBNWidYtORk1i1vybqDXaK6JysctB3p6f3 7QhIPrbPvB/56OCkiTnig+t6BUD4HWsjphmnnTN/NJ0H+T9qE82h3QyIEjB8u4wDRvXv TmQQzzLY1LoimL7k62XqxZdvVuYe1DJdcQnUWug3TnoxaZBbgRHfY5Ao2eh66lQJA7C8 b6hmgTVTezXrRsPkaTjMMlOKuHgCtF8d2II8PcVUjaeD3Bqfa+RmFImFK/uhx+r6fYiu ZW3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618287; x=1730223087; 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=4RCKTfa55Bgazupu7nQwlQJBbYx0nTCBpL94lBi/7F4=; b=IZRFJKPvniafW2agCirsJPb1FBqFdHai/Um+kjAFprAsjprQIISnmzcICDVvfL3evA b/Dw6M0ZTotN0R+gu7kWEr3WSMC2AYY1+2jgpfhn/DcZ1Guxhh8kzYXbB7HAueol/zZu 9WBQH0opam41xKPP8o256bmDSkszaH0Nh7Jq10T+GavTjK/x9dlVi/RZjBx2uN/ZIwhl PBUGJozMIujGXyvY6yAY0GCugeij+QeGdnlJxAC2dy7GiE5/8gTnQGc2f7H5ZErZJnDF muB1VYmfMaVQ2fKYdvxbNOPIlROO/KyYR9PjVDI5rIlf/ZL6tkT0vK8llrqSx7NtNt8k zwng== X-Forwarded-Encrypted: i=1; AJvYcCVM8XuwtwjhEIOJTVu+hSNoa1sD6LVSjIWJUCWMK2lUFxv9dmdO2I5obKzrgU89oxB0yXiBjMHKdgstVD0=@vger.kernel.org X-Gm-Message-State: AOJu0YytUK6O/bGFv0qO0uNPLwvhi81uXQhAOYC70ZtAwKa9vYJtnLS5 X58xthZXzKthKBhTZkupFvlJxPlIKwso1Yw3O2UBp+Ept5A0f44y5EHHlpCJbOb/BE9o6yA2EFu 6rRAkRw== X-Google-Smtp-Source: AGHT+IELK1cabkM9jyDLWipM07rBPcwjibrm8lK+0QxhvWjalP/V3OW1tr82/CblTbowpRmugUTYhUZLFi7Y X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:d350:0:b0:e28:fc1b:66bb with SMTP id 3f1490d57ef6-e2bb158a800mr8674276.6.1729618286412; Tue, 22 Oct 2024 10:31:26 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:14 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-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: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 16/16] 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 , 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. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 6e2ff0076daa..ec37f887db43 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1201,6 +1201,30 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel = *pevsel, #endif // HAVE_LIBTRACEEVENT } =20 +static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) +{ + const char *input; + struct pyrf_evlist *pevlist; + struct parse_events_error err; + + if (!PyArg_ParseTuple(args, "s", &input)) + return NULL; + + pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_evlist__type); + if (!pevlist) + return NULL; + + parse_events_error__init(&err); + memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); + evlist__init(&pevlist->evlist, NULL, NULL); + if (parse_events(&pevlist->evlist, input, &err)) { + parse_events_error__print(&err, input); + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + return (PyObject *)pevlist; +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "tracepoint", @@ -1208,6 +1232,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