From patchwork Tue Oct 3 08: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: 114671 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1590269qgn; Tue, 3 Oct 2017 01:02:23 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAhKlkT0Iy20Ht7bkNgMtdSgCqGU0/2V9kzM6A/8XyuO534yc5M6LDLRd6W/qACwOoImI3I X-Received: by 10.36.7.79 with SMTP id f76mr12073924itf.46.1507017743291; Tue, 03 Oct 2017 01:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507017743; cv=none; d=google.com; s=arc-20160816; b=M24N05I3zA7ofM6JBeZGmpvEaOXzkh7ZZ8zO0Y9CdLWCxTYJXFVID7XW7gleuAkm58 ZBwd6rVWiYZb1jgrMRbNf6bErXlXs+K1Ur5xnJVAeQi9OWeWTevfFUYYJ5Rgmq5tQK0R tcEmwDioDPFy5ESn0/UCEAMkwTDeV2kmamMxMTvTWLGMkf1cg1tYpcv0V0C/oczqE93R uR/0zvSZCS/Wtgrio8imNesT0cXddezQSeS+jZCTI7AGzQWhyqoRJYBSWY0Qyugrh8Q3 bxvXkND6SC+bpjBcoBJlml6ZI6sYqKYFFny935L58u1ccT2bJG4yst6f4Zzw5V4OIpHq L1Rg== 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=565u1LEotCOrDUJEOFWuCvc5hma1K1iXdqvBs1vysos=; b=gCKPrIbJZhcqpKDuMDGm0xPP7ZBvYt7Jvm4R9WaATIIDF8QYbx4P2NF3mLh+hpnFm/ T+jy3s5oMG3as+bfN/zbE4Lru80LAnkom6OV3USlS1xFAopAwJuvQaObXoPFYvWKKjgs AUanYJJ5JR+PrFioKdwXP3AXRjjS14RQYdl720cGZ1tsmXHVnnP6l2kz8Y8+UhhTTxhR I2e59hHlyCFJoyiTiMlx7KA4Iykgiv/PFkknm8i1PtZaCYAiPDGyaQkV7u5lSjwVW/dK +YH7epqD2r8JwIgdeNZovcNuhZIugCanJ/YOZCSt0gvrcrHLV4E4+pNCR2E4SatnNawR KfKg== 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 l195si10428996itl.105.2017.10.03.01.02.22; Tue, 03 Oct 2017 01:02:23 -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 D4F5864459; Tue, 3 Oct 2017 08:02:22 +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 2A6D564458; Tue, 3 Oct 2017 08:01:18 +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 853716445A; Tue, 3 Oct 2017 08:01:12 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 3894E6445D for ; Tue, 3 Oct 2017 08:00:43 +0000 (UTC) Received: from mxback17j.mail.yandex.net (mxback17j.mail.yandex.net [IPv6:2a02:6b8:0:1619::93]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 9DE75780EB7 for ; Tue, 3 Oct 2017 11:00:41 +0300 (MSK) Received: from smtp3o.mail.yandex.net (smtp3o.mail.yandex.net [2a02:6b8:0:1a2d::27]) by mxback17j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id CvZS8OXKi7-0f3awvxh; Tue, 03 Oct 2017 11:00:41 +0300 Received: by smtp3o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Hdd8XYtfWs-0eSCUOJx; Tue, 03 Oct 2017 11:00:40 +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: Tue, 3 Oct 2017 11:00:06 +0300 Message-Id: <1507017606-31412-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507017606-31412-1-git-send-email-odpbot@yandex.ru> References: <1507017606-31412-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 204 Subject: [lng-odp] [PATCH v1 1/1] linux-gen: User /proc/cpuinfo, if sysfs is not available. Fixes https://bugs.linaro.org/show_bug.cgi?id=3249 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 Signed-off-by: Ilias Apalodimas --- /** Email created from pull request 204 (apalos:bug_3249) ** https://github.com/Linaro/odp/pull/204 ** Patch: https://github.com/Linaro/odp/pull/204.patch ** Base sha: b4d17b1f6807cd980a1b2dd30573f17677ea371b ** Merge commit sha: b28ddffce2311826aca898bcc6a6ce16be083619 **/ platform/linux-generic/odp_system_info.c | 45 +++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index d310d7790..790bf68b0 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -378,6 +378,44 @@ int odp_system_info_term(void) return 0; } +static uint64_t get_cpuspeed(int id) +{ + char str[1024]; + char *pos; + FILE *file = NULL; + double mhz = 0.0; + int cur_id = 0; + uint64_t cur_hz = 0; + + if (id + 1 > odp_global_data.num_cpus_installed) { + ODP_ERR("Invalid number of CPUs requested\n"); + return cur_hz; + } + + file = fopen("/proc/cpuinfo", "rt"); + if (file == NULL) { + ODP_ERR("Failed to open /proc/cpuinfo\n"); + return cur_hz; + } + + while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) { + pos = strstr(str, "cpu MHz"); + if (pos) { + if (id != cur_id) { + cur_id++; + continue; + } + if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1) { + cur_hz = (uint64_t)(mhz * 1000000.0); + break; + } + } + } + fclose(file); + + return cur_hz; +} + /* ************************* * Public access functions @@ -385,7 +423,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 = get_cpuspeed(id); + + return cur_hz; } uint64_t odp_cpu_hz(void)