Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp512694iol; Thu, 9 Jun 2022 08:10:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLiJzi28VhtVCNVIXBAEfqyKU2v2SfY8mqks/4g5bCzR2yUr1twU81xEis1NkD400iiQF+ X-Received: by 2002:a05:6402:3291:b0:42d:dd03:cbb1 with SMTP id f17-20020a056402329100b0042ddd03cbb1mr45067137eda.268.1654787416730; Thu, 09 Jun 2022 08:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654787416; cv=none; d=google.com; s=arc-20160816; b=yCDpw2jE2ThJjc9k2Eh/gCXkEOTyOpdRD//Qh3XdkhLZe1hDIK18r8sXQekmq6H+xi /jGWN3RudsndC7mM3XUeKo3oVoi+jpT2lU1kI5bFUXiF/d4UFkp+wUaxoAKBXV5VEFdD uq/GdSqVL/irvAeNAVIFNw91ZgXbIM2n8DCMmjmp/3vqoQ6WD9gBIW76PwShyFLaWtCj qUqqH4lmcluVa4o0/3JGPwpkWIzfuCfsqbWwL4pL166lHUmswiQHKFvVJ7ByMOz6q+P5 PuGGb5gjRpk1WQ9cIxmFSX03FWTsFRekhgJEERErN8bwq/hoF2DiYU2iATYVyGxHlyse KAZQ== 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=0+SkCjGgZBFq5wRCXTYfFTyaGhOAcbR2Sdoh6LQhmUA=; b=k4biut84aXW3Qh4mqTjdXh7UC/etjSQ8q9lE5ITG5YwA7UCGFzqo/pq9+TBcbDVOAg BwkOr9TxY2CnG8z4sKCNklBNv8a6CiUtDWedGOBbTEvCZhR+eA4UIZa8ZbzwUbJZvu0n SDjRAWmaE+gXS5WfJ58aNozYzZvvlKG1vIQHgz+t4eae8ZSeYvDOcdk5pFf8lIJ9B0w0 Wenw7hJ/hUK2rx2G5nT70sp7GtZwGmDC+ggvlZ+lIUZeDgdmggY1Vo4JREd7o3o+wmhV uslaxmSLW8jJWoNn9sXhJPilfiDWF4F3/kBwJFAV7vjS7/Vnd2QS+uF11iZJfBNFdTSD 3p3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=deUfDUG4; 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 s13-20020a056402036d00b00423e1efca48si23712546edw.198.2022.06.09.08.09.50; Thu, 09 Jun 2022 08:10:16 -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=deUfDUG4; 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 S1344030AbiFIO42 (ORCPT + 99 others); Thu, 9 Jun 2022 10:56:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344012AbiFIO40 (ORCPT ); Thu, 9 Jun 2022 10:56:26 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2720C39182B for ; Thu, 9 Jun 2022 07:56:24 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-31336535373so92977127b3.2 for ; Thu, 09 Jun 2022 07:56:24 -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=0+SkCjGgZBFq5wRCXTYfFTyaGhOAcbR2Sdoh6LQhmUA=; b=deUfDUG4RR9z3kerucIqTXhqCeGsbHnfHtdvw5TsJVYFknetJ/w80Mv9kBz5l4wex9 TssewgR73O/IyB/u1mxjbxvVfqyOyYF82MCbjOeauw6zFo7MJimse2lx811joMZtXTdC uT5XfiXo74nBdAcht78tvAUnApid/SMJhbV+Nr+EedCSPzCr3MTOd8EP9AmTLlsnhGck znW1PntgjNv4SDv5OQvubmFMVhj/M7k5WoovioAqVoC/pkPL9GeBmYIXDknX5bKByQzG isj398VB6w8UihJLCkMJNEXGeGaR/Pfe/bXeUjDzdAAissGD1HmQ0PWrAQE6T2NwCeIX Z0+g== 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=0+SkCjGgZBFq5wRCXTYfFTyaGhOAcbR2Sdoh6LQhmUA=; b=4pYBXcrYX1KLFSXAfDIrBPQEZs/QA7wVAJrGx2rKwQLTS2/GZ+sJ9DhI09uQ+7jJw4 B+yxacj1RHI/uh2zdfRG37QvPizQGeNPsYPZ0Rh7UtSCZna0brpWcJ6HLIhWoDcrppNt P3Mxc0T+eWTVsPDZY+QMKq89FQPUzLIKLbY2hGO1d3NANVsAFITYrJEZ+E80p0808Eb/ beR1umqwVmW9dQb0aChv7HIMTlCzC88HEvpXgDRG5LBXcXyqdNVli6hDxFljXf1N6sCs AgBQmM71MelAMYrOJkN66wTtrHMfGUiDBywyfsNlkY5IkFUQuZ4J57zVVENjO9zh8ooQ oKlg== X-Gm-Message-State: AOAM5336CeB53Louorqi/+V6+oYZ85ty8HljiveF9Gare9PSb2NCzyAg QGR1s2HPOCc4rHhc0KEoIUH8SqMgDIgUtVFecSRk7Q== X-Received: by 2002:a0d:c0c6:0:b0:2ff:bb2:1065 with SMTP id b189-20020a0dc0c6000000b002ff0bb21065mr44984991ywd.512.1654786583034; Thu, 09 Jun 2022 07:56:23 -0700 (PDT) MIME-Version: 1.0 References: <20220609113046.780504-1-elver@google.com> <20220609113046.780504-2-elver@google.com> In-Reply-To: From: Marco Elver Date: Thu, 9 Jun 2022 16:55:46 +0200 Message-ID: Subject: Re: [PATCH 1/8] perf/hw_breakpoint: Optimize list of per-task breakpoints To: Dmitry Vyukov Cc: Peter Zijlstra , Frederic Weisbecker , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , 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=unavailable 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 Thu, 9 Jun 2022 at 16:29, Dmitry Vyukov wrote: > > On Thu, 9 Jun 2022 at 13:31, Marco Elver wrote: > > > > On a machine with 256 CPUs, running the recently added perf breakpoint > > benchmark results in: > > > > | $> perf bench -r 30 breakpoint thread -b 4 -p 64 -t 64 > > | # Running 'breakpoint/thread' benchmark: > > | # Created/joined 30 threads with 4 breakpoints and 64 parallelism > > | Total time: 236.418 [sec] > > | > > | 123134.794271 usecs/op > > | 7880626.833333 usecs/op/cpu > > > > The benchmark tests inherited breakpoint perf events across many > > threads. > > > > Looking at a perf profile, we can see that the majority of the time is > > spent in various hw_breakpoint.c functions, which execute within the > > 'nr_bp_mutex' critical sections which then results in contention on that > > mutex as well: > > > > 37.27% [kernel] [k] osq_lock > > 34.92% [kernel] [k] mutex_spin_on_owner > > 12.15% [kernel] [k] toggle_bp_slot > > 11.90% [kernel] [k] __reserve_bp_slot > > > > The culprit here is task_bp_pinned(), which has a runtime complexity of > > O(#tasks) due to storing all task breakpoints in the same list and > > iterating through that list looking for a matching task. Clearly, this > > does not scale to thousands of tasks. > > > > While one option would be to make task_struct a breakpoint list node, > > this would only further bloat task_struct for infrequently used data. > > task_struct already has: > > #ifdef CONFIG_PERF_EVENTS > struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts]; > struct mutex perf_event_mutex; > struct list_head perf_event_list; > #endif > > Wonder if it's possible to use perf_event_mutex instead of the task_sharded_mtx? > And possibly perf_event_list instead of task_bps_ht? It will contain > other perf_event types, so we will need to test type as well, but on > the positive side, we don't need any management of the separate > container. Hmm, yes, I looked at that but then decided against messing the perf/core internals. The main issue I have with using perf_event_mutex is that we might interfere with perf/core's locking rules as well as interfere with other concurrent perf event additions. Using perf_event_list is very likely a no-go because it requires reworking perf/core as well. I can already hear Peter shouting, but maybe I'm wrong. :-)