Message ID | 20230403090858.GT4253@hirez.programming.kicks-ass.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2171823vqo; Mon, 3 Apr 2023 02:34:34 -0700 (PDT) X-Google-Smtp-Source: AKy350bByDB+ooOsOPMBB793duozwjyU5X+rDUyT2mHhkOOsbyfAGx2TfPCkaDo2JLqoCKnRA3Oi X-Received: by 2002:aa7:c393:0:b0:502:8f49:2553 with SMTP id k19-20020aa7c393000000b005028f492553mr6285555edq.25.1680514473826; Mon, 03 Apr 2023 02:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680514473; cv=none; d=google.com; s=arc-20160816; b=JLKmj5iVknvmXwndRrWbAEufF5EOCfwENe4CZ4XZKYPAq91S2MY2pNDgd+l9jD179J +AbOsoFXY6O7sl9y40NFufYBPgsTSLRo9IXhfkUdeQhygcSvwv8H50n4g3pLoTCLXE2M jiu8/mfWUNTG5zpfuDvZisLjg7DzURo3y9wGn2dJP5eMqrmkGyErXChaZvTAvaa7I23x /fssocspHtiXfnUI6bkoKLJQ3eOvNWu5FCTc49HZr1OTDrkDLWutieVi05+lGMfHB/dO no7IKcs8ZJ6/BLmiRnd0pnOlXCJX3DCNjhpAMSTeEfc2Bgylv4CKynvaS8yvAfpLdFti +qpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=s5+SYFBClxDh4bJ30eLDdVhCobI2olLYK6GT1ov2ndE=; b=mGNcPMWL2dl9/xTNQJM+JIf3tWB0tJGXhaw49qW1gKKNd7WC5FlfJzIGYWd2IOnzb4 CiVGwvgCfSpC3t3laja+w9ajuu8O6EkO1T3crJ6ebvc0G8EUNYxud9dZOAZQxuPcUYi+ uAG2Q6AT+9jhQO6uuqgwki/0Q8auIwpluBmqF+w38v1DrOyCWMPdmElWZkXc7mVuJWQp RTpmWvf518IweAvzZdn4T8YZ0BRvhRTPWNL3rXYWpzvXzvSyZ/hPz1wwRvbv7uAOXuPS GLse/nXY9yFEv5ZeoZ6vZv/3ELsTV/3x60vUHBDYNs7BN240BOS3e+8Yx0ymBLZ9HqBL fsog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="JrK5oZ/o"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170906a00100b00947702d0ba2si7482351ejy.983.2023.04.03.02.34.08; Mon, 03 Apr 2023 02:34:33 -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="JrK5oZ/o"; 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 S231634AbjDCJJU (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Mon, 3 Apr 2023 05:09:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjDCJJT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 3 Apr 2023 05:09:19 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B937687 for <linux-kernel@vger.kernel.org>; Mon, 3 Apr 2023 02:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=s5+SYFBClxDh4bJ30eLDdVhCobI2olLYK6GT1ov2ndE=; b=JrK5oZ/o94uvV4z/gpuml4hvnz mexRqZV729zcVUL5s58Unf93AZ+Sj1Y82mNF8ZCFQ7VeuiUszuSSbIA5dWLdWhAZt9kvubQAenIDZ z8XufWjOSxHe5mtFcODptZMYwj6ynorDSVEgpW8BNu54C2R5koroWV8dexVQdc97tgr1cW8WiutKz goFD1LIGOEQSnpKU9jef2+fTiFYaPUBPBBiIwTDdEJuEJEGoO32/p+QEKz5f1ERbDqqShWttD3Qyx JYzfnVgOkmE0hdqEFKCZgF5lJXNYralH6PQC6ZmOwCm5OjsSsg0gKV6osfr3VU8PjurBc4iBInvXi Gj+pEL8w==; 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 1pjGBQ-00DyBN-Ip; Mon, 03 Apr 2023 09:09:00 +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 05597300194; Mon, 3 Apr 2023 11:08:59 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D7E3024233365; Mon, 3 Apr 2023 11:08:58 +0200 (CEST) Date: Mon, 3 Apr 2023 11:08:58 +0200 From: Peter Zijlstra <peterz@infradead.org> To: Thomas Gleixner <tglx@linutronix.de>, Ravi Bangoria <ravi.bangoria@amd.com>, Ingo Molnar <mingo@kernel.org> Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Jiri Olsa <jolsa@kernel.org> Subject: [PATCH] perf: Optimize perf_pmu_migrate_context() Message-ID: <20230403090858.GT4253@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762147144761432322?= X-GMAIL-MSGID: =?utf-8?q?1762147144761432322?= |
Series |
perf: Optimize perf_pmu_migrate_context()
|
|
Commit Message
Peter Zijlstra
April 3, 2023, 9:08 a.m. UTC
Thomas reported that offlining CPUs spends a lot of time in synchronize_rcu() as called from perf_pmu_migrate_context() even though he's not actually using uncore events. Turns out, the thing is unconditionally waiting for RCU, even if there's no actual events to migrate. Fixes: 0cda4c023132 ("perf: Introduce perf_pmu_migrate_context()") Reported-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Thomas Gleixner <tglx@linutronix.de> --- kernel/events/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Comments
On Mon, Apr 03 2023 at 11:08, Peter Zijlstra wrote: > Thomas reported that offlining CPUs spends a lot of time in > synchronize_rcu() as called from perf_pmu_migrate_context() even though > he's not actually using uncore events. That happens when offlining CPUs from a socket > 0 in the same order how those CPUs have been brought up. On socket 0 this is not observable unless the bogus CPU0 offlining hack is enabled. If the offlining happens in the reverse order then all is shiny. The reason is that the first online CPU on a socket gets the uncore events assigned and when it is offlined then those are moved to the next online CPU in the same socket. On a SKL-X with 56 threads per sockets this results in a whopping _1_ second delay per thread (except for the last one which shuts down the per socket uncore events with no delay because there are no users) due to 62 times of pointless synchronize_rcu() invocations where each takes ~16ms on a HZ=250 kernel. Which in turn is interesting because that machine is completely idle other than running the offline muck... > Turns out, the thing is unconditionally waiting for RCU, even if there's > no actual events to migrate. > > Fixes: 0cda4c023132 ("perf: Introduce perf_pmu_migrate_context()") > Reported-by: Thomas Gleixner <tglx@linutronix.de> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> > Tested-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
On Tue, Apr 04, 2023 at 12:07:30AM +0200, Thomas Gleixner wrote: > On Mon, Apr 03 2023 at 11:08, Peter Zijlstra wrote: > > Thomas reported that offlining CPUs spends a lot of time in > > synchronize_rcu() as called from perf_pmu_migrate_context() even though > > he's not actually using uncore events. > > That happens when offlining CPUs from a socket > 0 in the same order how > those CPUs have been brought up. On socket 0 this is not observable > unless the bogus CPU0 offlining hack is enabled. > > If the offlining happens in the reverse order then all is shiny. > > The reason is that the first online CPU on a socket gets the uncore > events assigned and when it is offlined then those are moved to the next > online CPU in the same socket. > > On a SKL-X with 56 threads per sockets this results in a whopping _1_ > second delay per thread (except for the last one which shuts down the > per socket uncore events with no delay because there are no users) due > to 62 times of pointless synchronize_rcu() invocations where each takes > ~16ms on a HZ=250 kernel. > > Which in turn is interesting because that machine is completely idle > other than running the offline muck... > > > Turns out, the thing is unconditionally waiting for RCU, even if there's > > no actual events to migrate. > > > > Fixes: 0cda4c023132 ("perf: Introduce perf_pmu_migrate_context()") > > Reported-by: Thomas Gleixner <tglx@linutronix.de> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> > > Tested-by: Thomas Gleixner <tglx@linutronix.de> > > Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Yow! ;-) Assuming that all the events run under RCU protection, as in preemption disabled: Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
diff --git a/kernel/events/core.c b/kernel/events/core.c index fb3e436bcd4a..115320faf1db 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -12893,12 +12893,14 @@ void perf_pmu_migrate_context(struct pmu *pmu, int src_cpu, int dst_cpu) __perf_pmu_remove(src_ctx, src_cpu, pmu, &src_ctx->pinned_groups, &events); __perf_pmu_remove(src_ctx, src_cpu, pmu, &src_ctx->flexible_groups, &events); - /* - * Wait for the events to quiesce before re-instating them. - */ - synchronize_rcu(); + if (!list_empty(&events)) { + /* + * Wait for the events to quiesce before re-instating them. + */ + synchronize_rcu(); - __perf_pmu_install(dst_ctx, dst_cpu, pmu, &events); + __perf_pmu_install(dst_ctx, dst_cpu, pmu, &events); + } mutex_unlock(&dst_ctx->mutex); mutex_unlock(&src_ctx->mutex);