From patchwork Fri Nov 11 09:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Duszynski X-Patchwork-Id: 119797 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 97506A0542; Fri, 11 Nov 2022 10:44:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5787442D37; Fri, 11 Nov 2022 10:44:00 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id BBDBA42D34 for ; Fri, 11 Nov 2022 10:43:58 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AB959ST021637; Fri, 11 Nov 2022 01:43:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=yMjdXhDj6aMAai62vfrcP7moSkEPuHrJD/JI1EYYTKA=; b=Zs7lEOQuH0sGbboDGEVU/mz0tNZdxBmdV6Egpl5mFdIt6rHGZ7HHo2XP2oxt179PG/RR lyE/oPOgD45/NxHDnETOo3TSIcIf7TWDYExewhBzZOTKVaiXDeARliqQm5OP2AXDVgMN gAfI9qhy5FcqwSVgWcyDH5hdHikJlCeUseykUuvXuwFX2+fT9gECe5KfNV4ZpSTGNcJw uto2EKkMN+xuRYy8bfQZI7Gp375SPhTGoV2afrjXdkouqRC0PUpJieeTqaHQsSSLsVPL ULZ4JUpK/6Yu3pvm8D4rA37qamm+5tyauTnf0WJ7fiKnuw5m8LJDYCIuPLsffDJr9UOi FA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3kskf0r34j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 11 Nov 2022 01:43:57 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 11 Nov 2022 01:43:56 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 11 Nov 2022 01:43:56 -0800 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id 2F1A13F70B4; Fri, 11 Nov 2022 01:43:53 -0800 (PST) From: Tomasz Duszynski To: , , Jerin Jacob , Sunil Kumar Kori CC: Subject: [PATCH 4/4] eal: add PMU support to tracing library Date: Fri, 11 Nov 2022 10:43:38 +0100 Message-ID: <20221111094338.2736065-5-tduszynski@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111094338.2736065-1-tduszynski@marvell.com> References: <20221111094338.2736065-1-tduszynski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: HfR4oBN9vk_y-vqiKqqakG_ZsEt5jacl X-Proofpoint-GUID: HfR4oBN9vk_y-vqiKqqakG_ZsEt5jacl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-11_05,2022-11-09_01,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In order to profile app one needs to store significant amount of samples somewhere for an analysis latern on. Since trace library supports storing data in a CTF format lets take adventage of that and add a dedicated PMU tracepoint. Signed-off-by: Tomasz Duszynski --- app/test/test_trace_perf.c | 4 ++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 32 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 3 ++ lib/eal/common/rte_pmu.c | 63 ++++++++++++++++++++++++ lib/eal/include/rte_eal_trace.h | 11 +++++ lib/eal/version.map | 1 + 7 files changed, 119 insertions(+) diff --git a/app/test/test_trace_perf.c b/app/test/test_trace_perf.c index 46ae7d8074..4851b6852f 100644 --- a/app/test/test_trace_perf.c +++ b/app/test/test_trace_perf.c @@ -114,6 +114,8 @@ worker_fn_##func(void *arg) \ #define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666) #define GENERIC_STR rte_eal_trace_generic_str("hello world") #define VOID_FP app_dpdk_test_fp() +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_eal_trace_pmu_read(0) WORKER_DEFINE(GENERIC_VOID) WORKER_DEFINE(GENERIC_U64) @@ -122,6 +124,7 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +WORKER_DEFINE(READ_PMU) static void run_test(const char *str, lcore_function_t f, struct test_data *data, size_t sz) @@ -174,6 +177,7 @@ test_trace_perf(void) run_test("double", worker_fn_GENERIC_DOUBLE, data, sz); run_test("string", worker_fn_GENERIC_STR, data, sz); run_test("void_fp", worker_fn_VOID_FP, data, sz); + run_test("read_pmu", worker_fn_READ_PMU, data, sz); rte_free(data); return TEST_SUCCESS; diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guide/profile_app.rst index 8fc1b20cab..977800ea01 100644 --- a/doc/guides/prog_guide/profile_app.rst +++ b/doc/guides/prog_guide/profile_app.rst @@ -16,6 +16,11 @@ that information, perf being an example here. Though in some scenarios, eg. when isolated (nohz_full) and run dedicated tasks, using perf is less than ideal. In such cases one can read specific events directly from application via ``rte_pmu_read()``. +Alternatively tracing library can be used which offers dedicated tracepoint +``rte_eal_trace_pmu_event()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ---------------- diff --git a/doc/guides/prog_guide/trace_lib.rst b/doc/guides/prog_guide/trace_lib.rst index 9a8f38073d..9a845fd86f 100644 --- a/doc/guides/prog_guide/trace_lib.rst +++ b/doc/guides/prog_guide/trace_lib.rst @@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format `_. +- Support reading PMU events on ARM64 and x86 (Intel) How to add a tracepoint? ------------------------ @@ -137,6 +138,37 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance measurement unit (PMU) event values can be read from hardware +registers using predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` and expression +``e=ev1[,ev2,...]`` matching particular events:: + + --trace='*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` +directory, where ``PMU`` is a placeholder for either a ``cpu`` or a directory +containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. Instead, caller passes index which follows the order of +events specified via ``--trace`` parameter. In the following example index ``0`` +corresponds to ``cpu_cyclces`` while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + ... + rte_eal_trace_pmu_read(0); + rte_eal_trace_pmu_read(1); + ... + +PMU tracing support must be explicitly enabled using the ``enable_trace_fp`` +option for meson build. + Event record mode ----------------- diff --git a/lib/eal/common/eal_common_trace_points.c b/lib/eal/common/eal_common_trace_points.c index 0b0b254615..de918ca618 100644 --- a/lib/eal/common/eal_common_trace_points.c +++ b/lib/eal/common/eal_common_trace_points.c @@ -75,3 +75,6 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +RTE_TRACE_POINT_REGISTER(rte_eal_trace_pmu_read, + lib.eal.pmu.read) diff --git a/lib/eal/common/rte_pmu.c b/lib/eal/common/rte_pmu.c index 7d3bd57d1d..40c454f92a 100644 --- a/lib/eal/common/rte_pmu.c +++ b/lib/eal/common/rte_pmu.c @@ -18,6 +18,7 @@ #include #include "pmu_private.h" +#include "eal_trace.h" #define EVENT_SOURCE_DEVICES_PATH "/sys/bus/event_source/devices" @@ -402,11 +403,70 @@ rte_pmu_add_event(const char *name) return event->index; } +static void +add_events(const char *pattern) +{ + char *token, *copy; + int ret; + + copy = strdup(pattern); + if (!copy) + return; + + token = strtok(copy, ","); + while (token) { + ret = rte_pmu_add_event(token); + if (ret < 0) + RTE_LOG(ERR, EAL, "failed to add %s event\n", token); + + token = strtok(NULL, ","); + } + + free(copy); +} + +static void +add_events_by_pattern(const char *pattern) +{ + regmatch_t rmatch; + char buf[BUFSIZ]; + unsigned int num; + regex_t reg; + + /* events are matched against occurrences of e=ev1[,ev2,..] pattern */ + if (regcomp(®, "e=([_[:alnum:]-],?)+", REG_EXTENDED)) + return; + + for (;;) { + if (regexec(®, pattern, 1, &rmatch, 0)) + break; + + num = rmatch.rm_eo - rmatch.rm_so; + if (num > sizeof(buf)) + num = sizeof(buf); + + /* skip e= pattern prefix */ + memcpy(buf, pattern + rmatch.rm_so + 2, num - 2); + buf[num] = '\0'; + add_events(buf); + + pattern += rmatch.rm_eo; + } + + regfree(®); +} + void eal_pmu_init(void) { + struct trace_arg *arg; + struct trace *trace; int ret; + trace = trace_obj_get(); + if (!trace) + RTE_LOG(WARNING, EAL, "tracing not initialized\n"); + pmu = rte_calloc(NULL, 1, sizeof(*pmu), RTE_CACHE_LINE_SIZE); if (!pmu) { RTE_LOG(ERR, EAL, "failed to alloc PMU\n"); @@ -428,6 +488,9 @@ eal_pmu_init(void) goto out; } + STAILQ_FOREACH(arg, &trace->args, next) + add_events_by_pattern(arg->val); + return; out: free(pmu->name); diff --git a/lib/eal/include/rte_eal_trace.h b/lib/eal/include/rte_eal_trace.h index 5ef4398230..2a10f63e97 100644 --- a/lib/eal/include/rte_eal_trace.h +++ b/lib/eal/include/rte_eal_trace.h @@ -17,6 +17,7 @@ extern "C" { #include #include +#include #include #include "eal_interrupts.h" @@ -279,6 +280,16 @@ RTE_TRACE_POINT( rte_trace_point_emit_string(cpuset); ) +/* PMU */ +RTE_TRACE_POINT_FP( + rte_eal_trace_pmu_read, + RTE_TRACE_POINT_ARGS(int index), + uint64_t val; + rte_trace_point_emit_int(index); + val = rte_pmu_read(index); + rte_trace_point_emit_u64(val); +) + #ifdef __cplusplus } #endif diff --git a/lib/eal/version.map b/lib/eal/version.map index e870c87493..d6ec3f3b0e 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -432,6 +432,7 @@ EXPERIMENTAL { rte_thread_set_priority; # added in 22.11 + __rte_eal_trace_pmu_read; # WINDOWS_NO_EXPORT rte_pmu_add_event; # WINDOWS_NO_EXPORT rte_pmu_read; # WINDOWS_NO_EXPORT rte_thread_attr_get_affinity;