Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2326468imm; Fri, 7 Sep 2018 14:43:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZbC277Zc2i0TZ/pjXBvHzltectRymwD80ChPKt1kqw8/VZeFLnTmF/te3Nl3YMw5CEeEoZ X-Received: by 2002:a62:2459:: with SMTP id r86-v6mr10789312pfj.31.1536356594289; Fri, 07 Sep 2018 14:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356594; cv=none; d=google.com; s=arc-20160816; b=YAuKX6ihUe6a8epSjnw1V9GGCKB54z8zRaYPSgPswHL6JjAK/Nv9z2413LB8/awemg ojRwyUimqy0xwwbKs+BDYK/lBwvpJEYIG2ci/tHlO/u9XQwyDpRnE+QrGuZ/MqfOuhVO f5F8QJoA9b6LU9Z3Ra6L86ud48PnLGMoIskYOd/cfDj+dEnuJZeF+ZgpF68mFWSAWee+ 7449hMZvDohFYNxmra/GlKQz9v66Fo31OblWkqGT/Rkn/zUW7eOekaaDBu4cznykJqt/ mgvwwOsjPklWIa6WxNeRvs6WF+0EgtmzGUDaF+BAUDFGi2+GLc5eE8jg6/X6fUs36EU+ qZ+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DgPsyn48O8Glx2DFGpBU1Ne5xK7AqrTdK2DEG0uX2ag=; b=MpmIM/HPY1a4KeRPUm7cdmS6SuBCIZmdvezhg9OGWTk+kMUVZeg97XYNEZmCXf/Jpx aoSes/o+JHC0Y1v8iBbaPH04BVoIByltc9goJrErZl75ZCjGDTv9NXREObxzyC3KsyEl UkLtYsNsK+8EE4bFUAJjO7Pr5g06wWMhHR3qaZ2B2yp4OB1niOEe0clA5IYe7KxiZzyp K2ddBDuUOcA49umbn41oBwEOBFYwEsjUBbQwkJVzlz+iVQCowcLYxZRDT+PzWB4acSyQ Ub1c5S8prnOoy1f5UyDGQqTz1LovwjM0uTkmizbtzws2YG4A2JinWr0obd5ONZCwmgkJ OfNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=iCn6B0Ih; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si8680894pli.238.2018.09.07.14.42.58; Fri, 07 Sep 2018 14:43:14 -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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=iCn6B0Ih; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730425AbeIHCYw (ORCPT + 99 others); Fri, 7 Sep 2018 22:24:52 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:46720 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727876AbeIHCYv (ORCPT ); Fri, 7 Sep 2018 22:24:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1536356516; x=1567892516; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DgPsyn48O8Glx2DFGpBU1Ne5xK7AqrTdK2DEG0uX2ag=; b=iCn6B0IhxO9Yi/B7C4bRTj9iQ0aSnEJIG58qAUhKdgLRdsifIe6+V/Hq g35pcpYbyXde58FXRNwphCheFFKBIDwlHSvGYXl3OjbizTQDRXaqka9KD 18Ip8g3RN0ps5zXtDeUhloatS8E1y5+TvsAdL2AU8CDOZ3yq5Ug7wMtly U=; X-IronPort-AV: E=Sophos;i="5.53,343,1531785600"; d="scan'208";a="737530425" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 Sep 2018 21:41:55 +0000 Received: from u7588a65da6b65f.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w87LfoLZ058989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 7 Sep 2018 21:41:52 GMT Received: from u7588a65da6b65f.ant.amazon.com (localhost [127.0.0.1]) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTPS id w87Lfmha027315 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 7 Sep 2018 23:41:49 +0200 Received: (from jschoenh@localhost) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Submit) id w87LfmwU027311; Fri, 7 Sep 2018 23:41:48 +0200 From: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= To: Ingo Molnar , Peter Zijlstra Cc: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= , linux-kernel@vger.kernel.org Subject: [RFC 19/60] sched: Add entity variants of enqueue_task_fair() and dequeue_task_fair() Date: Fri, 7 Sep 2018 23:40:06 +0200 Message-Id: <20180907214047.26914-20-jschoenh@amazon.de> X-Mailer: git-send-email 2.9.3.1.gcba166c.dirty In-Reply-To: <20180907214047.26914-1-jschoenh@amazon.de> References: <20180907214047.26914-1-jschoenh@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is fair amount of overlap between enqueue_task_fair() and unthrottle_cfs_rq(), as well as between dequeue_task_fair() and throttle_cfs_rq(). This is the first step toward having both of them use the same basic function. Signed-off-by: Jan H. Schönherr --- kernel/sched/fair.c | 82 ++++++++++++++++++++++++++++++---------------------- kernel/sched/sched.h | 3 ++ 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9f63ac37f5ef..a96328c5a864 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4979,32 +4979,9 @@ static inline void hrtick_update(struct rq *rq) } #endif -/* - * The enqueue_task method is called before nr_running is - * increased. Here we update the fair scheduling stats and - * then put the task into the rbtree: - */ -static void -enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) +bool enqueue_entity_fair(struct rq *rq, struct sched_entity *se, int flags) { struct cfs_rq *cfs_rq; - struct sched_entity *se = &p->se; - - /* - * The code below (indirectly) updates schedutil which looks at - * the cfs_rq utilization to select a frequency. - * Let's add the task's estimated utilization to the cfs_rq's - * estimated utilization, before we update schedutil. - */ - util_est_enqueue(&rq->cfs, p); - - /* - * If in_iowait is set, the code below may not trigger any cpufreq - * utilization updates, so do it here explicitly with the IOWAIT flag - * passed. - */ - if (p->in_iowait) - cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT); for_each_sched_entity(se) { if (se->on_rq) @@ -5036,7 +5013,38 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) update_cfs_group(se); } - if (!se) + return se != NULL; +} + +/* + * The enqueue_task method is called before nr_running is + * increased. Here we update the fair scheduling stats and + * then put the task into the rbtree: + */ +static void +enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) +{ + bool throttled; + + /* + * The code below (indirectly) updates schedutil which looks at + * the cfs_rq utilization to select a frequency. + * Let's add the task's estimated utilization to the cfs_rq's + * estimated utilization, before we update schedutil. + */ + util_est_enqueue(&rq->cfs, p); + + /* + * If in_iowait is set, the code below may not trigger any cpufreq + * utilization updates, so do it here explicitly with the IOWAIT flag + * passed. + */ + if (p->in_iowait) + cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT); + + throttled = enqueue_entity_fair(rq, &p->se, flags); + + if (!throttled) add_nr_running(rq, 1); hrtick_update(rq); @@ -5044,15 +5052,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) static void set_next_buddy(struct sched_entity *se); -/* - * The dequeue_task method is called before nr_running is - * decreased. We remove the task from the rbtree and - * update the fair scheduling stats: - */ -static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) +bool dequeue_entity_fair(struct rq *rq, struct sched_entity *se, int flags) { struct cfs_rq *cfs_rq; - struct sched_entity *se = &p->se; int task_sleep = flags & DEQUEUE_SLEEP; for_each_sched_entity(se) { @@ -5095,10 +5097,22 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) update_cfs_group(se); } - if (!se) + return se != NULL; +} + +/* + * The dequeue_task method is called before nr_running is + * decreased. We remove the task from the rbtree and + * update the fair scheduling stats: + */ +static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) +{ + bool throttled = dequeue_entity_fair(rq, &p->se, flags); + + if (!throttled) sub_nr_running(rq, 1); - util_est_dequeue(&rq->cfs, p, task_sleep); + util_est_dequeue(&rq->cfs, p, flags & DEQUEUE_SLEEP); hrtick_update(rq); } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 3e0ad36938fb..9016049f36c3 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1543,6 +1543,9 @@ extern const u32 sched_prio_to_wmult[40]; #define RETRY_TASK ((void *)-1UL) +bool enqueue_entity_fair(struct rq *rq, struct sched_entity *se, int flags); +bool dequeue_entity_fair(struct rq *rq, struct sched_entity *se, int flags); + struct sched_class { const struct sched_class *next; -- 2.9.3.1.gcba166c.dirty