Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2357526rdf; Mon, 6 Nov 2023 11:37:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4X80/rZ8TaABVPNWi+q1smt2q4iOfgI4aXfHNw57Wo7cZ5rRlfuByD8TEOkKo4PUZaT07 X-Received: by 2002:a05:6358:7248:b0:16b:7751:37a8 with SMTP id i8-20020a056358724800b0016b775137a8mr650382rwa.9.1699299458760; Mon, 06 Nov 2023 11:37:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699299458; cv=none; d=google.com; s=arc-20160816; b=VP+qFoYcdTgT8GFo+gMvhcm64gudMb7LXifoNP9MhgDhcTXztIvFonbulOCDS7xGNF 0H9eM9g73Ceb5FVbiB41ZBk9UebtQvGAqQl3l/5a56HPzLVizITZ4ERjmiFJvmiGoHnb jMfT6GvYih9e6CR+rLaDw0KHCm/VCrseFcSvFdn5hMBKOpS7CQrpukoY7u1W6/c3DZap xz4WC+No36nUJ1KJwbBEIPn4Tem/M26t60wlBlmW5j4b4scupX6tN4EgiWzs/wMe/b8r CQ1wYnrV/4QKesowEVyI/PvJ5N+EUIqCUgR5KVViBQsLPqcRd+6SNCla73aB1uwPNa2u 7xng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=SA9U3BYKpPLNMavyPlNHV0DBfe0X28VHPrgcDnlNWu4=; fh=E1g9yIoSurrDDzfb/otSzTalLQYyyMeFK3retSu/9Tc=; b=Q4Il0/UjQqmvJ4hCXOSk1Nrw9m+lEpF481/BQXLN2QaBmq5jTMxZ7T28Z4y9CRvFVK 9muNpjsOabANPax/Elp7a7Px7uwhHMzmvvkH0vplFu5JHH3glo+I/kzwASCPfLxz7qyD QwWeotMrIPxqN4ag1Ao2/Sbgfyb7STRFXNzshYmuA22pelyH1mES6YV0oFZrYnhwoMQI KLJSFsKxOW9UKUxAFZIFhZ+JKU3Iw0qh1T239qG4ou+B0rnMb/Mx8FTIM3W1gSQ1PMyq cgsD+uF9ey2fQUmyXDr5t1AEPRCYhgG9ZucgUKmIKoFIU30ck0TPsXMfmrPSYLCGk1iT b0Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dtPbMDaw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id by41-20020a056a0205a900b00566022bbcafsi370294pgb.566.2023.11.06.11.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:37:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dtPbMDaw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4749880323CC; Mon, 6 Nov 2023 11:37:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233083AbjKFTg0 (ORCPT + 99 others); Mon, 6 Nov 2023 14:36:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232748AbjKFTf7 (ORCPT ); Mon, 6 Nov 2023 14:35:59 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68B5E10C4 for ; Mon, 6 Nov 2023 11:35:56 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da03ef6fc30so5576977276.0 for ; Mon, 06 Nov 2023 11:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699299355; x=1699904155; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SA9U3BYKpPLNMavyPlNHV0DBfe0X28VHPrgcDnlNWu4=; b=dtPbMDawfzBhwhQq3OO+tqSrn9Z5NXNBhaCYZ0iaiOKCRu5v+wr4ItugAqtwQwRmH+ uP0YW2zXibSwOHKrnn96JOSFiloFEbTMa5IYbVJ1QNWJbpq+ZUvN86/rQFa8hDCwHXtV Bffm/zFcrGUJSR6pNzTE7IvDneaj9JKB2fulmEv0JzTi06PUaBFDUof+mafYI1naHrPm GYsWi6iMQRQoqX+oLKixJlre6CVGg0Qi6paJCmLo0hVrm9pkP2rgBhWLs4q0zNH9c+xg 2tOT0E1Z6f2VWQUUoSxZxQ7TbmMJmUkKuIS2Uz2X9JdvzFSQv5TqRxaNg6YIwUn0bWUi 6YWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699299355; x=1699904155; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SA9U3BYKpPLNMavyPlNHV0DBfe0X28VHPrgcDnlNWu4=; b=c9z2kFU4GhWvTIHxYoDSTLvmIpNwpXC1mKfDODzIHg7yvcC8BP0G9FgQdZEsCAJxpC AXGPQf+HJgG2mff0BST+5wyingxk/PbTnyUu6g+yWyn0MivPWFFSnn8eW64D+Fa/ON8/ wYPkQdUhdXH2o/i5KL8aK8Gl07osWnssi3ADBTyv4eWulgqQMcYro4mD9zQ0n4+JFUuH Cn47fFdz1A7lqBAjqrXUEislUhZg2SkMvSwLJrjA/yjR4m30JRl9ygj2WFtIHitxuddq iq6i6gIPC1rH+SQWkUtpOhROrTclgclbYpo2B8jlvfPvlTC+YVyavNAhsSiOd0ppOeb0 PvVg== X-Gm-Message-State: AOJu0YzbuRBitWnpaBM5SDdrDgIeAFBFbkS/4sM6t5/u11nwzzgKEBWe sCWOwPapNHBJgCa2Ys/wTiUKgex/kJqEC6QkOeMZ6faW2QB8Oqu2cnTJXOQr7DUHBk1FqSTUlOC Y3wLnoEyuBOOXs8ieIhfKbMw8qUt55YaXOaY5BUKs35nhO+H7OfrJNawfMJB5vLBe0+UYl+Y= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:1802:b0:da0:94e8:84d4 with SMTP id cf2-20020a056902180200b00da094e884d4mr554056ybb.12.1699299355240; Mon, 06 Nov 2023 11:35:55 -0800 (PST) Date: Mon, 6 Nov 2023 19:34:53 +0000 In-Reply-To: <20231106193524.866104-1-jstultz@google.com> Mime-Version: 1.0 References: <20231106193524.866104-1-jstultz@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231106193524.866104-11-jstultz@google.com> Subject: [PATCH v6 10/20] locking/mutex: Switch to mutex handoffs for CONFIG_PROXY_EXEC From: John Stultz To: LKML Cc: Peter Zijlstra , Joel Fernandes , Qais Yousef , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Youssef Esmat , Mel Gorman , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , "Paul E . McKenney" , kernel-team@android.com, Valentin Schneider , "Connor O'Brien" , John Stultz Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 06 Nov 2023 11:37:32 -0800 (PST) From: Peter Zijlstra Since with PROXY_EXEC, we will want to hand off locks to the task's we are running on behalf of, switch to using mutex handoffs. Cc: Joel Fernandes Cc: Qais Yousef Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Valentin Schneider Cc: Steven Rostedt Cc: Ben Segall Cc: Zimuzo Ezeozue Cc: Youssef Esmat Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E . McKenney" Cc: kernel-team@android.com Signed-off-by: Peter Zijlstra (Intel) [rebased, added comments and changelog] Signed-off-by: Juri Lelli [Fixed rebase conflicts] [squashed sched: Ensure blocked_on is always guarded by blocked_lock] Signed-off-by: Valentin Schneider [fix rebase conflicts, various fixes & tweaks commented inline] [squashed sched: Use rq->curr vs rq->proxy checks] Signed-off-by: Connor O'Brien [jstultz: Split out only the very basic initial framework for proxy logic from a larger patch.] Signed-off-by: John Stultz --- v5: * Split out from core proxy patch v6: * Rework to use sched_proxy_exec() instead of #ifdef CONFIG_PROXY_EXEC --- kernel/Kconfig.locks | 2 +- kernel/locking/mutex.c | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/kernel/Kconfig.locks b/kernel/Kconfig.locks index 4198f0273ecd..791c98f1d329 100644 --- a/kernel/Kconfig.locks +++ b/kernel/Kconfig.locks @@ -226,7 +226,7 @@ config ARCH_SUPPORTS_ATOMIC_RMW config MUTEX_SPIN_ON_OWNER def_bool y - depends on SMP && ARCH_SUPPORTS_ATOMIC_RMW + depends on SMP && ARCH_SUPPORTS_ATOMIC_RMW && !PROXY_EXEC config RWSEM_SPIN_ON_OWNER def_bool y diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index f37b7afe8aa5..5394a3c4b5d9 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -914,26 +914,31 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne mutex_release(&lock->dep_map, ip); - /* - * Release the lock before (potentially) taking the spinlock such that - * other contenders can get on with things ASAP. - * - * Except when HANDOFF, in that case we must not clear the owner field, - * but instead set it to the top waiter. - */ - owner = atomic_long_read(&lock->owner); - for (;;) { - MUTEX_WARN_ON(__owner_task(owner) != current); - MUTEX_WARN_ON(owner & MUTEX_FLAG_PICKUP); - - if (owner & MUTEX_FLAG_HANDOFF) - break; + if (sched_proxy_exec()) { + /* Always force HANDOFF for Proxy Exec for now. Revisit. */ + owner = MUTEX_FLAG_HANDOFF; + } else { + /* + * Release the lock before (potentially) taking the spinlock + * such that other contenders can get on with things ASAP. + * + * Except when HANDOFF, in that case we must not clear the + * owner field, but instead set it to the top waiter. + */ + owner = atomic_long_read(&lock->owner); + for (;;) { + MUTEX_WARN_ON(__owner_task(owner) != current); + MUTEX_WARN_ON(owner & MUTEX_FLAG_PICKUP); - if (atomic_long_try_cmpxchg_release(&lock->owner, &owner, __owner_flags(owner))) { - if (owner & MUTEX_FLAG_WAITERS) + if (owner & MUTEX_FLAG_HANDOFF) break; - return; + if (atomic_long_try_cmpxchg_release(&lock->owner, &owner, + __owner_flags(owner))) { + if (owner & MUTEX_FLAG_WAITERS) + break; + return; + } } } -- 2.42.0.869.gea05f2083d-goog