Received: by 2002:a05:7412:85a1:b0:e2:908c:2ebd with SMTP id n33csp38132rdh; Mon, 30 Oct 2023 13:03:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHd/qwUoz42X14VWcZ4EYSQzyg47wk86rZCwem5NmIWK7NJcKsJvDcVUnp5T1UfXJ+1hBp X-Received: by 2002:a05:6e02:1d09:b0:351:5d8f:d299 with SMTP id i9-20020a056e021d0900b003515d8fd299mr15017080ila.7.1698696181905; Mon, 30 Oct 2023 13:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698696181; cv=none; d=google.com; s=arc-20160816; b=LFW4PuT8/4qhe7WWgINm6itfwOYK6Kst0pbwNzz9K4phgSifEFTGKcrGhbGbdzlkyR g0KZ/uLUNldh7MVVeLOJYpgaW9+wzEix1SzldRntFsyXi7fZW7xZPLrxVBSD9UO+ySkl ICLHTdW4XKRA9WuaXRv1wkZ0cev2N2FUoWQIHypliH985IYy5nV1xxydwjFfnUSkIzY7 ZqqYwwNr/EAGPbF+zMWoBvKRiOy5/LoaakVLERK+1wQtj8Z6/2M1tq5zQYYzBsZQVA91 bVv8q5Stt3Qfnc1ohyts5uzmRqMi+ShnIqUPIJcQLMyWyS54Y7D549Qq4qsOd+9qk/dZ grqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CfU1Vfre9ZPJUwx/epHI06bmjrSaEYsIgo8tdkDUzfc=; fh=y2wcFkSEN9FoMUVzsfdf8TLJzLTNgkq3RktDPNb/Euc=; b=vRy6AP+3Vv7sxImvTXMk6pAztgSUpqWe3JGo+xKxF+8siRQdA6swzjn7OK17/lvSaM /w474IGlbuCvL0/P3ZkuyKeiO6DGau/xR9z9ivL0f7O0e2MVG3OZqtwBgGnAc6kbRCJf HVAViuUj+bakYqpDovkXWFu77uC/KtfYoxIK4ALrzJahxoOu5rCCDX+tRm68f/b4tEAz epchK3Fi+/xI49paYlj7kGjyiVV2P0DkZGN4EuPO08l1nDTxTzhwI9YxN1qPkmQ32I8b uPUFN/vdIs37OMbXVRG7UhWWyph7JN+vl2D3h4ESCIcNfQA0OfeLMztqZ3Npabmx13lr 2ZYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ME+9t+ht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s18-20020a63d052000000b005859e224617si5065403pgi.818.2023.10.30.13.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 13:03:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ME+9t+ht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F36C88046F1A; Mon, 30 Oct 2023 13:02:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229453AbjJ3UC0 (ORCPT + 99 others); Mon, 30 Oct 2023 16:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjJ3UCZ (ORCPT ); Mon, 30 Oct 2023 16:02:25 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A164CCC for ; Mon, 30 Oct 2023 13:02:22 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-66fbcaf03c6so23106066d6.1 for ; Mon, 30 Oct 2023 13:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698696142; x=1699300942; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CfU1Vfre9ZPJUwx/epHI06bmjrSaEYsIgo8tdkDUzfc=; b=ME+9t+htyQBWKQJdo32UkF+s3byQWFRMJXPb9sWf6SqDEbfhk8DI3Vbn6yRTtnKrBm bJCLLXqPS1/4yC6bivHhAUWDYNLyuvdliaq2TKTortlM1m0fjUBz4bN9Y8RnLCMOAwtq 8OJ+6Rm4wAtr8rEYyVxrdk8UrdLVhFV2osHLZr39PXj6HrB9WARpkBJ4VsfThFNsDtDj 5lP4475YJx/EhmOoO7FxylWkf+OH1MgS7Mw3dnImEyrthzCxvkWF7awxrrLViLzGayQu W2yOMjm59+3coJMD93BgpDnlI5PzpjFYoN9BFDbHNJNVOELZ9F4zTNiME1vnAVZ6PhlO rmrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698696142; x=1699300942; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CfU1Vfre9ZPJUwx/epHI06bmjrSaEYsIgo8tdkDUzfc=; b=h4aLfjeO5Jb/Y3Kk83pSuEu7Mc+7jo5HAmoswJFwa5EBB73Z+GyG/PE2XWlmCKhyWO S6g5p0YzIsdm/uVh6Oh9h9Cw6IPOA1bhvRrQ27krtImWc8amhGXQmGoTK/oqeZ4NKfdp T3zOMCKIRT2LI2xAS9cLqKfSM/+1J0OrV6OWgqsvFnKAYhIvz640gVC/C78qpJFUTXvW n5FXsW5xqOUmVpKq2ezemP7NbJ1i2OODrBQroaSgDT5tcNZSvd0NUoGxs2+VeMtQ1N90 VmMHAaEq25MQ9TSrs/oM3vYwhOI3Lx8LvYJH5/IQllgbRiWARJK/RAitazxPfgYOiKGk Ujvg== X-Gm-Message-State: AOJu0YwUfDfJ5wCy3VziRHC26tI5P2yMHyf64jSrNvGiqO/VTNNJg3x/ 34nJrWS/KCJU7y+5Nyug3yaN6lKX0LN3LOtruGgTcg== X-Received: by 2002:a05:6214:d09:b0:672:3f54:b94f with SMTP id 9-20020a0562140d0900b006723f54b94fmr4383869qvh.7.1698696141585; Mon, 30 Oct 2023 13:02:21 -0700 (PDT) MIME-Version: 1.0 References: <20230916040915.1075620-1-irogers@google.com> In-Reply-To: From: Mingwei Zhang Date: Mon, 30 Oct 2023 13:01:45 -0700 Message-ID: Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Jihong , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 30 Oct 2023 13:02:31 -0700 (PDT) On Mon, Oct 30, 2023 at 12:04=E2=80=AFPM Mingwei Zhang = wrote: > > On Fri, Sep 15, 2023 at 9:10=E2=80=AFPM Ian Rogers w= rote: > > > > Dummy events are created with an attribute where the period and freq > > are zero. evsel__config will then see the uninitialized values and > > initialize them in evsel__default_freq_period. As fequency mode is > > used by default the dummy event would be set to use frequency > > mode. However, this has no effect on the dummy event but does cause > > unnecessary timers/interrupts. Avoid this overhead by setting the > > period to 1 for dummy events. > > > > evlist__add_aux_dummy calls evlist__add_dummy then sets freq=3D0 and > > period=3D1. This isn't necessary after this change and so the setting i= s > > removed. > > > > From Stephane: > > > > The dummy event is not counting anything. It is used to collect mmap > > records and avoid a race condition during the synthesize mmap phase of > > perf record. As such, it should not cause any overhead during active > > profiling. Yet, it did. Because of a bug the dummy event was > > programmed as a sampling event in frequency mode. Events in that mode > > incur more kernel overheads because on timer tick, the kernel has to > > look at the number of samples for each event and potentially adjust > > the sampling period to achieve the desired frequency. The dummy event > > was therefore adding a frequency event to task and ctx contexts we may > > otherwise not have any, e.g., perf record -a -e > > cpu/event=3D0x3c,period=3D10000000/. On each timer tick the > > perf_adjust_freq_unthr_context() is invoked and if ctx->nr_freq is > > non-zero, then the kernel will loop over ALL the events of the context > > looking for frequency mode ones. In doing, so it locks the context, > > and enable/disable the PMU of each hw event. If all the events of the > > context are in period mode, the kernel will have to traverse the list f= or > > nothing incurring overhead. The overhead is multiplied by a very large > > factor when this happens in a guest kernel. There is no need for the > > dummy event to be in frequency mode, it does not count anything and > > therefore should not cause extra overhead for no reason. > > > > Fixes: 5bae0250237f ("perf evlist: Introduce perf_evlist__new_dummy con= structor") > > Reported-by: Stephane Eranian > > Signed-off-by: Ian Rogers > > --- > > tools/perf/util/evlist.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c > > index 25c3ebe2c2f5..e36da58522ef 100644 > > --- a/tools/perf/util/evlist.c > > +++ b/tools/perf/util/evlist.c > > @@ -251,6 +251,9 @@ static struct evsel *evlist__dummy_event(struct evl= ist *evlist) > > .type =3D PERF_TYPE_SOFTWARE, > > .config =3D PERF_COUNT_SW_DUMMY, > > .size =3D sizeof(attr), /* to capture ABI version */ > > + /* Avoid frequency mode for dummy events to avoid assoc= iated timers. */ > > + .freq =3D 0, > > + .sample_period =3D 1, > > }; > > > > return evsel__new_idx(&attr, evlist->core.nr_entries); > > @@ -277,8 +280,6 @@ struct evsel *evlist__add_aux_dummy(struct evlist *= evlist, bool system_wide) > > evsel->core.attr.exclude_kernel =3D 1; > > evsel->core.attr.exclude_guest =3D 1; > > evsel->core.attr.exclude_hv =3D 1; > > - evsel->core.attr.freq =3D 0; > > - evsel->core.attr.sample_period =3D 1; > > evsel->core.system_wide =3D system_wide; > > evsel->no_aux_samples =3D true; > > evsel->name =3D strdup("dummy:u"); > > -- > > 2.42.0.459.ge4e396fd5e-goog > > > > Hi Greg, > > This patch is a critical performance fix for perf and vPMU. Can you > help us dispatch the commit to all stable kernel versions? > > Appreciate your help. Thanks. > -Mingwei Oops... Update target email to: stable@vger.kernel.org