From patchwork Sat Nov 11 18:55: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: 118618 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp58787qgn; Sat, 11 Nov 2017 10:56:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMZLIdn9yBwWGqD+/yEzTsO4Ej1IHE9KbcXbTX22j/4GFfW03N5wlibXpwZmgKwnmSy65GFq X-Received: by 10.28.90.85 with SMTP id o82mr2939266wmb.69.1510426597581; Sat, 11 Nov 2017 10:56:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510426597; cv=none; d=google.com; s=arc-20160816; b=tmr4ftnXFcWMFDBAaiSBYRf+g9SZigSCtAAqhTYKtMU6vtoVL3B+kRMtPvKMey4yoJ iCdRWyej9tfr/dJiQRawUEKqOdvrw29JQCvzdz927MbJ7ue+Oupn29QTnM0KXXDCucsJ jioikQohvnfhr3xSyXQd2z/3gAKEYy8cVivLyBnT2TalLRGNHZwYX5YqdPihR2li+gop DbADUlOyxjaVtOMFNiUU94PeF03FKch83negrKY1a/7m1OncPW1CnLLJyBHC6CCcVnKm 6f+wRC4gvYzYKiRFKfRlFzR3haS0uucPyctriJxuffVPhoM0m+QaIfxb3yyQ+pkHpszU 6CRg== 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=ZCvXBggHUGQnUYfuG8wV9TMa2MRJADnDqHmf5te56Es=; b=B89eapPK1g3/Ry6xlefEliZWI4de8V1/NJGF3weLFas9+tZjCwIx0NjYvLS5boD30Y 8ETk+z05OzKulB/pKrYLF2u+gsIfDdx0xbIP+cyUU6cb/tlryPLPOsKFgB9zGiOvW8W1 SztUs4UL0QpN4w6HDwvI9YKhz8HCPhbqTjWGNoLvdeZGATlS6xcbFx3NLTTW1AG2yORI M8GmpHYNurmYd4D8olzlZ78keHtosTQNKBI0IFwZbmRzL3OiQqTW24PIpSVRYjtS+JKx CC19EbiXLKfIh8vnveIWqbnmp0bKCbqJdLM1FwPEEFG3eA3Ruco3Wx5B//p2h1dAHjta 44Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Epyg7F6j; 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 g13si10735592wrh.413.2017.11.11.10.56.37; Sat, 11 Nov 2017 10:56:37 -0800 (PST) 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=Epyg7F6j; 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 019A21B226; Sat, 11 Nov 2017 19:56:08 +0100 (CET) Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by dpdk.org (Postfix) with ESMTP id 1AA9D1B225 for ; Sat, 11 Nov 2017 19:56:07 +0100 (CET) Received: by mail-lf0-f68.google.com with SMTP id a2so14352551lfh.11 for ; Sat, 11 Nov 2017 10:56:07 -0800 (PST) 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=ZCvXBggHUGQnUYfuG8wV9TMa2MRJADnDqHmf5te56Es=; b=Epyg7F6jxZJzZ7epLoOKOcMQSiSZ1stc2mzOPO7EriTJfYroeSV5WV5ihRfEqdmYM6 Ll0On3XBiwCDsTHigO3Lx17sZRH4tYz68OY70OUwLRJbEkRG0Yh4rxNIZ+l8t14DxUPk NfKfSuzYIUtyVtlk6XdiM15eJ8vjCqJhx1pEE= 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=ZCvXBggHUGQnUYfuG8wV9TMa2MRJADnDqHmf5te56Es=; b=Kh9FnIJYzaeV9tvRY054xeDsOERm6GYXCbrjJjFx7JXc0sMLmWlZVF0A9oPKM1X7eb NEVe7gMbg6uUukOjw6Q458e0ykpVeeRD+zNfluLLcVHPsu6RjaC2pxbIRcBuS2WBJXZ6 Vm22vCSb9VLUzzCgtSycslMo59EsDY8Cozaa15stt+oGSRPkCG6264eSnhqazbu6p4U2 LC+r3zVzMVigbrHDVW+8UFweraAKat9dZjgar3oWCEFMcb1T2XDOMtVi3oJ+QYgWWs7m EOk+u5vChsMd9P3hgh25tvahOsNO7dyN7J8vd76KoRJrjcCJTxWZZcyTIVicon5dpMSZ IFOA== X-Gm-Message-State: AJaThX6VD+w2lmfP98OD+X5mGfCFnnZuHiueAosee118/kTH1InxpaOH L0Ei1VwCOk3kp26QmsXEZKmKAzNDsz0= X-Received: by 10.25.43.9 with SMTP id r9mr1304565lfr.128.1510426566551; Sat, 11 Nov 2017 10:56:06 -0800 (PST) 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 x90sm2342107ljb.86.2017.11.11.10.56.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Nov 2017 10:56:05 -0800 (PST) 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: Sat, 11 Nov 2017 19:55:07 +0100 Message-Id: <1510426507-28245-4-git-send-email-radoslaw.biernacki@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510426507-28245-1-git-send-email-radoslaw.biernacki@linaro.org> References: <1508161628-4265-1-git-send-email-radoslaw.biernacki@linaro.org> <1510426507-28245-1-git-send-email-radoslaw.biernacki@linaro.org> Subject: [dpdk-dev] [PATCH 3/3] 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 wise 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(). Signed-off-by: Radoslaw Biernacki --- lib/librte_power/rte_power_acpi_cpufreq.c | 74 +++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) -- 2.7.4 diff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c index f811bd3..0d9a2a5 100644 --- a/lib/librte_power/rte_power_acpi_cpufreq.c +++ b/lib/librte_power/rte_power_acpi_cpufreq.c @@ -65,6 +65,11 @@ #define POWER_CONVERT_TO_DECIMAL 10 #define POWER_GOVERNOR_USERSPACE "userspace" +#define POWER_SCALING_DRIVER_INTEL_PSTATE "intel_pstate" +#define POWER_SYSFILE_SCALING_DRIVER \ + "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver" +#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 \ @@ -139,6 +144,70 @@ set_freq_internal(struct rte_power_info *pi, uint32_t idx) return 1; } +/* check /sys file for presence of given string */ +static int +power_check_sysfile_string(const char *fullpath, const char *string) +{ + int fd; + int count; + int ret = -1; + char buf[BUFSIZ]; + + fd = open(fullpath, O_RDONLY); + if (fd < 0) { + RTE_LOG(ERR, POWER, "Failed to open %s\n", fullpath); + return ret; + } + + count = read(fd, buf, sizeof(buf)); + if (count < 0) { + RTE_LOG(ERR, POWER, "Failed to read from %s\n", fullpath); + goto out; + } + buf[min((size_t)count, sizeof(buf)-1)] = '\0'; + + if (strstr(buf, string)) + ret = 0; /* substring found */ + +out: + if (close(fd)) { + RTE_LOG(ERR, POWER, "Error while closing file %s\n", fullpath); + return -1; + } + + return ret; +} + +/* check if userspace governor is offered by the kernel */ +static int power_check_gov_userspace(unsigned int lcore_id) +{ + char fullpath[PATH_MAX]; + + snprintf(fullpath, sizeof(fullpath), + POWER_SYSFILE_AVAIL_GOVERNOR, lcore_id); + if (power_check_sysfile_string( + fullpath, POWER_GOVERNOR_USERSPACE)) { + + RTE_LOG(ERR, POWER, "Userspace governor is not available\n"); + + snprintf(fullpath, sizeof(fullpath), + POWER_SYSFILE_SCALING_DRIVER, lcore_id); + if (!power_check_sysfile_string( + fullpath, POWER_SCALING_DRIVER_INTEL_PSTATE)) { + + RTE_LOG(WARNING, POWER, + POWER_SCALING_DRIVER_INTEL_PSTATE "was detected" + " which does not offer userspace power governor" + ". \"intel_pstate=disable\" needs to be added " + "to the kernel boot parameters.\n"); + } + + return -1; + } + + return 0; +} + /** * It is to check the current scaling governor by reading sys file, and then * set it into 'userspace' if it is not by writing the sys file. The original @@ -154,6 +223,11 @@ power_set_governor(unsigned int lcore_id, const char *new_gov, char *old_gov, char buf[BUFSIZ]; char fullpath[PATH_MAX]; + /* check if userspace governor is available */ + if (power_check_gov_userspace(lcore_id)) + return ret; + + /* store current governor and set userspace governor */ snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR, lcore_id); fd = open(fullpath, O_RDWR);