From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 9F74CB373 for ; Fri, 29 Aug 2014 12:30:40 +0200 (CEST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by orsmga102.jf.intel.com with ESMTP; 29 Aug 2014 03:28:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,424,1406617200"; d="scan'208";a="473765799" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by azsmga001.ch.intel.com with ESMTP; 29 Aug 2014 03:34:51 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.158]) by IRSMSX103.ger.corp.intel.com ([169.254.3.112]) with mapi id 14.03.0195.001; Fri, 29 Aug 2014 11:34:48 +0100 From: "Ananyev, Konstantin" To: Tomas Vestelind , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] hash: added rte_hash_keys to extract all keys Thread-Index: AQHPtnd97UcVno++BkOj29lgazF9aJvndLtA Date: Fri, 29 Aug 2014 10:34:47 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772582135F65F@IRSMSX105.ger.corp.intel.com> References: <1407880053-14650-1-git-send-email-tomas.vestelind@gmail.com> In-Reply-To: <1407880053-14650-1-git-send-email-tomas.vestelind@gmail.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] hash: added rte_hash_keys to extract all keys X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Aug 2014 10:30:41 -0000 Hi Tomas, > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tomas Vestelind > Sent: Tuesday, August 12, 2014 10:48 PM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH] hash: added rte_hash_keys to extract all keys >=20 > I added a function which extracts all the configured keys in a hash map. > This is good to have when debugging and printing data store in hash > maps. >=20 > Signed-off-by: Tomas Vestelind > --- > lib/librte_hash/rte_hash.c | 26 ++++++++++++++++++++++++++ > lib/librte_hash/rte_hash.h | 15 +++++++++++++++ > 2 files changed, 41 insertions(+) >=20 > diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c > index d02b6b4..2108c4f 100644 > --- a/lib/librte_hash/rte_hash.c > +++ b/lib/librte_hash/rte_hash.c > @@ -481,3 +481,29 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const= void **keys, >=20 > return 0; > } > + > +unsigned int > +rte_hash_keys(const struct rte_hash *h, void *keys) > +{ > + unsigned int found_keys =3D 0; > + unsigned int bucket, entry; > + > + /* Go through each bucket and all its entries */ > + for (bucket =3D 0; bucket < h->num_buckets; bucket++) { > + const hash_sig_t *sig =3D get_sig_tbl_bucket(h, bucket); > + > + for (entry =3D 0; entry < h->bucket_entries; entry++) { > + /* If the signature is valid, find and save the correspondin= g key */ > + if (sig[entry] !=3D NULL_SIGNATURE) { > + uint8_t *key_bucket =3D get_key_tbl_bucket(h, bucket); > + void *key =3D get_key_from_bucket(h, key_bucket, entry); > + rte_memcpy(keys, key, h->key_len); > + > + keys =3D (uint8_t* )keys + h->key_len; > + found_keys++; > + } > + } > + } I suppose we need to add one extra parameter: keys_size (size of the buffe= r provided) and inside the loop check that we wouldn't go beyond it. Also it would probably helpful to have a function that would return to the = user size of buffer needed to sore all keys from the hash. What you probably can do: implement a function that would iterate over all = elements in the hash table and for each of them call a callback (taken as a= n argument). Then all these functions and rte_hash_clear() could be implemented on top o= f it. Something like: typedef int (*rte_hash_elem_iter_t)(const struct rte_hash*hash, const void = *key, void *user_arg); void rte_hash_elem_iterate(const struct rte_hash *h, rte_hash_key_elem_t iter, v= oid *arg) { ... } About rte_hash_clear(const struct rte_hash *h) - can't we just do memset(h-= >sig_tbl, NULL_SIGNATURE, sig_tbl_size);? BTW, why it is pointer to the const strucuture if we modifying it? > + > + return found_keys; > +} > diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h > index 2ecaf1a..e0fb28f 100644 > --- a/lib/librte_hash/rte_hash.h > +++ b/lib/librte_hash/rte_hash.h > @@ -303,6 +303,21 @@ rte_hash_hash(const struct rte_hash *h, const void *= key) > int > rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys, > uint32_t num_keys, int32_t *positions); > + > +/** > + * Copy the hash table keys to the supplied list of keys. > + * This operation is multi-thread safe. > + * > + * @param h > + * Hash table to look in. > + * @param keys > + * A pointer to a list of where keys will be written. > + * Must be large enough to fit a potentially full hash map. > + * @return > + * The number of found keys. > + */ > +unsigned int > +rte_hash_keys(const struct rte_hash *h, void *keys); > #ifdef __cplusplus > } > #endif > -- > 1.7.10.4