Re: [Patch net-next v2] net_sched: use idr to allocate u32 filter handles
From: Jiri Pirko <jiri@resnulli.us>
Date: 2017-09-25 19:00:33
Mon, Sep 25, 2017 at 07:13:51PM CEST, xiyou.wangcong@gmail.com wrote:
Instead of calling u32_lookup_ht() in a loop to find a unused handle, just switch to idr API to allocate new handles. u32 filters are special as the handle could contain a hash table id and a key id, so we need two IDR to allocate each of them. Cc: Chris Mi <redacted> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Cong Wang <redacted> ---
[...]
quoted hunk ↗ jump to hunk
@@ -311,19 +313,19 @@ static void *u32_get(struct tcf_proto *tp, u32 handle)return u32_lookup_key(ht, handle); } -static u32 gen_new_htid(struct tc_u_common *tp_c) +static u32 gen_new_htid(struct tc_u_common *tp_c, struct tc_u_hnode *ptr) { - int i = 0x800; + unsigned long idr_index; + int err; - /* hgenerator only used inside rtnl lock it is safe to increment + /* This is only used inside rtnl lock it is safe to increment * without read _copy_ update semantics */ - do { - if (++tp_c->hgenerator == 0x7FF) - tp_c->hgenerator = 1; - } while (--i > 0 && u32_lookup_ht(tp_c, (tp_c->hgenerator|0x800)<<20)); - - return i > 0 ? (tp_c->hgenerator|0x800)<<20 : 0; + err = idr_alloc_ext(&tp_c->handle_idr, ptr, &idr_index, + 1, 0x7FF, GFP_KERNEL);
Interesting, any idea why this is not 0x7FFFFFFF as well? I wonder if we could have 0x7FFFFFFF magic defined somewhere. Otherwise, "patchset" looks good. Thank you for taking care of this!