Received: by 2002:a05:7412:85a1:b0:e2:908c:2ebd with SMTP id n33csp9248rdh; Mon, 30 Oct 2023 12:05:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzUP4TW7MwZBrJIT86Hmnx/JIhKKIwILK3TCiV6aMqCIVC/iLTIAWfiu+GTn0vJPnnsDoN X-Received: by 2002:a05:6a20:e615:b0:159:f884:4d72 with SMTP id my21-20020a056a20e61500b00159f8844d72mr8369597pzb.42.1698692754370; Mon, 30 Oct 2023 12:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698692754; cv=none; d=google.com; s=arc-20160816; b=AReOEkQ5lw6eDTQkmqRtgLDrxoJxu+dMENSna+2FQNWpnbELcxHqdwnX4V6xuJa4fa YFCI7vhZUZCO2g/H/clHv/Yl9rZ8StJVBGqyyEwdD6V2e+LvfeBhtouPfLDhc60nn08J l8SRH0zfuaoK9sRaIf6Pa6IMSE/R6aoAykkn5vFGRisLzWNXjWF2ZOfypV9NWNrETPE8 mCLLzdTjkzPUKKZyYdmiN1TrXL4BGnIOE+HQyST7+2P5kqpepfCJg5QSwMyJC4UQLI1a xGZhXVVrFtQclbvnJYEtJ7iImvraZ+68QaniwWpjfM+8Ks0THX79wmH110Dun82QFxoL Ac7g== 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=fPq41GL4yH6DVVO3wMu/zZLhUfAE1z9hLgfWVkoLlNs=; fh=NXag7Z18GijU4uQdnpfr8xFzc0rWoOu6fq6oXQxV6SQ=; b=c1JiIpF2KLVMhOzOxUEjtBXFXk+8IEPHzxKO3XQPBiJ1uN/Emls7YwzPvM/Atnm36m jO7aPoGml1lesb223fg/hOzFOCxgAdjIQ8IJn+GfIn9lDOS4kQqxW8+4a5jE+14RwrXx QM+esdXevdyeXqDYRPmzeaIiNsets+NVaxsHn2yREvbEhWqYD1aZiLauKmc4x2ApIR2O xz4x8SZJRK012YsCwwZHG9Q5T3uaBrYTmdYbHLygq3NnGAw54uPIe+7ndQYltQGPD3vs dtKp8fDaXUpUE1ZqVFWQqjVLIJ1V+0faPwA+hlIOukTRgIEzG99CGaL7Ckq+R37gx8jB +f0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SBuA4MPI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a72-20020a63904b000000b005b95fbb1750si3665614pge.113.2023.10.30.12.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 12:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SBuA4MPI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 2B3988082AA2; Mon, 30 Oct 2023 12:05:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231430AbjJ3TFJ (ORCPT + 99 others); Mon, 30 Oct 2023 15:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjJ3TFI (ORCPT ); Mon, 30 Oct 2023 15:05:08 -0400 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9208DB for ; Mon, 30 Oct 2023 12:05:02 -0700 (PDT) Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5845213c583so2814631eaf.0 for ; Mon, 30 Oct 2023 12:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698692702; x=1699297502; 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=fPq41GL4yH6DVVO3wMu/zZLhUfAE1z9hLgfWVkoLlNs=; b=SBuA4MPIC+VmsWdMbFrHFWFYvQG2YSpgukSbcdnjxa1s9GgWLURxhYThIqePSGVv9j dglNiKyOxHRMgJmMLWe3JmRu00SwZjhhk0j+GsGt3oSFfZqiKI01JxfSTWK96BuQaOEW +FkpU1NNbPSoXGM9WYqvWsGc86hZlv/S7w21ofiryV/ia3ZMSI43RlHq5Dk3APoJF2om Z5F1e+yOq/IotfqxMGIl2sI+y8bozTLSZeuKWELcJl6uXkGoPORbWIgMWI0Xy6idCCRS ReXfqylqGm1BlvkhlDwNb15Kxes3lHu4WHAHND4wIidxJqqc82kUW3rmKSYTJapRP1Zu 1xog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698692702; x=1699297502; 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=fPq41GL4yH6DVVO3wMu/zZLhUfAE1z9hLgfWVkoLlNs=; b=HiEdY8urFA/eKz72BrDgo8O+FeaZY1VuRO4LyzBgfohxCggDZVy3V0xS5ATouCWHPf tFWbv9EKbrQEJWOvOBmcj0coG1dgQjSVS96pTODMr34g3NtCcyvLy8gKv0pFpKaELmWN DqjTriMMl4DzX3cld2n4TW3CgVMy7XJ89mnpE8oAs3EdrJmye1mYFAkopgxr7JZVMarA UGGo4JSqtnjgivzQ3zaI4DEOZHuizyhjYIax2E+bb9RUUk5iuJpV30pQZlXU/o8AjIwk zh7tqU+6vlUJqwYl7mv+zvmASJeY2k4ngkLEuKpLZF6Fq6REMf+CyWAAppLga5lXOM6A 3//Q== X-Gm-Message-State: AOJu0YxqDeoyHyNVeEQpKe2cn1iiQ9p26DpPiWagNqtl8xqm2vxSaMlQ n9u5sh931LqSe/Nhcd1otVBdMDCyDBUJ7b5l43Mejw== X-Received: by 2002:a05:6358:c381:b0:168:d12b:a166 with SMTP id fl1-20020a056358c38100b00168d12ba166mr10044450rwb.17.1698692701743; Mon, 30 Oct 2023 12:05:01 -0700 (PDT) MIME-Version: 1.0 References: <20230916040915.1075620-1-irogers@google.com> In-Reply-To: <20230916040915.1075620-1-irogers@google.com> From: Mingwei Zhang Date: Mon, 30 Oct 2023 12:04:25 -0700 Message-ID: Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event To: gregkh@linuxfoundation.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 , stable@vger.linux.org 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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 30 Oct 2023 12:05:39 -0700 (PDT) On Fri, Sep 15, 2023 at 9:10=E2=80=AFPM Ian Rogers wro= te: > > 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 is > 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 for > 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 const= ructor") > 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 evlis= t *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 associa= ted 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 *ev= list, 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