Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1072496imd; Sat, 3 Nov 2018 17:17:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5dzweTM7hai1LA1dtNmMq5hJpvAKhOBIA7SVr/ZOrcV7BfCHdmRh4TKSFvVFaaOmzacqbN1 X-Received: by 2002:a62:8749:: with SMTP id i70-v6mr2147806pfe.41.1541290630957; Sat, 03 Nov 2018 17:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541290630; cv=none; d=google.com; s=arc-20160816; b=pH01uxBaPoi0hyJG0X9KxoLaahhFIageDJqquivFYrNDl8FsLfbBqrh+FHT1Hof/91 FOd+Tp7XD0tdlecmgF20XgU9kVy5wStm5Rk80KSlk1IT2MZvQdtlOdSsrCHLULoepUIR VfFaTywztluJnWedDUlpNSz/NphRahIjF+7lP2iq7Lw8jeXm6obzqiFQOPvQXIDmC1F8 CQ5PhvRcFkaS3Abs4Fv4vpaJIbSw8Q4u9yXAmtnICvTS9LELgqKYCgTcWVwwRi0PK6d+ NFPbjYT6VGyyl7HA1gXCLYKQf5B7g8g2GJasUfrBQdMVgLbeMSeiACB0z4Xu20xdOXgs 5oXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=OfD6XuXlwIEFBFx5QLoXtbbLoLWMgyAVggGd414LdIY=; b=nGDmIaA1wHteqVq/EwGb8HdV/c6r3q/DTXqERAwMUiak+2H4G9mCeX1utNJnfNgrXi YF0YPmfkG38joND3FVi42DmatWTAbRTrkG53U4YGx90eSJRKgDke9NO8CH8iWP1694/N 5INXeI/CSiI/7P7SgAWUmvXPKLh/+lYLOwfIvhFDLA/rK3oCKimqHqUb+Nn7TkSt1MnD MSC5PWqZ/lwALsfPS4w7mkCV60V7FcbhrdflF1I9iMGRmFQGl4LAoZ57ALPluMkhmOOC bFh5PUxsYe5ZAan3EOX2xiayck9QTxoLB20kFv7WElqmotXajgQY7Tbf3eb6K3qDjBAd SSQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si4353297pgj.542.2018.11.03.17.16.56; Sat, 03 Nov 2018 17:17:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728816AbeKDJ12 (ORCPT + 99 others); Sun, 4 Nov 2018 04:27:28 -0500 Received: from terminus.zytor.com ([198.137.202.136]:33145 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeKDJ12 (ORCPT ); Sun, 4 Nov 2018 04:27:28 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wA40EEjn3851484 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 3 Nov 2018 17:14:14 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wA40EDd73851481; Sat, 3 Nov 2018 17:14:13 -0700 Date: Sat, 3 Nov 2018 17:14:13 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Muchun Song Message-ID: Cc: mingo@kernel.org, peterz@infradead.org, torvalds@linux-foundation.org, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, smuchun@gmail.com Reply-To: torvalds@linux-foundation.org, peterz@infradead.org, mingo@kernel.org, tglx@linutronix.de, smuchun@gmail.com, linux-kernel@vger.kernel.org, hpa@zytor.com In-Reply-To: <20181026131743.21786-1-smuchun@gmail.com> References: <20181026131743.21786-1-smuchun@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] sched/core: Introduce set_next_task() helper for better code readability Git-Commit-ID: ff1cdc94de4d336be45336d70709dfcf3d682514 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, FREEMAIL_FORGED_REPLYTO,T_DATE_IN_FUTURE_96_Q autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ff1cdc94de4d336be45336d70709dfcf3d682514 Gitweb: https://git.kernel.org/tip/ff1cdc94de4d336be45336d70709dfcf3d682514 Author: Muchun Song AuthorDate: Fri, 26 Oct 2018 21:17:43 +0800 Committer: Ingo Molnar CommitDate: Sun, 4 Nov 2018 00:59:24 +0100 sched/core: Introduce set_next_task() helper for better code readability When we pick the next task, we will do the following for the task: 1) p->se.exec_start = rq_clock_task(rq); 2) dequeue_pushable(_dl)_task(rq, p); When we call set_curr_task(), we also need to do the same thing above. In rt.c, the code at 1) is in the _pick_next_task_rt() and the code at 2) is in the pick_next_task_rt(). If we put two operations in one function, maybe better. So, we introduce a new function set_next_task(), which is responsible for doing the above. By introducing the function we can get rid of calling the dequeue_pushable(_dl)_task() directly(We can call set_next_task()) in pick_next_task() and have better code readability and reuse. In set_curr_task_rt(), we also can call set_next_task(). Do this things such that we end up with: static struct task_struct *pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) { /* do something else ... */ put_prev_task(rq, prev); /* pick next task p */ set_next_task(rq, p); /* do something else ... */ } put_prev_task() can match set_next_task(), which can make the code more readable. Signed-off-by: Muchun Song Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20181026131743.21786-1-smuchun@gmail.com Signed-off-by: Ingo Molnar --- kernel/sched/deadline.c | 19 ++++++++++--------- kernel/sched/rt.c | 24 +++++++++++------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 91e4202b0634..470ba6b464fe 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1695,6 +1695,14 @@ static void start_hrtick_dl(struct rq *rq, struct task_struct *p) } #endif +static inline void set_next_task(struct rq *rq, struct task_struct *p) +{ + p->se.exec_start = rq_clock_task(rq); + + /* You can't push away the running task */ + dequeue_pushable_dl_task(rq, p); +} + static struct sched_dl_entity *pick_next_dl_entity(struct rq *rq, struct dl_rq *dl_rq) { @@ -1750,10 +1758,8 @@ pick_next_task_dl(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) BUG_ON(!dl_se); p = dl_task_of(dl_se); - p->se.exec_start = rq_clock_task(rq); - /* Running task will never be pushed. */ - dequeue_pushable_dl_task(rq, p); + set_next_task(rq, p); if (hrtick_enabled(rq)) start_hrtick_dl(rq, p); @@ -1808,12 +1814,7 @@ static void task_fork_dl(struct task_struct *p) static void set_curr_task_dl(struct rq *rq) { - struct task_struct *p = rq->curr; - - p->se.exec_start = rq_clock_task(rq); - - /* You can't push away the running task */ - dequeue_pushable_dl_task(rq, p); + set_next_task(rq, rq->curr); } #ifdef CONFIG_SMP diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index a21ea6021929..9aa3287ce301 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1498,6 +1498,14 @@ static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flag #endif } +static inline void set_next_task(struct rq *rq, struct task_struct *p) +{ + p->se.exec_start = rq_clock_task(rq); + + /* The running task is never eligible for pushing */ + dequeue_pushable_task(rq, p); +} + static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq, struct rt_rq *rt_rq) { @@ -1518,7 +1526,6 @@ static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq, static struct task_struct *_pick_next_task_rt(struct rq *rq) { struct sched_rt_entity *rt_se; - struct task_struct *p; struct rt_rq *rt_rq = &rq->rt; do { @@ -1527,10 +1534,7 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq) rt_rq = group_rt_rq(rt_se); } while (rt_rq); - p = rt_task_of(rt_se); - p->se.exec_start = rq_clock_task(rq); - - return p; + return rt_task_of(rt_se); } static struct task_struct * @@ -1573,8 +1577,7 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) p = _pick_next_task_rt(rq); - /* The running task is never eligible for pushing */ - dequeue_pushable_task(rq, p); + set_next_task(rq, p); rt_queue_push_tasks(rq); @@ -2355,12 +2358,7 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued) static void set_curr_task_rt(struct rq *rq) { - struct task_struct *p = rq->curr; - - p->se.exec_start = rq_clock_task(rq); - - /* The running task is never eligible for pushing */ - dequeue_pushable_task(rq, p); + set_next_task(rq, rq->curr); } static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task)