linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Varad Gautam <varadgautam@google.com>
To: linux-arch@vger.kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>,
	Sai Prakash Ranjan <quic_saipraka@quicinc.com>,
	 linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] asm-generic/io.h: Skip trace helpers if rwmmio events are disabled
Date: Mon, 7 Apr 2025 18:13:44 +0200	[thread overview]
Message-ID: <CAOLDJO+=+hcz498KRc+95dF5y3hZdtm+3y35o2rBC9qAOF-vDg@mail.gmail.com> (raw)
In-Reply-To: <20250330164229.2174672-1-varadgautam@google.com>

On Sun, Mar 30, 2025 at 6:42 PM Varad Gautam <varadgautam@google.com> wrote:
>
> With `CONFIG_TRACE_MMIO_ACCESS=y`, the `{read,write}{b,w,l,q}{_relaxed}()`
> mmio accessors unconditionally call `log_{post_}{read,write}_mmio()`
> helpers, which in turn call the ftrace ops for `rwmmio` trace events
>
> This adds a performance penalty per mmio accessor call, even when
> `rwmmio` events are disabled at runtime (~80% overhead on local
> measurement).
>
> Guard these with `tracepoint_enabled()`.
>
> Signed-off-by: Varad Gautam <varadgautam@google.com>
> Fixes: 210031971cdd ("asm-generic/io: Add logging support for MMIO accessors")
> Cc: <stable@vger.kernel.org>

Ping.

> ---
>  include/asm-generic/io.h | 98 +++++++++++++++++++++++++++-------------
>  1 file changed, 66 insertions(+), 32 deletions(-)
>
> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> index 3c61c29ff6ab..a9b5da547523 100644
> --- a/include/asm-generic/io.h
> +++ b/include/asm-generic/io.h
> @@ -75,6 +75,7 @@
>  #if IS_ENABLED(CONFIG_TRACE_MMIO_ACCESS) && !(defined(__DISABLE_TRACE_MMIO__))
>  #include <linux/tracepoint-defs.h>
>
> +#define rwmmio_tracepoint_enabled(tracepoint) tracepoint_enabled(tracepoint)
>  DECLARE_TRACEPOINT(rwmmio_write);
>  DECLARE_TRACEPOINT(rwmmio_post_write);
>  DECLARE_TRACEPOINT(rwmmio_read);
> @@ -91,6 +92,7 @@ void log_post_read_mmio(u64 val, u8 width, const volatile void __iomem *addr,
>
>  #else
>
> +#define rwmmio_tracepoint_enabled(tracepoint) false
>  static inline void log_write_mmio(u64 val, u8 width, volatile void __iomem *addr,
>                                   unsigned long caller_addr, unsigned long caller_addr0) {}
>  static inline void log_post_write_mmio(u64 val, u8 width, volatile void __iomem *addr,
> @@ -189,11 +191,13 @@ static inline u8 readb(const volatile void __iomem *addr)
>  {
>         u8 val;
>
> -       log_read_mmio(8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(8, addr, _THIS_IP_, _RET_IP_);
>         __io_br();
>         val = __raw_readb(addr);
>         __io_ar(val);
> -       log_post_read_mmio(val, 8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 8, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -204,11 +208,13 @@ static inline u16 readw(const volatile void __iomem *addr)
>  {
>         u16 val;
>
> -       log_read_mmio(16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(16, addr, _THIS_IP_, _RET_IP_);
>         __io_br();
>         val = __le16_to_cpu((__le16 __force)__raw_readw(addr));
>         __io_ar(val);
> -       log_post_read_mmio(val, 16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 16, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -219,11 +225,13 @@ static inline u32 readl(const volatile void __iomem *addr)
>  {
>         u32 val;
>
> -       log_read_mmio(32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(32, addr, _THIS_IP_, _RET_IP_);
>         __io_br();
>         val = __le32_to_cpu((__le32 __force)__raw_readl(addr));
>         __io_ar(val);
> -       log_post_read_mmio(val, 32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 32, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -235,11 +243,13 @@ static inline u64 readq(const volatile void __iomem *addr)
>  {
>         u64 val;
>
> -       log_read_mmio(64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(64, addr, _THIS_IP_, _RET_IP_);
>         __io_br();
>         val = __le64_to_cpu((__le64 __force)__raw_readq(addr));
>         __io_ar(val);
> -       log_post_read_mmio(val, 64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 64, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -249,11 +259,13 @@ static inline u64 readq(const volatile void __iomem *addr)
>  #define writeb writeb
>  static inline void writeb(u8 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
>         __io_bw();
>         __raw_writeb(value, addr);
>         __io_aw();
> -       log_post_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> @@ -261,11 +273,13 @@ static inline void writeb(u8 value, volatile void __iomem *addr)
>  #define writew writew
>  static inline void writew(u16 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
>         __io_bw();
>         __raw_writew((u16 __force)cpu_to_le16(value), addr);
>         __io_aw();
> -       log_post_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> @@ -273,11 +287,13 @@ static inline void writew(u16 value, volatile void __iomem *addr)
>  #define writel writel
>  static inline void writel(u32 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
>         __io_bw();
>         __raw_writel((u32 __force)__cpu_to_le32(value), addr);
>         __io_aw();
> -       log_post_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> @@ -286,11 +302,13 @@ static inline void writel(u32 value, volatile void __iomem *addr)
>  #define writeq writeq
>  static inline void writeq(u64 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
>         __io_bw();
>         __raw_writeq((u64 __force)__cpu_to_le64(value), addr);
>         __io_aw();
> -       log_post_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>  #endif /* CONFIG_64BIT */
> @@ -306,9 +324,11 @@ static inline u8 readb_relaxed(const volatile void __iomem *addr)
>  {
>         u8 val;
>
> -       log_read_mmio(8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(8, addr, _THIS_IP_, _RET_IP_);
>         val = __raw_readb(addr);
> -       log_post_read_mmio(val, 8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 8, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -319,9 +339,11 @@ static inline u16 readw_relaxed(const volatile void __iomem *addr)
>  {
>         u16 val;
>
> -       log_read_mmio(16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(16, addr, _THIS_IP_, _RET_IP_);
>         val = __le16_to_cpu((__le16 __force)__raw_readw(addr));
> -       log_post_read_mmio(val, 16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 16, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -332,9 +354,11 @@ static inline u32 readl_relaxed(const volatile void __iomem *addr)
>  {
>         u32 val;
>
> -       log_read_mmio(32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(32, addr, _THIS_IP_, _RET_IP_);
>         val = __le32_to_cpu((__le32 __force)__raw_readl(addr));
> -       log_post_read_mmio(val, 32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 32, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -345,9 +369,11 @@ static inline u64 readq_relaxed(const volatile void __iomem *addr)
>  {
>         u64 val;
>
> -       log_read_mmio(64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_read))
> +               log_read_mmio(64, addr, _THIS_IP_, _RET_IP_);
>         val = __le64_to_cpu((__le64 __force)__raw_readq(addr));
> -       log_post_read_mmio(val, 64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_read))
> +               log_post_read_mmio(val, 64, addr, _THIS_IP_, _RET_IP_);
>         return val;
>  }
>  #endif
> @@ -356,9 +382,11 @@ static inline u64 readq_relaxed(const volatile void __iomem *addr)
>  #define writeb_relaxed writeb_relaxed
>  static inline void writeb_relaxed(u8 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
>         __raw_writeb(value, addr);
> -       log_post_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 8, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> @@ -366,9 +394,11 @@ static inline void writeb_relaxed(u8 value, volatile void __iomem *addr)
>  #define writew_relaxed writew_relaxed
>  static inline void writew_relaxed(u16 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
>         __raw_writew((u16 __force)cpu_to_le16(value), addr);
> -       log_post_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> @@ -376,9 +406,11 @@ static inline void writew_relaxed(u16 value, volatile void __iomem *addr)
>  #define writel_relaxed writel_relaxed
>  static inline void writel_relaxed(u32 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
>         __raw_writel((u32 __force)__cpu_to_le32(value), addr);
> -       log_post_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> @@ -386,9 +418,11 @@ static inline void writel_relaxed(u32 value, volatile void __iomem *addr)
>  #define writeq_relaxed writeq_relaxed
>  static inline void writeq_relaxed(u64 value, volatile void __iomem *addr)
>  {
> -       log_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_write))
> +               log_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
>         __raw_writeq((u64 __force)__cpu_to_le64(value), addr);
> -       log_post_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
> +       if (rwmmio_tracepoint_enabled(rwmmio_post_write))
> +               log_post_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
>  }
>  #endif
>
> --
> 2.49.0.472.ge94155a9ec-goog
>

  reply	other threads:[~2025-04-07 16:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-30 16:42 [PATCH] asm-generic/io.h: Skip trace helpers if rwmmio events are disabled Varad Gautam
2025-04-07 16:13 ` Varad Gautam [this message]
2025-04-28 19:41   ` Varad Gautam
2025-05-28 11:58     ` Varad Gautam
2025-07-24 11:49       ` Varad Gautam
2025-07-26 16:22         ` Arnd Bergmann
2025-09-23 11:07           ` Varad Gautam
2025-09-24 14:25             ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOLDJO+=+hcz498KRc+95dF5y3hZdtm+3y35o2rBC9qAOF-vDg@mail.gmail.com' \
    --to=varadgautam@google.com \
    --cc=arnd@arndb.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_saipraka@quicinc.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).