From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by dpdk.org (Postfix) with ESMTP id D534C590B for ; Fri, 29 Aug 2014 00:26:32 +0200 (CEST) Received: by mail-pa0-f41.google.com with SMTP id lj1so4463066pab.0 for ; Thu, 28 Aug 2014 15:30:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=MGzXORWre1qzpOn09C0NwWEQH0zXQ1HmkllccbUMW0U=; b=E48EEuT2JJz7MD/TeJap/EX+7NK2T0aUuH4KM/ZgL53ZkbkNt0vBNDew8am2CDmlkh JxW7jzPr6H2phcYKleZwHwxyOhv2T9Nn8LD32xyF0+77Ilp5HNz9XOXg5xU/FjIMx9bE FdckpTvm6YmLXPh5LkNKhs1SxErR7FBjohVP/g/dZAaQM7jcBENQyqZvJqqLpOPZzArz 1hfR7WJLfnEpKrTWU+nf1MpK4ohK2KkBtYhAOFb5Ed7UzzCgmsFLGefZcCMIJDl0NEYZ qm4WzYqt8y8vjSkAoGEPANfqsEUXqnHUGMaHYBJF6fybAfU3UFbAhKbUNAtEpBa+S3jq 3o1Q== X-Gm-Message-State: ALoCoQkjLK2EoMZ3x82mENTRXpG6oBu7CPMJJJra0g8RfDaBnddnYinTB/NHRTMD2iIuSBfB5YcV X-Received: by 10.70.91.208 with SMTP id cg16mr10137869pdb.91.1409265042683; Thu, 28 Aug 2014 15:30:42 -0700 (PDT) Received: from urahara (static-50-53-65-80.bvtn.or.frontiernet.net. [50.53.65.80]) by mx.google.com with ESMTPSA id hz1sm4578742pbb.75.2014.08.28.15.30.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Aug 2014 15:30:42 -0700 (PDT) Date: Thu, 28 Aug 2014 15:30:39 -0700 From: Stephen Hemminger To: Tomas Vestelind Message-ID: <20140828153039.3c469f95@urahara> In-Reply-To: <1407880053-14650-1-git-send-email-tomas.vestelind@gmail.com> References: <1407880053-14650-1-git-send-email-tomas.vestelind@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org 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: Thu, 28 Aug 2014 22:26:33 -0000 On Tue, 12 Aug 2014 23:47:33 +0200 Tomas Vestelind wrote: > 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. > > Signed-off-by: Tomas Vestelind > --- > lib/librte_hash/rte_hash.c | 26 ++++++++++++++++++++++++++ > lib/librte_hash/rte_hash.h | 15 +++++++++++++++ > 2 files changed, 41 insertions(+) > > 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, > > return 0; > } > + > +unsigned int > +rte_hash_keys(const struct rte_hash *h, void *keys) > +{ > + unsigned int found_keys = 0; > + unsigned int bucket, entry; > + > + /* Go through each bucket and all its entries */ > + for (bucket = 0; bucket < h->num_buckets; bucket++) { > + const hash_sig_t *sig = get_sig_tbl_bucket(h, bucket); > + > + for (entry = 0; entry < h->bucket_entries; entry++) { > + /* If the signature is valid, find and save the corresponding key */ > + if (sig[entry] != NULL_SIGNATURE) { > + uint8_t *key_bucket = get_key_tbl_bucket(h, bucket); > + void *key = get_key_from_bucket(h, key_bucket, entry); > + rte_memcpy(keys, key, h->key_len); > + > + keys = (uint8_t* )keys + h->key_len; > + found_keys++; > + } > + } > + } > + > + 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 Please indent with tabs not spaces. Using rte_memcpy() is no better than just using memcpy. Please put blank line after declartions. Writing code with continue makes it easier? for (entry = 0; entry < h->bucket_entries; entry++) { /* If the signature is valid, find and save the corresponding key */ if (sig[entry] == NULL_SIGNATURE continue;