From patchwork Mon Jan 18 10:10:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 59914 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1911497lbb; Mon, 18 Jan 2016 02:23:12 -0800 (PST) X-Received: by 10.140.92.215 with SMTP id b81mr30852737qge.44.1453112592614; Mon, 18 Jan 2016 02:23:12 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w21si30329514qka.42.2016.01.18.02.23.12; Mon, 18 Jan 2016 02:23:12 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 070356170D; Mon, 18 Jan 2016 10:23:12 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=RCpViZNS; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID,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 CA45E61635; Mon, 18 Jan 2016 10:21:09 +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 D0D8061719; Mon, 18 Jan 2016 10:21:05 +0000 (UTC) Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) by lists.linaro.org (Postfix) with ESMTPS id 89BD76162A for ; Mon, 18 Jan 2016 10:20:13 +0000 (UTC) Received: by mail-pf0-f177.google.com with SMTP id q63so160440108pfb.1 for ; Mon, 18 Jan 2016 02:20:13 -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=vSQF7hiy74VFimI00hOtHoKf8Ko3137eqo8GVemCxbo=; b=RCpViZNSyE6ZxFgFwjrMNBu7qxc5FV6pJ0d24klSMX1LFH/z/2az7EUkSAnqlPdhRT loh1O2+Hm8Anwqi3mKjzisS84Bjr7XpdU/wJ57QaXa0nHQIsRd5sipqSwzSsIo4u8CRj SN1hRYNRJKigoan9HkWlFrSVx5EOhC12whBhM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vSQF7hiy74VFimI00hOtHoKf8Ko3137eqo8GVemCxbo=; b=Fe/CLx7YApuKlBJUn55Kl06XaLemiB6jKluMc8IROQLkeaM8aeONAncpsIrnuHV28O fei0Ay47R18bQ6omOsWpRNmnViD2xC7Q6GgvgXGQFiEOs7+2hMqxSkAZLXj4fvAfyaCm yo0ZVg1hEDrQSCIVdFpbOzpHKIJJy8/za859SbFkPNodQggW7wlmGVWh3k+BHuZAoeF/ KXp4stQK/6E2OywcTuysbPATwi88tpu5Ff9dVx9TwI6A1cpZEqcngIgTzMdT4aHdaKFz RATOehDrF1wexfp9wNOvPCtYXZQobAgFfl6xq8Zxp5ZI90KE4U770h8l6tnz+Zj2i4LK spkw== X-Gm-Message-State: AG10YOQzIb5bFaQIaKgsciWey4DcDPaFFUmUmU5sshL5SmIM7N8fSiID9wc9b+Jxe77AYjwpgP0= X-Received: by 10.98.19.130 with SMTP id 2mr31801088pft.31.1453112412871; Mon, 18 Jan 2016 02:20:12 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id x10sm32844521pas.37.2016.01.18.02.20.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jan 2016 02:20:12 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Mon, 18 Jan 2016 18:10:00 +0800 Message-Id: <1453111808-15762-5-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453111808-15762-1-git-send-email-hongbo.zhang@linaro.org> References: <1453111808-15762-1-git-send-email-hongbo.zhang@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v5 API-NEXT 04/12] linux-generic: sysinfo: move x86 system info codes to its plarform file 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Hongbo Zhang This patch moves the x86 system info codes into the newly added x86 specific platform file. Signed-off-by: Hongbo Zhang --- platform/linux-generic/Makefile.am | 6 +- .../linux-generic/arch/x86/odp_sysinfo_parse.c | 70 ++++++++++++++++++++++ platform/linux-generic/include/odp_internal.h | 4 ++ platform/linux-generic/odp_system_info.c | 68 +-------------------- 4 files changed, 79 insertions(+), 69 deletions(-) create mode 100644 platform/linux-generic/arch/x86/odp_sysinfo_parse.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 9fbb3bd..de43eff 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -159,12 +159,14 @@ __LIB__libodp_la_SOURCES = \ odp_traffic_mngr.c \ odp_version.c \ odp_weak.c \ - arch/@ARCH@/odp_cpu_arch.c + arch/@ARCH@/odp_cpu_arch.c \ + arch/@ARCH@/odp_sysinfo_parse.c EXTRA_DIST = \ arch/linux/odp_cpu_arch.c \ arch/mips64/odp_cpu_arch.c \ - arch/x86/odp_cpu_arch.c + arch/x86/odp_cpu_arch.c \ + arch/x86/odp_sysinfo_parse.c if HAVE_PCAP __LIB__libodp_la_SOURCES += pktio/pcap.c diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c new file mode 100644 index 0000000..85cc34c --- /dev/null +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -0,0 +1,70 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) +{ + char str[1024]; + char *pos; + double ghz = 0.0; + int id = 0; + + while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) { + pos = strstr(str, "model name"); + if (pos) { + pos = strchr(str, ':'); + strncpy(sysinfo->model_str[id], pos + 2, + sizeof(sysinfo->model_str[id])); + + pos = strchr(sysinfo->model_str[id], '@'); + *(pos - 1) = '\0'; + if (sscanf(pos, "@ %lfGHz", &ghz) == 1) + sysinfo->cpu_hz[id] = (uint64_t)(ghz * 1000000000.0); + + id++; + } + } + + return 0; +} + +uint64_t odp_cpu_hz_current(int id) +{ + 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 -1; +} diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 2eeba42..d3cde5f 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -20,6 +20,7 @@ extern "C" { #include #include +#include extern __thread int __odp_errno; @@ -86,6 +87,9 @@ int odp_tm_init_global(void); void _odp_flush_caches(void); +int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo); +uint64_t odp_cpu_hz_current(int id); + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 449e500..4824d55 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -108,71 +108,7 @@ static int huge_page_size(void) /* * HW specific /proc/cpuinfo file parsing */ -#if defined __x86_64__ || defined __i386__ - -static int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) -{ - char str[1024]; - char *pos; - double ghz = 0.0; - int id = 0; - - while (fgets(str, sizeof(str), file) != NULL && id < MAX_CPU_NUMBER) { - pos = strstr(str, "model name"); - if (pos) { - pos = strchr(str, ':'); - strncpy(sysinfo->model_str[id], pos + 2, - sizeof(sysinfo->model_str[id])); - - pos = strchr(sysinfo->model_str[id], '@'); - *(pos - 1) = '\0'; - if (sscanf(pos, "@ %lfGHz", &ghz) == 1) - sysinfo->cpu_hz[id] = (uint64_t)(ghz * 1000000000.0); - - id++; - } - } - - return 0; -} - -static uint64_t odp_cpu_hz_current(int id) -{ - 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 -1; -} - -#elif defined __arm__ || defined __aarch64__ +#if defined __arm__ || defined __aarch64__ static int odp_cpuinfo_parser(FILE *file ODP_UNUSED, odp_system_info_t *sysinfo ODP_UNUSED) @@ -278,8 +214,6 @@ static uint64_t odp_cpu_hz_current(int id ODP_UNUSED) return -1; } -#else - #error GCC target not found #endif