Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2584150rwn; Fri, 9 Sep 2022 16:42:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR6NRTHbDIWl7h3ObEIb+4+SWzzf8w2jndn88UxARTCYro0hQpxjj8xdWO6WFE+iOvyAegeC X-Received: by 2002:a17:902:c189:b0:176:b871:8a1 with SMTP id d9-20020a170902c18900b00176b87108a1mr15993501pld.30.1662766968266; Fri, 09 Sep 2022 16:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662766968; cv=none; d=google.com; s=arc-20160816; b=HNKZ0Imw47/wFCXbBF0gbzAf/dtTedcdBkMAj3b/SmwWUvvFmFj1GHmHvnIX1ufpoN PVtJ0B9KBuiz3icPzCkacHjzhHQ2QDdQ0LoyXeR6bFNvSMydHZuKcQ4xP8k1RfdD2zE7 mWmOQY/miDnD6ZZOnqUB57oRKrRMxU13rLPBYgltfXjS3MsqFKvgkDVsPHAQX+uC/B9S tYgvS2uyHsrTeCxRR7GlGBG62ymVXp91U4p4ycCuj5QIwnvZTXYEcILu3m6VNxPq3Uj7 4deryCnBsS25kS50OjPqmOP/AeAsSD1psFjO9/MjcMYvf/7TRUBFb1kzGiXtp/9H1GgX AdSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=kzwRL0CtILSD7xtPq/vWs6AnP65M8kxQu9Vz7M9abB4=; b=JFJQrx7+hJ4nVIwwsmCl8VgDvvLEQpFhytLAKELDAcSCrAGBxhRPVx5VsGI/bmO9mt 1BRtkQGePEyHAtPXwxnKp8fVgPzLHovk7b4pwCLf4r/2Ch7XxU5qVBvdSMFkv7pJ+3qx CylK4J+ULHKJe45u1EbjEQwg1FiW5jxFP5RJixvfdxi4tJmvdclUhLORZpoRkMKjhvkG 1UoEDqcrboCqWjuMZWEEIfUy9IuTgV5/4luLSergBwpZOVNd5JvKUibddb9wi6jgZqqg wdxvUH4dWiGEvw1ix4PfDV9Y6MoAQBisq0s0PU7mUGJB2svqOOeD7m7rCKeaKQrzA7rZ OoMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QczBKilw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a170902ce8300b001733a212ccfsi2047769plg.330.2022.09.09.16.42.36; Fri, 09 Sep 2022 16:42:48 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=QczBKilw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232265AbiIIXIi (ORCPT + 99 others); Fri, 9 Sep 2022 19:08:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbiIIXGu (ORCPT ); Fri, 9 Sep 2022 19:06:50 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D449117488 for ; Fri, 9 Sep 2022 16:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662764806; x=1694300806; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=fqp/+ja2AfhJThgnSNq5HdkqvXnSgr2PPJsRa8AnaJk=; b=QczBKilwnDEPW/wBznPezBi3UWzYS+7y+AsICkn67juUBlF7kbn4eIxd hZq2e9QJzh/lZz6/cI9qoYQSB1rbnX9LKkdnguYfeNG9w23JHUjZXydD6 D/13cQ17jnnAOCe5xKyGCJORnkeKeZPPm1UvNafFKebuAyDBjJZVYRsnP aCRgqAcq9glQJqVIcWCqyQcDLkqftpgHaafm7GLr3TubU00UwVwXZld4q z8XrhBJFs+VX7ELxSPM/EybW8q865X0NLF1WSezxSaHrroip9I7xE023/ /j0k0Y8AV9oavFNnQwK7BRdDSKjX/OOIJ2RJ2y5v6Mnx/L+e1+BljdNlL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10465"; a="296325087" X-IronPort-AV: E=Sophos;i="5.93,304,1654585200"; d="scan'208";a="296325087" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2022 16:06:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,304,1654585200"; d="scan'208";a="677354999" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga008.fm.intel.com with ESMTP; 09 Sep 2022 16:06:33 -0700 From: Ricardo Neri To: "Peter Zijlstra (Intel)" , Juri Lelli , Vincent Guittot Cc: Ricardo Neri , "Ravi V. Shankar" , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Len Brown , Mel Gorman , "Rafael J. Wysocki" , Srinivas Pandruvada , Steven Rostedt , Tim Chen , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , "Tim C . Chen" Subject: [RFC PATCH 09/23] sched/fair: Use task-class performance score to pick the busiest group Date: Fri, 9 Sep 2022 16:11:51 -0700 Message-Id: <20220909231205.14009-10-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220909231205.14009-1-ricardo.neri-calderon@linux.intel.com> References: <20220909231205.14009-1-ricardo.neri-calderon@linux.intel.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 update_sd_pick_busiest() keeps on selecting as the busiest group scheduling groups of identical priority. Since both groups have the same priority, either group is a good choice. The classes of tasks in the scheduling groups can break this tie. Pick as busiest the scheduling group that yields a higher task-class performance score after load balancing. Cc: Ben Segall Cc: Daniel Bristot de Oliveira Cc: Dietmar Eggemann Cc: Len Brown Cc: Mel Gorman Cc: Rafael J. Wysocki Cc: Srinivas Pandruvada Cc: Steven Rostedt Cc: Tim C. Chen Cc: Valentin Schneider Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ricardo Neri --- kernel/sched/fair.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 97731f81b570..7368a0b453ee 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8777,6 +8777,60 @@ static void compute_ilb_sg_task_class_scores(struct sg_lb_task_class_stats *clas sgs->task_class_score_before = group_score; } +/** + * sched_asym_class_prefer - Select a sched group based on its classes of tasks + * @a: Load balancing statistics of @sg_a + * @b: Load balancing statistics of @sg_b + * + * Returns: true if preferring @a yields a higher overall throughput after + * balancing load. Returns false otherwise. + */ +static bool sched_asym_class_prefer(struct sg_lb_stats *a, + struct sg_lb_stats *b) +{ + if (!sched_task_classes_enabled()) + return false; + + /* @a increases overall throughput after load balance. */ + if (a->task_class_score_after > b->task_class_score_after) + return true; + + /* + * If @a and @b yield the same overall throughput, pick @a if + * its current throughput is lower than that of @b. + */ + if (a->task_class_score_after == b->task_class_score_after) + return a->task_class_score_before < b->task_class_score_before; + + return false; +} + +/** + * sched_asym_class_pick - Select a sched group based on classes of tasks + * @a: A scheduling group + * @b: A second scheduling group + * @a_stats: Load balancing statistics of @a + * @b_stats: Load balancing statistics of @b + * + * Returns: true if @a has the same priority and @a has classes of tasks that + * yield higher overall throughput after load balance. Returns false otherwise. + */ +static bool sched_asym_class_pick(struct sched_group *a, + struct sched_group *b, + struct sg_lb_stats *a_stats, + struct sg_lb_stats *b_stats) +{ + /* + * Only use the class-specific preference selection if both sched + * groups have the same priority. + */ + if (arch_asym_cpu_priority(a->asym_prefer_cpu) != + arch_asym_cpu_priority(b->asym_prefer_cpu)) + return false; + + return sched_asym_class_prefer(a_stats, b_stats); +} + #else /* CONFIG_SCHED_TASK_CLASSES */ static void update_rq_task_classes_stats(struct sg_lb_task_class_stats *class_sgs, struct rq *rq) @@ -8793,6 +8847,14 @@ static void compute_ilb_sg_task_class_scores(struct sg_lb_task_class_stats *clas { } +static bool sched_asym_class_pick(struct sched_group *a, + struct sched_group *b, + struct sg_lb_stats *a_stats, + struct sg_lb_stats *b_stats) +{ + return false; +} + #endif /* CONFIG_SCHED_TASK_CLASSES */ /** @@ -9049,6 +9111,12 @@ static bool update_sd_pick_busiest(struct lb_env *env, /* Prefer to move from lowest priority CPU's work */ if (sched_asym_prefer(sg->asym_prefer_cpu, sds->busiest->asym_prefer_cpu)) return false; + + /* @sg and @sds::busiest have the same priority. */ + if (sched_asym_class_pick(sds->busiest, sg, &sds->busiest_stat, sgs)) + return false; + + /* @sg has lower priority than @sds::busiest. */ break; case group_misfit_task: -- 2.25.1