From patchwork Tue Jan 19 10:17:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 59967 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2483489lbb; Tue, 19 Jan 2016 02:20:14 -0800 (PST) X-Received: by 10.140.102.11 with SMTP id v11mr37835421qge.39.1453198813928; Tue, 19 Jan 2016 02:20:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g128si36813053qkb.78.2016.01.19.02.20.13; Tue, 19 Jan 2016 02:20:13 -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 80A8E61782; Tue, 19 Jan 2016 10:20:13 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=WhtH+u3J; 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 5E61461780; Tue, 19 Jan 2016 10:18:11 +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 D6F3161760; Tue, 19 Jan 2016 10:18:06 +0000 (UTC) Received: from mail-pf0-f170.google.com (mail-pf0-f170.google.com [209.85.192.170]) by lists.linaro.org (Postfix) with ESMTPS id 9A8206165F for ; Tue, 19 Jan 2016 10:17:36 +0000 (UTC) Received: by mail-pf0-f170.google.com with SMTP id n128so173049941pfn.3 for ; Tue, 19 Jan 2016 02:17:36 -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=3sBZDnPHtYIi6YJ0EZR8SGZcng7dKepp7Rnn1m2fOQ0=; b=WhtH+u3JDOzwj4comgNzG+anpdIh/TsUSMcXYwpm/BWXn5voPSyuWzBf6/PNa+VzaD AJKOxrkoghUws8pmtVT1mykemQBliLINBdA1Z6zDWgRAbP+NWyG+8SYaHrPEWbHwEvaT 7fsuPEEnEraC0Ce4SwAQgSh9+0sl6iVTB+RSc= 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=3sBZDnPHtYIi6YJ0EZR8SGZcng7dKepp7Rnn1m2fOQ0=; b=CJI9lpcJ3TmvNeVyhcMXpW6/uma2M6sk5DNe+YX94DAUvGOtyaCPvqiFf6aKtetkdV mf61d/PjOengWCfTDZtzqjLLsV3JCd4xbtXPKp4nmXW0B/3YF3tNww0Y/TPYTxPPvMi8 CivoJnmEH8YWD0ox/DHHbEuJp7+eUJQfoFm4vmRNb+DSxzy3U6gvdO3ViMDf7ytN8zzB 8Aq0B+BnrJ452tF83kEnye2elc7qogNu0h54fBZDJL73H9T7j7dIYpvZTq58iF0MjDXf ie1UEDQ0NV+tFz6MRqxMb1aYGvWtCcRGmVGH8IoDQZdsO0EupyRWxDknF6C5yUweEPKn OLwA== X-Gm-Message-State: ALoCoQkTRL1+CwRusRm4GqOleiVvT/x9UuXBw+AeWJbeMG/m49UIxH7MW/HuzkRkz6aEVHc9K0lbSZUXxrbjAy4oLNSaHuRltw== X-Received: by 10.98.71.3 with SMTP id u3mr43014241pfa.111.1453198655963; Tue, 19 Jan 2016 02:17:35 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id k74sm40313374pfb.30.2016.01.19.02.17.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Jan 2016 02:17:35 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Tue, 19 Jan 2016 18:17:05 +0800 Message-Id: <1453198633-24365-5-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453198633-24365-1-git-send-email-hongbo.zhang@linaro.org> References: <1453198633-24365-1-git-send-email-hongbo.zhang@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v6 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 | 72 ++++++++++++++++++++++ platform/linux-generic/include/odp_internal.h | 4 ++ platform/linux-generic/odp_system_info.c | 68 +------------------- 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 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..e2931cb --- /dev/null +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -0,0 +1,72 @@ +/* Copyright (c) 2016, 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; + uint64_t hz; + 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) { + hz = (uint64_t)(ghz * 1000000000.0); + sysinfo->cpu_hz[id] = hz; + } + 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 39e6f78..b527438 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; @@ -108,6 +109,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 d05176c..d2b0a68 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