Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1014118pxf; Thu, 18 Mar 2021 18:03:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmSCZcPvRoNs4Lir/d1uZcUgDfe0KXc9LTJKTIrEwbFH8YOlbsU/WWcqtxSkCUKmj0OTWC X-Received: by 2002:a05:6402:4395:: with SMTP id o21mr6756313edc.22.1616115812635; Thu, 18 Mar 2021 18:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616115812; cv=none; d=google.com; s=arc-20160816; b=JuxYwVwqk8V9Wc6JPCWW4bS8PLg2t6LIETkxv85JRsMDSqyxI7SeO01yONevIFhfwI kzFnYSzeNNTMeqYewxl0yh8wAYLaZah6UL7AxZ9tzTFFXWzPw0IXNccHP/SbS40MpPLr BTZLhXnRaK03l07ckY37WxaB64qTpFbh8PbINOkfp0Q1xspE4Z5FHwN0u2SS+4EcSVHW HBrm2+2nD1qLC40z9C7SqkDUfyYnfxGhQU2oYi/lEU57/Yt2FfQmv4Ue8PnWo3uYr1jd bShdgbdR6NDv5UBE7HYR3yTac0y2XDJ4ik5iLVcYixc/VTvbZcOPEdBmm5lH+4O9cSm0 g+nA== 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; bh=Oxe5YfOrxBUWElx/94xRYd2RS+DDZ7+GbaS5AvvQUPE=; b=YV1zpECiZgvWEfaGXeL6T2MOT7lWYFHrv2LdsfLprhMaLotyhtSFc8wPmjhsGJpNy9 R6OSY7AwqpKGfcjbPnGrLhf64bPgRCpU0Gd4TWy1HDO75ipke4RBQGUWGVE3eSCboaY+ gw6rw96JyqNB2AedqQ/DhheZ4QKhFlpOShLcXbmGvpBrG3SpmvHOgu5YSYDP6EryqgGb gGunQJGm/tiKgCQHXsvMIzzkRPV/nWhJRFJf7AQ+n5notvtC9bdtQQtikGMXPFJ1D0md zg6wEbAgzsw1OqH+ZWbMwG/9hFw4QXVeJSwcwAPe82LCgQeaaQzNJq4tywPTuZqmw7iK Q5QQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si2740514edu.606.2021.03.18.18.03.09; Thu, 18 Mar 2021 18:03:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbhCSAzp (ORCPT + 99 others); Thu, 18 Mar 2021 20:55:45 -0400 Received: from mail-lf1-f50.google.com ([209.85.167.50]:36564 "EHLO mail-lf1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232674AbhCSAzM (ORCPT ); Thu, 18 Mar 2021 20:55:12 -0400 Received: by mail-lf1-f50.google.com with SMTP id n138so7442138lfa.3 for ; Thu, 18 Mar 2021 17:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Oxe5YfOrxBUWElx/94xRYd2RS+DDZ7+GbaS5AvvQUPE=; b=Rlh4iKp/sExQVEy2DwT2vDRNRVS+GSlmqOBqeKy4TPpZ/nM0WW2NNeTz1Mk+DpG4wc /ycWdzhDrNTJgr36LJ0GkehpPChEGP77q8Mk++t2j97KIujfK9y/jK010/NtD+HVcEIC WzZFuM/XpwJqFKf7dHqOW9Ut2yCtJsCsbr8sO8EU1kdnFiQTzIQFvzxgOOhfNcLoTuxW E0R3kMy7gOnM5IlAKn4uCtnGaQGJzuG8Fru1wjbfj8Re5gq320kuJfEJCp+B9JHoLd1K +3DKsrw5MDtkCGQVSyW2HHAkoQn5pF39r7+8LuOtjCLTjjXFRvE4fJqVxdOEC2tLsQVH W1SQ== X-Gm-Message-State: AOAM533pJcOgyvZaSfPDwrzFtOqW8hOBItQiRHX0d9FgrdP7An27ENi1 rZsLSigbFaezaj22m5uBL+owhGriddTBxFheWp8= X-Received: by 2002:a05:6512:3c9a:: with SMTP id h26mr2190442lfv.112.1616115310824; Thu, 18 Mar 2021 17:55:10 -0700 (PDT) MIME-Version: 1.0 References: <20210316211837.910506-1-songliubraving@fb.com> <7D48A756-C253-48DE-B536-826314778404@fb.com> <388AF530-5176-4DB9-93C4-6C302432CE12@gmail.com> <3E65B60E-B120-4E1A-BAF2-2FAEF136A4CD@fb.com> In-Reply-To: <3E65B60E-B120-4E1A-BAF2-2FAEF136A4CD@fb.com> From: Namhyung Kim Date: Fri, 19 Mar 2021 09:54:59 +0900 Message-ID: Subject: Re: [PATCH v2 0/3] perf-stat: share hardware PMCs with BPF To: Song Liu Cc: Arnaldo , Jiri Olsa , Arnaldo Carvalho de Melo , linux-kernel , Kernel Team , Arnaldo Carvalho de Melo , Jiri Olsa Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 19, 2021 at 9:22 AM Song Liu wrote: > > > > > On Mar 18, 2021, at 5:09 PM, Arnaldo wrote: > > > > > > > > On March 18, 2021 6:14:34 PM GMT-03:00, Jiri Olsa wrote: > >> On Thu, Mar 18, 2021 at 03:52:51AM +0000, Song Liu wrote: > >>> > >>> > >>>> On Mar 17, 2021, at 6:11 AM, Arnaldo Carvalho de Melo > >> wrote: > >>>> > >>>> Em Wed, Mar 17, 2021 at 02:29:28PM +0900, Namhyung Kim escreveu: > >>>>> Hi Song, > >>>>> > >>>>> On Wed, Mar 17, 2021 at 6:18 AM 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. > >>>>> > >>>>> Right, it'd be really helpful when the PMCs are frequently or > >> mostly shared. > >>>>> But it'd also increase the overhead for uncontended cases as BPF > >> programs > >>>>> need to run on every context switch. Depending on the workload, > >> it may > >>>>> cause a non-negligible performance impact. So users should be > >> aware of it. > >>>> > >>>> Would be interesting to, humm, measure both cases to have a firm > >> number > >>>> of the impact, how many instructions are added when sharing using > >>>> --bpf-counters? > >>>> > >>>> I.e. compare the "expensive time multiplexing of events" with its > >>>> avoidance by using --bpf-counters. > >>>> > >>>> Song, have you perfmormed such measurements? > >>> > >>> I have got some measurements with perf-bench-sched-messaging: > >>> > >>> The system: x86_64 with 23 cores (46 HT) > >>> > >>> The perf-stat command: > >>> perf stat -e > >> cycles,cycles,instructions,instructions,ref-cycles,ref-cycles >> etc.> > >>> > >>> The benchmark command and output: > >>> ./perf bench sched messaging -g 40 -l 50000 -t > >>> # Running 'sched/messaging' benchmark: > >>> # 20 sender and receiver threads per group > >>> # 40 groups == 1600 threads run > >>> Total time: 10X.XXX [sec] > >>> > >>> > >>> I use the "Total time" as measurement, so smaller number is better. > >>> > >>> For each condition, I run the command 5 times, and took the median of > >> > >>> "Total time". > >>> > >>> Baseline (no perf-stat) 104.873 [sec] > >>> # global > >>> perf stat -a 107.887 [sec] > >>> perf stat -a --bpf-counters 106.071 [sec] > >>> # per task > >>> perf stat 106.314 [sec] > >>> perf stat --bpf-counters 105.965 [sec] > >>> # per cpu > >>> perf stat -C 1,3,5 107.063 [sec] > >>> perf stat -C 1,3,5 --bpf-counters 106.406 [sec] > >> > >> I can't see why it's actualy faster than normal perf ;-) > >> would be worth to find out > > > > Isn't this all about contended cases? > > Yeah, the normal perf is doing time multiplexing; while --bpf-counters > doesn't need it. Yep, so for uncontended cases, normal perf should be the same as the baseline (faster than the bperf). But for contended cases, the bperf works faster. Thanks, Namhyung