From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2B9F1A054F; Tue, 16 Mar 2021 10:38:31 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 11E762428EE; Tue, 16 Mar 2021 10:38:31 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 051F22428CA for ; Tue, 16 Mar 2021 10:38:28 +0100 (CET) IronPort-SDR: mSWS3d1IlT+NgtCDdUlLjXD2oe2bYxpDbh+kxqbZlKJB9KFRD9oC0/8ACtLAlnLfhhR+FPLT9v JMNLBjjaFzvg== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="253246294" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="253246294" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 02:38:27 -0700 IronPort-SDR: qAZNYzvD5oeEmaaaiUDOOrWrvPUJObf+Au68jrOo5GHuGdxDU/rFIny5iTayf5Re/PRYo1E4Lp i6xXM3HX+jqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="590601620" Received: from silpixa00399952.ir.intel.com (HELO silpixa00399952.ger.corp.intel.com) ([10.237.222.38]) by orsmga005.jf.intel.com with ESMTP; 16 Mar 2021 02:38:26 -0700 From: David Hunt To: dev@dpdk.org Cc: david.hunt@intel.com, anatoly.burakov@intel.com Date: Tue, 16 Mar 2021 09:38:11 +0000 Message-Id: <20210316093811.32651-1-david.hunt@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v1] lib/power: add check for sysfs base frequency X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some kernels may show in incorrect value for base frequency in sysfs (e.g. 15 GHz). This throws off the SST-BF algorithm for high and low priority cores. So if base_frequency is greater than max turbo frequency, ignore, and handle it as a normal core. Known Kernel version with issue: Linux 5.8.7 Signed-off-by: David Hunt --- lib/librte_power/power_pstate_cpufreq.c | 40 ++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c index edf6328e5..8a1fffaed 100644 --- a/lib/librte_power/power_pstate_cpufreq.c +++ b/lib/librte_power/power_pstate_cpufreq.c @@ -154,29 +154,49 @@ out: close(fd); static int power_init_for_setting_freq(struct pstate_power_info *pi) { - FILE *f_min, *f_max, *f_base; + FILE *f_min, *f_max, *f_base = NULL, *f_base_max; char fullpath_min[PATH_MAX]; char fullpath_max[PATH_MAX]; char fullpath_base[PATH_MAX]; + char fullpath_base_max[PATH_MAX]; char buf_base[BUFSIZ]; char *s_base; + char *s_base_max; uint32_t base_ratio = 0; + uint32_t base_max_ratio = 0; uint64_t max_non_turbo = 0; int ret_val = 0; - snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ, + snprintf(fullpath_base_max, + sizeof(fullpath_base_max), + POWER_SYSFILE_BASE_MAX_FREQ, pi->lcore_id); + f_base_max = fopen(fullpath_base_max, "r"); + FOPEN_OR_ERR_RET(f_base_max, -1); + if (f_base_max != NULL) { + s_base_max = fgets(buf_base, sizeof(buf_base), f_base_max); + FOPS_OR_NULL_GOTO(s_base_max, out); + buf_base[BUFSIZ-1] = '\0'; + if (strlen(buf_base)) + /* Strip off terminating '\n' */ + strtok(buf_base, "\n"); + + base_max_ratio = + strtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL) + / BUS_FREQ; + } + + snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ, + pi->lcore_id); f_min = fopen(fullpath_min, "rw+"); FOPEN_OR_ERR_RET(f_min, -1); snprintf(fullpath_max, sizeof(fullpath_max), POWER_SYSFILE_MAX_FREQ, pi->lcore_id); - f_max = fopen(fullpath_max, "rw+"); if (f_max == NULL) fclose(f_min); - FOPEN_OR_ERR_RET(f_max, -1); pi->f_cur_min = f_min; @@ -186,6 +206,7 @@ power_init_for_setting_freq(struct pstate_power_info *pi) pi->lcore_id); f_base = fopen(fullpath_base, "r"); + FOPEN_OR_ERR_RET(f_base, -1); if (f_base == NULL) { /* No sysfs base_frequency, that's OK, continue without */ base_ratio = 0; @@ -215,6 +236,17 @@ power_init_for_setting_freq(struct pstate_power_info *pi) pi->non_turbo_max_ratio = max_non_turbo; + /* + * If base_frequency is reported as greater than the maximum + * turbo frequency, that's a known issue with some kernels. + * Set base_frequency to max_non_turbo as a workaround. + */ + if (base_ratio > base_max_ratio) { + /* base_ratio is greater than max turbo. Kernel bug. */ + pi->priority_core = 0; + goto out; + } + /* * If base_frequency is reported as greater than the maximum * non-turbo frequency, then mark it as a high priority core. -- 2.17.1