Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1031604pxb; Wed, 1 Sep 2021 15:48:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyaB9y+GgTR7Fly3MaOTqLEfsoq3UvuKz88Z+G+2ZE0Fi0OyhJRV2ghhACkEf4EhfOi/eQ X-Received: by 2002:a17:906:730a:: with SMTP id di10mr216510ejc.428.1630536487469; Wed, 01 Sep 2021 15:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630536487; cv=none; d=google.com; s=arc-20160816; b=Sx4QBuLBCcMnr313febqRUvpB4+eH+uNqQXeOK3MDIU1izNGj56jNUEVRsHP/5LOHR SlCXuO9oUUrCGgVIfofm4dNJET81fESwPaZcy9Ky1eWlmoaNBDjdNpzGik8Co3laQiap BoZ2/rwnMgrdO3ERVeUjJ0PgqQdD2BzFfbxwLDhXgjTZMXrONQw35Wo0nlQPdiA7t7ES Gg3Z4qzLUdKyZ9h+vzglpy7fYLfOdPouy8HbvwBEJyGmlVTO0LBo45XmcMbg4tr8vkuZ knU4M+jwzO/ds/K343E5lXWayOnjy1iEZBeuoGonWihbSKFe+PjrSIZWCKtv5vVJ9YjR 5wPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bb7cGX8EmG7MkwUiNs36WV+nm681tb0H2tUrRezgfe0=; b=hhG/jBHgeJ4laPc+8pRoGQ0OOZH3TFb6GnuJ35NlIG8cmb3OyZVdu6XweYLJXLzCwm mx+mlk4Hb3sjlcTO6dxnslEAjZWmgb8yDxzcncITlaQto8ErDWJtBgv+OnqonJnWdvxY LSyQUGsFJBPlCh4QiqoGvhyaSKNpAhiKztxc+qP9HDJ96FkYbaLRMg7O2koX/VO1B0kC j82RSC8Bf+2DQIiFg56oc6CMdvvhPRrWO+dY/DNXhSRZ/QN6PQusUjnEGpfuda0jOFr3 RaTvwIxQlDZHF/Uojz9BMMk4dbodVVNcBGA0FOsAJR0i2kVAHSFXW4eMw3e8lcMm+1Mi iDqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn3si1062858ejc.2.2021.09.01.15.47.44; Wed, 01 Sep 2021 15:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242332AbhIAWaZ (ORCPT + 99 others); Wed, 1 Sep 2021 18:30:25 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:39664 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbhIAWaY (ORCPT ); Wed, 1 Sep 2021 18:30:24 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7CFEA22576; Wed, 1 Sep 2021 22:29:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1D02A13B03; Wed, 1 Sep 2021 22:29:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CMdYN8P+L2FiJgAAMHmgww (envelope-from ); Wed, 01 Sep 2021 22:29:23 +0000 From: Davidlohr Bueso To: tglx@linutronix.de Cc: peterz@infradead.org, mingo@kernel.org, rostedt@goodmis.org, longman@redhat.com, bigeasy@linutronix.de, boqun.feng@gmail.com, dave@stgolabs.net, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 1/2] sched: Move wake_q code below try_to_wake_up() Date: Wed, 1 Sep 2021 15:28:24 -0700 Message-Id: <20210901222825.6313-2-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210901222825.6313-1-dave@stgolabs.net> References: <20210901222825.6313-1-dave@stgolabs.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Such that wake_up_q() can make use of it instead of wake_up_process(). No change in code. Signed-off-by: Davidlohr Bueso --- kernel/sched/core.c | 172 ++++++++++++++++++++++---------------------- 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c4462c454ab9..7fc3d22bc6d8 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -865,92 +865,6 @@ static bool set_nr_if_polling(struct task_struct *p) #endif #endif -static bool __wake_q_add(struct wake_q_head *head, struct task_struct *task) -{ - struct wake_q_node *node = &task->wake_q; - - /* - * Atomically grab the task, if ->wake_q is !nil already it means - * it's already queued (either by us or someone else) and will get the - * wakeup due to that. - * - * In order to ensure that a pending wakeup will observe our pending - * state, even in the failed case, an explicit smp_mb() must be used. - */ - smp_mb__before_atomic(); - if (unlikely(cmpxchg_relaxed(&node->next, NULL, WAKE_Q_TAIL))) - return false; - - /* - * The head is context local, there can be no concurrency. - */ - *head->lastp = node; - head->lastp = &node->next; - return true; -} - -/** - * wake_q_add() - queue a wakeup for 'later' waking. - * @head: the wake_q_head to add @task to - * @task: the task to queue for 'later' wakeup - * - * Queue a task for later wakeup, most likely by the wake_up_q() call in the - * same context, _HOWEVER_ this is not guaranteed, the wakeup can come - * instantly. - * - * This function must be used as-if it were wake_up_process(); IOW the task - * must be ready to be woken at this location. - */ -void wake_q_add(struct wake_q_head *head, struct task_struct *task) -{ - if (__wake_q_add(head, task)) - get_task_struct(task); -} - -/** - * wake_q_add_safe() - safely queue a wakeup for 'later' waking. - * @head: the wake_q_head to add @task to - * @task: the task to queue for 'later' wakeup - * - * Queue a task for later wakeup, most likely by the wake_up_q() call in the - * same context, _HOWEVER_ this is not guaranteed, the wakeup can come - * instantly. - * - * This function must be used as-if it were wake_up_process(); IOW the task - * must be ready to be woken at this location. - * - * This function is essentially a task-safe equivalent to wake_q_add(). Callers - * that already hold reference to @task can call the 'safe' version and trust - * wake_q to do the right thing depending whether or not the @task is already - * queued for wakeup. - */ -void wake_q_add_safe(struct wake_q_head *head, struct task_struct *task) -{ - if (!__wake_q_add(head, task)) - put_task_struct(task); -} - -void wake_up_q(struct wake_q_head *head) -{ - struct wake_q_node *node = head->first; - - while (node != WAKE_Q_TAIL) { - struct task_struct *task; - - task = container_of(node, struct task_struct, wake_q); - /* Task can safely be re-inserted now: */ - node = node->next; - task->wake_q.next = NULL; - - /* - * wake_up_process() executes a full barrier, which pairs with - * the queueing in wake_q_add() so as not to miss wakeups. - */ - wake_up_process(task); - put_task_struct(task); - } -} - /* * resched_curr - mark rq's current task 'to be rescheduled now'. * @@ -4172,6 +4086,92 @@ int wake_up_state(struct task_struct *p, unsigned int state) return try_to_wake_up(p, state, 0); } +static bool __wake_q_add(struct wake_q_head *head, struct task_struct *task) +{ + struct wake_q_node *node = &task->wake_q; + + /* + * Atomically grab the task, if ->wake_q is !nil already it means + * it's already queued (either by us or someone else) and will get the + * wakeup due to that. + * + * In order to ensure that a pending wakeup will observe our pending + * state, even in the failed case, an explicit smp_mb() must be used. + */ + smp_mb__before_atomic(); + if (unlikely(cmpxchg_relaxed(&node->next, NULL, WAKE_Q_TAIL))) + return false; + + /* + * The head is context local, there can be no concurrency. + */ + *head->lastp = node; + head->lastp = &node->next; + return true; +} + +/** + * wake_q_add() - queue a wakeup for 'later' waking. + * @head: the wake_q_head to add @task to + * @task: the task to queue for 'later' wakeup + * + * Queue a task for later wakeup, most likely by the wake_up_q() call in the + * same context, _HOWEVER_ this is not guaranteed, the wakeup can come + * instantly. + * + * This function must be used as-if it were wake_up_process(); IOW the task + * must be ready to be woken at this location. + */ +void wake_q_add(struct wake_q_head *head, struct task_struct *task) +{ + if (__wake_q_add(head, task)) + get_task_struct(task); +} + +/** + * wake_q_add_safe() - safely queue a wakeup for 'later' waking. + * @head: the wake_q_head to add @task to + * @task: the task to queue for 'later' wakeup + * + * Queue a task for later wakeup, most likely by the wake_up_q() call in the + * same context, _HOWEVER_ this is not guaranteed, the wakeup can come + * instantly. + * + * This function must be used as-if it were wake_up_process(); IOW the task + * must be ready to be woken at this location. + * + * This function is essentially a task-safe equivalent to wake_q_add(). Callers + * that already hold reference to @task can call the 'safe' version and trust + * wake_q to do the right thing depending whether or not the @task is already + * queued for wakeup. + */ +void wake_q_add_safe(struct wake_q_head *head, struct task_struct *task) +{ + if (!__wake_q_add(head, task)) + put_task_struct(task); +} + +void wake_up_q(struct wake_q_head *head) +{ + struct wake_q_node *node = head->first; + + while (node != WAKE_Q_TAIL) { + struct task_struct *task; + + task = container_of(node, struct task_struct, wake_q); + /* Task can safely be re-inserted now: */ + node = node->next; + task->wake_q.next = NULL; + + /* + * wake_up_process() executes a full barrier, which pairs with + * the queueing in wake_q_add() so as not to miss wakeups. + */ + wake_up_process(task); + put_task_struct(task); + } +} + /* * Perform scheduler related setup for a newly forked process p. * p is forked by current. -- 2.26.2