From patchwork Thu Oct 5 12:00:17 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: 114922 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp509272qgn; Thu, 5 Oct 2017 05:04:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBQyvkD15hBUQZ4hygT3SJ8s+GF9iLhU2nD2xv5vza2P4QQssPl9DFgAteuQYsDDhHfci/Y X-Received: by 10.55.38.193 with SMTP id m62mr30437916qkm.21.1507205045459; Thu, 05 Oct 2017 05:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507205045; cv=none; d=google.com; s=arc-20160816; b=t5xsPoq1jgsPWgBeWR+UDOwDzWFwsJ7/9zbSNieU7jl2A4ryVNBuy/hTOGXmo3ts7b sejMJLB/EsFfiosGWJzcC+EMagl3DNI1ndP8HQ9KxigOXdxqK6c4r1UV50RzqIZJjmmg h9WLITkddW5B0rLETXC9Ih+otrDTB8k5zH15Wx7lgEw46qIehWYAdq3J9JaNbqI7vqGd Q40FHGvi/ws/xX/dUEeIeYCWu9Jq6QACDfgMvzjdwl59f2nK1IaLr2YhF1l45kvUOSIU miVhCyLxcId4EA+4c29fRMn4r1cQ650FXGZy8HNhpIX3KQa3dfT4RiQjBu6ScyqL1T8c iDZw== 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=iYeXQCttdgduXm/7FkW3mwg6gM0aqAgmKtZIelqgsoY=; b=kO7fdpvF3RBDrZaleOXrphhrS6cWDJ1pQsagxF1+sFolfVBeqBjzNy/p/f7gnevr5r Bc9ClbdVbXrVS4iBtanGG24ucS2XCCVZ6Vb0O+udPsmAiqwEvbRu1MmFuuxtp6fAzdLI ug/by9RiOWkq5ZgFRldXPIF1bTgIYGNJhVqoddEVQBavsXSMIZLAed6FO58a+kE7/0jx ktJHj/HJcVGoTNMqQ4Sif3ryEZ/FhjBARv8SoBt5XjB8Wiun51krN32W8ucTUYRiNhqA F0gcVyO+ByKw50nnlMO0768bC/cmqH/LTlykpQOYWG24TbY0dCmiYaIiR0S9pyvT6KbO TI1Q== 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 i1si7585587qkc.127.2017.10.05.05.04.05; Thu, 05 Oct 2017 05:04:05 -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 EB7B460C20; Thu, 5 Oct 2017 12:04:04 +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 E7CC0644D1; Thu, 5 Oct 2017 12:01:39 +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 696F9644BA; Thu, 5 Oct 2017 12:01:15 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 35EBC644C3 for ; Thu, 5 Oct 2017 12:00:24 +0000 (UTC) Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward106o.mail.yandex.net (Yandex) with ESMTP id B3B26781C2A for ; Thu, 5 Oct 2017 15:00:22 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 6lEj06HAQq-0MVaUBPb; Thu, 05 Oct 2017 15:00:22 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id HwfzEKoU9S-0MAGvxRR; Thu, 05 Oct 2017 15:00:22 +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: Thu, 5 Oct 2017 15:00:17 +0300 Message-Id: <1507204817-24183-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507204817-24183-1-git-send-email-odpbot@yandex.ru> References: <1507204817-24183-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 214 Subject: [lng-odp] [PATCH v2 1/1] 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: 52cfe7ba6d2541cf5ee464e46e91b2da5efe1497 ** Merge commit sha: dddeb89bfc44ad9fbb9ec9f943a1a5712322eefd **/ .../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)