From nobody Sun Dec 14 06:21:54 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A80C433EF for ; Mon, 14 Feb 2022 11:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350368AbiBNLQe convert rfc822-to-8bit (ORCPT ); Mon, 14 Feb 2022 06:16:34 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350718AbiBNLPv (ORCPT ); Mon, 14 Feb 2022 06:15:51 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E172A1A4 for ; Mon, 14 Feb 2022 02:46:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-223-Z48kIwZ6OBWnlfFdy6e65g-1; Mon, 14 Feb 2022 05:46:36 -0500 X-MC-Unique: Z48kIwZ6OBWnlfFdy6e65g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 787313E741; Mon, 14 Feb 2022 10:46:34 +0000 (UTC) Received: from x1.com (unknown [10.22.16.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id C868C26DFB; Mon, 14 Feb 2022 10:46:19 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt Cc: Daniel Bristot de Oliveira , Jonathan Corbet , Ingo Molnar , Thomas Gleixner , Peter Zijlstra , Will Deacon , Catalin Marinas , Marco Elver , Dmitry Vyukov , "Paul E. McKenney" , Shuah Khan , Gabriele Paoloni , Juri Lelli , Clark Williams , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [RFC V2 05/21] rv/include: Add tracing helper functions Date: Mon, 14 Feb 2022 11:44:56 +0100 Message-Id: <6b1c197c0b1dc9a27cfb71330ee2a0d670c93366.1644830251.git.bristot@kernel.org> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=bristot@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Tracing helper functions to facilitate the instrumentation of auto-generated RV monitors create by dot2k. Cc: Jonathan Corbet Cc: Steven Rostedt Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Will Deacon Cc: Catalin Marinas Cc: Marco Elver Cc: Dmitry Vyukov Cc: "Paul E. McKenney" Cc: Shuah Khan Cc: Gabriele Paoloni Cc: Juri Lelli Cc: Clark Williams Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-trace-devel@vger.kernel.org Signed-off-by: Daniel Bristot de Oliveira --- include/rv/trace_helpers.h | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 include/rv/trace_helpers.h diff --git a/include/rv/trace_helpers.h b/include/rv/trace_helpers.h new file mode 100644 index 000000000000..440c681148a8 --- /dev/null +++ b/include/rv/trace_helpers.h @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Helper functions to facilitate the instrumentation of auto-generated + * RV monitors create by dot2k. + * + * The dot2k tool is available at tools/tracing/rv/dot2/ + * + * Copyright (C) 2019-2022 Daniel Bristot de Oliveira + */ + +#include + +struct tracepoint_hook_helper { + struct tracepoint *tp; + void *probe; + int registered; + char *name; +}; + +static inline void thh_compare_name(struct tracepoint *tp, void *priv) +{ + struct tracepoint_hook_helper *thh =3D priv; + + if (!strcmp(thh->name, tp->name)) + thh->tp =3D tp; +} + +static inline bool thh_fill_struct_tracepoint(struct tracepoint_hook_helpe= r *thh) +{ + for_each_kernel_tracepoint(thh_compare_name, thh); + + return !!thh->tp; +} + +static inline void thh_unhook_probes(struct tracepoint_hook_helper *thh, i= nt helpers_count) +{ + int i; + + for (i =3D 0; i < helpers_count; i++) { + if (!thh[i].registered) + continue; + + tracepoint_probe_unregister(thh[i].tp, thh[i].probe, NULL); + } +} + +static inline int thh_hook_probes(struct tracepoint_hook_helper *thh, int = helpers_count) +{ + int retval; + int i; + + for (i =3D 0; i < helpers_count; i++) { + retval =3D thh_fill_struct_tracepoint(&thh[i]); + if (!retval) + goto out_err; + + retval =3D tracepoint_probe_register(thh[i].tp, thh[i].probe, NULL); + + if (retval) + goto out_err; + + thh[i].registered =3D 1; + } + return 0; + +out_err: + thh_unhook_probes(thh, helpers_count); + return -EINVAL; +} --=20 2.33.1