From patchwork Mon Nov 28 13:20:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Neri X-Patchwork-Id: 26761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5657514wrr; Mon, 28 Nov 2022 05:15:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf5d8/55RmpMwLTYgIo6D6XgPDxX3yxKhCCy1SyACaaniZuVRVVyyjcXNxsXizLpRrcN/mud X-Received: by 2002:a63:4d0d:0:b0:477:14ea:cee6 with SMTP id a13-20020a634d0d000000b0047714eacee6mr26751940pgb.303.1669641320776; Mon, 28 Nov 2022 05:15:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669641320; cv=none; d=google.com; s=arc-20160816; b=eDB1/hWn1bkRDT44Nrn+XoGQW66+7dBx8JSUy4ZLvtxtjPzi6g9oDK/GBUnxaAKLY0 TdLTrZDCyiwYILtwM8ONGe6dKjVgWoUIeQBLdLwTgcu1M0YYJE4PzxIfiHggUrpvo36M 1kiPTyHJcDTlLuHygDosQ4oJxja/KITqiJVp9msu1WYBKRHTWWckeTYeCdGVW/nzffxw sPKWkz8RFNkNli5MW4zlepuMNhUkxsHZyZlPaLHkJhkQR+hhmpMlZz5aBiFcaYGIVCbj d3RV6snWaJaRpbVZQbuHHhnUSfR4ZQtkU1ZfWHF1HiziQq0m9MszK5x0CmKKrl5mqWDu xa0Q== 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=Q5g+SkK7SMS0wRfzaqwAP6IW6cEVIex09RzeAgTPI5k=; b=EVuvLxYzv1Mhd5PA71b1nGrWzDZF1xggLarcgICd5QIf+Wwz5aWMuYPRsD36m3eD4l uiBd6VOmn8mFEA96MPL/YUX9Oo2Xy0t3gu/8DWLA4UgNPJAm9YlFViMqNR3rP0agnG3A dV6a3gPMGpMo73sL6rrVNeAK9gq+QdoDIwk02Q0Eaw80UweAqMxE3Wv/K79vEU0RHxol yRbwbaYt9R2+CcJbS1RS5nfY8Au6QltC+zuDQ8npiECYqkMf6uDYLsvNwscWE3upt+gg XE8lfoIuXiFviU2eJJnq3wDMqqT0urO2+VY2Y/M5DDuPIZA7wSlEGUmPKk9YKkxlSV35 7wSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ku9+ujnj; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w2-20020a170902904200b0018981c83ffcsi4132772plz.4.2022.11.28.05.15.02; Mon, 28 Nov 2022 05:15:20 -0800 (PST) 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=Ku9+ujnj; 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 S231865AbiK1NOb (ORCPT + 99 others); Mon, 28 Nov 2022 08:14:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231531AbiK1NNk (ORCPT ); Mon, 28 Nov 2022 08:13:40 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDEFA46F; Mon, 28 Nov 2022 05:13:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669641219; x=1701177219; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ElamVYUpgDqJdxkmls7IkTtE4f7JXYRsemQvg1xBFFc=; b=Ku9+ujnj0jt1DV4ZEqWbFcflA/Y5vkn34TyYe0Bz1h7aC2yrSAKha9K5 N0lM62DkG2hcWWgGMPqRYervSHCKX1FgnHYN3bZzBOWw/nCdF4cZAAabx yZ2Dn00nr8wrnuvhUKP5tlO6rpzbEBdpJCn/lt6G0gFV1IrD6WR2uxqNw jhRlK+Lk6xMXvkEsVtrRQkUG8Kn269QlSWABtxPaP6abUCeGp3gdoEbmN GsQL5cZzxMf4HiBs8/QNTD1JqmCWHnCDH1xGSPH1/BxS8Usx1NMF1s3vj Vy5wNR1uow/QWbttI5ioYBPHhIvvXGgfpnz/YNrnp6OPd0tXLEH2GRQYB Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="401117179" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="401117179" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2022 05:13:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="749381369" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="749381369" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga002.fm.intel.com with ESMTP; 28 Nov 2022 05:13:34 -0800 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, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ricardo Neri , "Tim C . Chen" Subject: [PATCH v2 13/22] thermal: intel: hfi: Update the IPC class of the current task Date: Mon, 28 Nov 2022 05:20:51 -0800 Message-Id: <20221128132100.30253-14-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221128132100.30253-1-ricardo.neri-calderon@linux.intel.com> References: <20221128132100.30253-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750745817412737459?= X-GMAIL-MSGID: =?utf-8?q?1750745817412737459?= Use Intel Thread Director classification to update the IPC class of a task. Implement the needed scheduler interfaces. Cc: Ben Segall Cc: Daniel Bristot de Oliveira Cc: Dietmar Eggemann Cc: Joel Fernandes (Google) 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-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ricardo Neri --- Changes since v1: * Adjusted the result the classification of Intel Thread Director to start at class 1. Class 0 for the scheduler means that the task is unclassified. * Redefined union hfi_thread_feedback_char_msr to ensure all bit-fields are packed. (PeterZ) * Removed CONFIG_INTEL_THREAD_DIRECTOR. (PeterZ) * Shortened the names of the functions that implement IPC classes. * Removed argument smt_siblings_idle from intel_hfi_update_ipcc(). (PeterZ) --- arch/x86/include/asm/topology.h | 8 +++++++ drivers/thermal/intel/intel_hfi.c | 37 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 458c891a8273..cf46a3aea283 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -227,4 +227,12 @@ void init_freq_invariance_cppc(void); #define arch_init_invariance_cppc init_freq_invariance_cppc #endif +#if defined(CONFIG_IPC_CLASSES) && defined(CONFIG_INTEL_HFI_THERMAL) +int intel_hfi_has_ipc_classes(void); +void intel_hfi_update_ipcc(struct task_struct *curr); + +#define arch_has_ipc_classes intel_hfi_has_ipc_classes +#define arch_update_ipcc intel_hfi_update_ipcc +#endif /* defined(CONFIG_IPC_CLASSES) && defined(CONFIG_INTEL_HFI_THERMAL) */ + #endif /* _ASM_X86_TOPOLOGY_H */ diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index 56dba967849c..f85394b532a7 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -74,6 +74,17 @@ union cpuid6_edx { u32 full; }; +#ifdef CONFIG_IPC_CLASSES +union hfi_thread_feedback_char_msr { + struct { + u64 classid : 8; + u64 __reserved : 55; + u64 valid : 1; + } split; + u64 full; +}; +#endif + /** * struct hfi_cpu_data - HFI capabilities per CPU * @perf_cap: Performance capability @@ -176,6 +187,32 @@ static struct workqueue_struct *hfi_updates_wq; #ifdef CONFIG_IPC_CLASSES static int __percpu *hfi_ipcc_scores; +int intel_hfi_has_ipc_classes(void) +{ + return cpu_feature_enabled(X86_FEATURE_ITD); +} + +void intel_hfi_update_ipcc(struct task_struct *curr) +{ + union hfi_thread_feedback_char_msr msr; + + /* We should not be here if ITD is not supported. */ + if (!cpu_feature_enabled(X86_FEATURE_ITD)) { + pr_warn_once("task classification requested but not supported!"); + return; + } + + rdmsrl(MSR_IA32_HW_FEEDBACK_CHAR, msr.full); + if (!msr.split.valid) + return; + + /* + * 0 is a valid classification for Intel Thread Director. A scheduler + * IPCC class of 0 means that the task is unclassified. Adjust. + */ + curr->ipcc = msr.split.classid + 1; +} + static int alloc_hfi_ipcc_scores(void) { hfi_ipcc_scores = __alloc_percpu(sizeof(*hfi_ipcc_scores) *