Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14967308rwb; Mon, 28 Nov 2022 06:45:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5siQkTfqYhY3ESVlQ4GCQlzoZvn64hzKIU3siZbzXN57eILvRJhenkjm9HLV7C8tXL1Bwx X-Received: by 2002:a17:903:d1:b0:186:8376:209f with SMTP id x17-20020a17090300d100b001868376209fmr37927498plc.161.1669646710286; Mon, 28 Nov 2022 06:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669646710; cv=none; d=google.com; s=arc-20160816; b=XXqCb54mnvtogaCN8VzQozzGGkjVOl7FKcyaF6JNns6KaBwgtuoAcMsYGtTvK+CwNo 7x0ZEo1jQUdqDU8ojh+whBg+k3OZNdo813BFs99EuhTsIffoebaqwH+vMRUgOCJoU8Ft Li/sgP+JWGeExBamha7Jgt7mfib/0r2uLvSsy4M2z163FhPrCBtty6gScSTSPk7nebL7 8a6KRBA1zAmxo7XXLlmRWCVnbns/Fa3psJkle1k9LxE4vQdwInrQyRAbo+Hd2/3+c7LH NHE+GEP2wY26CSRdic5GvBSbohljQRsXwRua9arozBEgNVP28oqz+tOhi6HxawKnZbsa g6nA== 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=VjaTWZV01qae2eSB11xOlwaKTA3Es1Na+6uJqUtfh6o=; b=nckOs4wy61dnuNliPdOtncxdtOFG00S8Pk1T4yrZcuZtpRSFchVT5o2jqvMQ/AZoOk pTRKmRBb4d/FWN29dx0ObnVzR7bdZAgOuflLgGd+U9/an+fpI10PJxGa/xaaZrHWoc5D Sh6YAZhZLGA4sF6zVN8K016D3VRgMe4jTmf0qlczhJ9TboV6NUh65pgJGDwv+Aluz6id ctbAZpzzj6s/0YDKRpEYvSJTdBKyZcMQ9rR/YHprL+3iG8k/O2fu/n54GjskywALWr53 vgq6CdCMVxwGU4r/DsfYUXqHHkMyz2NqMkZKW7LWjx4zxO+QZAgLpg8YCL9E6Gsqi9Ux w9oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=amtFdyXM; 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 e11-20020a17090a684b00b001fe1cc52234si11446293pjm.67.2022.11.28.06.44.58; Mon, 28 Nov 2022 06:45:10 -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=amtFdyXM; 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 S231895AbiK1NOv (ORCPT + 84 others); Mon, 28 Nov 2022 08:14:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbiK1NNl (ORCPT ); Mon, 28 Nov 2022 08:13:41 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C06A41CB37; Mon, 28 Nov 2022 05:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669641220; x=1701177220; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=6bnvjZwJXP3wVx/GzfxHDbk1nNW034G+XQZFyKkDwVI=; b=amtFdyXMYRlgqZ6C2IJoEYMFqv7J+hI5ztwU8lFKkAn6ZsCKsJ7iJI31 76gQv550LresMwB59yQfho+lV3JuSd2+VWD4eJlgGxhMGnjP1+ltI6CoZ ESJ+Nb6v0BM5B1yigVQLtxul6plcd7magRzbu3XQMIJBU3odV4uBFgs6T w9zb7VflXdnNwYfJExNjRi58n4bQbEXk6P5rq/G7ALyoNBs/v2Hv6YTW6 juTbRSK8QOCS04SY/Hv41JXvRvCvAicaYTn1kgQfGh+szSCXm7r4ugsJn Rd5DnlCWbL0Ziwn4vXFUqIfNLS7gVzmWli7LSp5SKo55Gm9aFnuY2xz1m Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="401117249" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="401117249" 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:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="749381393" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="749381393" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga002.fm.intel.com with ESMTP; 28 Nov 2022 05:13:35 -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 19/22] thermal: intel: hfi: Implement model-specific checks for task classification Date: Mon, 28 Nov 2022 05:20:57 -0800 Message-Id: <20221128132100.30253-20-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 In Alderlake and Raptorlake, the result of thread classification is more accurate when only one SMT sibling is busy. Classification results for class 2 and 3 that are always reliable. To avoid unnecessary migrations, only update the class of a task if it has been the same during 4 consecutive ticks. 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. * Used the new names of the IPC classes members in task_struct. * Reworked helper functions to use sched_smt_siblings_idle() to query the idle state of the SMT siblings of a CPU. --- drivers/thermal/intel/intel_hfi.c | 60 ++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index 8287bfd7d6b6..a9ae09036909 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -40,6 +40,7 @@ #include #include +#include #include "../thermal_core.h" #include "intel_hfi.h" @@ -216,9 +217,64 @@ int intel_hfi_has_ipc_classes(void) return cpu_feature_enabled(X86_FEATURE_ITD); } +#define CLASS_DEBOUNCER_SKIPS 4 + +/** + * debounce_and_update_class() - Process and update a task's classification + * + * @p: The task of which the classification will be updated + * @new_ipcc: The new IPC classification + * + * Update the classification of @p with the new value that hardware provides. + * Only update the classification of @p if it has been the same during + * CLASS_DEBOUNCER_SKIPS consecutive ticks. + */ +static void debounce_and_update_class(struct task_struct *p, u8 new_ipcc) +{ + u16 debounce_skip; + + /* The class of @p changed, only restart the debounce counter. */ + if (p->ipcc_tmp != new_ipcc) { + p->ipcc_cntr = 1; + goto out; + } + + /* + * The class of @p did not change. Update it if it has been the same + * for CLASS_DEBOUNCER_SKIPS user ticks. + */ + debounce_skip = p->ipcc_cntr + 1; + if (debounce_skip < CLASS_DEBOUNCER_SKIPS) + p->ipcc_cntr++; + else + p->ipcc = new_ipcc; + +out: + p->ipcc_tmp = new_ipcc; +} + +static bool classification_is_accurate(u8 hfi_class, bool smt_siblings_idle) +{ + switch (boot_cpu_data.x86_model) { + case INTEL_FAM6_ALDERLAKE: + case INTEL_FAM6_ALDERLAKE_L: + case INTEL_FAM6_RAPTORLAKE: + case INTEL_FAM6_RAPTORLAKE_P: + case INTEL_FAM6_RAPTORLAKE_S: + if (hfi_class == 3 || hfi_class == 2 || smt_siblings_idle) + return true; + + return false; + + default: + return true; + } +} + void intel_hfi_update_ipcc(struct task_struct *curr) { union hfi_thread_feedback_char_msr msr; + bool idle; /* We should not be here if ITD is not supported. */ if (!cpu_feature_enabled(X86_FEATURE_ITD)) { @@ -234,7 +290,9 @@ void intel_hfi_update_ipcc(struct task_struct *curr) * 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; + idle = sched_smt_siblings_idle(task_cpu(curr)); + if (classification_is_accurate(msr.split.classid, idle)) + debounce_and_update_class(curr, msr.split.classid + 1); } int intel_hfi_get_ipcc_score(unsigned short ipcc, int cpu) -- 2.25.1