Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4536704rdh; Wed, 29 Nov 2023 04:24:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtRk5O1xJVCSxY9eom6MqswzGezI7HjFuSCrSsRXXFgt/WTZUPoeTM/Ycq2smK1e4iLIBr X-Received: by 2002:a17:902:7483:b0:1cc:54fb:60f9 with SMTP id h3-20020a170902748300b001cc54fb60f9mr20855580pll.37.1701260653191; Wed, 29 Nov 2023 04:24:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701260653; cv=none; d=google.com; s=arc-20160816; b=WuWE//0odAOkD0b9Obdhg2P6kwHlH5WzNITvjeToEYxG972f06cWxOFuEAromMPJW4 71KKoSORBTFSwXsNTh94rHJOVW94XA08jO+2Wq1vuWzqsv5wg9mJbVzT2IuDlwu628Ei u0MKnKJTefHx5S/4RpoZL8rGs7bsUAFNHaWWoVPT5fERfgSnKio88RseAq3SMkCuk6Go mCrMcktrz6Og5KkN9Ny/LZVeVYiU/PY0mhdoxMI6KKGe5Nhtiw7+vgXbziVfzwbecD0S WpD3uVC7WENQg35GfCXs1nkejmXQLi2PN6bljp9fqcg831XpS++C3xEo7GOGyhfFmnjv +uDg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pNYBN4X8Pb/Yx1Vd4NeSsqJHNsCvDKBkPdpgHN9QiTY=; fh=BnIcw2Iwf0sUmhZ42T3t6IfQ6JXIFZfEyt44swpq4Xg=; b=V0foaxybgHiKRmMpqR+MqPuTqHkSGeN24DpoAPfUK3I0T8FBDb1jytOdfXhWl3248a K1wt3w42dejFvXhYK8d4q8I2eDfs7OI2KnSP9hRIoSinuOBnJ4zXOq+X9snsqE5hijOj RNEFr5wcoQHtFDA4Wm+N1TPFzDx5seuMvU/+L6PEaqdX0zDXAUGkxngekOJpZm8827IQ 4iggj/I+WR9D4UXsz5tIRLR61l1g+a/v8nVQEXGpL1jcTWp30YkAVf3v5kO4XjJAM/80 oAb02iK8HhxVUK3DMdFtD9SW0DxJxhkuekRvfiby9NFnyJ4J6f94RQOjv+2ChP3qQ+0q qb9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=c03Ofld+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s13-20020a170902ea0d00b001cfdf56c2a6si4765635plg.13.2023.11.29.04.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 04:24:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=c03Ofld+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2D8FD8039F51; Wed, 29 Nov 2023 04:24:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233283AbjK2MXy (ORCPT + 99 others); Wed, 29 Nov 2023 07:23:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbjK2MXx (ORCPT ); Wed, 29 Nov 2023 07:23:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7DFBD48; Wed, 29 Nov 2023 04:23:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=pNYBN4X8Pb/Yx1Vd4NeSsqJHNsCvDKBkPdpgHN9QiTY=; b=c03Ofld+THOSR45IGAoDp8+pt+ UkfL9dRdtWJkl7qb6AU+5c+x7KX6JkdgemiwCTtdFLtC8j3nqM8IVqnrXMofOelxpK29X8uF5ZtqK 2psuTW1FBHw7w+hCAukfMR+AbdMf4DY/XhmeCl29l+MfJN1SJ1PJx8jAD2H7bBe/pj7nl2oALLxTQ /Wq9rmsH7ut3/zJvmxsteA+NWfhM0iTJv5+2fIYirsXNN2z3k3oqWVXNW+EmUuRGCbVR2gZ+vinsR mMtyscTw9AeKHR2Ata9aGOkAtE7CW4vS+gUvFOQgZD958IO8eheGXfLqbaFjb9TAuhe82KOK/eFx7 PW7yzbiQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1r8Jb8-00DNTe-4M; Wed, 29 Nov 2023 12:23:22 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id DAA0B30017D; Wed, 29 Nov 2023 13:23:20 +0100 (CET) Date: Wed, 29 Nov 2023 13:23:20 +0100 From: Peter Zijlstra To: Adrian Hunter Cc: James Clark , Ingo Molnar , Mark Rutland , Alexander Shishkin , Heiko Carstens , Thomas Richter , Hendrik Brueckner , Suzuki K Poulose , Mike Leach , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Yicong Yang , Jonathan Cameron , Will Deacon , Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH RFC 2/3] perf/x86/intel/pt: Add support for pause_resume() Message-ID: <20231129122320.GH30650@noisy.programming.kicks-ass.net> References: <20231123121851.10826-1-adrian.hunter@intel.com> <20231123121851.10826-3-adrian.hunter@intel.com> <20231129105836.GF30650@noisy.programming.kicks-ass.net> <842ce784-fbd2-4667-a5f7-aaa10a1108dc@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <842ce784-fbd2-4667-a5f7-aaa10a1108dc@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 04:24:09 -0800 (PST) On Wed, Nov 29, 2023 at 01:15:43PM +0200, Adrian Hunter wrote: > On 29/11/23 12:58, Peter Zijlstra wrote: > > On Wed, Nov 29, 2023 at 09:53:39AM +0000, James Clark wrote: > >> On 23/11/2023 12:18, Adrian Hunter wrote: > > > >>> +static void pt_event_pause_resume(struct perf_event *event) > >>> +{ > >>> + if (event->aux_paused) > >>> + pt_config_stop(event); > >>> + else if (!event->hw.state) > >>> + pt_config_start(event); > >>> +} > >> > >> It seems like having a single pause/resume callback rather than separate > >> pause and resume ones pushes some of the event state management into the > >> individual drivers and would be prone to code duplication and divergent > >> behavior. > >> > >> Would it be possible to move the conditions from here into the core code > >> and call separate functions instead? > >> > >>> + > >>> static void pt_event_start(struct perf_event *event, int mode) > >>> { > >>> struct hw_perf_event *hwc = &event->hw; > >>> @@ -1798,6 +1809,7 @@ static __init int pt_init(void) > >>> pt_pmu.pmu.del = pt_event_del; > >>> pt_pmu.pmu.start = pt_event_start; > >>> pt_pmu.pmu.stop = pt_event_stop; > >>> + pt_pmu.pmu.pause_resume = pt_event_pause_resume; > >> > >> The general idea seems ok to me. Is there a reason to not use the > >> existing start() stop() callbacks, rather than adding a new one? > >> > >> I assume it's intended to be something like an optimisation where you > >> can turn it on and off without having to do the full setup, teardown and > >> emit an AUX record because you know the process being traced never gets > >> switched out? > > > > So the actual scheduling uses ->add() / ->del(), the ->start() / > > ->stop() methods are something that can be used after ->add() and before > > ->del() to 'temporarily' pause things. > > > > Pretty much exactly what is required here I think. We currently use this > > for PMI throttling and adaptive frequency stuff, but there is no reason > > it could not also be used for this. > > > > As is, we don't track the paused state across ->del() / ->add(), but > > perhaps that can be fixed. We can easily add more PERF_EF_ / PERF_HES_ > > bits to manage things. > > > > > > I am not sure stop / start play nice with NMI's from other events e.g. > > PMC NMI wants to pause or resume AUX but what if AUX event is currently > being processed in ->stop() or ->start()? Or maybe that can't happen? I think that can happen, and pt_event_stop() can actually handle some of that, while your pause_resume() thing, which uses pt_config_stop() does not. But yes, I think that if you add pt_event_{stop,start}() calls from *other* events their PMI, then you get to deal with more 'fun'. Something like: perf_addr_filters_adjust() __perf_addr_filters_adjust() perf_event_stop() __perf_event_stop() event->pmu->stop() ... perf_event_overflow() pt_event->pmu->stop() event->pmu->start() // whoopsie! Should now be possible. I think what you want to do is rename pt->handle_nmi into pt->stop_count and make it a counter, then ->stop() increments it, and ->start() decrements it and everybody ensures the thing doesn't get restart while !0 etc.. I suspect you need to guard the generic part of this feature with a new PERF_PMU_CAP_ flag and then have the coresight/etc. people opt-in once they've audited things. James, does that work for you?