Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1335876lqd; Thu, 25 Apr 2024 12:15:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1SdGamOH1kusW5voiW/GcWZGufI+KBWK94wIxtjmTk1EDKD3oDe8MDBljQfCcTPWbR6++qhyrRSfU+WeISPLdFoJw/80iYGi69B7E2A== X-Google-Smtp-Source: AGHT+IFoyz6LSUYrUir70APh5JU1XDB5EkGTiv1q8Cwe2f8i82adLi3MCFcmAQy6F2sk3NwKA1s0 X-Received: by 2002:ac2:4354:0:b0:51a:cc00:951b with SMTP id o20-20020ac24354000000b0051acc00951bmr190021lfl.49.1714072543848; Thu, 25 Apr 2024 12:15:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714072543; cv=pass; d=google.com; s=arc-20160816; b=zX6LqsOWzpH9HZLIcHpw9EMUmnesVuV8mcZUIXjepwbNK2fHokgAmNsWyXSy50wHyq +SyqeCPYRqFduEmN0IK+iAmFxti6FrgsLmwmPD+eJW1k1VvF2WHaKXdxYXStE+fmYBo2 c/q4nKyPY4e2jmyS2JGtg2qXDzYMWyrVKlMuRwLKhSgVa+6WrJmu6n+n8tNwznm1aVEc 1+ZnzNh1ENgvjWS+A6yA3338NzGAvCZUgae8XMSxhwpXNj3BA85wSxN4VnGg5mPXHy9/ +p+2emESlCVyb2M6b0v+lgCuTWSiJc0D4WLcQzRmW/sDev++DiKTC13pTtyG+Tr25yRD qSFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Njn3nta8ZGCrBAe5s2a7LkfaY0CfMi+tGHe4fAxKTBQ=; fh=GZRYfEpFGmb5gDdEaR5uGygbJ3pdWhF82GprXoJnKHU=; b=iyRr1TI29WEqwanKC6AFQxYOftQyaoa3ovMNSPfsoCvhBNknRUaQAMUa5RR0w07N2e HE8V3rCdVTgPkrHRQGlUaCNyrM9uweBYbTmOLd5vFo1ZMGUtNJUN4JDC2MJnEVsghYOj Edrw4nTYHy5QpL3iu+mESSZVAixnE4wId7A6gf9IQypVtexGA5GJOthrGgKYt2VKwXgF PFz8rFKXvHfTBrcdGlM/+DWoVC6yQ6zFAs4XSpOqBK9Us1Ar4krjgvh/uy21UwBI3aAT WF8YMk7le9I/sE4DlHgv4ppkICWzn+X1w70WCOqTdEmSyFwb7eBGAV8XjsP6SuAWg3ZP wuIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=mkBhHeMD; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-159070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159070-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id mc11-20020a170906eb4b00b00a52438e11b5si9996955ejb.711.2024.04.25.12.15.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 12:15:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=mkBhHeMD; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-159070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159070-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6591D1F23D31 for ; Thu, 25 Apr 2024 19:15:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F18715359F; Thu, 25 Apr 2024 19:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="mkBhHeMD" Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DEFE15099C; Thu, 25 Apr 2024 19:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714072506; cv=none; b=JBmVLO9ARbL1AWNbwUJLpKkU4prZ3OxA139Zz8vOS4l2HjINSCEACkqlA4mWTeTxUwh8+Bwsp/e9SYpUlE/39/lDR7/SGWSp3hNyndq+VMeXFqf8ov3igLZnqYR9icJtPIERcsH3IByQc/T1d42zfO6bFO3JXZXC5Lj3JBmjUSc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714072506; c=relaxed/simple; bh=WFHgedParJiMztTbyoW1ulB0kaEI8f5AmAhdKpkopQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MJe0XT3iJ1n1iR6oDAH/VTIq17i7FNGFonZT+7wlRmfDVd2to+wh9IYxB7Po7ES1F7x6VlhJ97x6sdTju+QYTtWpJg557fsY4TUhw/xf8IF7gA5TvCWecx61DfY87Tm/hwhX1HAvKUQBWn/A/lqymQ4ePsyLf8Qu5P0UeIxAesA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=mkBhHeMD reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.0.0) id 1aa4fdb3953d0eae; Thu, 25 Apr 2024 21:15:02 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id A994C66DF24; Thu, 25 Apr 2024 21:15:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1714072502; bh=WFHgedParJiMztTbyoW1ulB0kaEI8f5AmAhdKpkopQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mkBhHeMDkFuruz3i4m9nfl4ILiv/W57tM4XRJwYb0D+hzXDHH9pxCrG8BnfpqestL vnCRACGgo0n09Pf6xSzjlVDRO+7ZVaxJtdofIpflk4bMqDhFmtDaixsf39NTfcEsDP H+4JdBO+BP5HcCKosoEK/+TDVx4LZOjx2cZgaw7tda463dnV4x+y+nKfPSe0MorTwB DVWrq6simKnZGkr2yUtNJ/6dhYqJWMRNoIj409KtJ0uH3tNRAr8DEUvEVQYfpTvgVF JcLGaLgLZl87QIJKTuelkbspVSbOO0hyBmBwvsh9hBX2Khr627deOVoj1Xuv0Vn1/l xc2iJMisqmv+A== From: "Rafael J. Wysocki" To: x86 Maintainers Cc: LKML , Linux PM , Thomas Gleixner , Peter Zijlstra , Srinivas Pandruvada , "Rafael J. Wysocki" , Dietmar Eggemann , Ricardo Neri , Tim Chen Subject: [RFC][PATCH v1 2/3] x86/sched: Add basic support for CPU capacity scaling Date: Thu, 25 Apr 2024 21:15:01 +0200 Message-ID: <5784915.DvuYhMxLoT@kreacher> In-Reply-To: <2738703.mvXUDI8C0e@kreacher> References: <7663799.EvYhyI6sBW@kreacher> <3227587.5fSG56mABF@kreacher> <2738703.mvXUDI8C0e@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrudeljedgudefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopedutddprhgtphhtthhopeigkeeisehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehtghhlgieslhhinhhuthhrohhnihigrdguvgdprhgtphhtthhopehpvghtvghriiesihhnfhhrrggu vggrugdrohhrghdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki In order be able to compute the sizes of tasks consistently across all CPUs in a hybrid system, it is necessary to provide CPU capacity scaling information to the scheduler via arch_scale_cpu_capacity(). Add support for it via arch_cpu_scale per-CPU variables that can be set by whoever has sufficient information on the CPU capacities. By default, arch_cpu_scale is equal to SCHED_CAPACITY_SCALE for all CPUs, so this change by itself is not expected to alter the current behavior of the kernel. Signed-off-by: Rafael J. Wysocki --- arch/x86/include/asm/topology.h | 15 +++++++++++++++ arch/x86/kernel/smpboot.c | 3 +++ 2 files changed, 18 insertions(+) Index: linux-pm/arch/x86/include/asm/topology.h =================================================================== --- linux-pm.orig/arch/x86/include/asm/topology.h +++ linux-pm/arch/x86/include/asm/topology.h @@ -280,11 +280,26 @@ static inline long arch_scale_freq_capac } #define arch_scale_freq_capacity arch_scale_freq_capacity +DECLARE_PER_CPU(unsigned long, arch_cpu_scale); + +static inline unsigned long arch_scale_cpu_capacity(int cpu) +{ + return READ_ONCE(per_cpu(arch_cpu_scale, cpu)); +} +#define arch_scale_cpu_capacity arch_scale_cpu_capacity + +static inline void arch_set_cpu_capacity(int cpu, unsigned long cap) +{ + WRITE_ONCE(per_cpu(arch_cpu_scale, cpu), cap); +} + extern void arch_set_max_freq_ratio(bool turbo_disabled); extern void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled); void arch_rebuild_sched_domains(void); #else +static inline void arch_set_cpu_capacity(int cpu, unsigned long cap) { } + static inline void arch_set_max_freq_ratio(bool turbo_disabled) { } static inline void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled) { } Index: linux-pm/arch/x86/kernel/smpboot.c =================================================================== --- linux-pm.orig/arch/x86/kernel/smpboot.c +++ linux-pm/arch/x86/kernel/smpboot.c @@ -141,6 +141,9 @@ void arch_rebuild_sched_domains(void) { x86_topology_update = true; rebuild_sched_domains(); } + +/* CPU capacity scaling support */ +DEFINE_PER_CPU(unsigned long, arch_cpu_scale) = SCHED_CAPACITY_SCALE; #endif static unsigned int smpboot_warm_reset_vector_count;