From patchwork Sat May 14 07:14:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duncan Bellamy X-Patchwork-Id: 111144 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 1B1EDA00C3; Sat, 14 May 2022 09:14:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0249C410E0; Sat, 14 May 2022 09:14:58 +0200 (CEST) Received: from tentoumushi.denkimushi.com (tentoumushi.denkimushi.com [81.187.253.217]) by mails.dpdk.org (Postfix) with ESMTP id 82C4B40395 for ; Sat, 14 May 2022 09:14:51 +0200 (CEST) From: Duncan Bellamy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denkimushi.com; s=dkim; t=1652512487; 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=gZ0WhMY5QIANmVBB4jmWu7yn7smBiMlODyi0YPeDkq4=; b=CxgwQ1PMpRut92kY7r0aHj9k4QCzXkn0ET9a3VvwBvtpvF2ZeRKV/s9qwjE5qj2HHBuOo2 YMAjgjvLb+ZNCP9PjgLEWLBPDM7z4G12UaZ2TvzfNctgv4w1OhBdW2lI8ebq2e4jQtM9gs Yc6yy/AbYgW35X0MyXZb0C1dbxBFwDU= To: dev@dpdk.org Cc: Duncan Bellamy Subject: [PATCH v7] eal/ppc: fix compilation for musl Date: Sat, 14 May 2022 08:14:35 +0100 Message-Id: <20220514071435.3024492-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-Seal: i=1; s=dkim; d=denkimushi.com; t=1652512487; a=rsa-sha256; cv=none; b=Zdz2Cxm+6xRT7UNug9YoAnKa+bdREc5HhctYk0nP7xORCPhkdvsGyoFmQhuS45/CfHCqWR 1Fs2jpvfG2IidzkeE0l7NYYlLcNQeufuinUr6+eqKpp3y8GDkQU7FRr1qTJv84KFpZ3Ivi Jl0/0DKOIBSwjf7HH2pOyDLks17Q9NY= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=dunk@denkimushi.com smtp.mailfrom=dunk@denkimushi.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=denkimushi.com; s=dkim; t=1652512487; 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=gZ0WhMY5QIANmVBB4jmWu7yn7smBiMlODyi0YPeDkq4=; b=Xm/gXv4ackvPfYzZcQfdwq8CUrBnPO3tUtkcTBbNzWPcuLmNqbmVu6f4+eRH1HnzzDxwxu OnL4Y6lLePd/Tncdqei1MmGK82ruyfSqUN2NOtvMtDA7RrcJsC5KN2xNb4ucDMqdkUGwk3 3DI4Gb8wkjlH9qCGRVizzOPzrFMtwZM= 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() Signed-off-by: Duncan Bellamy Reviewed-by: David Christensen --- lib/eal/ppc/include/rte_cycles.h | 7 ++++++ lib/eal/ppc/rte_cycles.c | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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..cd4bdff8b8 100644 --- a/lib/eal/ppc/rte_cycles.c +++ b/lib/eal/ppc/rte_cycles.c @@ -2,12 +2,51 @@ * Copyright (C) IBM Corporation 2019. */ +#include +#ifdef __GLIBC__ #include +#elif RTE_EXEC_ENV_LINUX +#include +#include +#endif #include "eal_private.h" uint64_t get_tsc_freq_arch(void) { +#ifdef __GLIBC__ return __ppc_get_timebase_freq(); +#elif RTE_EXEC_ENV_LINUX + static unsigned long base; + char buf[512]; + ssize_t nr; + FILE *f; + + if (base != 0) + goto out; + + f = fopen("/proc/cpuinfo", "rb"); + if (f == NULL) + goto out; + + while (fgets(buf, sizeof(buf), f) != NULL) { + char *ret = strstr(buf, "timebase"); + + if (ret == NULL) + continue; + ret += sizeof("timebase") - 1; + ret = strchr(ret, ':'); + if (ret == NULL) + continue; + base = strtoul(ret + 1, NULL, 10); + break; + } + fclose(f); +out: + return (uint64_t) base; +#else + return 0; +#endif + }