From patchwork Fri Oct 6 17:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 115109 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2017615qgn; Fri, 6 Oct 2017 10:04:10 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDElMF0u+z38sIX0bo+LjQGsY0J8HBdOMc1xO+am50FKh1egTQrtNJVXpbVsIFGYO+4wCJG X-Received: by 10.107.134.31 with SMTP id i31mr3488741iod.237.1507309450540; Fri, 06 Oct 2017 10:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507309450; cv=none; d=google.com; s=arc-20160816; b=MbsjHr2epShJMyN74X16qNbrUaI5IHCAYr7lp+3RWSp79CIQdDbbida5ZNBO248BvY UVo0nIRNheezgENaRk1WzM7sCFRIrvCtbM1em8D53nXEXuoWblEyklTUXVvrIYnZvmQM QOJHZ+8jsacKrtm0gMu8koq3fVNuVGJRAMnt7Q3Rzdapqwkq2GrD+x0vZ0AiY+0krhcl fBBKqs0lGbAr4p/vLwi/NQMIRI9DxLGWilqthTGxFAWIkIMaNUAu7OJ2NqhK9aSl9OnV 51shFYTzcpf+bTk7Cr6Sc9IvPmqurYiN5fFD+7qFyp3/sc/w+imkMpp7Iqkon3TypnJv TZKw== 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:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=UWUhbZkLrIr5YAEAaxBHkkhms27KFOvpH6fNHR6ysP8=; b=SGLu68p1SclzuytOQ/36aB1h1J0b7MoaNm2yxujmP6tkeFDDBr3MB8pCMSCwZzQuxf JOB4F2n+npEaHXBNzOl9kHL9ciM7VJ1madxaBx0J6R15DyOszTM9Rjdg+VjXtO/GjTLL +UyWP3tppbQDDmMeXo7JI7+d6olWM963silh5hxnjrxluPbvNUOenr5TFP3Nd9TILOK+ 1re7c70KA3KrEHpNFh2SRzE6GUHAdUs+x7COjwIosG73Gm8tUwoEjMIJiOgkliiXADfO SgfgPUwbADqDUqUgGh4lox/sX7j2Hr6t4kZNk1wYG5bmfTixWsoZ04PSYRn8B7CpGIZr Sb+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 82si1564146ita.152.2017.10.06.10.04.09; Fri, 06 Oct 2017 10:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id A660A64FD5; Fri, 6 Oct 2017 17:04:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 94C8665BB7; Fri, 6 Oct 2017 17:00:47 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 795D160996; Fri, 6 Oct 2017 17:00:29 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id 2F1C26097D for ; Fri, 6 Oct 2017 17:00:26 +0000 (UTC) Received: from mxback5o.mail.yandex.net (mxback5o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1f]) by forward100o.mail.yandex.net (Yandex) with ESMTP id 9B72E2A21C47 for ; Fri, 6 Oct 2017 20:00:24 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback5o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id mEx8CgzEUT-0OrCc8a7; Fri, 06 Oct 2017 20:00:24 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 0Y31n8xpdr-0Omea0E4; Fri, 06 Oct 2017 20:00:24 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Fri, 6 Oct 2017 20:00:13 +0300 Message-Id: <1507309214-28483-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507309214-28483-1-git-send-email-odpbot@yandex.ru> References: <1507309214-28483-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 214 Subject: [lng-odp] [PATCH v4 1/2] linux-gen: Use /proc/cpuinfo, if sysfs is not available to get cpu info. X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Ilias Apalodimas PR#171 broke some of the functionality we had on getting cpu speed. This patch reverts parts of that commit adding a fallback when /sys/devices/system/cpu/cpuX/cpufreq/ is not available. Solves https://bugs.linaro.org/show_bug.cgi?id=3249 Signed-off-by: Ilias Apalodimas --- /** Email created from pull request 214 (apalos:bug_3249) ** https://github.com/Linaro/odp/pull/214 ** Patch: https://github.com/Linaro/odp/pull/214.patch ** Base sha: a63f25ff2994b2df78c24f1f8b63d0e06628eb68 ** Merge commit sha: 57fff95425e76f7cec228f7a9471ca07c25cf029 **/ .../linux-generic/arch/default/odp_sysinfo_parse.c | 5 +++ .../linux-generic/arch/mips64/odp_sysinfo_parse.c | 5 +++ .../linux-generic/arch/powerpc/odp_sysinfo_parse.c | 5 +++ .../linux-generic/arch/x86/odp_sysinfo_parse.c | 36 ++++++++++++++++++++++ platform/linux-generic/include/odp_internal.h | 1 + platform/linux-generic/odp_system_info.c | 7 ++++- 6 files changed, 58 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/arch/default/odp_sysinfo_parse.c b/platform/linux-generic/arch/default/odp_sysinfo_parse.c index 1e2c729a7..68d3d9caf 100644 --- a/platform/linux-generic/arch/default/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/default/odp_sysinfo_parse.c @@ -26,3 +26,8 @@ int cpuinfo_parser(FILE *file ODP_UNUSED, system_info_t *sysinfo) void sys_info_print_arch(void) { } + +uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED) +{ + return 0; +} diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c index 5ed7a398e..313e58e88 100644 --- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c @@ -63,3 +63,8 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) void sys_info_print_arch(void) { } + +uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED) +{ + return 0; +} diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c index 02a83e514..461edf9d9 100644 --- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c @@ -62,3 +62,8 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo) void sys_info_print_arch(void) { } + +uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED) +{ + return 0; +} diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c index 55bbda8c4..f3fd8c146 100644 --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -45,3 +45,39 @@ void sys_info_print_arch(void) { cpu_flags_print_all(); } + +uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED) +{ + char str[1024]; + FILE *file; + int cpu; + char *pos; + double mhz = 0.0; + + file = fopen("/proc/cpuinfo", "rt"); + + /* find the correct processor instance */ + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "processor"); + if (pos) { + if (sscanf(pos, "processor : %d", &cpu) == 1) + if (cpu == id) + break; + } + } + + /* extract the cpu current speed */ + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "cpu MHz"); + if (pos) { + if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1) + break; + } + } + + fclose(file); + if (mhz) + return (uint64_t)(mhz * 1000000.0); + + return 0; +} diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index e0cc6dd4a..fc69cd0c5 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -133,6 +133,7 @@ int _odp_ishm_term_local(void); int cpuinfo_parser(FILE *file, system_info_t *sysinfo); uint64_t odp_cpufreq_id(const char *filename, int id); uint64_t odp_cpu_hz_current(int id); +uint64_t odp_cpu_arch_hz_current(int id); void sys_info_print_arch(void); #ifdef __cplusplus diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index d310d7790..1303d7937 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -385,7 +385,12 @@ int odp_system_info_term(void) */ uint64_t odp_cpu_hz_current(int id) { - return odp_cpufreq_id("cpuinfo_cur_freq", id); + uint64_t cur_hz = odp_cpufreq_id("cpuinfo_cur_freq", id); + + if (!cur_hz) + cur_hz = odp_cpu_arch_hz_current(id); + + return cur_hz; } uint64_t odp_cpu_hz(void)