From patchwork Thu Jan 7 07:38:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 59264 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp393155lbb; Wed, 6 Jan 2016 23:41:49 -0800 (PST) X-Received: by 10.141.28.149 with SMTP id f143mr142229848qhe.66.1452152509249; Wed, 06 Jan 2016 23:41:49 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e64si81894810qgf.1.2016.01.06.23.41.48; Wed, 06 Jan 2016 23:41:49 -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 CA80561CB0; Thu, 7 Jan 2016 07:41:48 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=kTEHgeGG; 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_H3, RCVD_IN_MSPIKE_WL, 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 8986F61C8F; Thu, 7 Jan 2016 07:40:04 +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 4AC9661CC2; Thu, 7 Jan 2016 07:39:58 +0000 (UTC) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by lists.linaro.org (Postfix) with ESMTPS id 9B0D761C9B for ; Thu, 7 Jan 2016 07:38:57 +0000 (UTC) Received: by mail-pa0-f52.google.com with SMTP id cy9so252163099pac.0 for ; Wed, 06 Jan 2016 23:38:57 -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=cfSyUF0iNlcRXM3gM61HMMOo5qpTsSB/OeXXxqEBptc=; b=kTEHgeGGFWocnv7xx0C0kdZkNYYtRAk08cqAsTmmWOnlD8JJSVvaEFf1Ks/ZehddtW U3w25i+HYZ3zTFM9lz5EYgpbuxMcDxYDF2uiaNhkCdB8k9EkIvCPSluVPo0CQ9HP32qg u9UoFZW9LNJAyZwgatByeliEAO6Nbn9owVoDc= 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=cfSyUF0iNlcRXM3gM61HMMOo5qpTsSB/OeXXxqEBptc=; b=YxCoSgbXUZWWLkKSGP5iClC6jou2t3/miABUV47xCAIeM5i/RVE/CjujLtoIoLvdIb /5q9cb0nXlmHdP5LvYNSCa1K8pmReBly8ZoYxBZuvkqJy9nhVXjWFdukdoHJbvJiRqpk Mrnz30ESDkvxEpfUJG3MO+YEhBDO/PstheJFJg+MCvdUAMDxfK2Lg+l5TdXGp/6p5d8J iQGqYu+Vsowtznw+MY7HneEdokihCWoLwuwyOq+iGZiH+t50vDubTKX+MRmsDFm0SJEw 2opugzhKrOn0Ark1VDlORAxT7G/Ipa3CX8I8sd306+uALXbcUS4Fye8RXVAAxFoKU62/ alyQ== X-Gm-Message-State: ALoCoQn/NexW1N0INI7jCtZ6Hy346osQMjZLTVPaHB4o0z/keym/Bbm06fHlJ2FooURm6fX6X9aBKIEJpLyEQdj3+5/vY5A3GQ== X-Received: by 10.66.141.109 with SMTP id rn13mr145962089pab.83.1452152336998; Wed, 06 Jan 2016 23:38:56 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id tb8sm150067484pab.22.2016.01.06.23.38.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jan 2016 23:38:56 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Thu, 7 Jan 2016 15:38:25 +0800 Message-Id: <1452152313-27276-5-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452152313-27276-1-git-send-email-hongbo.zhang@linaro.org> References: <1452152313-27276-1-git-send-email-hongbo.zhang@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v4 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 | 71 ++++++++++++++++++++++ platform/linux-generic/include/odp_cpu_internal.h | 4 ++ platform/linux-generic/odp_system_info.c | 69 +-------------------- 4 files changed, 81 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 75ca703..f19a858 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -158,12 +158,14 @@ __LIB__libodp_la_SOURCES = \ odp_traffic_mngr.c \ odp_version.c \ odp_weak.c \ - arch/@ARCH@/odp_cpu_cycles.c + arch/@ARCH@/odp_cpu_cycles.c \ + arch/@ARCH@/odp_sysinfo_parse.c EXTRA_DIST = \ arch/linux/odp_cpu_cycles.c \ arch/mips64/odp_cpu_cycles.c \ - arch/x86/odp_cpu_cycles.c + arch/x86/odp_cpu_cycles.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..2da0b1b --- /dev/null +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#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_cpu_internal.h b/platform/linux-generic/include/odp_cpu_internal.h index 664e2df..38b1a3a 100644 --- a/platform/linux-generic/include/odp_cpu_internal.h +++ b/platform/linux-generic/include/odp_cpu_internal.h @@ -12,6 +12,7 @@ extern "C" { #endif #include +#include static inline uint64_t _odp_cpu_cycles_diff(uint64_t c2, uint64_t c1) @@ -22,6 +23,9 @@ uint64_t _odp_cpu_cycles_diff(uint64_t c2, uint64_t c1) return c2 + (odp_cpu_cycles_max() - c1) + 1; } +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..fc5ee3b 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -7,6 +7,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -108,71 +109,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 +215,6 @@ static uint64_t odp_cpu_hz_current(int id ODP_UNUSED) return -1; } -#else - #error GCC target not found #endif