From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 264F4A0093; Mon, 2 May 2022 16:26:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C346340F35; Mon, 2 May 2022 16:26:40 +0200 (CEST) Received: from tentoumushi.denkimushi.com (tentoumushi.denkimushi.com [81.187.253.217]) by mails.dpdk.org (Postfix) with ESMTP id 1FF9340E28 for ; Mon, 2 May 2022 16:26:33 +0200 (CEST) From: Duncan Bellamy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denkimushi.com; s=dkim; t=1651501589; 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=tWfkWJzUmKdYEUGTu0CcddxR9r60TBc2w90cM72OLAw=; b=KLWlGs59rtD17Tg0w5Fz8fUgl+J2XxT/nhj1Gt4CjByDCdtNzdsF/MkhVR8w2aRzj/Q7cO zp0PLfyQC7D3rTnqV9QcB341QKMS8xzw5lZhMrsmPEENRILEPqaFZLQKaS4/jqKCAx66Tj fe55JGUSNvwTfqDZOKA0TvvDC56GXFY= To: dev@dpdk.org Cc: Duncan Bellamy Subject: [PATCH v2] lib/eal/ppc fix compilation for musl Date: Mon, 2 May 2022 15:26:15 +0100 Message-Id: <20220502142615.3705639-1-dunk@denkimushi.com> In-Reply-To: <20220502115228.3AAAB1242D4@dpdk.org> References: <20220502115228.3AAAB1242D4@dpdk.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=dkim; d=denkimushi.com; t=1651501589; a=rsa-sha256; cv=none; b=jD/iIwBeU7+pGujLXKWVxabcWDWPWUkoVh15po1KAn11PxCWCMrp9vbFnTe6AFkfj9ixmx XLzg/5o4/pxcWRb2c6WMZ0qeoNhqEf5QUxzTndxKsrOxv7h4lLeyo/Bpcr/j3P458AxYTg S4edQOhxAKU4ynPxCoRkLP95XoJkO0E= 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=1651501589; 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=tWfkWJzUmKdYEUGTu0CcddxR9r60TBc2w90cM72OLAw=; b=yzeDOWn9ef1lOf2oK+kYtA5gEptWCM346BnnkfhFvmGYdbfNIiXkOfwo24abMJlXWe/H+x 3iURCpOugwOZACcK4VHe89M73MgyMJ/xI03GQ+45qvkY96dTi9HbrsYWmfpr+VUY5ZvZMa jTioV1Eez07BPVsbh1BEm6Ic4wBZHv8= 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/ppc/include/rte_cycles.h | 6 ++++++ lib/eal/ppc/rte_cycles.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h index 5585f9273c..98ffbd2592 100644 --- a/lib/eal/ppc/include/rte_cycles.h +++ b/lib/eal/ppc/include/rte_cycles.h @@ -10,7 +10,9 @@ extern "C" { #endif +#if defined(__GLIBC__) #include +#endif #include "generic/rte_cycles.h" @@ -26,7 +28,11 @@ extern "C" { static inline uint64_t rte_rdtsc(void) { +#if defined(__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..154eba722c 100644 --- a/lib/eal/ppc/rte_cycles.c +++ b/lib/eal/ppc/rte_cycles.c @@ -2,12 +2,44 @@ * Copyright (C) IBM Corporation 2019. */ +#if defined(__GLIBC__) #include +#else +#include +#include +#endif #include "eal_private.h" uint64_t get_tsc_freq_arch(void) { +#if defined(__GLIBC__) return __ppc_get_timebase_freq(); +#else + static uint64_t base; + 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); + } + } + return base;; +#endif } -- 2.32.0