From patchwork Thu Oct 5 09:00:06 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: 114848 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp1668edb; Thu, 5 Oct 2017 02:01:28 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD3W0q8ifldipmq50tSucG4EoHV+NPrOuV4ph+ytekpu0G+SDZi/xjq/FSN/9pjDRPiLdee X-Received: by 10.55.104.6 with SMTP id d6mr10592862qkc.15.1507194088159; Thu, 05 Oct 2017 02:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507194088; cv=none; d=google.com; s=arc-20160816; b=P5T3I9TVN7aeKe1+i/YWNAqPVh+xeMnVOycMHWhCmoGuMF/Ww//cD2qLpkV+iQ/VE3 wPWfekoKA0B3wC1nwuIf8LBmI32RU8/YqFnbGhufQPJDpL5JaRc1r8nR+qmZ6ZynYlRt dJldxZwe3t1IheUPF6vyLjd+5XHsniqu3lSL2FFxTWc9uRzhwpo8q4IBj43UF1fCzwfI gldQJloIuwcRGpKhI8VT/ZxCF2WaHn0IYpR2hIutsaAIcNwUevwq0M2eeKWH2vlm+4NL 0kIDrzeuquachH2PXACITNeNfaivoAnRKeQtPWAfVbxhDDJQxSGSHsGMRD0Kf+kAy22k OzAQ== 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=2duA2SJn/v6tq3vsLti31U3T8r/hsDi+met81a6NQ5k=; b=z7kQY7jAF8qYOETPaix677b5F0ZdNNiI2McsdFBW9sWQdl0Q6FOV9L9ZnaV0VaCok8 L5Ytgi+CoAhYPiODFGtZtHYS2+hYJXiLtVkl14wlmUVIPP9neFS1Gzh2jsj76P4LTKW2 PxOceWFOTfGTPritkCDmvvEfRwdT2ZNUzavPdIFHDAGLslsQR5oiPLan5RvFVhG/aGqY 6l0c4+TJuByqZPBZQKkzGf0g2Kmuf+OkBQVEB2MWrzeIDtmFfruPxaPkj9WiNJgE1/Pt LF6LflUELFNCbUZCz8jtl1e6eXKOmV5HT2/koSwC+q7VoLLvppMlCAQpNhiyxyI82JR/ m+Bw== 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 l126si1355236qkb.334.2017.10.05.02.01.27; Thu, 05 Oct 2017 02:01:28 -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 AD79A644BB; Thu, 5 Oct 2017 09:01:27 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 196D364485; Thu, 5 Oct 2017 09:00:32 +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 448F46448F; Thu, 5 Oct 2017 09:00:28 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 12A5C62C5C for ; Thu, 5 Oct 2017 09:00:19 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward102j.mail.yandex.net (Yandex) with ESMTP id 7E9E856052CD for ; Thu, 5 Oct 2017 12:00:17 +0300 (MSK) Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [2a02:6b8:0:1a2d::25]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 1tBmkcc13B-0HIeesTf; Thu, 05 Oct 2017 12:00:17 +0300 Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id PNwPeSdNvH-0GaiH2v6; Thu, 05 Oct 2017 12:00:16 +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 12:00:06 +0300 Message-Id: <1507194006-5358-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507194006-5358-1-git-send-email-odpbot@yandex.ru> References: <1507194006-5358-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 214 Subject: [lng-odp] [PATCH v1 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: 727c690d283bbfbae7f14b3293d347836fb353df **/ .../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)