From patchwork Tue Dec 29 08:56:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 59033 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2161010lbb; Tue, 29 Dec 2015 01:00:04 -0800 (PST) X-Received: by 10.55.80.86 with SMTP id e83mr75582975qkb.91.1451379604464; Tue, 29 Dec 2015 01:00:04 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p23si51170368qkl.19.2015.12.29.01.00.04; Tue, 29 Dec 2015 01:00:04 -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 E519F616E1; Tue, 29 Dec 2015 09:00:03 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=WCo50Rt9; 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 5E1B461703; Tue, 29 Dec 2015 08:57:36 +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 8B095616E3; Tue, 29 Dec 2015 08:57:25 +0000 (UTC) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by lists.linaro.org (Postfix) with ESMTPS id 7DF45616E6 for ; Tue, 29 Dec 2015 08:56:51 +0000 (UTC) Received: by mail-pa0-f53.google.com with SMTP id do7so2760143pab.2 for ; Tue, 29 Dec 2015 00:56:51 -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=WCo50Rt98LxrWGRxm+zHPGdxYHQybZTtjFSZZz0naic9AgaD9DQ40WOyuAG+DrSja0 dAcKYP2fON2SlKjvlZJkHQTLxhehUgj8FZCFaagyN7kHV0lnjh1cnOEwcNB0Qc4a0B9M YVFbl0WNVpAZeyCrJ+M2plzTxhqzviZjDPTK0= 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=R7OhhkbikFWoudu5APZpYqV6SrdK5ibsJ1+0XlHnMBinuYo+kZ2//BPGVt6i0SPiXP /N5DjFFdczHios1C0SGmq0mk3vB5ovkrlICI9jQg9EarofL6JGuGyp+ObrZRebr1qRVs aUk1Ji5w24QY+c3wHO+mj9ZiMqFbIFMs6ZdK5L3c2yFKVKLZ33Wvhehy2Cwroad4cG/a ex/V5AzzSHlCMzpK6WGZ550enIMvQhOw4FTq0MGSxuOtGR3cohWFyGIYhaKSnzaxb1xB CESNuzK1jE0rMFpeVMCbvIOiPEo1RyPg3N7Lis/i4qjEsbRsJ4c9NArkktqwMExVMkE+ p02g== X-Gm-Message-State: ALoCoQkvgf/fU3ZqylKQwfGI9K2h09dNYTUvOKxK48pfbU3DMTOLnyvrNYeTKtQfLWpuTtAst9vhC4Pk8XoIx9IMX2Ernrqrxw== X-Received: by 10.66.227.102 with SMTP id rz6mr84102929pac.4.1451379410829; Tue, 29 Dec 2015 00:56:50 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id p83sm81609266pfi.96.2015.12.29.00.56.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Dec 2015 00:56:50 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Tue, 29 Dec 2015 16:56:23 +0800 Message-Id: <1451379388-7533-6-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451379388-7533-1-git-send-email-hongbo.zhang@linaro.org> References: <1451379388-7533-1-git-send-email-hongbo.zhang@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v2 API-NEXT 04/11] 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