Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4261219rwl; Mon, 3 Apr 2023 02:16:18 -0700 (PDT) X-Google-Smtp-Source: AKy350bZhN6wLglnxbfyTIfly7j6Kt37IAhgMn/94E3Fbn449PceUlXPFkQURm09aW31iNAkeWUu X-Received: by 2002:a50:fa96:0:b0:4fb:78a0:eac2 with SMTP id w22-20020a50fa96000000b004fb78a0eac2mr31131910edr.31.1680513377779; Mon, 03 Apr 2023 02:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680513377; cv=none; d=google.com; s=arc-20160816; b=IgtFVRCE06ON0xTO6PFSi2a1Af5XuNJuUWkzz49gmBGAgHL1KLyZ2yY+NfbM/CHUB2 Pja2qWCeJkPB5UxSCvJE0zZtrdXMjyMqTSvOAYh/lBIIZCmwe0aOuIZaQ991glMyvPHK yG10QCa5tP9Dk3yVI1q/8RhdGbYOlYXJYiO1o91i6FixrnnejhrdBrPVYzPm1Z5455te VcPyBnTvALxtzYZufvhBu9fSFpt0VqbdErDzHncGgtNfTqxZ76Q5v9wsvkqNQKtjpWwK qD/TgZXsXFlnYFq6vlguybMU2TKJvSkgpTz1rDueFY34OQHHA4LkTrrXx6++BEy42tMy Khwg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a056402078b00b004fd236f945csi3533903edy.63.2023.04.03.02.15.53; Mon, 03 Apr 2023 02:16:17 -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 S231624AbjDCJJU (ORCPT + 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 ); 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 ; 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 To: Thomas Gleixner , Ravi Bangoria , Ingo Molnar Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Mark Rutland , Jiri Olsa 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Peter Zijlstra (Intel) Tested-by: Thomas Gleixner --- kernel/events/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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);