On Wed, May 19, 2021, at 09:55, Maxime Coquelin wrote:
> Hi Liang-min,
> 
> When replying inline, please do not prefix with ">>" as it is handled as
> quoted text. There is no need to prefix.
> 
> On 5/18/21 8:00 PM, Wang, Liang-min wrote:
> >> -----Original Message-----
> >> From: Maxime Coquelin <[email protected]>
> >> Sent: Tuesday, May 18, 2021 12:15 PM
> >> To: Miskell, Timothy <[email protected]>; [email protected]
> >> Cc: Wang, Liang-min <[email protected]>
> >> Subject: Re: [PATCH] Extends the existing mirror configuration parameters
> >>
> [...]
> >>> +            pkt_buf[match_count]->vlan_tci = dst_vlan_id;
> >>> +            rte_mbuf_refcnt_update(pkt_buf[match_count], 1);
> >>
> >>
> >>
> >>> +            match_count++;
> >>> +        }
> >>> +    }
> >>> +
> >>> +    dst_qidx = (data->n_dst_queue > qidx)?qidx:(data->n_dst_queue -1);
> >>
> >> Wouldn't it scale better with:
> >> dst_qidx = qidx % data->n_dst_queue
> >> ?
> >>
> >>> We tried to avoid using "%" operator. We could add "unlikely" and the 
> >>> suggested "%" to make improvement
> 
> Not sure adding 'unlikely' is really necessary. The cost of the modulo
> operation is nothing compared to all we do in this path.
> 

Hi,

Although the modulo might well be nothing compared to the rest,
an alternative is to use Lemire's fastrange: https://github.com/lemire/fastrange
Here is the uint32_t version:

/*
* Given a value "word", produces an integer in [0,p) without division.
* The function is as fair as possible in the sense that if you iterate
* through all possible values of "word", then you will generate all
* possible outputs as uniformly as possible.
*/
static inline uint32_t
fastrange32(uint32_t word, uint32_t p) {
    return (uint32_t)(((uint64_t)word * (uint64_t)p) >> 32);
}

It should be as fair as the modulo.

Kind regards,
-- 
Gaetan Rivet
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to