From patchwork Thu Apr 1 15:06:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 90433 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BE87EA0548; Thu, 1 Apr 2021 17:06:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A4BAE14116E; Thu, 1 Apr 2021 17:06:20 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 7D9D7140EE8 for ; Thu, 1 Apr 2021 17:06:18 +0200 (CEST) IronPort-SDR: qH5wx64G6VpYujbtUEox2ULnljEYxzgAuZf25m6iMovpe776Bt9q2zlAvDTBFG8v0b8qJ/USoC iU3xVeijGSQg== X-IronPort-AV: E=McAfee;i="6000,8403,9941"; a="256247255" X-IronPort-AV: E=Sophos;i="5.81,296,1610438400"; d="scan'208";a="256247255" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 08:06:16 -0700 IronPort-SDR: G16hAkhFLIQk6HjSyb5IfUI8axbLFdk4l0qjOJrpJa4lVUZKp0Hu6zMaqeapg3/Ss4r0Y/rC6L 9tov07gmsEfg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,296,1610438400"; d="scan'208";a="412722692" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.222.97]) by fmsmga008.fm.intel.com with ESMTP; 01 Apr 2021 08:06:15 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: anatoly.burakov@intel.com, david.hunt@intel.com Date: Thu, 1 Apr 2021 15:06:13 +0000 Message-Id: <20210401150614.234257-1-anatoly.burakov@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/2] power: fix pstate base frequency handling 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" Previous fix for base frequency handling in pstate mode introduced a couple of issues: - When base_frequency file does not exist, it simply bails out because of what appears to be accidental addition of FOPEN_OR_ERR_RET. This is incorrect, as absence of this file is not fatal and is in fact expected on kernel versions earlier than 5.3 - When base_frequency file does exist, it gets opened, but never gets closed, resulting in a resource leak Both issues also manifest themselves as Coverity defects (dead code, and a resource leak), so this fix addresses both. Fixes: 4db9587bbf72 ("power: check sysfs base frequency") Cc: david.hunt@intel.com Coverity issue: 369693 Coverity issue: 369694 Bugzilla ID: 668 Signed-off-by: Anatoly Burakov --- lib/librte_power/power_pstate_cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c index 8a1fffaed5..af5ad0b506 100644 --- a/lib/librte_power/power_pstate_cpufreq.c +++ b/lib/librte_power/power_pstate_cpufreq.c @@ -172,7 +172,6 @@ power_init_for_setting_freq(struct pstate_power_info *pi) 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); @@ -185,6 +184,7 @@ power_init_for_setting_freq(struct pstate_power_info *pi) base_max_ratio = strtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL) / BUS_FREQ; + fclose(f_base_max); } snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ, From patchwork Fri Apr 2 09:26:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 90458 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5CF66A0548; Fri, 2 Apr 2021 11:26:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD691140EC5; Fri, 2 Apr 2021 11:26:51 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 3E90840141 for ; Fri, 2 Apr 2021 11:26:49 +0200 (CEST) IronPort-SDR: fMAkO/x0RQQKlpeg0vjmSNgZizF03N+KvvzHQsp05iQCHNqoEglBunV68KKza0VpUIym9aDupx au8WtnFcKUyQ== X-IronPort-AV: E=McAfee;i="6000,8403,9941"; a="192536548" X-IronPort-AV: E=Sophos;i="5.81,299,1610438400"; d="scan'208";a="192536548" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2021 02:26:48 -0700 IronPort-SDR: Fr6JPBbgpX5KYJalPMq8Pu8up0clEK+PGC4pbcAnEsqp37aQuti3iud8XotBtGFLCaSRvqAcXk wqsLtKBJBnDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,299,1610438400"; d="scan'208";a="394900917" Received: from silpixa00399498.ir.intel.com (HELO silpixa00399498.ger.corp.intel.com) ([10.237.222.97]) by orsmga002.jf.intel.com with ESMTP; 02 Apr 2021 02:26:47 -0700 From: Anatoly Burakov To: dev@dpdk.org Cc: david.hunt@intel.com Date: Fri, 2 Apr 2021 09:26:45 +0000 Message-Id: <20210402092645.258257-2-anatoly.burakov@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210401150614.234257-1-anatoly.burakov@intel.com> References: <20210401150614.234257-1-anatoly.burakov@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v4 2/2] power: do not skip saving original pstate governor 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" Currently, when we set the pstate governor to "performance", we check if it is already set to this value, and if it is, we skip setting it. However, we never save this value anywhere, so that next time we come back and request the governor to be set to its original value, the original value is empty. Fix it by saving the original pstate governor first. While we're at it, replace `strlcpy` with `rte_strscpy`. Fixes: e6c6dc0f96c8 ("power: add p-state driver compatibility") Cc: david.hunt@intel.com Signed-off-by: Anatoly Burakov Acked-by: Reshma Pattan --- lib/librte_power/power_pstate_cpufreq.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c index c4639e4b8a..1cb0e4d917 100644 --- a/lib/librte_power/power_pstate_cpufreq.c +++ b/lib/librte_power/power_pstate_cpufreq.c @@ -382,6 +382,9 @@ power_set_governor_performance(struct pstate_power_info *pi) /* Strip off terminating '\n' */ strtok(buf, "\n"); + /* Save the original governor */ + rte_strscpy(pi->governor_ori, buf, sizeof(pi->governor_ori)); + /* Check if current governor is performance */ if (strncmp(buf, POWER_GOVERNOR_PERF, sizeof(POWER_GOVERNOR_PERF)) == 0) { @@ -390,8 +393,6 @@ power_set_governor_performance(struct pstate_power_info *pi) "already performance\n", pi->lcore_id); goto out; } - /* Save the original governor */ - strlcpy(pi->governor_ori, buf, sizeof(pi->governor_ori)); /* Write 'performance' to the governor */ val = fseek(f, 0, SEEK_SET);