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 418A5A034C; Mon, 9 May 2022 14:06:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E2B1F407FF; Mon, 9 May 2022 14:06:18 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 5BC914068F for ; Mon, 9 May 2022 14:06:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652097976; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AnmDFOenR87lynfsykGiQ+fjWuGC2OLqqdwu10YYRvo=; b=frSz2Fd8vOEOJwfmnt4CCGTGIWGW0lsGH0vqocFMULzEsOSLcM/0yBvnBnIqYwdPpZXOuw JUTCVFBi2WcfVW809LBvqpmezem2ujRZs6aqrJnFavKe4EcH7nBNpQ+G23uW/CGf2RnSbv 9FKCemGbWiOrN5+4MA2E4XuYqgquRjY= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-513-1bGolATdMsGjL5Lkj7p8fA-1; Mon, 09 May 2022 08:06:15 -0400 X-MC-Unique: 1bGolATdMsGjL5Lkj7p8fA-1 Received: by mail-lj1-f197.google.com with SMTP id a9-20020a2e88c9000000b0024f37c179d3so4083132ljk.19 for ; Mon, 09 May 2022 05:06:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AnmDFOenR87lynfsykGiQ+fjWuGC2OLqqdwu10YYRvo=; b=DORwc7px0aGx8T6zPzlWaax643LyPHAb+XAQi2yPKnToZbkRiJ5Q1nag9F2C3JW20Y DecbM8BJ9vn0ZfijVf2AHiOQkyDV1Hmu/sKdXr9W5iJ/iVxjJKRM8A6Ro9clm8IBU1YS IPrKiHpwZTxv5nxGqOIWrlbJThCPpDXQ61WemjYurxNJkc2xSM6G1Jvm8grqsbwW1w4V LjAVx2KWx0gda03qn01W0nquEzfUzmlQe8BxUFg51c1NegX8cIDK0qqK3WDWN2RUmuLd Fxo1P5dA6UWjmWTSk0lnxPJtNCewvXdjjMm5jt0zzvLeH/VgLOz5SaQZstQndi8ZqsKk REoQ== X-Gm-Message-State: AOAM532Dn62QNuX09X6NUT58s2s7rY5zpE85rUZpTejYfHI2HA2OHvXE P5UGT/VkmvDe97I7ofpWQTCCOIossBjFwTJLoY+tYU+T8BzivCtY2g8r9hY/o640GRdFIgSEvEJ y/gG6ha+dhr7yQxqOcfY= X-Received: by 2002:a05:651c:2046:b0:250:cf36:eb77 with SMTP id t6-20020a05651c204600b00250cf36eb77mr1490837ljo.159.1652097973807; Mon, 09 May 2022 05:06:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJQkV8JL/31GjA7tuggI83uKsOPGbXiqc2ASJhap2X5ndIr6x9B1dVAk2XW5g+5c0WXAvb3kVvoPKLB5BygGY= X-Received: by 2002:a05:651c:2046:b0:250:cf36:eb77 with SMTP id t6-20020a05651c204600b00250cf36eb77mr1490812ljo.159.1652097973254; Mon, 09 May 2022 05:06:13 -0700 (PDT) MIME-Version: 1.0 References: <20220502142615.3705639-1-dunk@denkimushi.com> <20220507211546.2363770-1-dunk@denkimushi.com> In-Reply-To: <20220507211546.2363770-1-dunk@denkimushi.com> From: David Marchand Date: Mon, 9 May 2022 14:06:01 +0200 Message-ID: Subject: Re: [PATCH v6] lib/eal/ppc fix compilation for musl To: Duncan Bellamy Cc: dev , David Christensen Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" 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 On Sat, May 7, 2022 at 11:16 PM Duncan Bellamy wrote: > > 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 - A patch title does not need lib/ prefix. Here, "eal/ppc: " is enough. - Code in lib/eal/linux won't be used for FreeBSD/Windows. On the other hand, arch-specific code (here, lib/eal/ppc/) can be used for the various OS. Besides, as far as I can see in the Linux kernel sources, powerpc is the only architecture that exports a "timebase" entry in /proc/cpuinfo. So, I see no reason to put any code out of lib/eal/ppc. - In the end, unless I missed some point, the patch could probably look like (untested): 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..99d36b2f7e 100644 --- a/lib/eal/ppc/rte_cycles.c +++ b/lib/eal/ppc/rte_cycles.c @@ -2,12 +2,50 @@ * 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 } -- David Marchand