From patchwork Mon Apr 3 09:08:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 78435 Return-Path: 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 + 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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762147144761432322?= X-GMAIL-MSGID: =?utf-8?q?1762147144761432322?= 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 Reviewed-by: Thomas Gleixner Reviewed-by: Paul E. McKenney --- 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);