Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp676980rwd; Mon, 12 Jun 2023 21:23:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kwYE3fgQ/WpScQ6JVFuhp0xvIOZP8sVxMd8v09EVL5teJ8PcX9ODMnQ12AREAAajyzAtS X-Received: by 2002:a17:907:320e:b0:974:b15:fce5 with SMTP id xg14-20020a170907320e00b009740b15fce5mr11680290ejb.38.1686630202957; Mon, 12 Jun 2023 21:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686630202; cv=none; d=google.com; s=arc-20160816; b=m0yxBOxAVgg0xUn3UXcvACrYrcn8mqWug/O0/NGguWhlM/vzq1knh1Fuqr5d0Am8t1 SQzGp0U39e4aVH3Yp/0Bp7HFiHN2bAcTHADgCNjyT55y/M0ooj+53zEiMmRlu81fVFuW TcCBL0RRVNhiD8kkoWG583RcKwcSerP8MwjD2Ww984CwIvcEHDMGq/PEZ2XUbFpByfr6 /a+CqKRD5VlkHPfif/XnahT03KTYrcBcdlWLNALGqVfsd79Bq/hbupMtXEnviVyloDK6 Iy52c9I8L7Ya3akh9xWLlOTvqVJ6M11fx+5JtyP3jcmFCMbvYSCvn5As4sxezSNUhKlN Oxeg== 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=0gEn4pKXXkWrnNqKpQtTvAMhVMr0JzS90VCxRixIaCc=; b=kJNlX80KxZ3dQdT4sZslvvFzuqX9QGNa7nauNWOiwdX8divELSL6eQgvEwT3px4Ziy zBvBLhlY6YM8PEEbWFuCXM9Yikc6eJ5pVpFicYwAaGkyg2xE1ILCgsaKVOw1rXDoDALo t67U31x5rSrYMT94vfQaOmbOr3ucWoUzNq4mpF0XTIscTmRxFF9gKbwlVx325hq0T+ux h5bn8pk09B9r6U2jzBDy9rDDojhEwu6335q+SeHiBCkjiewytKgLHnEGVZ7uns80dRpl 7Vd8fN/vQiEclWnzeFZhzM9od4NZt0zZYDEKmDldut8sJ2IJccPsTtyBN32VlVaBNWyQ U5Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Inp6q5rZ; 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 o18-20020a17090637d200b00977c8c89258si6279083ejc.1016.2023.06.12.21.22.58; Mon, 12 Jun 2023 21:23:22 -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=Inp6q5rZ; 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 S239136AbjFMEVq (ORCPT + 99 others); Tue, 13 Jun 2023 00:21:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239046AbjFMEVj (ORCPT ); Tue, 13 Jun 2023 00:21:39 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 632B510DA; Mon, 12 Jun 2023 21:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686630098; x=1718166098; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=f70oxXzoYQGDme9oRHr+6EBjtL+JoDXEljhGKTzB1PQ=; b=Inp6q5rZdf0BFS+6rBMTb2BCUnj/nbrH5uiwTyGR8kS9/ZmGb9E6wJav O8FZ9foj9UBc++WUQbvZL785/hyl2FPNd+ZIGgsTgLJVz6VddmukMrA7H jwShHf6j4KCSQ7ijB1UEHweH7O9cRBciGQzO1L3NP419iaTjNZLURVB3D x1k840CNUJGx4YtGA2ZsdHSOY0O39Gosd87RoMR++rzWoJMQt4BhsQSfr x6mwSAChNDTREi3lfwfGsmShANr/leM4K9W+e2BBOO1mM3muFwuqK230x /d8BOf0/CRHLisGRHjg1FwT4Uitzeuw23NRC5eUntU+SVanhVr438Yd9k g==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="358222044" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="358222044" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 21:21:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="661854932" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="661854932" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by orsmga003.jf.intel.com with ESMTP; 12 Jun 2023 21:21:36 -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 , Lukasz Luba , Ionela Voinescu , Zhao Liu , "Yuan, Perry" , x86@kernel.org, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ricardo Neri , "Tim C . Chen" , Zhao Liu Subject: [PATCH v4 02/24] sched: Add interfaces for IPC classes Date: Mon, 12 Jun 2023 21:24:00 -0700 Message-Id: <20230613042422.5344-3-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230613042422.5344-1-ricardo.neri-calderon@linux.intel.com> References: <20230613042422.5344-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,URIBL_BLOCKED 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 Add the interfaces that architectures shall implement to convey the data to support IPC classes. arch_update_ipcc() updates the IPC classification of the current task as given by hardware. arch_get_ipcc_score() provides a performance score for a given IPC class when placed on a specific CPU. Higher scores indicate higher performance. When a driver or equivalent enablement code has configured the necessary hardware to support IPC classes, it should call sched_enable_ipc_classes() to notify the scheduler that it can start using IPC classes data. The number of classes and the score of each class of task are determined by hardware. Cc: Ben Segall Cc: Daniel Bristot de Oliveira Cc: Dietmar Eggemann Cc: Ionela Voinescu Cc: Joel Fernandes (Google) Cc: Len Brown Cc: Lukasz Luba Cc: Mel Gorman Cc: Perry Yuan Cc: Rafael J. Wysocki Cc: Srinivas Pandruvada Cc: Steven Rostedt Cc: Tim C. Chen Cc: Valentin Schneider Cc: Zhao Liu Cc: x86@kernel.org Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ricardo Neri --- Changes since v3: * None Changes since v2: * Clarified the properties of the IPC score: abstract, and linear. It can normalized when needed. (Ionela) * Selected a better default IPC score. (Ionela) * Removed arch_has_ipc_classes(). It is not suitable for hardware that is not ready to support IPC classes after boot. (Lukasz) * Added a new sched_enable_ipc_classes() interface that drivers or enablement code can call when ready to support IPC classes. (Lukasz) Changes since v1: * Shortened the names of the IPCC interfaces (PeterZ): sched_task_classes_enabled >> sched_ipcc_enabled arch_has_task_classes >> arch_has_ipc_classes arch_update_task_class >> arch_update_ipcc arch_get_task_class_score >> arch_get_ipcc_score * Removed smt_siblings_idle argument from arch_update_ipcc(). (PeterZ) --- include/linux/sched/topology.h | 6 ++++ kernel/sched/sched.h | 66 ++++++++++++++++++++++++++++++++++ kernel/sched/topology.c | 9 +++++ 3 files changed, 81 insertions(+) diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index 816df6cc444e..5b084d3c9ad1 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -280,4 +280,10 @@ static inline int task_node(const struct task_struct *p) return cpu_to_node(task_cpu(p)); } +#ifdef CONFIG_IPC_CLASSES +extern void sched_enable_ipc_classes(void); +#else +static inline void sched_enable_ipc_classes(void) { } +#endif + #endif /* _LINUX_SCHED_TOPOLOGY_H */ diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 556496c77dc2..03fb53e9f340 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2544,6 +2544,72 @@ void arch_scale_freq_tick(void) } #endif +#ifdef CONFIG_IPC_CLASSES +DECLARE_STATIC_KEY_FALSE(sched_ipcc); + +static inline bool sched_ipcc_enabled(void) +{ + return static_branch_unlikely(&sched_ipcc); +} + +#ifndef arch_update_ipcc +/** + * arch_update_ipcc() - Update the IPC class of the current task + * @curr: The current task + * + * Request that the IPC classification of @curr is updated. + * + * Returns: none + */ +static __always_inline +void arch_update_ipcc(struct task_struct *curr) +{ +} +#endif + +#ifndef arch_get_ipcc_score + +#define SCHED_IPCC_SCORE_SCALE (1L << SCHED_FIXEDPOINT_SHIFT) +/** + * arch_get_ipcc_score() - Get the IPC score of a class of task + * @ipcc: The IPC class + * @cpu: A CPU number + * + * The IPC performance scores reflects (but it is not identical to) the number + * of instructions retired per cycle for a given IPC class. It is a linear and + * abstract metric. Higher scores reflect better performance. + * + * The IPC score can be normalized with respect to the class, i, with the + * highest IPC score on the CPU, c, with highest performance: + * + * IPC(i, c) + * ------------------------------------ * SCHED_IPCC_SCORE_SCALE + * max(IPC(i, c) : (i, c)) + * + * Scheduling schemes that want to use the IPC score along with other + * normalized metrics for scheduling (e.g., CPU capacity) may need to normalize + * it. + * + * Other scheduling schemes (e.g., asym_packing) do not need normalization. + * + * Returns the performance score of an IPC class, @ipcc, when running on @cpu. + * Error when either @ipcc or @cpu are invalid. + */ +static __always_inline +unsigned long arch_get_ipcc_score(unsigned short ipcc, int cpu) +{ + return SCHED_IPCC_SCORE_SCALE; +} +#endif +#else /* CONFIG_IPC_CLASSES */ + +#define arch_get_ipcc_score(ipcc, cpu) (-EINVAL) +#define arch_update_ipcc(curr) + +static inline bool sched_ipcc_enabled(void) { return false; } + +#endif /* CONFIG_IPC_CLASSES */ + #ifndef arch_scale_freq_capacity /** * arch_scale_freq_capacity - get the frequency scale factor of a given CPU. diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index ca4472281c28..c3a633a4b474 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -672,6 +672,15 @@ DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing); DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity); DEFINE_STATIC_KEY_FALSE(sched_asym_cpucapacity); +#ifdef CONFIG_IPC_CLASSES +DEFINE_STATIC_KEY_FALSE(sched_ipcc); + +void sched_enable_ipc_classes(void) +{ + static_branch_enable_cpuslocked(&sched_ipcc); +} +#endif + static void update_top_cache_domain(int cpu) { struct sched_domain_shared *sds = NULL; -- 2.25.1