From patchwork Sat May 7 21:15:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duncan Bellamy X-Patchwork-Id: 110842 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3C798A04FF; Sat, 7 May 2022 23:16:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3BF540DDB; Sat, 7 May 2022 23:16:13 +0200 (CEST) Received: from tentoumushi.denkimushi.com (tentoumushi.denkimushi.com [81.187.253.217]) by mails.dpdk.org (Postfix) with ESMTP id E3DDF40395 for ; Sat, 7 May 2022 23:16:05 +0200 (CEST) From: Duncan Bellamy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denkimushi.com; s=dkim; t=1651958161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RYCbvKQ02H/JR7v8rT6ejAnH5mrfynYDBLCvTQ0Hrvc=; b=Heuy8AS4/shd3ztz6BEo3t8Ya3rlJLuGSoDrvf7Qw5HeeWu2c1ob4QAJVyiM1Q7A9YbVw7 QxFZUlhVrwbJZCJsgjm5kdo/9gExEQ/ldoggTrAiP/FjnmExM8900SjQ5EASbZT/RmAsjD NsG2w5mmW6UDPVgzOTQlrEpygXY7rrU= To: dev@dpdk.org Cc: Duncan Bellamy Subject: [PATCH v6] lib/eal/ppc fix compilation for musl Date: Sat, 7 May 2022 22:15:46 +0100 Message-Id: <20220507211546.2363770-1-dunk@denkimushi.com> In-Reply-To: <20220502142615.3705639-1-dunk@denkimushi.com> References: <20220502142615.3705639-1-dunk@denkimushi.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=denkimushi.com; s=dkim; t=1651958161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RYCbvKQ02H/JR7v8rT6ejAnH5mrfynYDBLCvTQ0Hrvc=; b=LVZIsddKOVTDYlClvEP+W2kqvEhOOJTEW3NglpsgGMnnnLM2m0GRh/HTAcDOXOb0U4tgvA rMKAN6EwG1FGTY1SwpAin9bWCxsqmPW9akfNj6WwhRlB85MoWnSRapZPMFOlIRmbRzv+IB cMGx+xztzFofmMaAL19pSFNtF5SgumQ= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=dunk@denkimushi.com smtp.mailfrom=dunk@denkimushi.com ARC-Seal: i=1; s=dkim; d=denkimushi.com; t=1651958161; a=rsa-sha256; cv=none; b=s1wnRwlGo2XUmUuRtwEGhpu+XTy48WHMWbR3kfmtjDuQdKI3ajAvOz+olg0Wb5Qrxnyqpk Wtfs2eEcvcUdrJD1EYJl0ApmutAFUz4RIwaEyCg/6dH3MKIfFsEF1Mv+I6qoPFzg9fKLkx 8dbkL+WPyn8mACe5Bg/13T2jKN4AXaE= X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase() the __ppc_get_timebase_freq() is taken from: https://git.alpinelinux.org/aports/commit/?id=06b03f70fb94972286c0c9f6278df89e53903833 Signed-off-by: Duncan Bellamy --- lib/eal/common/eal_private.h | 7 ++++++ lib/eal/linux/eal_timer.c | 37 ++++++++++++++++++++++++++++++++ lib/eal/ppc/include/rte_cycles.h | 7 ++++++ lib/eal/ppc/rte_cycles.c | 10 +++++++++ 4 files changed, 61 insertions(+) diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 44d14241f0..9ac1949e1c 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -743,4 +743,11 @@ int eal_asprintf(char **buffer, const char *format, ...); eal_asprintf(buffer, format, ##__VA_ARGS__) #endif +/** + * Function for systems with no __ppc_get_timebase_freq function. + */ +#ifndef RTE_ARCH_PPC_64 +uint64_t no_ppc_get_timebase_freq(void); +#endif + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 620baf038d..4f46f5411d 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include @@ -222,3 +224,38 @@ rte_eal_timer_init(void) set_tsc_freq(); return 0; } + +#ifndef RTE_ARCH_PPC_64 +uint64_t +no_ppc_get_timebase_freq(void) +{ + static uint64_t base; + #if defined(__LINUX__) + if (!base) { + FILE *f = fopen("/proc/cpuinfo", "rb"); + if (f) { + ssize_t nr; + /* virtually always big enough to hold the line */ + char buf[512]; + while (fgets(buf, sizeof(buf), f)) { + char *ret = strstr(buf, "timebase"); + if (!ret) + continue; + ret += sizeof("timebase") - 1; + ret = strchr(ret, ':'); + if (!ret) + continue; + base = strtoul(ret + 1, 0, 10); + break; + } + fclose(f); + } + } + #elif defined(_WIN32) || defined(_WIN64) + /* windows code here */ + #elif defined(RTE_EXEC_ENV_FREEBSD) + /* freebsd code here */ + #endif + return base; +} +#endif diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h index 5585f9273c..666fc9b0bf 100644 --- a/lib/eal/ppc/include/rte_cycles.h +++ b/lib/eal/ppc/include/rte_cycles.h @@ -10,7 +10,10 @@ extern "C" { #endif +#include +#ifdef __GLIBC__ #include +#endif #include "generic/rte_cycles.h" @@ -26,7 +29,11 @@ extern "C" { static inline uint64_t rte_rdtsc(void) { +#ifdef __GLIBC__ return __ppc_get_timebase(); +#else + return __builtin_ppc_get_timebase(); +#endif } static inline uint64_t diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c index 3180adb0ff..b69fc701a6 100644 --- a/lib/eal/ppc/rte_cycles.c +++ b/lib/eal/ppc/rte_cycles.c @@ -2,12 +2,22 @@ * Copyright (C) IBM Corporation 2019. */ +#include +#ifdef __GLIBC__ #include +#else +#include +#include +#endif #include "eal_private.h" uint64_t get_tsc_freq_arch(void) { +#ifdef __GLIBC__ return __ppc_get_timebase_freq(); +#else + return no_ppc_get_timebase_freq(); +#endif }