Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp206100imn; Fri, 29 Jul 2022 04:45:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1usaUX/bkkmkQ/oSYPtGPCbxuEbRcW1a6BJC6VVzO7CFwc4uu/T48sXcu5CLRXpDDIuSfty X-Received: by 2002:a05:6402:e93:b0:43b:6a49:7e88 with SMTP id h19-20020a0564020e9300b0043b6a497e88mr3238235eda.132.1659095116692; Fri, 29 Jul 2022 04:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659095116; cv=none; d=google.com; s=arc-20160816; b=0xF+/lJrg6WSykHB7bE2Vhxgq0aN5ojqCBOCNAeOVBkSDnvrZ0uRmlf/M2C7MsAKZB /qBVNVtYuIgmc4jsmQ7zUqq/DU+MrFM/WMq+qbsxgG4qoILMIWnl3dz1qLp6Z6ODIXpv FAi+z4je9/a24oErH800+APBDFUL5wgRbG1NsmfOIyTAqMJ7wrK+8Ph/hZbflrTNyIyv j+VCSsSWpP40Gn8RR8sQlzE7en0rYfwVa7GNzThB1AxLks6OK5QPNQB0dMLsSMOVraFy Fr9OpfRwpVEkt9JTisGqDyC5F8kJ3F6pF3J0fb9nysC5tUuAr2wWEjd+AmACIH0ppA5L qaTA== 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=4L1fjh9bnrjrBCkVru3xwOwL8yvwznO6uv+zcqB7u7Y=; b=z6lkGyedh8zAQEi+RCguPupCmJ6ARsTydfszsx8Kw6zRKBI0C64bVJ8GPnMkSNShjf zyKh//bjr8/RcSkdJPyDUVH+heIalGkHaqnSVv6qvOW+yzyjoWB+/n1NoYyiOYwYJnkQ Jt9Ih0b0q+6T0HSidmF0PiDNsorusgy2PvoiwXWVHnXUID2m9QJUKY6EExmjTw6ePIQK A+vRsyt2rxSyVhLLmTYd6MPyc6Qrznymg0KVyWhEqS/1wIBGTyUngShFZlk7PPzcQkTI 0u3wUFyL8B8gZtLITgH6cJNnEvXhCM9fKoEaRuLUVvWLwvq+y6nUA9Y5V157mlZcBr3y K+qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gh4-20020a170906e08400b0072a84044156si2658966ejb.849.2022.07.29.04.44.51; Fri, 29 Jul 2022 04:45:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235944AbiG2LNj (ORCPT + 99 others); Fri, 29 Jul 2022 07:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235560AbiG2LNf (ORCPT ); Fri, 29 Jul 2022 07:13:35 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E88067AC0E for ; Fri, 29 Jul 2022 04:13:33 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 572501576; Fri, 29 Jul 2022 04:13:34 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 558AF3F73D; Fri, 29 Jul 2022 04:13:31 -0700 (PDT) From: Dietmar Eggemann To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt Cc: Daniel Bristot de Oliveira , Valentin Schneider , Mel Gorman , Ben Segall , Luca Abeni , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] sched/deadline: Use sched_dl_entity's dl_density in dl_task_fits_capacity() Date: Fri, 29 Jul 2022 13:13:05 +0200 Message-Id: <20220729111305.1275158-4-dietmar.eggemann@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729111305.1275158-1-dietmar.eggemann@arm.com> References: <20220729111305.1275158-1-dietmar.eggemann@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Save a multiplication in dl_task_fits_capacity() by using already maintained per-sched_dl_entity (i.e. per-task) `dl_runtime/dl_deadline` (dl_density). cap_scale(dl_deadline, cap) >= dl_runtime dl_deadline * cap >> SCHED_CAPACITY_SHIFT >= dl_runtime cap >= dl_runtime << SCHED_CAPACITY_SHIFT / dl_deadline cap >= (dl_runtime << BW_SHIFT / dl_deadline) >> BW_SHIFT - SCHED_CAPACITY_SHIFT cap >= dl_density >> BW_SHIFT - SCHED_CAPACITY_SHIFT __sched_setscheduler()->__checkparam_dl() ensures that the 2 corner cases (if conditions) `runtime == RUNTIME_INF (-1)` and `period == 0` of to_ratio(deadline, runtime) are not met when setting dl_density in __sched_setscheduler()-> __setscheduler_params()->__setparam_dl(). Signed-off-by: Dietmar Eggemann --- kernel/sched/sched.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 72704b2b4a45..cdfe52cd8d39 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -320,21 +320,6 @@ struct dl_bw { u64 total_bw; }; -/* - * Verify the fitness of task @p to run on @cpu taking into account the - * CPU original capacity and the runtime/deadline ratio of the task. - * - * The function will return true if the CPU original capacity of the - * @cpu scaled by SCHED_CAPACITY_SCALE >= runtime/deadline ratio of the - * task and false otherwise. - */ -static inline bool dl_task_fits_capacity(struct task_struct *p, int cpu) -{ - unsigned long cap = arch_scale_cpu_capacity(cpu); - - return cap_scale(p->dl.dl_deadline, cap) >= p->dl.dl_runtime; -} - extern void init_dl_bw(struct dl_bw *dl_b); extern int sched_dl_global_validate(void); extern void sched_dl_do_global(void); @@ -2894,6 +2879,21 @@ unsigned long effective_cpu_util(int cpu, unsigned long util_cfs, enum cpu_util_type type, struct task_struct *p); +/* + * Verify the fitness of task @p to run on @cpu taking into account the + * CPU original capacity and the runtime/deadline ratio of the task. + * + * The function will return true if the original capacity of @cpu is + * greater than or equal to task's deadline density right shifted by + * (BW_SHIFT - SCHED_CAPACITY_SHIFT) and false otherwise. + */ +static inline bool dl_task_fits_capacity(struct task_struct *p, int cpu) +{ + unsigned long cap = arch_scale_cpu_capacity(cpu); + + return cap >= p->dl.dl_density >> (BW_SHIFT - SCHED_CAPACITY_SHIFT); +} + static inline unsigned long cpu_bw_dl(struct rq *rq) { return (rq->dl.running_bw * SCHED_CAPACITY_SCALE) >> BW_SHIFT; -- 2.25.1