From patchwork Mon Oct 16 13:47:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radoslaw Biernacki X-Patchwork-Id: 115920 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3705304qgn; Mon, 16 Oct 2017 06:47:55 -0700 (PDT) X-Received: by 10.223.164.138 with SMTP id g10mr633670wrb.134.1508161675164; Mon, 16 Oct 2017 06:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508161675; cv=none; d=google.com; s=arc-20160816; b=QCq/ah6qulWvOL8mMXoBBxeoxLqjOJ0KL7skFng727+vHn2BWoQQQvYgTHKFVIMEUY 1qapQw4g0KHEML47srkEXTvfxIbx3BXCeco77ymeKLHnv0iud87EQ2ULI9mgRMj5CVaL n4Lvt9rgvoECDT5LmqtIEwBwRDTjN6w7k5iGh46Jl7gEtL/HFeJzymvsLCCwGEqXkkEd gNepN4SVMEpKGld4zj5a39Tj0pCoyLrgYrijHDvkSZ/u8v9nVpOfP8pAleNtIMEsAmN3 vOfC2G7WUzVUAzpFKhkOTVQ/FZjhdIkx1Vb614KN7Z+2ZO+B+BKiRyv4vnBvDe++hVlk 7FeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:cc:to :from:dkim-signature:arc-authentication-results; bh=IXSlB8dLce1UJHQrX7EUcMcHmjPVoKX4THVNxVH+4iU=; b=bNrRdTMTJ1lL+Fek1/ppYlOYlkSngE71O9Hutu1maV6rVSOBSVrsz05fBBdw1A8qCK g73oLjR7AgOatpk0GonI6rKUYtMrZAl/MiSbe9naLAKYq1ao1ocA24OmLdOqFEb4qkqw 9DgQZrICRPRkxP8vDp4z9jObdP59TomkTbCEhfH1+8Su3vYQetfdK06FJELpte8mYZlo DCJvn8DxKjY+TVXcDFMT9CUeVQNvKsV9fppxvSQclvPQXh0MYGuucubCJ7Nm/xPod4aX iuRqsMeqzs7c0HoZYr8qOBYNfuuwVbbToR/gMsYz9QXkvs8weHHmo4r5HpWdpmjXPKY1 7HOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ILgmbvKf; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id a197si5179027wmd.134.2017.10.16.06.47.54; Mon, 16 Oct 2017 06:47:55 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ILgmbvKf; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BE4531B714; Mon, 16 Oct 2017 15:47:54 +0200 (CEST) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com [209.85.215.48]) by dpdk.org (Postfix) with ESMTP id CBD0A1B70B for ; Mon, 16 Oct 2017 15:47:53 +0200 (CEST) Received: by mail-lf0-f48.google.com with SMTP id a132so17054007lfa.7 for ; Mon, 16 Oct 2017 06:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=IXSlB8dLce1UJHQrX7EUcMcHmjPVoKX4THVNxVH+4iU=; b=ILgmbvKfbGIhYKUz3jIZ12Mg+ZS6h9lPb8a0OwWjloCPZiPhT2C4iu4oQ+VlUz1BTV kyiSfKrmyuvXv0eRN53c9M0xwFRn47WnlkOhf7/dRbkqyM7oZUMXFfFKF+CyivvppZp4 8uDwP0wedQ0bj+3qtIaM7VxTgUczU1Gi6RvtI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=IXSlB8dLce1UJHQrX7EUcMcHmjPVoKX4THVNxVH+4iU=; b=EOG4rH4U+HbxuHG6zKB/i3cQnmbFU5YZ77JTfTsyKTkpPOOKYRKePbzCiLmDsaS472 zB6HfGRyPuCLAesiccUafmvpPTF7OGQx5xY3GrHXWMRdrjcjMaK1yEfQwpGRvIlEsSXP EyJuv15juW7OT36/nnQuEaOnOYAcfKCf0mB1P49oTNpcj7PLnhd6ngiPqRp/hZq5rMSu BwHVhRA+zAmVfE+TheKbpLR/whOx9Ig1YiEVX/5ceUfc6p491rmL8jIhQ0+bJBZfmAxL ApVd3EmOvYPwpO7Y8JWZZaW7mprltriQwBbb+ufI2/+h/iD5p1ZFBfKxAZkbderhYlms Oqcw== X-Gm-Message-State: AMCzsaVu0mCit9aynS3YXx+zoq3qrf1dWAgbUasqp/QU6hlghnv/9AIi PEAyPUWfHxOs/bLenJaYoOgjbEVUrV0= X-Google-Smtp-Source: ABhQp+QkncKenmn2LySt9TPWrqpNBgaJGRxvy8doQFNIhphWHvPgrN455BouBOAun3B9gp8eQYhTfQ== X-Received: by 10.25.90.77 with SMTP id o74mr3138575lfb.212.1508161672896; Mon, 16 Oct 2017 06:47:52 -0700 (PDT) Received: from rad-H81M-S1.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id s193sm1519140lfe.22.2017.10.16.06.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Oct 2017 06:47:52 -0700 (PDT) From: Radoslaw Biernacki To: dev@dpdk.org, david.hunt@intel.com Cc: stable@dpdk.org, alan.carew@intel.com, pablo.de.lara.guarch@intel.com Date: Mon, 16 Oct 2017 15:47:07 +0200 Message-Id: <1508161628-4265-1-git-send-email-radoslaw.biernacki@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" This patch fixes the bug caused by improper use of buffered stdio file access for switching the CPU frequency and governor. Each write operation when using buffered stdio must be flushed out and the return code from fflush() must be verified. In buffered mode, write() syscall return value is is not returned by fwrite()/fputs()/fprintf(). Since with buffered approatch, fflush() need to be done every time it is better to use unbuffered mode or not use stdio at all (instead use plain open/write functions). To minimize amount of changes this fix use first approach. Signed-off-by: Radoslaw Biernacki --- lib/librte_power/rte_power_acpi_cpufreq.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c index 01ac5ac..8bf5685 100644 --- a/lib/librte_power/rte_power_acpi_cpufreq.c +++ b/lib/librte_power/rte_power_acpi_cpufreq.c @@ -143,12 +143,13 @@ set_freq_internal(struct rte_power_info *pi, uint32_t idx) "for setting frequency for lcore %u\n", pi->lcore_id); return -1; } + /* we use unbuffered mode so following will fail if kernel will refuse + * freq setting */ if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) { RTE_LOG(ERR, POWER, "Fail to write new frequency for " "lcore %u\n", pi->lcore_id); return -1; } - fflush(pi->f); pi->curr_idx = idx; return 1; @@ -174,6 +175,11 @@ power_set_governor_userspace(struct rte_power_info *pi) f = fopen(fullpath, "rw+"); FOPEN_OR_ERR_RET(f, ret); + if (setvbuf(f, NULL, _IONBF, 0)) { + RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n"); + goto out; + } + s = fgets(buf, sizeof(buf), f); FOPS_OR_NULL_GOTO(s, out); @@ -292,6 +298,11 @@ power_init_for_setting_freq(struct rte_power_info *pi) f = fopen(fullpath, "rw+"); FOPEN_OR_ERR_RET(f, -1); + if (setvbuf(f, NULL, _IONBF, 0)) { + RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n"); + goto out; + } + s = fgets(buf, sizeof(buf), f); FOPS_OR_NULL_GOTO(s, out); @@ -389,6 +400,11 @@ power_set_governor_original(struct rte_power_info *pi) f = fopen(fullpath, "rw+"); FOPEN_OR_ERR_RET(f, ret); + if (setvbuf(f, NULL, _IONBF, 0)) { + RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n"); + goto out; + } + s = fgets(buf, sizeof(buf), f); FOPS_OR_NULL_GOTO(s, out); From patchwork Mon Oct 16 13:47:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radoslaw Biernacki X-Patchwork-Id: 115921 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3705422qgn; Mon, 16 Oct 2017 06:48:03 -0700 (PDT) X-Received: by 10.223.198.134 with SMTP id j6mr622251wrg.213.1508161683059; Mon, 16 Oct 2017 06:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508161683; cv=none; d=google.com; s=arc-20160816; b=G8tvbhadar/AvCs0bQbQMPJewAEnOsw6CytgxSMSY7nSpASjUAdFN4UV1kV6GUCcwf W6PvJeNT6/MdbpHBElc9UHdt0r9gIJ+IpI+e42ap5nJqZOMIbO5AV1jboLuBztOO/1yO CiHbLEBUhCVyfqFAg8kaV5gF+eTscOHP1Eghey5+5fjfe4ErYxpgdFTXOc5Okod/r9XR 3kfgSdx9ZSySt9HDp+tXYXLX+rHmYY3oB2srJlJNWh5ZK7G9PPu7gEIYexz+AKeW0egn IVj/hY+0uGryqCGbqDD6I5Wz+yqPFLHL1wzVzVts4qfLm+pMhPvq20xZXXBlSARWBaoy BkQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from:dkim-signature :arc-authentication-results; bh=8zwcC+/g0SiYH1EaVGrJDfZWGMDooFsO3tB/92US0uA=; b=XSozvRVsN06EbxAD7IVEyU4Pc7AjUN7uipSq4a54uKM2RoI2D7a6vfIY2ZXfGWfXQP sncWzhgF/GdXy38hON8YQmlLDZOXxwP6c9RYz8q2YxClSq9EbVEjfZDgC62Ma1RYIFsa DKNo1BztzJo2jfnhppyHwCOnsF1wAO8uTYtxP9+fQPrCstGnbCUJ8ky9rmBCIWw78811 1vPQzbPz+UMk1Os6WgOe1aTQ5OR1LAsBDOevorHIpdxmkcHPodnXZx24Jw+VhhGaxbRn iv+MoiPdypvmq1XuUA0Wo1RL8aFyeuVMTPYJXAtPExT4z50rueLI4dB9NzRHR9j4GpQ/ 3s3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VVejeWMe; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id o201si5428333wmg.151.2017.10.16.06.48.02; Mon, 16 Oct 2017 06:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VVejeWMe; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F09081B71C; Mon, 16 Oct 2017 15:47:58 +0200 (CEST) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by dpdk.org (Postfix) with ESMTP id 34D3F1B70E for ; Mon, 16 Oct 2017 15:47:57 +0200 (CEST) Received: by mail-lf0-f43.google.com with SMTP id w21so9426760lfc.6 for ; Mon, 16 Oct 2017 06:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8zwcC+/g0SiYH1EaVGrJDfZWGMDooFsO3tB/92US0uA=; b=VVejeWMeVlptm5h1v73aor05fLFgbTclatgrz26xB7flb8t9M51BhdPI+XhEulbWim beYXxl8ZJ1aXiXJroVWb3nUurC4iZ42sCyJF6x/An5fXNx8miEwN7CiZig0qnbTwJm3Z 9f5+r4np7A2LCwbYgzS+49zZjq0EUBjeZGZT4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8zwcC+/g0SiYH1EaVGrJDfZWGMDooFsO3tB/92US0uA=; b=SyWrQ7rnG4sNYaEpaOUTpaXvbG628C7/G4B6n/estFI+6ZjoTrHDlWy+0hTIOsdowm htLNu8ki8xRe1yZ16DJ6U1g0Sc8U4LcLjpcvjzF6Oj4POB9NyF/x1IFNxtX9h+vOY6P+ 2Pn23TReS/4jdkQqDzScs+xRp5ZG5b8K1q1Kp/JXgkhtWIPiVAklqbxJRsf9RATqQLlb Gbv/KlH0gUjwAr5lBkKpBwDF1Pms5B7iecRw/P47gqsWV3+HBd/Pe2LrMEOKZU9ZZ/F6 T91i5W1FBJFjprmwbZmaQnF0Qf4j7WCTDk9EvrVpeu9ji+oc/dHlGdh6+trB0tivAuCv 12QQ== X-Gm-Message-State: AMCzsaWano5Sc3DBW0NQl9FCqv0YMZBjhB5Efbg2eCx83iXjMlr3+Avn TPfxTCGqC5L+vGmic4FKuuCj4oi2NKk= X-Google-Smtp-Source: ABhQp+QnV4kqKrQi6lhYt1A1kTgr+5DQOTnA3yB7DEi9TGgIvHSIWdZqFXCzWjLdLlBSnttk8FtngQ== X-Received: by 10.25.202.82 with SMTP id h18mr3064987lfj.54.1508161676674; Mon, 16 Oct 2017 06:47:56 -0700 (PDT) Received: from rad-H81M-S1.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id s193sm1519140lfe.22.2017.10.16.06.47.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Oct 2017 06:47:56 -0700 (PDT) From: Radoslaw Biernacki To: dev@dpdk.org, david.hunt@intel.com Cc: stable@dpdk.org, alan.carew@intel.com, pablo.de.lara.guarch@intel.com Date: Mon, 16 Oct 2017 15:47:08 +0200 Message-Id: <1508161628-4265-2-git-send-email-radoslaw.biernacki@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508161628-4265-1-git-send-email-radoslaw.biernacki@linaro.org> References: <1508161628-4265-1-git-send-email-radoslaw.biernacki@linaro.org> Subject: [dpdk-dev] [PATCH 2/2] power: check if userspace governor is available X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Since for new Intel CPU's kernel use intel_pstate driver, which does not offer userspace governor, it is vise to check the userspace governor availability before trying to perform governor switch. The outcome from this patch is direct information for user about the root cause of failure during the rte_power_acpi_cpufreq_init(). This patch also add the /sys file name to error message as on some platforms some files expected by this rte_power are not available. This is also useful for pinning down the root cause of the problem. Signed-off-by: Radoslaw Biernacki --- lib/librte_power/rte_power_acpi_cpufreq.c | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c index 8bf5685..342eb22 100644 --- a/lib/librte_power/rte_power_acpi_cpufreq.c +++ b/lib/librte_power/rte_power_acpi_cpufreq.c @@ -55,9 +55,9 @@ #define POWER_DEBUG_TRACE(fmt, args...) #endif -#define FOPEN_OR_ERR_RET(f, retval) do { \ +#define FOPEN_OR_ERR_RET(f, fullpath, retval) do { \ if ((f) == NULL) { \ - RTE_LOG(ERR, POWER, "File not openned\n"); \ + RTE_LOG(ERR, POWER, "File %s not openned\n", fullpath); \ return retval; \ } \ } while (0) @@ -80,6 +80,8 @@ #define POWER_CONVERT_TO_DECIMAL 10 #define POWER_GOVERNOR_USERSPACE "userspace" +#define POWER_SYSFILE_AVAIL_GOVERNOR \ + "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_governors" #define POWER_SYSFILE_GOVERNOR \ "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor" #define POWER_SYSFILE_AVAIL_FREQ \ @@ -170,10 +172,28 @@ power_set_governor_userspace(struct rte_power_info *pi) char *s; int val; + /* check if userspace governor is available */ + + snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_AVAIL_GOVERNOR, + pi->lcore_id); + f = fopen(fullpath, "r"); + FOPEN_OR_ERR_RET(f, fullpath, ret); + + s = fgets(buf, sizeof(buf), f); + FOPS_OR_NULL_GOTO(s, out); + + if (!strstr(buf, POWER_GOVERNOR_USERSPACE)) { + RTE_LOG(ERR, POWER, "Userspace governor is not available\n"); + goto out; + } + fclose(f); + + /* store current governor and set userspace governor */ + snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR, pi->lcore_id); f = fopen(fullpath, "rw+"); - FOPEN_OR_ERR_RET(f, ret); + FOPEN_OR_ERR_RET(f, fullpath, ret); if (setvbuf(f, NULL, _IONBF, 0)) { RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n"); @@ -184,8 +204,7 @@ power_set_governor_userspace(struct rte_power_info *pi) FOPS_OR_NULL_GOTO(s, out); /* Check if current governor is userspace */ - if (strncmp(buf, POWER_GOVERNOR_USERSPACE, - sizeof(POWER_GOVERNOR_USERSPACE)) == 0) { + if (!strcmp(buf, POWER_GOVERNOR_USERSPACE)) { ret = 0; POWER_DEBUG_TRACE("Power management governor of lcore %u is " "already userspace\n", pi->lcore_id); @@ -228,7 +247,7 @@ power_get_available_freqs(struct rte_power_info *pi) snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_AVAIL_FREQ, pi->lcore_id); f = fopen(fullpath, "r"); - FOPEN_OR_ERR_RET(f, ret); + FOPEN_OR_ERR_RET(f, fullpath, ret); s = fgets(buf, sizeof(buf), f); FOPS_OR_NULL_GOTO(s, out); @@ -296,7 +315,7 @@ power_init_for_setting_freq(struct rte_power_info *pi) snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SETSPEED, pi->lcore_id); f = fopen(fullpath, "rw+"); - FOPEN_OR_ERR_RET(f, -1); + FOPEN_OR_ERR_RET(f, fullpath, -1); if (setvbuf(f, NULL, _IONBF, 0)) { RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n"); @@ -398,7 +417,7 @@ power_set_governor_original(struct rte_power_info *pi) snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR, pi->lcore_id); f = fopen(fullpath, "rw+"); - FOPEN_OR_ERR_RET(f, ret); + FOPEN_OR_ERR_RET(f, fullpath, ret); if (setvbuf(f, NULL, _IONBF, 0)) { RTE_LOG(ERR, POWER, "Cannot set unbuffered mode\n");