Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp39545rdb; Mon, 30 Oct 2023 22:52:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENAexqXWU2P7M9Bz4QyRAxmMz8ShQiEZmKb4fCnOXRTLASLnAmJaAfZvvxmYV+CDMiO5p8 X-Received: by 2002:a17:90a:c7c7:b0:27d:10b1:5deb with SMTP id gf7-20020a17090ac7c700b0027d10b15debmr8870495pjb.31.1698731554875; Mon, 30 Oct 2023 22:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698731554; cv=none; d=google.com; s=arc-20160816; b=wH9InXAc47B5CKxyroy0DYADXuVQaaajZdR6+370gFvnpi7mDNtYjXXV49vlNzpIgg DmvEyKPUP41W0aWKN6VHOZgVQobPFlEVp1SFN/gUiAIo9gWPebSMksG3gBWKb3rLC/71 +XcR+WhQFfce/IGNlFfTzI8ZtRvr5EA7ID+TbcTm0MHA3kLmpa9n1u/uFxq0DaWZR5MI uWcYeOv5amYoLltj9YJyfeny5BYnNGeB+iH7rC4oNBCmw02rMDjAunZyrGm/2iN/orpY oSHUBYZQsX7kdMYGz/o4vQ2m1Q9ayjP1aOj95/0FY5GZ0Fg+YrhNHhlTFodAe8ihffeM jFUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CvARqHOeR+Lis6jEOUq3NPwwuDOydydGML3NlxR7Qp4=; fh=u5pJbP/xAzPHkcMPsZbdGzHAxXXsiGmjUPqXfcgJq6c=; b=00E4EnFDhULjMlv7yLdUVac5+01pXk2Y5feQZnRmBJC/UdWo52qfjTK25TpST2hFiv 1r1vs5LxZ3ao/j3dBmB/wtkkb87YEIA9XicRKz//rRE2m7QD+DNaO09vl3iGosu1y1Ww myPMIvlknWK7Yt9aANnAKxu4nR4hxsBFlvuMnRgRV9fOeenMJAgiQ0NKTKjGLxBp2QbX arttVjFZecxapEbwzn0sNY277zST8RBBEhLo//kUsYuewn6rEdWB1nu/M2penEiMzn6D S/O8VneRFCvIj5b8Ydcq1nHhtHQggLz1Fp4/uytpEgexQTTigvan+lybzdBg7J7LECfM Ibvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kL5jWchS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i3-20020a17090acf8300b00252d84b7af0si469501pju.181.2023.10.30.22.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 22:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kL5jWchS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2D8F18073282; Mon, 30 Oct 2023 22:48:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbjJaFsG (ORCPT + 99 others); Tue, 31 Oct 2023 01:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjJaFsD (ORCPT ); Tue, 31 Oct 2023 01:48:03 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C60F891; Mon, 30 Oct 2023 22:48:00 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0188C433CA; Tue, 31 Oct 2023 05:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1698731280; bh=p+P/xP9EbaQml5yZke5QeF30o+WUdV6v112azu7rFLo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kL5jWchSNYYCG3LQ6IBTiLQvi1Kwr5DwhYV0HdB1dWKwXD3e56mQGPbDbCzpDlean 8/nQgpmdN69VoOZrKLQsKx9X2W+iBuR8+4kFbdY4y+Vb71arz8+ob9ncW5o4NuRSzS 4mdEiGZjKXHZgqNnm3TWqq5rawamhXR1evc9SsVI= Date: Tue, 31 Oct 2023 06:47:55 +0100 From: Greg KH To: Mingwei Zhang Cc: stable@vger.kernel.org, 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 Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event Message-ID: <2023103145-ruse-statue-9b8f@gregkh> References: <20230916040915.1075620-1-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 22:48:13 -0700 (PDT) On Mon, Oct 30, 2023 at 01:01:45PM -0700, Mingwei Zhang wrote: > On Mon, Oct 30, 2023 at 12:04 PM Mingwei Zhang wrote: > > > > On Fri, Sep 15, 2023 at 9:10 PM Ian Rogers wrote: > > > > > > 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=0 and > > > period=1. 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=0x3c,period=10000000/. 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 constructor") > > > 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 evlist *evlist) > > > .type = PERF_TYPE_SOFTWARE, > > > .config = PERF_COUNT_SW_DUMMY, > > > .size = sizeof(attr), /* to capture ABI version */ > > > + /* Avoid frequency mode for dummy events to avoid associated timers. */ > > > + .freq = 0, > > > + .sample_period = 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 = 1; > > > evsel->core.attr.exclude_guest = 1; > > > evsel->core.attr.exclude_hv = 1; > > > - evsel->core.attr.freq = 0; > > > - evsel->core.attr.sample_period = 1; > > > evsel->core.system_wide = system_wide; > > > evsel->no_aux_samples = true; > > > evsel->name = 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 This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read: https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html for how to do this properly.