From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0CFAF45ACD; Mon, 7 Oct 2024 08:59:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFCBF402A5; Mon, 7 Oct 2024 08:59:33 +0200 (CEST) Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by mails.dpdk.org (Postfix) with ESMTP id 7330340151 for ; Mon, 7 Oct 2024 08:59:33 +0200 (CEST) Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-458320b30e7so30260341cf.0 for ; Sun, 06 Oct 2024 23:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728284373; x=1728889173; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KSOo6jj4rYDDM4V9gZFLUk5nzalz/VjvZVboe+uRcLw=; b=Uv7uEszdztUvAIGYX2o0U08tgzrNCBLPaPW/PcVAi/lFhujk9XyVxlhSyjZg14WDH/ F0TQ5Ko/23XP2WcFpeonhkwzISJ4KeGUHiaeIWcdk/+mnPzqKv1oHhPK979bCcBBHcfm XByxggt2V9y5fFVAE5kYMM8jUQ8cF1IzvtL7N4PgxOjogHiH1uCjef+YXZVEZHZ2xoqN zPIkqbB/EKD4ZlzHJ+8yxlnXUt7Xuyr7HExbuXoCFLccdkTV2zW6qU74QcG2lUuFcJIt czOm1hUJtLoUJJzAbSx6E/Z0PN9ZenlAhX5i/GLjZtyUa/y4y3hXlH9LQB9F2XW1TiRA Ns8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728284373; x=1728889173; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KSOo6jj4rYDDM4V9gZFLUk5nzalz/VjvZVboe+uRcLw=; b=sCGfZOcOLlqc/7CrAZT66LkIfi7iHUUSh8A0vGFbeEElsJC7EwJhI9pkABXcHAEd5B Y1vEdfGv30xyeo+hsWwe2rkaE2l/G0WJmFneQtSPZjb3p4O+c8UaJ7lJ2f9iL8P+ZwQC FpOlBupdROy3vJw7LlX7+4+NOgAOlqpH0btSX4hdpBEvfvaXE2Cq5Wi3ZDpR/7Ay//E2 Kg5RWsM2IWzV7hDkTMe0NhIcSALzRdIQNEg7WHl4HQW7CUvYkR8XRikGLx3l97GujMWO xON5l430vjc/ik7pJVK8rxn7PrqT0mextFv5SLRtWcA5Rt0Cl4hwoAlY/EgH+1vC9OhN mRXA== X-Forwarded-Encrypted: i=1; AJvYcCUzo4hoRCQFxrHUHfhg7r4eY4Ok18Vw5g3N3nC6MdKHAS+JsgFHn4n7QydIdJAn3Pn+5PQ=@dpdk.org X-Gm-Message-State: AOJu0YzJ/eVlzU9gFmhz/v2J0iA40zUQ9eZu2J3zdjynzeFs4JHykmNf UFcJu/m7fL1EUelMW5QKuT6P3LG26CO6XoMsKmvvVCAvq0veM/x8badIk8d4TcK4ESf4eVnEL1p tg0D8Y8OFB6up0zg+acGBeDlIzW4= X-Google-Smtp-Source: AGHT+IG1LFt0G/kbnRqsIWIVQLY7pxDTam6nE0IE2WQrog8VK0ucjJvmO4gzV1XeEam1Gps66cYPvkmROwbAQhfy/Qo= X-Received: by 2002:ac8:578d:0:b0:456:45c6:2c30 with SMTP id d75a77b69052e-45d9bb7c434mr159701061cf.53.1728284372666; Sun, 06 Oct 2024 23:59:32 -0700 (PDT) MIME-Version: 1.0 References: <20230216175502.3164820-1-tduszynski@marvell.com> <20240927220630.1802971-1-tduszynski@marvell.com> <20240927220630.1802971-2-tduszynski@marvell.com> In-Reply-To: <20240927220630.1802971-2-tduszynski@marvell.com> From: Jerin Jacob Date: Mon, 7 Oct 2024 12:29:06 +0530 Message-ID: Subject: Re: [PATCH v12 1/4] lib: add generic support for reading PMU events To: Tomasz Duszynski Cc: Ruifeng.Wang@arm.com, bruce.richardson@intel.com, david.marchand@redhat.com, dev@dpdk.org, jerinj@marvell.com, mattias.ronnblom@ericsson.com, mb@smartsharesystems.com, roretzla@linux.microsoft.com, thomas@monjalon.net, zhoumin@loongson.cn, konstantin.v.ananyev@yandex.ru Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Sat, Sep 28, 2024 at 3:37=E2=80=AFAM Tomasz Duszynski wrote: > > Add support for programming PMU counters and reading their values > in runtime bypassing kernel completely. > > This is especially useful in cases where CPU cores are isolated > i.e run dedicated tasks. In such cases one cannot use standard > perf utility without sacrificing latency and performance. > > Signed-off-by: Tomasz Duszynski > --- > MAINTAINERS | 5 + > app/test/meson.build | 1 + > app/test/test_pmu.c | 62 ++++ > doc/api/doxy-api-index.md | 3 +- > doc/api/doxy-api.conf.in | 1 + > doc/guides/prog_guide/profile_app.rst | 26 ++ > doc/guides/rel_notes/release_24_11.rst | 7 + > lib/meson.build | 1 + > lib/pmu/meson.build | 15 + > lib/pmu/pmu_private.h | 32 ++ > lib/pmu/rte_pmu.c | 465 +++++++++++++++++++++++++ > lib/pmu/rte_pmu.h | 206 +++++++++++ > lib/pmu/version.map | 14 + > 13 files changed, 837 insertions(+), 1 deletion(-) > create mode 100644 app/test/test_pmu.c > create mode 100644 lib/pmu/meson.build > create mode 100644 lib/pmu/pmu_private.h > create mode 100644 lib/pmu/rte_pmu.c > create mode 100644 lib/pmu/rte_pmu.h > create mode 100644 lib/pmu/version.map > > diff --git a/MAINTAINERS b/MAINTAINERS > index c5a703b5c0..80bf5968de 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -1811,6 +1811,11 @@ M: Nithin Dabilpuram > M: Pavan Nikhilesh > F: lib/node/ > > +PMU - EXPERIMENTAL > +M: Tomasz Duszynski > +F: lib/pmu/ > +F: app/test/test_pmu* > + > > Test Applications > ----------------- > diff --git a/app/test/meson.build b/app/test/meson.build > index e29258e6ec..45f56d8aae 100644 > --- a/app/test/meson.build > +++ b/app/test/meson.build > @@ -139,6 +139,7 @@ source_file_deps =3D { > 'test_pmd_perf.c': ['ethdev', 'net'] + packet_burst_generator_deps, > 'test_pmd_ring.c': ['net_ring', 'ethdev', 'bus_vdev'], > 'test_pmd_ring_perf.c': ['ethdev', 'net_ring', 'bus_vdev'], > + 'test_pmu.c': ['pmu'], > 'test_power.c': ['power'], > 'test_power_cpufreq.c': ['power'], > 'test_power_intel_uncore.c': ['power'], > diff --git a/app/test/test_pmu.c b/app/test/test_pmu.c > new file mode 100644 > index 0000000000..5792cf1963 > --- /dev/null > +++ b/app/test/test_pmu.c > @@ -0,0 +1,62 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. 2023 -> 2024 across the patches. > + */ > + > +#include "test.h" > + > +#ifndef RTE_EXEC_ENV_LINUX There is a lot of condition compilation across the series. I think, we can remove all that by returning -ENOSUP for rte_pmu_init() and friends for Non Linux Operating systems and adjusting the documentation, so the caller is aware of the contract. or add rte_pmd_feature_is_enabled() or so. > > - **misc**: > [EAL config](@ref rte_eal.h), > diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in > index a8823c046f..658490b6a2 100644 > --- a/doc/api/doxy-api.conf.in > +++ b/doc/api/doxy-api.conf.in > @@ -69,6 +69,7 @@ INPUT =3D @TOPDIR@/doc/api/doxy-api-i= ndex.md \ > @TOPDIR@/lib/pdcp \ > @TOPDIR@/lib/pdump \ > @TOPDIR@/lib/pipeline \ > + @TOPDIR@/lib/pmu \ > @TOPDIR@/lib/port \ > @TOPDIR@/lib/power \ > @TOPDIR@/lib/ptr_compress \ > diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guid= e/profile_app.rst > index a6b5fb4d5e..ecb90a0d94 100644 > --- a/doc/guides/prog_guide/profile_app.rst > +++ b/doc/guides/prog_guide/profile_app.rst > @@ -7,6 +7,32 @@ Profile Your Application > The following sections describe methods of profiling DPDK applications o= n > different architectures. > > +Performance counter based profiling > +----------------------------------- > + > +Majority of architectures support some performance monitoring unit (PMU)= . > +Such unit provides programmable counters that monitor specific events. > + > +Different tools gather that information, like for example perf. > +However, in some scenarios when CPU cores are isolated and run > +dedicated tasks interrupting those tasks with perf may be undesirable. > + > +In such cases, an application can use the PMU library to read such event= s via ``rte_pmu_read()``. > + > +By default, userspace applications are not allowed to access PMU interna= ls. That can be changed > +by setting ``/sys/kernel/perf_event_paranoid`` to 2 (that should be a de= fault value anyway) and > +adding ``CAP_PERFMON`` capability to DPDK application. Please refer to > +``Documentation/admin-guide/perf-security.rst`` under Linux sources for = more information. Fairly > +recent kernel, i.e >=3D 5.9, is advised too. > + > +As of now implementation imposes certain limitations: > + > +* Only EAL lcores are supported > + > +* EAL lcores must not share a cpu > + > +* Each EAL lcore measures same group of events > + > > new file mode 100644 > index 0000000000..abf32da967 > --- /dev/null > +++ b/lib/pmu/rte_pmu.h > @@ -0,0 +1,206 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2024 Marvell > + */ > + > +#ifndef _RTE_PMU_H_ > +#define _RTE_PMU_H_ > + > +/** > + * @file > + * > + * PMU event tracing operations > + * > + * This file defines generic API and types necessary to setup PMU and > + * read selected counters in runtime. > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +/** Maximum number of events in a group */ > +#define RTE_MAX_NUM_GROUP_EVENTS 8 > + > +/** > + * A structure describing a group of events. > + */ > +struct __rte_cache_aligned rte_pmu_event_group { > + /**< array of user pages */ Remove < as comment is before the symbol. Please check generated documentation to tally all documentation. > + struct perf_event_mmap_page *mmap_pages[RTE_MAX_NUM_GROUP_EVENTS]= ; > + int fds[RTE_MAX_NUM_GROUP_EVENTS]; /**< array of event descriptor= s */ > + bool enabled; /**< true if group was enabled on particular lcore = */ > + TAILQ_ENTRY(rte_pmu_event_group) next; /**< list entry */ > +}; > +