Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp731313iog; Mon, 13 Jun 2022 11:39:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vwgiFdCHc+iQp1a8c2vsTSksnddzeE/OCMaqawDBhWHouZRipQ2In8nDuf74aP491d/fir X-Received: by 2002:a17:906:1c4e:b0:707:959:8cfd with SMTP id l14-20020a1709061c4e00b0070709598cfdmr1041018ejg.738.1655145575101; Mon, 13 Jun 2022 11:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655145575; cv=none; d=google.com; s=arc-20160816; b=zN7Wne0MrnWHwirBXES1NpexTuRDkNhzqEwS/gGdL8rF7xKHrqHqPPpiU8zIhS5luG 9E+OsCmm7tHXIRBzgh3U3OGbnEWkrkp+Djm8oWGcG0ERYvmlYkRjGh7u5hdBQ98dOqI5 1Cz+JUxmzzncyrzBazNL+ft4IsowxkBGIgsT+6O38zu4B1aYKnNQJe0ooWQoxreZFlC0 3Ll/sW4bbx6mlX9eqVXbSNamz0SqAbqfEGDzRfzFjGXMzEFXOIlb/boj8CXDTlTfz+55 EA8QTFVlTtXs8D/MWF/Gg7Yuav6+m8qLo6KI/W1YaZCDnnB5zcniG7Lzqcz+UfLadARq IgxA== 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=IEfVO3p8TtmbkhfyAZCfpHMcYnsk1901oHfnPETiUxk=; b=prx5oYlKcmdL32w19Zu2VeawhFe6v6n+ZdASk9CmTIszdgDKoJlWAjQURyqiFcFqGU h9eOg/ZHnPwyMRWaVJi7u7NUbJPV9cRReJV8kB6Z1H4DvNiQEA/p1VIDsiL46CbLp/yp tzMohzmTBK8cQl7yA1w0qM8iE3KPaAvLvjg0H5AAPuhcIWNKFbv9C+TRCHdouyFNc2hE XRJ7JYIJqSJ2lPjCEx2Ku8JostZOGN6/fv2bjq21YV6UWipOE5kTGUfcQ0GDcaNyf5E2 6y/xgpny3TR9xKQRrc9uKHGkepeoO55vj2clDJOjaZtWDSz8GqBnvKHgLmHGgpltn0t1 KrHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=lA+oiSff; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a056402280600b00434dcb3190csi7074091ede.585.2022.06.13.11.39.09; Mon, 13 Jun 2022 11:39:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=lA+oiSff; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235224AbiFMS3L (ORCPT + 99 others); Mon, 13 Jun 2022 14:29:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343993AbiFMS2o (ORCPT ); Mon, 13 Jun 2022 14:28:44 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 293BDB225B for ; Mon, 13 Jun 2022 07:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=IEfVO3p8TtmbkhfyAZCfpHMcYnsk1901oHfnPETiUxk=; b=lA+oiSffR4bHoAK/vJesjSm3LC iOXSHmhjhGvnJAPG5VrcmU/ECoQobY1YDOf98/cIA4KhDXRObEFXNGAW7DP+8fL9RoPxjxvtAomHS mfZkq4xsCGyya7Jqtd8gAMt3nLYBBPwVHs3OxkLhk/ht34YAqqXjqQKcL67rS4qgfA68kpi1r+40Z 0sJvOyEP/EqWHHdKbmk6kdispjZe7A1Mp2eF7DQXxg07UNTjT3+LjdemvLPa34rKTNqc6lqZqxDx+ Q+jebNIZgh0VZ9oW9g9T6rA6A6aMasi7QOJG84qV822lzyCaNl/DgqZexFYzMLCtv2wEY27JKLtc7 cxfTlEKA==; Received: from dhcp-077-249-017-003.chello.nl ([77.249.17.3] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0lII-007aoc-TQ; Mon, 13 Jun 2022 14:43:55 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id EAE333002BE; Mon, 13 Jun 2022 16:43:52 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D1E8D284A2B0D; Mon, 13 Jun 2022 16:43:52 +0200 (CEST) Date: Mon, 13 Jun 2022 16:43:52 +0200 From: Peter Zijlstra To: Ravi Bangoria Cc: acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, songliubraving@fb.com, eranian@google.com, alexey.budankov@linux.intel.com, ak@linux.intel.com, mark.rutland@arm.com, megha.dey@intel.com, frederic@kernel.org, maddy@linux.ibm.com, irogers@google.com, kim.phillips@amd.com, linux-kernel@vger.kernel.org, santosh.shukla@amd.com Subject: Re: [RFC v2] perf: Rewrite core context handling Message-ID: References: <20220113134743.1292-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Mon, Jun 13, 2022 at 04:35:11PM +0200, Peter Zijlstra wrote: > @@ -3652,17 +3697,28 @@ static noinline int visit_groups_merge(s > .size = ARRAY_SIZE(itrs), > }; > /* Events not within a CPU context may be on any CPU. */ > - __heap_add(&event_heap, perf_event_groups_first(groups, -1, NULL)); > + __heap_add(&event_heap, perf_event_groups_first(groups, -1, pmu, NULL)); > } > evt = event_heap.data; > > - __heap_add(&event_heap, perf_event_groups_first(groups, cpu, NULL)); > + __heap_add(&event_heap, perf_event_groups_first(groups, cpu, pmu, NULL)); > > #ifdef CONFIG_CGROUP_PERF > for (; css; css = css->parent) > - __heap_add(&event_heap, perf_event_groups_first(groups, cpu, css->cgroup)); > + __heap_add(&event_heap, perf_event_groups_first(groups, cpu, pmu, css->cgroup)); > #endif > > + if (event_heap.nr) { > + /* > + * XXX: For now, visit_groups_merge() gets called with pmu > + * pointer never NULL. But these functions needs to be called > + * once for each pmu if I implement pmu=NULL optimization. > + */ > + __link_epc((*evt)->pmu_ctx); > + perf_assert_pmu_disabled((*evt)->pmu_ctx->pmu); > + } > + > + > min_heapify_all(&event_heap, &perf_min_heap); > > while (event_heap.nr) { > @@ -3741,39 +3799,67 @@ static int merge_sched_in(struct perf_ev > return 0; > } > > -static void > -ctx_pinned_sched_in(struct perf_event_context *ctx, > - struct perf_cpu_context *cpuctx) > +static void ctx_pinned_sched_in(struct perf_event_context *ctx, struct pmu *pmu) > { > + struct perf_event_pmu_context *pmu_ctx; > int can_add_hw = 1; > > - if (ctx != &cpuctx->ctx) > - cpuctx = NULL; > - > - visit_groups_merge(cpuctx, &ctx->pinned_groups, > - smp_processor_id(), > - merge_sched_in, &can_add_hw); > + if (pmu) { > + visit_groups_merge(ctx, &ctx->pinned_groups, > + smp_processor_id(), pmu, > + merge_sched_in, &can_add_hw); > + } else { > + /* > + * XXX: This can be optimized for per-task context by calling > + * visit_groups_merge() only once with: > + * 1) pmu=NULL > + * 2) Ignoring pmu in perf_event_groups_cmp() when it's NULL > + * 3) Making can_add_hw a per-pmu variable > + * > + * Though, it can not be opimized for per-cpu context because > + * per-cpu rb-tree consist of pmu-subtrees and pmu-subtrees > + * consist of cgroup-subtrees. i.e. a cgroup events of same > + * cgroup but different pmus are seperated out into respective > + * pmu-subtrees. > + */ > + list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry) { > + can_add_hw = 1; > + visit_groups_merge(ctx, &ctx->pinned_groups, > + smp_processor_id(), pmu_ctx->pmu, > + merge_sched_in, &can_add_hw); > + } > + } > } I'm not sure I follow.. task context can have multiple PMUs just the same as CPU context can, that's more or less the entire point of the patch.