DPDK patches and discussions
 help / color / mirror / Atom feed
From: "De Lara Guarch, Pablo" <pablo.de.lara.guarch@intel.com>
To: "Richardson, Bruce" <bruce.richardson@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] test/hash: improve hash unit tests
Date: Wed, 8 Jul 2015 15:14:39 +0000	[thread overview]
Message-ID: <E115CCD9D858EF4F90C690B0DCB4D897272D4B53@IRSMSX108.ger.corp.intel.com> (raw)
In-Reply-To: <20150708150417.GB2676@bricha3-MOBL3>

Hi Bruce,

> -----Original Message-----
> From: Richardson, Bruce
> Sent: Wednesday, July 08, 2015 4:04 PM
> To: De Lara Guarch, Pablo
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] test/hash: improve hash unit tests
> 
> On Wed, Jul 08, 2015 at 02:12:06PM +0100, Pablo de Lara wrote:
> > Add new unit test for calculating the average table utilization,
> > using random keys, based on number of entries that can be added
> > until we encounter one that cannot be added (bucket if full)
> >
> > Also, replace current hash_perf unit test to see performance more clear.
> > The current hash_perf unit test takes too long and add keys that
> > may or may not fit in the table and look up/delete that may not be
> > in the table. This new unit test gets a set of keys that we know
> > that fits in the table, and then measure the time to add/look up/delete
> > them.
> >
> > Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> 
> Few more comments on the change to test_hash.c
> 
> /Bruce
> > ---
> >  app/test/test_hash.c      |  61 ++++
> >  app/test/test_hash_perf.c | 906 +++++++++++++++++++--------------------
> -------
> >  2 files changed, 439 insertions(+), 528 deletions(-)
> >
> > diff --git a/app/test/test_hash.c b/app/test/test_hash.c
> > index 4300de9..4d538b2 100644
> > --- a/app/test/test_hash.c
> > +++ b/app/test/test_hash.c
> > @@ -1147,6 +1147,65 @@
> test_hash_creation_with_good_parameters(void)
> >  	return 0;
> >  }
> >
> > +#define ITERATIONS 50
> > +/*
> > + * Test to see the average table utilization (entries added/max entries)
> > + * before hitting a random entry that cannot be added
> > + */
> > +static int test_average_table_utilization(void)
> > +{
> > +	struct rte_hash *handle;
> > +	void *simple_key;
> > +	unsigned i, j, no_space = 0;
> > +	double added_keys_until_no_space = 0;
> > +	int ret;
> > +
> > +	ut_params.entries = 1 << 20;
> > +	ut_params.name = "test_average_utilization";
> > +	ut_params.hash_func = rte_jhash;
> > +	handle = rte_hash_create(&ut_params);
> > +	RETURN_IF_ERROR(handle == NULL, "hash creation failed");
> > +
> > +	simple_key = rte_zmalloc(NULL, ut_params.key_len, 0);
> > +
> > +	for (j = 0; j < ITERATIONS; j++) {
> > +		while (!no_space) {
> > +			for (i = 0; i < ut_params.key_len; i++)
> > +				((uint8_t *) simple_key)[i] = rte_rand() %
> 255;
> > +
> > +			ret = rte_hash_add_key(handle, simple_key);
> > +			print_key_info("Add", simple_key, ret);
> > +
> > +			if (ret == -ENOSPC) {
> > +				if (rte_hash_lookup(handle, simple_key) != -
> ENOENT)
> > +					printf("Found key that should not be
> present\n");
> Should this not be an immediate test failure?
> In fact, is it really worth testing, for this condition. Why not just have
> the loop and test as:
> 
> do {
> 	/*set up simple key */
> } while ((ret = rte_hash_add_key(...)) >= 0);
> if (ret != -ENOSPC) {
> 	/* print error */
> 	return -1;
> }
> 

Sure, I forgot to return an error in this case.
And yes, you are right, that's more elegant.
Only thing missing there is freeing the hash table.

> > +				no_space = 1;
> > +			} else {
> > +				if (ret < 0)
> > +					rte_free(simple_key);
> 
> Rather than using malloc free, why not just make simple_key a local array of
> size MAX_KEY_SIZE.

Will do.

> 
> > +				RETURN_IF_ERROR(ret < 0,
> > +						"failed to add key (ret=%d)",
> ret);
> > +				added_keys_until_no_space++;
> > +			}
> > +		}
> > +		no_space = 0;
> > +
> > +		/* Reset the table */
> > +		rte_hash_free(handle);
> > +		handle = rte_hash_create(&ut_params);
> > +		RETURN_IF_ERROR(handle == NULL, "hash creation failed");
> 
> Would a reset call work better than a free/recreate?

It would, but that function was not present in the current implementation.
I have added it in the new implementation, so I changed this as soon as
I implement it.

> 
> > +	}
> > +
> > +	const unsigned average_keys_added = added_keys_until_no_space
> / ITERATIONS;
> > +
> > +	printf("Average table utilization = %.2f%% (%u/%u)\n",
> > +		((double) average_keys_added / ut_params.entries * 100),
> > +		average_keys_added, ut_params.entries);
> > +	rte_hash_free(handle);
> > +
> > +	return 0;
> > +}
> > +
> >  static uint8_t key[16] = {0x00, 0x01, 0x02, 0x03,
> >  			0x04, 0x05, 0x06, 0x07,
> >  			0x08, 0x09, 0x0a, 0x0b,
> > @@ -1405,6 +1464,8 @@ test_hash(void)
> >  		return -1;
> >  	if (test_hash_creation_with_good_parameters() < 0)
> >  		return -1;
> > +	if (test_average_table_utilization() < 0)
> > +		return -1;
> >
> >  	run_hash_func_tests();
> >

  reply	other threads:[~2015-07-08 15:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 13:12 [dpdk-dev] [PATCH] Improve hash unit tests - Cuckoo hash part 2 Pablo de Lara
2015-07-08 13:12 ` [dpdk-dev] [PATCH] test/hash: improve hash unit tests Pablo de Lara
2015-07-08 13:39   ` Bruce Richardson
2015-07-08 15:04   ` Bruce Richardson
2015-07-08 15:14     ` De Lara Guarch, Pablo [this message]
2015-07-08 16:30 ` [dpdk-dev] [PATCH v2] Improve hash unit tests - Cuckoo hash part 2 Pablo de Lara
2015-07-08 16:30   ` [dpdk-dev] [PATCH v2] test/hash: improve hash unit tests Pablo de Lara
2015-07-09 12:19   ` [dpdk-dev] [PATCH v3] Improve hash unit tests - Cuckoo hash part 2 Pablo de Lara
2015-07-09 12:19     ` [dpdk-dev] [PATCH v3] test/hash: improve hash unit tests Pablo de Lara
2015-07-09 16:54       ` [dpdk-dev] [PATCH v4] Improve hash unit tests - Cuckoo hash part 2 Pablo de Lara
2015-07-09 16:54         ` [dpdk-dev] [PATCH v4] test/hash: improve hash unit tests Pablo de Lara
2015-07-10  9:11           ` Bruce Richardson
2015-07-10 10:35             ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E115CCD9D858EF4F90C690B0DCB4D897272D4B53@IRSMSX108.ger.corp.intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).