From nobody Wed Dec 31 14:58:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95F9BC4332F for ; Thu, 2 Nov 2023 15:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376820AbjKBPd1 (ORCPT ); Thu, 2 Nov 2023 11:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347591AbjKBPdH (ORCPT ); Thu, 2 Nov 2023 11:33:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A415B187 for ; Thu, 2 Nov 2023 08:32:53 -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:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=vBUL+P10jAOvg5j6kSlF2qo+oprvGK1yGYCCYSiAqlM=; b=sZEQnqGXe7KSXx/yVjySpREPrn 0QnaDtfJ4YE6CUOXoCoN8KNoCOu8lcspocLrKrgaugUK4GSm+mvfllmLeN/Sk8ePDXVi14V28PqPu swe3JNG+QFhta7azvPzQDhUsBmYHOYZvWV81qUGSURgqFmzBCl/bbj2Ju21q43AWoKbV0hsNZgkVc 5aJ25OIwHdVcZdMmFDUSqr0/feccxlzH71QSjwPdy8wDQBwh5kMASmhhAmZ6+11tzn9n3oOSVJZrj MaGlVb6zrAeiPe6+ODTLQcrwrSGEUym0qiNqyGHhY8TQBpbYymFq1rjuJAA2OOUkPZIQKxnCAKIJV iRcWyoRA==; 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 1qyZgV-0005PJ-Et; Thu, 02 Nov 2023 15:32:40 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 54ACC3021E1; Thu, 2 Nov 2023 16:32:39 +0100 (CET) Message-Id: <20231102152018.499897182@infradead.org> User-Agent: quilt/0.65 Date: Thu, 02 Nov 2023 16:09:26 +0100 From: Peter Zijlstra To: mingo@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com Subject: [PATCH 07/13] perf: Simplify: __perf_install_in_context() References: <20231102150919.719936610@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Zijlstra (Intel) --- kernel/events/core.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2732,13 +2732,13 @@ static int __perf_install_in_context(vo struct perf_cpu_context *cpuctx =3D this_cpu_ptr(&perf_cpu_context); struct perf_event_context *task_ctx =3D cpuctx->task_ctx; bool reprogram =3D true; - int ret =3D 0; =20 - raw_spin_lock(&cpuctx->ctx.lock); - if (ctx->task) { - raw_spin_lock(&ctx->lock); + if (ctx->task) task_ctx =3D ctx; =20 + guard(perf_ctx_lock)(cpuctx, task_ctx); + + if (ctx->task) { reprogram =3D (ctx->task =3D=3D current); =20 /* @@ -2748,14 +2748,10 @@ static int __perf_install_in_context(vo * If its not running, we don't care, ctx->lock will * serialize against it becoming runnable. */ - if (task_curr(ctx->task) && !reprogram) { - ret =3D -ESRCH; - goto unlock; - } + if (task_curr(ctx->task) && !reprogram) + return -ESRCH; =20 WARN_ON_ONCE(reprogram && cpuctx->task_ctx && cpuctx->task_ctx !=3D ctx); - } else if (task_ctx) { - raw_spin_lock(&task_ctx->lock); } =20 #ifdef CONFIG_CGROUP_PERF @@ -2778,10 +2774,7 @@ static int __perf_install_in_context(vo add_event_to_ctx(event, ctx); } =20 -unlock: - perf_ctx_unlock(cpuctx, task_ctx); - - return ret; + return 0; } =20 static bool exclusive_event_installable(struct perf_event *event,