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=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 E3326C433DB for ; Sat, 13 Mar 2021 22:06:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0A0164ED7 for ; Sat, 13 Mar 2021 22:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234331AbhCMWGW (ORCPT ); Sat, 13 Mar 2021 17:06:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31278 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234385AbhCMWGN (ORCPT ); Sat, 13 Mar 2021 17:06:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615673172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iseltM4LgjyIVgTiWfZZkXhoKEkeLJmibBx74YIpNhQ=; b=NSh1PK1aeov5/zVSgf1KikZd80RxyAqbW1U/LoIgO0FrZVdcWsCa6U7uEaBbT2dDcl1lUy /Rz3FS1OxeXpaLwSV/FeU9Sohrz4wkPZ1CmXU5DFT0SRfZYxyqD1ko2WTPhfoe/YmTKzmN 7jeuzbswVxIFCfytCGtpRxe9IWCt2J8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-FbnAbQokORC1jNEJI87OEA-1; Sat, 13 Mar 2021 17:06:09 -0500 X-MC-Unique: FbnAbQokORC1jNEJI87OEA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 05CDF91178; Sat, 13 Mar 2021 22:06:08 +0000 (UTC) Received: from krava (unknown [10.40.192.29]) by smtp.corp.redhat.com (Postfix) with SMTP id 7819810016FB; Sat, 13 Mar 2021 22:06:06 +0000 (UTC) Date: Sat, 13 Mar 2021 23:06:05 +0100 From: Jiri Olsa To: Song Liu Cc: linux-kernel , Kernel Team , "acme@kernel.org" , "acme@redhat.com" , "namhyung@kernel.org" , "jolsa@kernel.org" Subject: Re: [PATCH] perf-stat: introduce bperf, share hardware PMCs with BPF Message-ID: References: <20210312020257.197137-1-songliubraving@fb.com> <45BCAC33-1626-42D1-A170-92DC8D7BAAF8@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 12, 2021 at 04:09:53PM +0000, Song Liu wrote: > > > > On Mar 12, 2021, at 7:45 AM, Song Liu wrote: > > > > > > > >> On Mar 12, 2021, at 4:12 AM, Jiri Olsa wrote: > >> > >> On Thu, Mar 11, 2021 at 06:02:57PM -0800, Song Liu wrote: > >>> perf uses performance monitoring counters (PMCs) to monitor system > >>> performance. The PMCs are limited hardware resources. For example, > >>> Intel CPUs have 3x fixed PMCs and 4x programmable PMCs per cpu. > >>> > >>> Modern data center systems use these PMCs in many different ways: > >>> system level monitoring, (maybe nested) container level monitoring, per > >>> process monitoring, profiling (in sample mode), etc. In some cases, > >>> there are more active perf_events than available hardware PMCs. To allow > >>> all perf_events to have a chance to run, it is necessary to do expensive > >>> time multiplexing of events. > >>> > >>> On the other hand, many monitoring tools count the common metrics (cycles, > >>> instructions). It is a waste to have multiple tools create multiple > >>> perf_events of "cycles" and occupy multiple PMCs. > >>> > >>> bperf tries to reduce such wastes by allowing multiple perf_events of > >>> "cycles" or "instructions" (at different scopes) to share PMUs. Instead > >>> of having each perf-stat session to read its own perf_events, bperf uses > >>> BPF programs to read the perf_events and aggregate readings to BPF maps. > >>> Then, the perf-stat session(s) reads the values from these BPF maps. > >>> > >>> Please refer to the comment before the definition of bperf_ops for the > >>> description of bperf architecture. > >>> > >>> bperf is off by default. To enable it, pass --use-bpf option to perf-stat. > >>> bperf uses a BPF hashmap to share information about BPF programs and maps > >>> used by bperf. This map is pinned to bpffs. The default address is > >>> /sys/fs/bpf/bperf_attr_map. The user could change the address with option > >>> --attr-map. > >> > >> nice, I recall the presentation about that and was wondering > >> when this will come up ;-) > > > > The progress is slower than I expected. But I finished some dependencies of > > this in the last year: > > > > 1. BPF_PROG_TEST_RUN for raw_tp event; > > 2. perf-stat -b, which introduced skeleton and bpf_counter; > > 3. BPF task local storage, I didn't use it in this version, but it could, > > help optimize bperf in the future. > > > >> > >>> > >>> --- > >>> Known limitations: > >>> 1. Do not support per cgroup events; > >>> 2. Do not support monitoring of BPF program (perf-stat -b); > >>> 3. Do not support event groups. > >>> > >>> The following commands have been tested: > >>> > >>> perf stat --use-bpf -e cycles -a > >>> perf stat --use-bpf -e cycles -C 1,3,4 > >>> perf stat --use-bpf -e cycles -p 123 > >>> perf stat --use-bpf -e cycles -t 100,101 > >> > >> I assume the output is same as standard perf? > > Btw, please give it a try. :) > > It worked pretty well in my tests. If it doesn't work for some combination > of options, please let me know. heya, can't compile CLANG /home/jolsa/linux-perf/tools/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o util/bpf_skel/bperf_follower.bpf.c:8:10: fatal error: 'bperf_u.h' file not found #include "bperf_u.h" ^~~~~~~~~~~ jirka