From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B720C4727E for ; Thu, 24 Sep 2020 17:18:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0764823A5C for ; Thu, 24 Sep 2020 17:18:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbgIXRSu (ORCPT ); Thu, 24 Sep 2020 13:18:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:60642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728501AbgIXRSt (ORCPT ); Thu, 24 Sep 2020 13:18:49 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1184B2395C; Thu, 24 Sep 2020 17:18:49 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94) (envelope-from ) id 1kLUtK-0029ba-VA; Thu, 24 Sep 2020 13:18:46 -0400 Message-ID: <20200924170928.466191266@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Sep 2020 13:09:28 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Yafang Shao , Axel Rasmussen , Andrew Morton , Vlastimil Babka , Michel Lespinasse , Daniel Jordan , Davidlohr Bueso , Linux MM , Ingo Molnar , Joonsoo Kim , Mathieu Desnoyers Subject: [PATCH 0/2] tracing/mm: Add tracepoint_enabled() helper function for headers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tracepoints are not safe to be called directly from header files as they may be included by C code that has CREATE_TRACE_POINTS defined, and this would cause side effects and possibly break the build in hard to debug ways. Instead, it is recommended to call a tracepoint helper function that is defined in a C file that calls the tracepoint. But we would only want this function to be called if the tracepoint is enabled, as function calls add overhead. The trace__enabled() function is also no safe to be called in a header file as it is created by the tracepoint header, which suffers the same fate if CREATE_TRACE_POINTS is defined. Instead, the tracepoint needs to be declared as an extern, and the helper function can test the static key to call the helper function that calls the tracepoint. This has been done by open coding the tracepoint extern and calling the static key directly: commit 95813b8faa0cd ("mm/page_ref: add tracepoint to track down page reference manipulation") does this (back in 2016). Now we have another use case, so a helper function should be created to keep the internals of the tracepoints from being spread out in other subsystems. Link: https://lore.kernel.org/r/20200922125113.12ef1e03@gandalf.local.home This adds tracepoint_enabled() helper macro and DECLARE_TRACEPOINT() macro to allow this to be done without exposing the internals of the tracepoints. The first patch adds the infrastructure, the second converts page_ref over to it. I also noticed that the msr tracepoint needs to be converted as well. Steven Rostedt (VMware) (2): tracepoints: Add helper to test if tracepoint is enabled in a header mm/page_ref: Convert the open coded tracepoint enabled to the new helper ---- Documentation/trace/tracepoints.rst | 25 ++++++++++++++++++++++ include/linux/page_ref.h | 42 ++++++++++++++++++------------------- include/linux/tracepoint-defs.h | 33 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 21 deletions(-)