From patchwork Mon Nov 6 19:34:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 162148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2884946vqu; Mon, 6 Nov 2023 11:38:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFW7/lv4YQD22GrMPOwnJr6PowyzXpA0IFeRQhw442uWW6jRSHBts5pMtlcLHNjQtAuK+n2 X-Received: by 2002:a05:6870:a910:b0:1e9:ddc5:99a3 with SMTP id eq16-20020a056870a91000b001e9ddc599a3mr800744oab.16.1699299482780; Mon, 06 Nov 2023 11:38:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699299482; cv=none; d=google.com; s=arc-20160816; b=dhmRIFZcyORwl6kf3R2lNqYG4hKG946GJEwz3xDtaEYQHwwz6svdfthX2Wx6qde3fs D9DxyH3Qi92M5aMrTzKvHCN4AnbCcMXOzFg+PsHBC7AkLTRHRYKxibAoucQhNaZOgcBP JIcwKkCuURTtBg/VQr3i1z39CUCIwaXIf0n1kNmGxPKnil1duWYa4VgzPAz0r+XAaQBx e4PcSJ0cDbvFDfDMJnwmQxqsb93jrJFgBHrvzqtGzrgNYkJ7ZUguE9eLRpgFYmNvJGcu tBM4BSlnwMau/jOXrF3hG4XW9+uQ68gxAzoGDNusXfIJrdJkJoTMOMZgFloZyTq78iTU 1Beg== 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=0t48YFx0UVkNi0jaFWpek94vC78jiuGmEf4m+wee/fQ=; fh=7UDRnXAyFwoHSGMn0t+ldgDKuKM1JE0l1TSpusfeMFI=; b=FeBrzZsjTiE/gjqE4x3xyCOJRvlTdoKlNSbxULDLONPvvbLAi9741/FPbo+u7TS4aw Se6fNVis5zu0e+x6Cfbn1y5mUc4QnGYPNBMHHyX6i9Yx+bDfYBo5SOXGk/vpdFFrIBbX 0L2vGCYWaw4ZGoZmTC+20cRGbdtBvh6XfCuV5zLYYH6zmM87earV+PoWbb2gY8pz//Q0 k+1vUxBL8C0rJ0HwDBVBPLFoN3xCPl8RepFn6IcMPfQ2d7Gm7U0MEBh5XJ7Aw13vpqAm bdEcggNjApVxyaEEdh1bYy7MVlNmUPoSjSfkidadRZVjI8qKfC+frConWZTbBsfpdJY+ WeGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=C0tmMvW6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o8-20020a656a48000000b005b8edc8ad3asi497843pgu.370.2023.11.06.11.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:38:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=C0tmMvW6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 94A4A8032BAD; Mon, 6 Nov 2023 11:37:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232979AbjKFThH (ORCPT + 34 others); Mon, 6 Nov 2023 14:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbjKFTgk (ORCPT ); Mon, 6 Nov 2023 14:36:40 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AC371707 for ; Mon, 6 Nov 2023 11:36:07 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5ae5b12227fso67172917b3.0 for ; Mon, 06 Nov 2023 11:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699299366; x=1699904166; 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=0t48YFx0UVkNi0jaFWpek94vC78jiuGmEf4m+wee/fQ=; b=C0tmMvW6EDloKdIqfq6GmYrjwV31rwd00BAc5YzsVqYfSReZHw0VOD2LNj6hDMaNR+ mcxx9ogkukKMM4MfNVh+FX2DQYlItetz2AzR0IsxlcfgsJEVHa5DQCe6D3wNiSWEcLHM 8JIU/jSTh4C3NHmwZETY97Y8UIQjhNAuTNbW9XppccP98o3j7sh5LBVqoD8Tyf/525d+ 6TcyjfG/8NYOfK4PYHDcMuPKkBDezK90h42vNgLEUBbJUS3ps+PiburhiPKf3xYFdY6X sFbzm4OtE2nImHOlnYHfeIA6C7fmOvwUT/5fAIiZ2jaHDnrHhRasrDBROmh8WDPI/jIo GP+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699299366; x=1699904166; 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=0t48YFx0UVkNi0jaFWpek94vC78jiuGmEf4m+wee/fQ=; b=eH0eOz2NkAVFbdemG5VLReZjubpgEllj835O4S+aaVIKUJNZUAqB+V69k91MGAFk4A ZIhuRUcHdq5tdweKVUYwzTFxQxIm5zA8duI27GRQfhHt5Brcdn3Wvd4Puz0V4P8Hk9TH zHJ/RY67IZikUCbkJTiv/bRSMwgLSLavbQ9CiPnppgXUdux3gmzj/rjaYShhv8AjZAnw kqjOfeoFcMQZycUzQzn+GzXxVelv0O+HkrY1tTCWhr2TyfCdExs+AtLR9vVCD+7liLRy rp/R7nIftTTwWww72FQ3Nn1e53fseNP4ljXA8LFsBfFhtFNtrArFOwQmSHtyG22siJ+W dkVw== X-Gm-Message-State: AOJu0YxplOcN1udXeds8mxl202HfvMh5MdSj2XzgUmHiQbEj2x5zPyZh 4k8qgSnEJnBNkDiXcj4wxHHvY2cMtZKNG+d+7Gz3uetMUeO+MPrbcvzJymqCY0jSLWNmRgkS8PH ItmmHFc4Pm2cwzXnFX2YA4Jgd58bzDNz08qMWl7rRVbxckSJbXDIkJ/RpC29LFlWlQgYNOlU= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:4855:0:b0:592:83d2:1f86 with SMTP id v82-20020a814855000000b0059283d21f86mr221121ywa.4.1699299365819; Mon, 06 Nov 2023 11:36:05 -0800 (PST) Date: Mon, 6 Nov 2023 19:34:58 +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-16-jstultz@google.com> Subject: [PATCH v6 15/20] sched: Add proxy deactivate helper From: John Stultz To: LKML Cc: John Stultz , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , 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 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 06 Nov 2023 11:37:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781844654373157222 X-GMAIL-MSGID: 1781844654373157222 Add small helper for deactivating the selected task 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: John Stultz --- kernel/sched/core.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5770656b898d..1b84d612332e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6612,6 +6612,22 @@ static bool try_to_deactivate_task(struct rq *rq, struct task_struct *p, } #ifdef CONFIG_PROXY_EXEC + +bool proxy_deactivate(struct rq *rq, struct task_struct *next) +{ + unsigned long state = READ_ONCE(next->__state); + + /* Don't deactivate if the state has been changed to TASK_RUNNING */ + if (!state) + return false; + if (!try_to_deactivate_task(rq, next, state, true)) + return false; + put_prev_task(rq, next); + rq_set_selected(rq, rq->idle); + resched_curr(rq); + return true; +} + /* * Initial simple proxy that just returns the task if its waking * or deactivates the blocked task so we can pick something that @@ -6620,10 +6636,9 @@ static bool try_to_deactivate_task(struct rq *rq, struct task_struct *p, static struct task_struct * proxy(struct rq *rq, struct task_struct *next, struct rq_flags *rf) { + struct task_struct *ret = NULL; struct task_struct *p = next; struct mutex *mutex; - unsigned long state; - mutex = p->blocked_on; /* Something changed in the chain, pick_again */ if (!mutex) @@ -6645,30 +6660,14 @@ proxy(struct rq *rq, struct task_struct *next, struct rq_flags *rf) */ raw_spin_unlock(&p->blocked_lock); raw_spin_unlock(&mutex->wait_lock); - return NULL; - } - - state = READ_ONCE(p->__state); - /* Don't deactivate if the state has been changed to TASK_RUNNING */ - if (!state) { - raw_spin_unlock(&p->blocked_lock); - raw_spin_unlock(&mutex->wait_lock); - return p; + return ret; } - try_to_deactivate_task(rq, next, state, true); - - /* - * If next is the selected task, then remove lingering - * references to it from rq and sched_class structs after - * dequeueing. - */ - put_prev_task(rq, next); - rq_set_selected(rq, rq->idle); - resched_curr(rq); + if (!proxy_deactivate(rq, next)) + ret = p; raw_spin_unlock(&p->blocked_lock); raw_spin_unlock(&mutex->wait_lock); - return NULL; + return ret; } #else /* PROXY_EXEC */ static struct task_struct *