Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp104413lqb; Tue, 4 Jun 2024 06:29:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKiBrxAvkJ7bohCn7vwGYxl8OuulIXpooMoae8ccO2qjvpee6IV9c3fud7raW3V+h6lpeHkiGQkz1KvuIwjvO/KpnFynmi9e4hjF56kg== X-Google-Smtp-Source: AGHT+IHU6xVD58Ckb70gxFFYeurMsw/DuGvITQOpvMUOcjhral/eeMmroQ53w+9P3K98jCKy9fz3 X-Received: by 2002:a17:906:eb46:b0:a68:bfe9:a111 with SMTP id a640c23a62f3a-a68bfe9a651mr596623466b.55.1717507773734; Tue, 04 Jun 2024 06:29:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717507773; cv=pass; d=google.com; s=arc-20160816; b=Yb7BqI0Ob0LWLIa51/UGCWCOErreOY973kmqXQg2X/fqO9ssSYGtiu0ZZzztDtAjGg mK/2lzVXJHjQz4NlJYrwJl7P989SAWhOcRvRWbPjnRBOs4S7/YzbV2vSg1dso0Yrn3jH vtYK5d0LmRLw076mfkWo133piPHz5jGaA9rh4xyEAzaBqePx9mcdMmzxMha99w6jHQCm CCdpDNhkT+HTOVbKu4GIbhSQjZPXSBnWtixzGU3UEroigdOp4F/vQOEA6mcFh5vjzncO mekoatdRhgDltJqsUIOLPMyJRNk8CbPnSmYxfLBkYbF0KwQTEcPy6uI8vJrzUKN7x6HM rTlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LYcvAoRebzfM9FUzxsxh5Z/gVBI6ElMARHyhZH9mzfE=; fh=2xS93fNbHbtQMtD6inpYfF2esjwjs/1xitKaAqh7ZIs=; b=GbCoVS4h7kKCGMRJxFNr6zH03nDU0UieJZwaomrXxB/cr+ZpIWA8OIOi3JmmxgA7Ye I2I+/afF7ohqD0ed9NYI9NmEGOXD5C+H2KytSk3jIjhTnlp7yCTyVdtz8oq2othhPUd1 WQn9sA+2lyNp7A8zmAHYNLSQx+3qXgp8adNWpha5f6Ua6UQP+cdhO7Azsc4RoPZ0M2r1 PW8hZ1+tfa7x0HR3uu1KY9h0witxQnGD6nRUGqgn2h93m24e3nBLZYjYTYKiUR6PpJrA +RnkD/BgTFdgJuH5kRGypryQpkOsBYIn0Zf4wHtn2Vm6hVvZ3itzPhYJshiDBbh0FJG0 QokQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@layalina-io.20230601.gappssmtp.com header.s=20230601 header.b=LSZqRd7K; arc=pass (i=1 spf=pass spfdomain=layalina.io dkim=pass dkdomain=layalina-io.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-200707-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200707-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a691073abd9si186478566b.72.2024.06.04.06.29.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 06:29:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200707-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@layalina-io.20230601.gappssmtp.com header.s=20230601 header.b=LSZqRd7K; arc=pass (i=1 spf=pass spfdomain=layalina.io dkim=pass dkdomain=layalina-io.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-200707-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200707-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 49E101F2171C for ; Tue, 4 Jun 2024 13:29:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3032B146A9F; Tue, 4 Jun 2024 13:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=layalina-io.20230601.gappssmtp.com header.i=@layalina-io.20230601.gappssmtp.com header.b="LSZqRd7K" Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12762146A87 for ; Tue, 4 Jun 2024 13:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717507756; cv=none; b=j3WOpIXWOtRF/M8BhN5MiyjhcX+oml6qPLirIN9mrrL6xc4XTTlGc2nHc0VQgUVN/PEuibyrZ/E+IQjqQUz99rmtA/kC8CAWpNmCm/U5qT4fOe0tmIetha3nZO1N+ofg+/pAZUGB3RqPieUVZzvMmGUELSB8nJdrgCjo5nKp2XM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717507756; c=relaxed/simple; bh=SgPEpS+MqulS2tsTeKftzbR4Z9uYwx6KnXBdOcorlVo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k66m90k+fo/HbV9UTVLvbZuCs4aDlp2XljlMs5Y+2m6OTBlILcrRDcjJPZOapDiDknSnTp5ppt1CLF9bzwS6boR2AIMdYY4k4wUwNiAG3RUhQsliHFro0ByIbUg666zksXNVQuDeDfAafrmb9YSDlAXRSrnsNJCt/pK6GclsRVI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=layalina.io; spf=pass smtp.mailfrom=layalina.io; dkim=pass (2048-bit key) header.d=layalina-io.20230601.gappssmtp.com header.i=@layalina-io.20230601.gappssmtp.com header.b=LSZqRd7K; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=layalina.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=layalina.io Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2e78fe9fc2bso78446891fa.3 for ; Tue, 04 Jun 2024 06:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=layalina-io.20230601.gappssmtp.com; s=20230601; t=1717507752; x=1718112552; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=LYcvAoRebzfM9FUzxsxh5Z/gVBI6ElMARHyhZH9mzfE=; b=LSZqRd7KnKQ0KqUQhwovCqMSI8cN5V4yvNfL53RiCsfavKHWRxTHVEJWxA0BWOt6IP wkKqcl8LyYyePtojLcDfys3xwvXJiR4zcgHazh38lKgUFJ6ZT8juzuzuad7R4cPdBeuP CPJhM8ata5GngeOMg3sscMaAAQujANhovW0kGvixnvrXXRmwU6D6kkY5Lxdjavzmp0Hu QYA7xadztQWLRqOz/+NdJR4TBqenEdWZap/a1+ikVG1eJBvC1Mdn50yDmemR+yZjJQQk GkdII7ULp0Dmql0aNKtpXArUSDZADEF7QTQOcunn6yLsn8bHtniH/IFMwBojZcgHxG0o JPOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717507752; x=1718112552; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LYcvAoRebzfM9FUzxsxh5Z/gVBI6ElMARHyhZH9mzfE=; b=Zc60RVYsWC5msnRjHustoQ8D0dMBeeObJxIlzuvdnKeihogM8BE/f+ciE6lRTB0jLr /J5ioZvpccEa0sA+vHaCbxk9svborqltUuYMJHHHuvfLv9Z09AXfyQL/lEHdBq3Qe+Hp PVDvAN+K8Jjze/FisvfbpeTD56ESnMuNMZoCl3Q3gU3xHjF3foypEp9NEX20khF0S1B2 eCjm1+3xrgQ6Bz+17X+jUqw60aRRD9/5gj5WUJK3KnxzkK8gTfosAwovCRQyRBlKH/c9 DnqFbF9uVmwgi0LNlG39DQce+88gB+CpFvH9LJ9b+x/X/yTyLRua7byyjqxdDInCiDrQ 8vlA== X-Gm-Message-State: AOJu0Yyj3zA/14+8n2lTXy2diUiJODZmgibS5AiDIYN/5ipy6eNBuQcc 87gq+VT01C+sTm/0hQC88Pl0RLrIGfVtde+Klditga7WfaljQGZl8V4wsOjPj/E= X-Received: by 2002:a2e:9acd:0:b0:2e7:bc7:b6ea with SMTP id 38308e7fff4ca-2ea9512afdfmr76112151fa.14.1717507752012; Tue, 04 Jun 2024 06:29:12 -0700 (PDT) Received: from airbuntu ([87.127.96.170]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd04d9c73sm11632280f8f.58.2024.06.04.06.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 06:29:11 -0700 (PDT) Date: Tue, 4 Jun 2024 14:29:10 +0100 From: Qais Yousef To: John Stultz Cc: LKML , Joel Fernandes , 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" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , kernel-team@android.com Subject: Re: [PATCH v10 6/7] sched: Split out __schedule() deactivate task logic into a helper Message-ID: <20240604132910.25pgz3mjrnnwitve@airbuntu> References: <20240507045450.895430-1-jstultz@google.com> <20240507045450.895430-7-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240507045450.895430-7-jstultz@google.com> On 05/06/24 21:54, John Stultz wrote: > As we're going to re-use the deactivation logic, > split it into a helper. > > 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: Metin Kaya > Cc: Xuewen Yan > Cc: K Prateek Nayak > Cc: Thomas Gleixner > Cc: kernel-team@android.com > Tested-by: K Prateek Nayak > Tested-by: Metin Kaya > Reviewed-by: Metin Kaya > Signed-off-by: John Stultz > --- > v6: > * Define function as static to avoid "no previous prototype" > warnings as Reported-by: kernel test robot > v7: > * Rename state task_state to be more clear, as suggested by > Metin Kaya > --- > kernel/sched/core.c | 72 +++++++++++++++++++++++++++------------------ > 1 file changed, 43 insertions(+), 29 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 48f0d4b381d5..8bc5844ebab9 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6572,6 +6572,48 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > # define SM_MASK_PREEMPT SM_PREEMPT > #endif > > +/* > + * Helper function for __schedule() > + * > + * If a task does not have signals pending, deactivate it and return true > + * Otherwise marks the task's __state as RUNNING and returns false > + */ > +static bool try_to_deactivate_task(struct rq *rq, struct task_struct *p, > + unsigned long task_state) > +{ > + if (signal_pending_state(task_state, p)) { > + WRITE_ONCE(p->__state, TASK_RUNNING); We can avoid extra indention for the other (lengthy) leg if we return here? The return value is ignored for now, I don't mind keeping it but better call it out in the commit message or when you add the new user later you can update the signature more easily. Generally I think patches 4, 5 and 6 could be sent as their own series with minor commit messages tweaks to make them more independent and I hope Ingo and Peter are okay to pick them up as they look a nice clean up in general. Anyway: Reviewed-by: Qais Yousef > + } else { > + p->sched_contributes_to_load = > + (task_state & TASK_UNINTERRUPTIBLE) && > + !(task_state & TASK_NOLOAD) && > + !(task_state & TASK_FROZEN); > + > + if (p->sched_contributes_to_load) > + rq->nr_uninterruptible++; > + > + /* > + * __schedule() ttwu() > + * prev_state = prev->state; if (p->on_rq && ...) > + * if (prev_state) goto out; > + * p->on_rq = 0; smp_acquire__after_ctrl_dep(); > + * p->state = TASK_WAKING > + * > + * Where __schedule() and ttwu() have matching control dependencies. > + * > + * After this, schedule() must not care about p->state any more. > + */ > + deactivate_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); > + > + if (p->in_iowait) { > + atomic_inc(&rq->nr_iowait); > + delayacct_blkio_start(); > + } > + return true; > + } > + return false; > +} > + > /* > * __schedule() is the main scheduler function. > * > @@ -6665,35 +6707,7 @@ static void __sched notrace __schedule(unsigned int sched_mode) > */ > prev_state = READ_ONCE(prev->__state); > if (!(sched_mode & SM_MASK_PREEMPT) && prev_state) { > - if (signal_pending_state(prev_state, prev)) { > - WRITE_ONCE(prev->__state, TASK_RUNNING); > - } else { > - prev->sched_contributes_to_load = > - (prev_state & TASK_UNINTERRUPTIBLE) && > - !(prev_state & TASK_NOLOAD) && > - !(prev_state & TASK_FROZEN); > - > - if (prev->sched_contributes_to_load) > - rq->nr_uninterruptible++; > - > - /* > - * __schedule() ttwu() > - * prev_state = prev->state; if (p->on_rq && ...) > - * if (prev_state) goto out; > - * p->on_rq = 0; smp_acquire__after_ctrl_dep(); > - * p->state = TASK_WAKING > - * > - * Where __schedule() and ttwu() have matching control dependencies. > - * > - * After this, schedule() must not care about p->state any more. > - */ > - deactivate_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); > - > - if (prev->in_iowait) { > - atomic_inc(&rq->nr_iowait); > - delayacct_blkio_start(); > - } > - } > + try_to_deactivate_task(rq, prev, prev_state); > switch_count = &prev->nvcsw; > } > > -- > 2.45.0.rc1.225.g2a3ae87e7f-goog >