get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/92034/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 92034,
    "url": "http://patchwork.dpdk.org/api/patches/92034/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/2fae7084c99dc8223e8d3a0aa9c2e5ba18bf1e6b.1619104102.git.anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<2fae7084c99dc8223e8d3a0aa9c2e5ba18bf1e6b.1619104102.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/2fae7084c99dc8223e8d3a0aa9c2e5ba18bf1e6b.1619104102.git.anatoly.burakov@intel.com",
    "date": "2021-04-22T15:08:36",
    "name": "[21.08,v3,1/1] power: refactor pstate sysfs handling",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "bb191593061af0c5c586df042251d0355fc90271",
    "submitter": {
        "id": 4,
        "url": "http://patchwork.dpdk.org/api/people/4/?format=api",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/2fae7084c99dc8223e8d3a0aa9c2e5ba18bf1e6b.1619104102.git.anatoly.burakov@intel.com/mbox/",
    "series": [
        {
            "id": 16611,
            "url": "http://patchwork.dpdk.org/api/series/16611/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=16611",
            "date": "2021-04-22T15:08:36",
            "name": "[21.08,v3,1/1] power: refactor pstate sysfs handling",
            "version": 3,
            "mbox": "http://patchwork.dpdk.org/series/16611/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/92034/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/92034/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "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])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 34F43A0548;\n\tThu, 22 Apr 2021 17:08:44 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 9FDE741CAF;\n\tThu, 22 Apr 2021 17:08:43 +0200 (CEST)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n by mails.dpdk.org (Postfix) with ESMTP id BC5FE41C9D\n for <dev@dpdk.org>; Thu, 22 Apr 2021 17:08:41 +0200 (CEST)",
            "from orsmga001.jf.intel.com ([10.7.209.18])\n by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 22 Apr 2021 08:08:39 -0700",
            "from silpixa00399498.ir.intel.com (HELO\n silpixa00399498.ger.corp.intel.com) ([10.237.223.216])\n by orsmga001.jf.intel.com with ESMTP; 22 Apr 2021 08:08:37 -0700"
        ],
        "IronPort-SDR": [
            "\n 2lyESgGpjSg1rRdgWXaDoBKw4A0LZhaWVsEXg5VMFTxfHUawnIOQHKEJExHcqsc19oaoPSrmAd\n DtZeuUFefevQ==",
            "\n JrcBrZ3AmFWj/uWEIFU5+MCR1t70YQy1VtAkV69vkWF0NeYc3vU8z5xlEOt4LPGYa0GiHbe0gT\n 5NE9tjLi80qA=="
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,9962\"; a=\"195459195\"",
            "E=Sophos;i=\"5.82,242,1613462400\"; d=\"scan'208\";a=\"195459195\"",
            "E=Sophos;i=\"5.82,242,1613462400\"; d=\"scan'208\";a=\"463975413\""
        ],
        "X-ExtLoop1": "1",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "david.hunt@intel.com, stephen.hemminger@intel.com, reshma.pattan@intel.com",
        "Date": "Thu, 22 Apr 2021 15:08:36 +0000",
        "Message-Id": "\n <2fae7084c99dc8223e8d3a0aa9c2e5ba18bf1e6b.1619104102.git.anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<89a8e353-c2b6-12dd-1228-10029f8824e5@intel.com>",
        "References": "<89a8e353-c2b6-12dd-1228-10029f8824e5@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [21.08 PATCH v3 1/1] power: refactor pstate sysfs\n handling",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Currently, pstate sysfs handling code is a bit of an unmaintainable\nmess, which has contributed to various errors leading to bugs. Refactor\nthe code in a way that makes it more maintainable and less error prone.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/power/meson.build            |   7 +\n lib/power/power_pstate_cpufreq.c | 357 ++++++++++++++++---------------\n 2 files changed, 191 insertions(+), 173 deletions(-)",
    "diff": "diff --git a/lib/power/meson.build b/lib/power/meson.build\nindex a2cc9fe2ef..85324d48d2 100644\n--- a/lib/power/meson.build\n+++ b/lib/power/meson.build\n@@ -5,6 +5,13 @@ if not is_linux\n     build = false\n     reason = 'only supported on Linux'\n endif\n+\n+# we do some snprintf magic so silence format-nonliteral\n+flag_nonliteral = '-Wno-format-nonliteral'\n+if cc.has_argument(flag_nonliteral)\n+\tcflags += flag_nonliteral\n+endif\n+\n sources = files(\n         'guest_channel.c',\n         'power_acpi_cpufreq.c',\ndiff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c\nindex 2cfc54acf3..4357ac4920 100644\n--- a/lib/power/power_pstate_cpufreq.c\n+++ b/lib/power/power_pstate_cpufreq.c\n@@ -37,6 +37,13 @@\n \t\t} \\\n } while (0)\n \n+#define FOPEN_OR_ERR_GOTO(f, label) do { \\\n+\t\tif ((f) == NULL) { \\\n+\t\t\tRTE_LOG(ERR, POWER, \"File not opened\\n\"); \\\n+\t\t\tgoto label; \\\n+\t\t} \\\n+} while (0)\n+\n #define FOPS_OR_NULL_GOTO(ret, label) do { \\\n \t\tif ((ret) == NULL) { \\\n \t\t\tRTE_LOG(ERR, POWER, \"fgets returns nothing\\n\"); \\\n@@ -148,97 +155,145 @@ out:\tclose(fd);\n \treturn ret;\n }\n \n+static int\n+open_core_sysfs_file(const char *template, unsigned int core, const char *mode,\n+\t\tFILE **f)\n+{\n+\tchar fullpath[PATH_MAX];\n+\tFILE *tmpf;\n+\n+\t/* silenced -Wformat-nonliteral here */\n+\tsnprintf(fullpath, sizeof(fullpath), template, core);\n+\ttmpf = fopen(fullpath, mode);\n+\tif (tmpf == NULL)\n+\t\treturn -1;\n+\t*f = tmpf;\n+\n+\treturn 0;\n+}\n+\n+static int\n+read_core_sysfs_u32(FILE *f, uint32_t *val)\n+{\n+\tchar buf[BUFSIZ];\n+\tuint32_t fval;\n+\tchar *s;\n+\n+\ts = fgets(buf, sizeof(buf), f);\n+\tif (s == NULL)\n+\t\treturn -1;\n+\n+\t/* fgets puts null terminator in, but do this just in case */\n+\tbuf[BUFSIZ - 1] = '\\0';\n+\n+\t/* strip off any terminating newlines */\n+\t*strchrnul(buf, '\\n') = '\\0';\n+\n+\tfval = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);\n+\n+\t/* write the value */\n+\t*val = fval;\n+\n+\treturn 0;\n+}\n+\n+static int\n+read_core_sysfs_s(FILE *f, char *buf, unsigned int len)\n+{\n+\tchar *s;\n+\n+\ts = fgets(buf, len, f);\n+\tif (s == NULL)\n+\t\treturn -1;\n+\n+\t/* fgets puts null terminator in, but do this just in case */\n+\tbuf[len - 1] = '\\0';\n+\n+\t/* strip off any terminating newlines */\n+\t*strchrnul(buf, '\\n') = '\\0';\n+\n+\treturn 0;\n+}\n+\n+static int\n+write_core_sysfs_s(FILE *f, const char *str)\n+{\n+\tint ret;\n+\n+\tret = fseek(f, 0, SEEK_SET);\n+\tif (ret != 0)\n+\t\treturn -1;\n+\n+\tret = fputs(str, f);\n+\tif (ret != 0)\n+\t\treturn -1;\n+\n+\t/* flush the output */\n+\tret = fflush(f);\n+\tif (ret != 0)\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n /**\n  * It is to fopen the sys file for the future setting the lcore frequency.\n  */\n static int\n power_init_for_setting_freq(struct pstate_power_info *pi)\n {\n-\tFILE *f_min, *f_max, *f_base = NULL, *f_base_max;\n-\tchar fullpath_min[PATH_MAX];\n-\tchar fullpath_max[PATH_MAX];\n-\tchar fullpath_base[PATH_MAX];\n-\tchar fullpath_base_max[PATH_MAX];\n-\tchar buf_base[BUFSIZ];\n-\tchar *s_base;\n-\tchar *s_base_max;\n-\tuint32_t base_ratio = 0;\n-\tuint32_t base_max_ratio = 0;\n-\tuint64_t max_non_turbo = 0;\n-\tint  ret_val = 0;\n-\n-\tsnprintf(fullpath_base_max,\n-\t\t\tsizeof(fullpath_base_max),\n-\t\t\tPOWER_SYSFILE_BASE_MAX_FREQ,\n-\t\t\tpi->lcore_id);\n-\tf_base_max = fopen(fullpath_base_max, \"r\");\n-\tFOPEN_OR_ERR_RET(f_base_max, -1);\n-\tif (f_base_max != NULL) {\n-\t\ts_base_max = fgets(buf_base, sizeof(buf_base), f_base_max);\n-\n-\t\t/* close the file unconditionally */\n-\t\tfclose(f_base_max);\n-\t\tf_base_max = NULL;\n-\n-\t\tFOPS_OR_NULL_GOTO(s_base_max, out);\n-\n-\t\tbuf_base[BUFSIZ-1] = '\\0';\n-\t\tif (strlen(buf_base))\n-\t\t\t/* Strip off terminating '\\n' */\n-\t\t\tstrtok(buf_base, \"\\n\");\n-\n-\t\tbase_max_ratio =\n-\t\t\tstrtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL)\n-\t\t\t\t/ BUS_FREQ;\n-\t}\n-\n-\tsnprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ,\n-\t\t\tpi->lcore_id);\n-\tf_min = fopen(fullpath_min, \"rw+\");\n-\tFOPEN_OR_ERR_RET(f_min, -1);\n-\n-\tsnprintf(fullpath_max, sizeof(fullpath_max), POWER_SYSFILE_MAX_FREQ,\n-\t\t\tpi->lcore_id);\n-\tf_max = fopen(fullpath_max, \"rw+\");\n-\tif (f_max == NULL)\n-\t\tfclose(f_min);\n-\tFOPEN_OR_ERR_RET(f_max, -1);\n-\n-\tpi->f_cur_min = f_min;\n-\tpi->f_cur_max = f_max;\n-\n-\tsnprintf(fullpath_base, sizeof(fullpath_base), POWER_SYSFILE_BASE_FREQ,\n-\t\t\tpi->lcore_id);\n-\n-\tf_base = fopen(fullpath_base, \"r\");\n-\tif (f_base == NULL) {\n-\t\t/* No sysfs base_frequency, that's OK, continue without */\n-\t\tbase_ratio = 0;\n+\tFILE *f_base = NULL, *f_base_max = NULL, *f_min = NULL, *f_max = NULL;\n+\tuint32_t base_ratio, base_max_ratio;\n+\tuint64_t max_non_turbo;\n+\tint ret;\n+\n+\t/* open all files we expect to have open */\n+\topen_core_sysfs_file(POWER_SYSFILE_BASE_MAX_FREQ, pi->lcore_id, \"r\",\n+\t\t\t&f_base_max);\n+\tFOPEN_OR_ERR_GOTO(f_base_max, err);\n+\n+\topen_core_sysfs_file(POWER_SYSFILE_MIN_FREQ, pi->lcore_id, \"rw+\",\n+\t\t\t&f_min);\n+\tFOPEN_OR_ERR_GOTO(f_min, err);\n+\n+\topen_core_sysfs_file(POWER_SYSFILE_MAX_FREQ, pi->lcore_id, \"rw+\",\n+\t\t\t&f_max);\n+\tFOPEN_OR_ERR_GOTO(f_max, err);\n+\n+\topen_core_sysfs_file(POWER_SYSFILE_BASE_FREQ, pi->lcore_id, \"r\",\n+\t\t\t&f_base);\n+\t/* base ratio file may not exist in some kernels, so no error check */\n+\n+\t/* read base max ratio */\n+\tret = read_core_sysfs_u32(f_base_max, &base_max_ratio);\n+\tFOPS_OR_ERR_GOTO(ret, err);\n+\n+\t/* base ratio may not exist */\n+\tif (f_base != NULL) {\n+\t\tret = read_core_sysfs_u32(f_base, &base_ratio);\n+\t\tFOPS_OR_ERR_GOTO(ret, err);\n \t} else {\n-\t\ts_base = fgets(buf_base, sizeof(buf_base), f_base);\n-\t\tFOPS_OR_NULL_GOTO(s_base, out);\n-\n-\t\tbuf_base[BUFSIZ-1] = '\\0';\n-\t\tif (strlen(buf_base))\n-\t\t\t/* Strip off terminating '\\n' */\n-\t\t\tstrtok(buf_base, \"\\n\");\n-\n-\t\tbase_ratio = strtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL)\n-\t\t\t\t/ BUS_FREQ;\n+\t\tbase_ratio = 0;\n \t}\n \n \t/* Add MSR read to detect turbo status */\n+\tif (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0)\n+\t\tgoto err;\n+\t/* no errors after this point */\n \n-\tif (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0) {\n-\t\tret_val = -1;\n-\t\tgoto out;\n-\t}\n+\t/* convert ratios to bins */\n+\tbase_max_ratio /= BUS_FREQ;\n+\tbase_ratio /= BUS_FREQ;\n+\n+\t/* assign file handles */\n+\tpi->f_cur_min = f_min;\n+\tpi->f_cur_max = f_max;\n \n \tmax_non_turbo = (max_non_turbo&NON_TURBO_MASK)>>NON_TURBO_OFFSET;\n \n \tPOWER_DEBUG_TRACE(\"no turbo perf %\"PRIu64\"\\n\", max_non_turbo);\n \n-\tpi->non_turbo_max_ratio = max_non_turbo;\n+\tpi->non_turbo_max_ratio = (uint32_t)max_non_turbo;\n \n \t/*\n \t * If base_frequency is reported as greater than the maximum\n@@ -264,7 +319,20 @@ power_init_for_setting_freq(struct pstate_power_info *pi)\n out:\n \tif (f_base != NULL)\n \t\tfclose(f_base);\n-\treturn ret_val;\n+\tfclose(f_base_max);\n+\t/* f_min and f_max are stored, no need to close */\n+\treturn 0;\n+\n+err:\n+\tif (f_base != NULL)\n+\t\tfclose(f_base);\n+\tif (f_base_max != NULL)\n+\t\tfclose(f_base_max);\n+\tif (f_min != NULL)\n+\t\tfclose(f_min);\n+\tif (f_max != NULL)\n+\t\tfclose(f_max);\n+\treturn -1;\n }\n \n static int\n@@ -369,22 +437,16 @@ set_freq_internal(struct pstate_power_info *pi, uint32_t idx)\n static int\n power_set_governor_performance(struct pstate_power_info *pi)\n {\n-\tFILE *f;\n+\tFILE *f_governor = NULL;\n \tint ret = -1;\n \tchar buf[BUFSIZ];\n-\tchar fullpath[PATH_MAX];\n-\tchar *s;\n-\tint val;\n \n-\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,\n-\t\t\tpi->lcore_id);\n-\tf = fopen(fullpath, \"rw+\");\n-\tFOPEN_OR_ERR_RET(f, ret);\n+\topen_core_sysfs_file(POWER_SYSFILE_GOVERNOR, pi->lcore_id, \"rw+\",\n+\t\t\t&f_governor);\n+\tFOPEN_OR_ERR_GOTO(f_governor, out);\n \n-\ts = fgets(buf, sizeof(buf), f);\n-\tFOPS_OR_NULL_GOTO(s, out);\n-\t/* Strip off terminating '\\n' */\n-\tstrtok(buf, \"\\n\");\n+\tret = read_core_sysfs_s(f_governor, buf, sizeof(buf));\n+\tFOPS_OR_ERR_GOTO(ret, out);\n \n \t/* Save the original governor */\n \trte_strscpy(pi->governor_ori, buf, sizeof(pi->governor_ori));\n@@ -399,21 +461,15 @@ power_set_governor_performance(struct pstate_power_info *pi)\n \t}\n \n \t/* Write 'performance' to the governor */\n-\tval = fseek(f, 0, SEEK_SET);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\tval = fputs(POWER_GOVERNOR_PERF, f);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\t/* We need to flush to see if the fputs succeeds */\n-\tval = fflush(f);\n-\tFOPS_OR_ERR_GOTO(val, out);\n+\tret = write_core_sysfs_s(f_governor, POWER_GOVERNOR_PERF);\n+\tFOPS_OR_ERR_GOTO(ret, out);\n \n \tret = 0;\n \tRTE_LOG(INFO, POWER, \"Power management governor of lcore %u has been \"\n \t\t\t\"set to performance successfully\\n\", pi->lcore_id);\n out:\n-\tfclose(f);\n+\tif (f_governor != NULL)\n+\t\tfclose(f_governor);\n \n \treturn ret;\n }\n@@ -425,20 +481,16 @@ power_set_governor_performance(struct pstate_power_info *pi)\n static int\n power_set_governor_original(struct pstate_power_info *pi)\n {\n-\tFILE *f;\n+\tFILE *f_governor = NULL;\n \tint ret = -1;\n \tchar buf[BUFSIZ];\n-\tchar fullpath[PATH_MAX];\n-\tchar *s;\n-\tint val;\n \n-\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,\n-\t\t\tpi->lcore_id);\n-\tf = fopen(fullpath, \"rw+\");\n-\tFOPEN_OR_ERR_RET(f, ret);\n+\topen_core_sysfs_file(POWER_SYSFILE_GOVERNOR, pi->lcore_id, \"rw+\",\n+\t\t\t&f_governor);\n+\tFOPEN_OR_ERR_GOTO(f_governor, out);\n \n-\ts = fgets(buf, sizeof(buf), f);\n-\tFOPS_OR_NULL_GOTO(s, out);\n+\tret = read_core_sysfs_s(f_governor, buf, sizeof(buf));\n+\tFOPS_OR_ERR_GOTO(ret, out);\n \n \t/* Check if the governor to be set is the same as current */\n \tif (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {\n@@ -450,19 +502,16 @@ power_set_governor_original(struct pstate_power_info *pi)\n \t}\n \n \t/* Write back the original governor */\n-\tval = fseek(f, 0, SEEK_SET);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\tval = fputs(pi->governor_ori, f);\n-\tFOPS_OR_ERR_GOTO(val, out);\n+\tret = write_core_sysfs_s(f_governor, pi->governor_ori);\n+\tFOPS_OR_ERR_GOTO(ret, out);\n \n \tret = 0;\n \tRTE_LOG(INFO, POWER, \"Power management governor of lcore %u \"\n \t\t\t\"has been set back to %s successfully\\n\",\n \t\t\tpi->lcore_id, pi->governor_ori);\n out:\n-\tfclose(f);\n-\n+\tif (f_governor != NULL)\n+\t\tfclose(f_governor);\n \treturn ret;\n }\n \n@@ -473,51 +522,26 @@ power_set_governor_original(struct pstate_power_info *pi)\n static int\n power_get_available_freqs(struct pstate_power_info *pi)\n {\n-\tFILE *f_min, *f_max;\n+\tFILE *f_min = NULL, *f_max = NULL;\n \tint ret = -1;\n-\tchar *p_min, *p_max;\n-\tchar buf_min[BUFSIZ];\n-\tchar buf_max[BUFSIZ];\n-\tchar fullpath_min[PATH_MAX];\n-\tchar fullpath_max[PATH_MAX];\n-\tchar *s_min, *s_max;\n \tuint32_t sys_min_freq = 0, sys_max_freq = 0, base_max_freq = 0;\n \tuint32_t i, num_freqs = 0;\n \n-\tsnprintf(fullpath_max, sizeof(fullpath_max),\n-\t\t\tPOWER_SYSFILE_BASE_MAX_FREQ,\n-\t\t\tpi->lcore_id);\n-\tsnprintf(fullpath_min, sizeof(fullpath_min),\n-\t\t\tPOWER_SYSFILE_BASE_MIN_FREQ,\n-\t\t\tpi->lcore_id);\n+\t/* open all files */\n+\topen_core_sysfs_file(POWER_SYSFILE_BASE_MAX_FREQ, pi->lcore_id, \"r\",\n+\t\t\t&f_max);\n+\tFOPEN_OR_ERR_GOTO(f_max, out);\n \n-\tf_min = fopen(fullpath_min, \"r\");\n-\tFOPEN_OR_ERR_RET(f_min, ret);\n+\topen_core_sysfs_file(POWER_SYSFILE_BASE_MIN_FREQ, pi->lcore_id, \"r\",\n+\t\t\t     &f_min);\n+\tFOPEN_OR_ERR_GOTO(f_max, out);\n \n-\tf_max = fopen(fullpath_max, \"r\");\n-\tif (f_max == NULL)\n-\t\tfclose(f_min);\n+\t/* read base ratios */\n+\tret = read_core_sysfs_u32(f_max, &sys_max_freq);\n+\tFOPS_OR_ERR_GOTO(ret, out);\n \n-\tFOPEN_OR_ERR_RET(f_max, ret);\n-\n-\ts_min = fgets(buf_min, sizeof(buf_min), f_min);\n-\tFOPS_OR_NULL_GOTO(s_min, out);\n-\n-\ts_max = fgets(buf_max, sizeof(buf_max), f_max);\n-\tFOPS_OR_NULL_GOTO(s_max, out);\n-\n-\n-\t/* Strip the line break if there is */\n-\tp_min = strchr(buf_min, '\\n');\n-\tif (p_min != NULL)\n-\t\t*p_min = 0;\n-\n-\tp_max = strchr(buf_max, '\\n');\n-\tif (p_max != NULL)\n-\t\t*p_max = 0;\n-\n-\tsys_min_freq = strtoul(buf_min, &p_min, POWER_CONVERT_TO_DECIMAL);\n-\tsys_max_freq = strtoul(buf_max, &p_max, POWER_CONVERT_TO_DECIMAL);\n+\tret = read_core_sysfs_u32(f_min, &sys_min_freq);\n+\tFOPS_OR_ERR_GOTO(ret, out);\n \n \tif (sys_max_freq < sys_min_freq)\n \t\tgoto out;\n@@ -576,27 +600,14 @@ power_get_cur_idx(struct pstate_power_info *pi)\n {\n \tFILE *f_cur;\n \tint ret = -1;\n-\tchar *p_cur;\n-\tchar buf_cur[BUFSIZ];\n-\tchar fullpath_cur[PATH_MAX];\n-\tchar *s_cur;\n \tuint32_t sys_cur_freq = 0;\n \tunsigned int i;\n \n-\tsnprintf(fullpath_cur, sizeof(fullpath_cur),\n-\t\t\tPOWER_SYSFILE_CUR_FREQ,\n-\t\t\tpi->lcore_id);\n-\tf_cur = fopen(fullpath_cur, \"r\");\n-\tFOPEN_OR_ERR_RET(f_cur, ret);\n+\topen_core_sysfs_file(POWER_SYSFILE_CUR_FREQ, pi->lcore_id, \"r\", &f_cur);\n+\tFOPEN_OR_ERR_GOTO(f_cur, fail);\n \n-\t/* initialize the cur_idx to matching current frequency freq index */\n-\ts_cur = fgets(buf_cur, sizeof(buf_cur), f_cur);\n-\tFOPS_OR_NULL_GOTO(s_cur, fail);\n-\n-\tp_cur = strchr(buf_cur, '\\n');\n-\tif (p_cur != NULL)\n-\t\t*p_cur = 0;\n-\tsys_cur_freq = strtoul(buf_cur, &p_cur, POWER_CONVERT_TO_DECIMAL);\n+\tret = read_core_sysfs_u32(f_cur, &sys_cur_freq);\n+\tFOPS_OR_ERR_GOTO(ret, fail);\n \n \t/* convert the frequency to nearest 100000 value\n \t * Ex: if sys_cur_freq=1396789 then freq_conv=1400000\n@@ -615,10 +626,10 @@ power_get_cur_idx(struct pstate_power_info *pi)\n \t\t}\n \t}\n \n-\tfclose(f_cur);\n-\treturn 0;\n+\tret = 0;\n fail:\n-\tfclose(f_cur);\n+\tif (f_cur != NULL)\n+\t\tfclose(f_cur);\n \treturn ret;\n }\n \n",
    "prefixes": [
        "21.08",
        "v3",
        "1/1"
    ]
}