Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3988771iog; Tue, 28 Jun 2022 06:57:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sv81DUsQMzdrVlcqq5tmRCX5DdsPFPsK1l5vJxHiuPTZksadjm9pZJzstpsKbO7oPlBcLt X-Received: by 2002:a17:902:da91:b0:16a:4760:a4d3 with SMTP id j17-20020a170902da9100b0016a4760a4d3mr3807713plx.150.1656424652870; Tue, 28 Jun 2022 06:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656424652; cv=none; d=google.com; s=arc-20160816; b=ATopJC4A612lEQwqLq2r1VABst9+7Wv7AN7bbH/ORmPWtu6bVDHNXXwZ4qqYxmkHu+ hWboZMxe1MYrYEURJWoe+7kJk0fekAGYreDfJaTPOYUbdtwNdREEp8FbUTqETU7tQZlt 33tboOtD0PXpMtXSXLZm6QWojdYCdg/urPnTndLnMdYZeJoK0vY/j5SULhgE/327lobr 3XXzRvkJTzxdjTnegF23Oyuyg/DJX296zCr2KS9H0y6rhKmCs1bO22/IzPAuc/HkUM5N cddUOh7qvmE9xNmnUwob9Bm6kg8qnlVVyBPKPEHq7R6ZnHzP7rYlX5nchDOXIl9J2ehV Bcow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=X57uwopXnuwAGxBJfo3nXt3MJLIDmWTaNVtJmoGBIrs=; b=tHzElqhxp60n7tHVNiVt5Y5lSKeIgVNeDCW2hvQOhiQchWv2eupO152A2or0wqaZCS OHphrqiu6AXBbuM9G1bakVJ72XBoYN65We2LJ5rOUAuv12YZoAbF2h5QBTZxmFG6uaQf HmdjMJLlMZAlShmK3uCR5DdgcBFUBBuiVG/YTOvydLFJg/ZkNSZoX8L3FL1p9cmycnLP aKt3HK2O2h9DNTLL/uqQN2n5V8py68qLFPwxfS8GJNVK6DBgfrzdQsTimxG5cjGWyHER xbJwlmo4MLho/qb9EtzYHktL6q88BMkdF7SnRoCsiUJStAi021QTYD3D0IRVUSnBlx8o 1csQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AT2t+rTr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x27-20020a637c1b000000b003fc4d7e5410si16864492pgc.850.2022.06.28.06.57.19; Tue, 28 Jun 2022 06:57:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AT2t+rTr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346249AbiF1NRv (ORCPT + 99 others); Tue, 28 Jun 2022 09:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346211AbiF1NRM (ORCPT ); Tue, 28 Jun 2022 09:17:12 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D86F32052 for ; Tue, 28 Jun 2022 06:17:02 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id i18so22220566lfu.8 for ; Tue, 28 Jun 2022 06:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=X57uwopXnuwAGxBJfo3nXt3MJLIDmWTaNVtJmoGBIrs=; b=AT2t+rTr3KgCX8AA8eDt3WrbxtMhylo4g1A8Gxq1VecJhw5AD9vpsoz/2xq2XcDZUW tptAB4ig8ybMBqdwhS7/u5onHQdA/cUFgW1Ek02/2U2+Gtw3+8M6eRTac5lfoAAsHvgz sF7cUuFbFVDR3quRsL6I5+94M/OE/UypLaxuAlAgRuKl+84iwY2kdjwtNwj/SnloBiO8 kk/odc9q3zUdO+qVSQVt5Aex46qwxbLOO+ypHzWbk1RNAm1y5U8i4UZ6aSNKoLhC42Tu 3hKZMpRbPk9Y7KC45eeLp7Q6lCepZHZhMUNxP/XCOKqwWXygnxUMKaLuCS5aiD3/K6PE Yaeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=X57uwopXnuwAGxBJfo3nXt3MJLIDmWTaNVtJmoGBIrs=; b=oyNGTbA2zc9Gq4wkwrrDWY5fZRE8pGXyWZPvRoqOQj53y0nhhCe18X4GbIaMx1qc4m 7YWTVWGCO+J75BNpohB2kT1hZmPHOP08Dfh1DN268Q3TJJf5mnNczE6cst84pngyxJr4 /Ov8+HyteszaKMh1hDepxEwA7nBDxn2nHOF+rizNA1TRAbb2s1h1qDDSVNTmaOzsziBA I0GiCzJ6lELCxickZhlIlbXILXftYfmn3I/dxj850IbtRQ1xwdtIM873i2yihF/0RZHC HcHZCSKGqKJmGSGFltsOOK41yncxq1gWgfl1gZOJ1ZxXNrKdaFgHROnHbVdLZyT69T/2 8bDQ== X-Gm-Message-State: AJIora89Zw2zaUZOP1r2+Bwep3T0BsSV4TlHvnm3W8iy5LZoOfwvmL5U Ln1Yv3qygSDdDoXanUixIYTHhUemfk3XFF+fjsA8aA== X-Received: by 2002:a05:6512:39ce:b0:481:31e4:1e06 with SMTP id k14-20020a05651239ce00b0048131e41e06mr1777836lfu.376.1656422220502; Tue, 28 Jun 2022 06:17:00 -0700 (PDT) MIME-Version: 1.0 References: <20220628095833.2579903-1-elver@google.com> <20220628095833.2579903-7-elver@google.com> In-Reply-To: <20220628095833.2579903-7-elver@google.com> From: Dmitry Vyukov Date: Tue, 28 Jun 2022 15:16:49 +0200 Message-ID: Subject: Re: [PATCH v2 06/13] perf/hw_breakpoint: Make hw_breakpoint_weight() inlinable To: Marco Elver Cc: Peter Zijlstra , Frederic Weisbecker , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-perf-users@vger.kernel.org, x86@kernel.org, linux-sh@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 28 Jun 2022 at 11:59, Marco Elver wrote: > > Due to being a __weak function, hw_breakpoint_weight() will cause the > compiler to always emit a call to it. This generates unnecessarily bad > code (register spills etc.) for no good reason; in fact it appears in > profiles of `perf bench -r 100 breakpoint thread -b 4 -p 128 -t 512`: > > ... > 0.70% [kernel] [k] hw_breakpoint_weight > ... > > While a small percentage, no architecture defines its own > hw_breakpoint_weight() nor are there users outside hw_breakpoint.c, > which makes the fact it is currently __weak a poor choice. > > Change hw_breakpoint_weight()'s definition to follow a similar protocol > to hw_breakpoint_slots(), such that if defines > hw_breakpoint_weight(), we'll use it instead. > > The result is that it is inlined and no longer shows up in profiles. > > Signed-off-by: Marco Elver Reviewed-by: Dmitry Vyukov > --- > include/linux/hw_breakpoint.h | 1 - > kernel/events/hw_breakpoint.c | 4 +++- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h > index 78dd7035d1e5..9fa3547acd87 100644 > --- a/include/linux/hw_breakpoint.h > +++ b/include/linux/hw_breakpoint.h > @@ -79,7 +79,6 @@ extern int dbg_reserve_bp_slot(struct perf_event *bp); > extern int dbg_release_bp_slot(struct perf_event *bp); > extern int reserve_bp_slot(struct perf_event *bp); > extern void release_bp_slot(struct perf_event *bp); > -int hw_breakpoint_weight(struct perf_event *bp); > int arch_reserve_bp_slot(struct perf_event *bp); > void arch_release_bp_slot(struct perf_event *bp); > void arch_unregister_hw_breakpoint(struct perf_event *bp); > diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c > index a089302ddf59..a124786e3ade 100644 > --- a/kernel/events/hw_breakpoint.c > +++ b/kernel/events/hw_breakpoint.c > @@ -124,10 +124,12 @@ static __init int init_breakpoint_slots(void) > } > #endif > > -__weak int hw_breakpoint_weight(struct perf_event *bp) > +#ifndef hw_breakpoint_weight > +static inline int hw_breakpoint_weight(struct perf_event *bp) > { > return 1; > } > +#endif > > static inline enum bp_type_idx find_slot_idx(u64 bp_type) > { > -- > 2.37.0.rc0.161.g10f37bed90-goog >