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 9EB0143DFB; Thu, 4 Apr 2024 18:16:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 22D6A402E8; Thu, 4 Apr 2024 18:16:11 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 4ECC5402BC for ; Thu, 4 Apr 2024 18:16:09 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id A61F020E94A3; Thu, 4 Apr 2024 09:16:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A61F020E94A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1712247368; bh=Nf9dYS5M32zjJi7dV7zqdi7K2ahOBnqh7raQXfkMq+s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eR88wygfSgsjHdXMXggRCgpHSr0JEs/7HfYHw2BIDNc7xnZobOF60KOM4rIvMG1oD BLH/58q5INd/FeG9ZHPs8+fL40PFdSz8cFuvn314Z/QnBzzb7CLSgLvu6D9yEtIP2B 4fSa+zVJULEE2OPl0uDsHjyS4CBKq6r2e1uFMyA0= Date: Thu, 4 Apr 2024 09:16:08 -0700 From: Tyler Retzlaff To: Stephen Hemminger Cc: dev@dpdk.org Subject: Re: [PATCH v2 1/2] eal: add functions to generate uuid values Message-ID: <20240404161608.GB18708@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20240403163432.437275-1-stephen@networkplumber.org> <20240403221319.499014-1-stephen@networkplumber.org> <20240403221319.499014-2-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240403221319.499014-2-stephen@networkplumber.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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 Wed, Apr 03, 2024 at 03:11:07PM -0700, Stephen Hemminger wrote: > Useful to be able to generate uuid values for tests or > for interaction with other subsystems as magic cookie. > Naming and overall algorithm come from libuuid which is used > by permission of original author. > > Signed-off-by: Stephen Hemminger > --- > lib/eal/common/eal_common_uuid.c | 56 ++++++++++++++++++++++++++++++++ > lib/eal/include/rte_uuid.h | 22 ++++++++++++- > lib/eal/version.map | 2 ++ > 3 files changed, 79 insertions(+), 1 deletion(-) > > diff --git a/lib/eal/common/eal_common_uuid.c b/lib/eal/common/eal_common_uuid.c > index 0a80bfbb38..fc8f58e8a4 100644 > --- a/lib/eal/common/eal_common_uuid.c > +++ b/lib/eal/common/eal_common_uuid.c > @@ -7,7 +7,12 @@ > #include > #include > #include > +#include > > +#include should be rte_stdatomic.h > +#include > +#include > +#include > #include > > /* UUID packed form */ > @@ -165,3 +170,54 @@ void rte_uuid_unparse(const rte_uuid_t uu, char *out, size_t len) > uuid.node[0], uuid.node[1], uuid.node[2], > uuid.node[3], uuid.node[4], uuid.node[5]); > } > + > +void rte_uuid_generate_random(rte_uuid_t out) > +{ > + union { > + uint64_t words[2]; > + rte_uuid_t uuid; > + } buf; > + struct uuid uu; > + > + /* UUID is 128 bit */ > + buf.words[0] = rte_rand(); > + buf.words[1] = rte_rand(); > + > + /* Mark these random bytes a version 4 random uuid */ > + uuid_unpack(buf.uuid, &uu); > + uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000; > + uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; > + uuid_pack(&uu, out); > +} > + > +void rte_uuid_generate_time(rte_uuid_t out) > +{ > + struct uuid uu; > + struct timespec ts; > + uint64_t ns, rnd; > + static uint16_t sequence; should be ``static RTE_ATOMIC(uint16_t) sequence;`` > + > + /* The time value for UUID is 100ns since 15 October 1582 */ > + clock_gettime(CLOCK_REALTIME, &ts); > + > + ns = ts.tv_nsec / 100; > + ns += (uint64_t) ts.tv_sec * (NSEC_PER_SEC / 100); > + ns += (((uint64_t) 0x01B21DD2) << 32) + 0x13814000; > + > + uu.time_low = (uint32_t) ns; > + uu.time_mid = (uint16_t) (ns >> 32); > + uu.time_hi_and_version = (uint16_t) (ns >> 48); > + uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; > + uu.clock_seq = rte_atomic_fetch_add_explicit(&sequence, 1, > + rte_memory_order_relaxed); > + > + rnd = rte_rand(); > + memcpy(uu.node, &rnd, 6); > + /* > + * What libuuid does set multicast bit. > + * This avoids conflicts with network cards. > + */ > + uu.node[0] |= 0x1; > + > + uuid_pack(&uu, out); > +} > diff --git a/lib/eal/include/rte_uuid.h b/lib/eal/include/rte_uuid.h > index cfefd4308a..052b78a812 100644 > --- a/lib/eal/include/rte_uuid.h > +++ b/lib/eal/include/rte_uuid.h > @@ -18,6 +18,8 @@ extern "C" { > #include > #include > > +#include > + > /** > * Struct describing a Universal Unique Identifier > */ > @@ -94,12 +96,30 @@ int rte_uuid_parse(const char *in, rte_uuid_t uu); > * @param uu > * UUID to format > * @param out > - * Resulting string buffer > + * Resulting string bufferm intentional change buffer -> bufferm? > * @param len > * Sizeof the available string buffer > */ > void rte_uuid_unparse(const rte_uuid_t uu, char *out, size_t len); > > +/** > + * Generate a random uuid > + * > + * @param uu > + * Resulting UUID > + */ > +__rte_experimental > +void rte_uuid_generate_random(rte_uuid_t uu); > + > +/** > + * Generate a uuid based on time stamp. > + * > + * @param uu > + * Resulting UUID > + */ > +__rte_experimental > +void rte_uuid_generate_time(rte_uuid_t uu); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/eal/version.map b/lib/eal/version.map > index 3df50c3fbb..5a8aa67244 100644 > --- a/lib/eal/version.map > +++ b/lib/eal/version.map > @@ -396,6 +396,8 @@ EXPERIMENTAL { > > # added in 24.03 > rte_vfio_get_device_info; # WINDOWS_NO_EXPORT # added in 24.07 > + rte_uuid_generate_random; > + rte_uuid_generate_time; > }; > > INTERNAL { > -- i actually didn't see the RTE_ATOMIC get added in v2 as per cover letter, so i'm thinking maybe the v1 series was re-submitted as v2? > 2.43.0