Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3225642rwa; Tue, 23 Aug 2022 00:34:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6tktmruKJ0MK3merz5iOThA5eGnLx3ww0dfnvaDOoJLH9bYPX2hOwt1nDIJ6sGaZhD2rov X-Received: by 2002:a63:d617:0:b0:422:4d27:5817 with SMTP id q23-20020a63d617000000b004224d275817mr19955190pgg.412.1661240066413; Tue, 23 Aug 2022 00:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661240066; cv=none; d=google.com; s=arc-20160816; b=bAskTm9Mf2YJAZbYIUT++JsfY3YefFo23KDbLPyM/kQOzBi+wYtFuOSO5LbNCmc37y OTo59AyL01FyvfddQivb/li8zzMe70RbmraPLHgXbZspElOyZgIdWG+O75fSIgnt7g9S DuaXsqi9AhEn/IRRIw+FKpiaFF8nmAataHctumLW6MJvcwCc1KpMJKC/e41oNhDdh2OE NHctlanZ89WARG0WtW+3fo16Oz5KownEGdqGWA6eVpEYaW+A8yqOoS0iyl38SE5SRzdu MSaKuOXZGPcSxvCGYXWtYt5vo69YITKPa6hV5gDHJtD0DXGS8vYqHiTJsNe+pncPvu3E ivdg== 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=C2pTduGyZThsWDZ7oC5CKV3xWc+y+875pkYxXtFqY94=; b=gI2pi0CBs9+xqB5Pr9O9EwQ0PRE7QiN7cU14Ddn0Y3Y53UWN6hx+cRtDRaKJKOE8By el4ecf+QrokFUV9/mTfVIU3xp72aHZ7FH2PRcZjzNnS9jf+DScz+p+amvBoGVvt5l6U9 OwzZWakO3BzKKcxngEa8iQDtYOqtOmijPygch1x1e35ZaBM9rZCxEEi2QSxcSREMVPbF N9/jpuYjEL4zCZBafPW7HWncwfLsAC1mwN54K6/n859FlRqrMsHnFhADhQbHZmUQUxBs SX2tN/E74jZ+1BE/kG0Ar/M5SvgZl1MYEIWLl39rxXCeA0/Rl5S0VZBXhFuShQTuk7On n7aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kTxXVzaj; 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 1-20020a170902c20100b0016da85c2115si13606531pll.489.2022.08.23.00.34.14; Tue, 23 Aug 2022 00:34:26 -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=casper.20170209 header.b=kTxXVzaj; 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 S240898AbiHWHLU (ORCPT + 99 others); Tue, 23 Aug 2022 03:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240901AbiHWHKa (ORCPT ); Tue, 23 Aug 2022 03:10:30 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5AE161D4D for ; Tue, 23 Aug 2022 00:10:29 -0700 (PDT) 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=C2pTduGyZThsWDZ7oC5CKV3xWc+y+875pkYxXtFqY94=; b=kTxXVzajFLNaE21Oh0oBb5svei YALwqCin7NrV0NgtCaQEf12Ay6WPdvFTlr/x69cbTnb1czPMSYO8AQdC4y4ov19zADapzu9zmPCZb YrohODibAGyH5IlYQ2H7hc7bN+aOYjrZAA99PUuuxkhjyLfcejpsMA+AvwQ18T+CzpP6TOgjcB26K +nc8vzpmXnEpi/sgYhrLxWkmjzDPTZQjybmkjE9YVG0n4ncKdexBn47psr8FZiHVh8Giw198epFeM MKaSx4QBZlEJ4JIlc5o9tuRG2RLXS9D23q4u04cnvQHqkF12w4gMQnjquAfMW4rGCpcAx+dWPBeQ6 UTbYeGzA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQO32-00F2yZ-GR; Tue, 23 Aug 2022 07:10:04 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 64F12980403; Tue, 23 Aug 2022 09:10:02 +0200 (CEST) Date: Tue, 23 Aug 2022 09:10:02 +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> <2acacbcb-2bdb-30d6-3300-8d125b06a0f3@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2acacbcb-2bdb-30d6-3300-8d125b06a0f3@amd.com> 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 Tue, Aug 02, 2022 at 11:43:03AM +0530, Ravi Bangoria wrote: > [...] > > > /* > > @@ -2718,7 +2706,6 @@ static void ctx_resched(struct perf_cpu_context *cpuctx, > > struct perf_event_context *task_ctx, > > enum event_type_t event_type) > > { > > - enum event_type_t ctx_event_type; > > bool cpu_event = !!(event_type & EVENT_CPU); > > > > /* > > @@ -2728,11 +2715,13 @@ static void ctx_resched(struct perf_cpu_context *cpuctx, > > if (event_type & EVENT_PINNED) > > event_type |= EVENT_FLEXIBLE; > > > > - ctx_event_type = event_type & EVENT_ALL; > > + event_type &= EVENT_ALL; > > > > - perf_pmu_disable(cpuctx->ctx.pmu); > > - if (task_ctx) > > - task_ctx_sched_out(cpuctx, task_ctx, event_type); > > + perf_ctx_disable(&cpuctx->ctx); > > + if (task_ctx) { > > + perf_ctx_disable(task_ctx); > > + task_ctx_sched_out(task_ctx, event_type); > > + } > > > > /* > > * Decide which cpu ctx groups to schedule out based on the types > > @@ -2742,17 +2731,20 @@ static void ctx_resched(struct perf_cpu_context *cpuctx, > > * - otherwise, do nothing more. > > */ > > if (cpu_event) > > - cpu_ctx_sched_out(cpuctx, ctx_event_type); > > - else if (ctx_event_type & EVENT_PINNED) > > - cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE); > > + ctx_sched_out(&cpuctx->ctx, event_type); > > + else if (event_type & EVENT_PINNED) > > + ctx_sched_out(&cpuctx->ctx, EVENT_FLEXIBLE); > > > > perf_event_sched_in(cpuctx, task_ctx, current); > > - perf_pmu_enable(cpuctx->ctx.pmu); > > + > > + perf_ctx_enable(&cpuctx->ctx); > > + if (task_ctx) > > + perf_ctx_enable(task_ctx); > > } > > ctx_resched() reschedule entire perf_event_context while adding new event > to the context or enabling existing event in the context. We can probably > optimize it by rescheduling only affected pmu_ctx. Yes, it would probably make sense to add a pmu argument there and limit the rescheduling where possible.