From: Alex Kiselev <alex@therouter.net>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [PATCH v2] librte_lpm: Improve performance of the delete and add functions
Date: Mon, 9 Jul 2018 15:33:44 +0300 [thread overview]
Message-ID: <55621439.20180709153344@therouter.net> (raw)
In-Reply-To: <20180709112439.GA18644@bricha3-MOBL.ger.corp.intel.com>
>> + int ret = rte_hash_lookup_data(lpm->rules_tbl, (void *) &rule_key,
>> + (void **) &rule);
>> + if (ret >= 0) {
>> + /* delete the rule */
>> + rte_hash_del_key(lpm->rules_tbl, (void *) &rule_key);
>> + lpm->used_rules--;
>> + rte_mempool_put(lpm->rules_pool, rule);
>> + }
> Rather than doing a lookup and then delete, why not just try the delete
> straight off. If you want to check for the key not being present, it can be
> detected from the output of the delete call. From rte_hash.h:
> * @return
> * - -EINVAL if the parameters are invalid.
> * - -ENOENT if the key is not found.
A deleted rule has to be returned back to the mempool.
And I don't see any delete function in the rte_hash that can
return a deleted item back to a caller.
>> +
>> + return ret;
>> }
>>
>> /*
>> - * Deletes a rule
>> + * Deletes a group of rules
> Include a comment that this bulk function will rebuild the lpm table,
> rather than doing incremental updates like the regular delete function.
ok
>> + * Convert a depth to a one byte long mask
>> + */
>> +static uint8_t __attribute__((pure))
>> +depth_to_mask_1b(uint8_t depth)
>> +{
>> + /* To calculate a mask start with a 1 on the left hand side and right
>> + * shift while populating the left hand side with 1's
>> */
>> - if ((lpm == NULL) || (ips == NULL) || (depths == NULL)) {
>> - return -EINVAL;
>> + return (signed char)0x80 >> (depth - 1);
> I'd make the comment on the function a little clearer e.g. using an
example: "4 =>> 0xF0", which should remove the need to have the second comment
> above the return statement.
> An alternative that might be a little clearer for the calculation would be:
"(uint8_t)(~(0xFF >>> depth))".
I've just copied this function from rte_lpm.c and converted it to 1byte version.
I'll add an example 4 =>> 0xF0.
>> +}
>> +
>> +/*
>> + * Find a less specific rule
>> + */
>> +static struct rte_lpm6_rule*
>> +rule_find_less_specific(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth)
>> +{
>> + if (depth == 1)
>> + return NULL;
>> +
>> + struct rte_lpm6_rule *rule;
>> + struct rte_lpm6_rule_key rule_key;
>> + rule_key_init(&rule_key, ip, depth);
>> + uint8_t mask;
>> +
>> + while (depth > 1) {
>> + depth--;
>> +
>> + /* each iteration zero one more bit of the key */
>> + mask = depth & 7; /* depth % 8 */
>> + if (mask > 0)
>> + mask = depth_to_mask_1b(mask);
>> +
>> + rule_key.depth = depth;
>> + rule_key.ip[depth >> 3] &= mask;
>> +
> It seems strange that when you adjust the depth, you also need to mask out
> bits of the key which should be ignored. Can you make the masking part of
> the hash calculation, which would simplify the logic here a lot, and if so,
> does it affect performance much?
The first version of rule_find_less_specific() was doing exactly what you are proposing,
masking whole ipv6 address every time. But then I just couldn't stop myself from
using this shortcut since it's a performance optimization patch.
So, yes, it could be a part of the hash calculation, but why? It's definetly not
the most difficult part of the algorithm (even without this optimizations),
so it would not make life easier :)
>> }
>> --
> Rest of the patch looks fine to me, though I can't say I've followed all
> the logic paths in full detail.
> Main concern I have about the patch is the size. Is there any way this
> patch could be split up into a few smaller ones with more gradual changes?
I could try to split it in two parts. The first part will introduce the new rule
subsystem using a hashtable instead of a flat array. And the second one will include
the rest.
> Regards,
> /Bruce
--
Alex
next prev parent reply other threads:[~2018-07-09 12:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <c6068a65-bee2-4f34-944a-6cd46ac6a188@orsmsx104.amr.corp.intel.com>
2018-07-06 10:13 ` [PATCH v2] librte_lpm: Improve performance of the delete and add functions Bruce Richardson
2018-07-06 10:25 ` Bruce Richardson
2018-07-06 10:23 ` Bruce Richardson
2018-07-06 10:56 ` Bruce Richardson
2018-07-06 12:00 ` Alex Kiselev
2018-07-06 16:16 ` Bruce Richardson
2018-07-06 16:59 ` Alex Kiselev
2018-07-09 9:07 ` Bruce Richardson
2018-07-09 11:24 ` Bruce Richardson
2018-07-09 12:33 ` Alex Kiselev [this message]
2018-07-09 13:35 ` Bruce Richardson
2018-07-02 16:42 Alex Kiselev
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=55621439.20180709153344@therouter.net \
--to=alex@therouter.net \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.