From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by dpdk.org (Postfix) with ESMTP id ABDBF1B6E5 for ; Mon, 16 Oct 2017 15:47:53 +0200 (CEST) Received: by mail-lf0-f52.google.com with SMTP id k40so17074773lfi.4 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=SJAGr02TdSx74w5Qeybw0DwPcD3o0v7HgfyU/FIfMucidPVEmJRQNh2c5dWW76LW9g c1fgsfqEFI+P9Q9NmfNnsYkivIT6OAi/QYwe0/8HUCZF6v/w+T7tDgaTTxx0FmIL4rPb JkiErabqmwRgwmTfDkQeOuRjKeTUYn3G2v3yblvku7xupxNe2iMZVbKR4sqh7dpalLoK vXDlkTfm9/HadoQN2gXSWMdnQDmAQ6ngmabdswwkghbdRWrp3vql+pGbJw/XOWYabsmN qdx3Lz/1LjWsBvxpPxRUlwVYO7GuxKinGpUAagsrSJRvbQ4ucGS/t9SOuIWTzE5tvMf3 f3TA== X-Gm-Message-State: AMCzsaXE8dBNmy4UbcNfn/euXS1QV2ODTOP5yY5JVkXQfPnrajtjsCEl dN2EiIuuIZgnmtUyslkEqzw6pw== 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-stable] [PATCH 1/2] power: switching to unbuffered stdio for /sys file access X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Oct 2017 13:47:53 -0000 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(-) 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); -- 2.7.4