From patchwork Fri Dec 25 08:29:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 58994 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp213713lbb; Fri, 25 Dec 2015 00:32:39 -0800 (PST) X-Received: by 10.107.129.149 with SMTP id l21mr38433367ioi.174.1451032359056; Fri, 25 Dec 2015 00:32:39 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 64si36707132iop.175.2015.12.25.00.32.38; Fri, 25 Dec 2015 00:32:39 -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 1FEDB616B5; Fri, 25 Dec 2015 08:32:38 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=ALVWeFG0; 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 642CD616DD; Fri, 25 Dec 2015 08:31:16 +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 07AB2616BC; Fri, 25 Dec 2015 08:31:09 +0000 (UTC) Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by lists.linaro.org (Postfix) with ESMTPS id 9D3BE616BC for ; Fri, 25 Dec 2015 08:30:24 +0000 (UTC) Received: by mail-pa0-f41.google.com with SMTP id jx14so131970135pad.2 for ; Fri, 25 Dec 2015 00:30:24 -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=ALVWeFG0j9GG8Nbup4zAH5LqPpE8/AT8A59/qaMU/+/Id/eMoYF9KPd4mkcn0DCgIw vDYOXpqNyaP2lm7EhCM+aLQChJmu93+KGHua8E7OY5+eSL3M1N7PcQNdeotIVvBqMJ5r 8IrHy5Q9LxvAE5ZtnDtUTsz1w0gNWZqoFtSEs= 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=CZfxNHi2A5haVUbYX2sbQgSdVZYXWh4v1zb7DN1vINBR7DqshaWCfldqoKha8vt3PR wsQUXrNyIU6YWXejldwscDZpqSfK9kAddzcArODztHwWvV7RFqiKP+kWhH2hfcqQUYxq 7YbwXMFk0nPCbbpCGkfWMg0lcoHkrdcMYHNdpM+W4XmZx4WheIzNTD+rC6QOfKquZMIt EOSTP+Qx+EYAX8zgqqqzbxCWY9sNqX1sfR8rv33GwQLIWCPAZlhqV8nH9P1py9fvjwkU hEPexAcU+DvrzRhyQ3kRj5uzTe9pjQzYWb3USMObnIovubai1wK/2CEAZIeENb39ktu9 WAMA== X-Gm-Message-State: ALoCoQlsTIh4cxpyxP2KmeUo9lH0UmitKhWZhcpGzK7NfgN7oNGhswWKJ6tLzxrycdq2BYved8zy7mfDZafH+jjUj8cJct2bdQ== X-Received: by 10.66.161.70 with SMTP id xq6mr56932816pab.73.1451032223939; Fri, 25 Dec 2015 00:30:23 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id p80sm33503452pfi.12.2015.12.25.00.30.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Dec 2015 00:30:23 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Fri, 25 Dec 2015 16:29:58 +0800 Message-Id: <1451032201-19954-5-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451032201-19954-1-git-send-email-hongbo.zhang@linaro.org> References: <1451032201-19954-1-git-send-email-hongbo.zhang@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH API-NEXT 4/7] 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