From: Simon Horman <simon.horman@netronome.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@mellanox.com>,
netdev@vger.kernel.org, oss-drivers@netronome.com,
Baowen Zheng <baowen.zheng@corigine.com>,
Louis Peens <louis.peens@netronome.com>
Subject: Re: [PATCH RFC net-next] net/sched: act_police: add support for packet-per-second policing
Date: Thu, 28 Jan 2021 13:02:34 +0100 [thread overview]
Message-ID: <20210128120233.GA8059@netronome.com> (raw)
In-Reply-To: <20210127125905.628c0a9d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
On Wed, Jan 27, 2021 at 12:59:05PM -0800, Jakub Kicinski wrote:
> On Wed, 27 Jan 2021 12:02:23 +0100 Simon Horman wrote:
> > > > +void psched_ppscfg_precompute(struct psched_pktrate *r,
> > > > + u64 pktrate64)
> > > > +{
> > > > + memset(r, 0, sizeof(*r));
> > > > + r->rate_pkts_ps = pktrate64;
> > > > + r->mult = 1;
> > > > + /* The deal here is to replace a divide by a reciprocal one
> > > > + * in fast path (a reciprocal divide is a multiply and a shift)
> > > > + *
> > > > + * Normal formula would be :
> > > > + * time_in_ns = (NSEC_PER_SEC * pkt_num) / pktrate64
> > > > + *
> > > > + * We compute mult/shift to use instead :
> > > > + * time_in_ns = (len * mult) >> shift;
> > > > + *
> > > > + * We try to get the highest possible mult value for accuracy,
> > > > + * but have to make sure no overflows will ever happen.
> > > > + */
> > > > + if (r->rate_pkts_ps > 0) {
> > > > + u64 factor = NSEC_PER_SEC;
> > > > +
> > > > + for (;;) {
> > > > + r->mult = div64_u64(factor, r->rate_pkts_ps);
> > > > + if (r->mult & (1U << 31) || factor & (1ULL << 63))
> > > > + break;
> > > > + factor <<= 1;
> > > > + r->shift++;
> > >
> > > Aren't there helpers somewhere for the reciprocal divide
> > > pre-calculation?
> >
> > Now that you mention it, yes.
> >
> > Looking over reciprocal_divide() I don't think it a good fit here as it
> > operates on 32bit values, whereas the packet rate is 64 bit.
> >
> > Packet rate could be changed to a 32 bit entity if we convince ourselves we
> > don't want more than 2^32 - 1 packets per second (a plausible position
> > IMHO) - but that leads us to a secondary issue.
> >
> > The code above is very similar to an existing (long existing)
> > byte rate variant of this helper - psched_ratecfg_precompute().
> > And I do think we want to:
> > a) Support 64-bit byte rates. Indeed such support seems to have
> > been added to support 25G use-cases
> > b) Calculate byte and packet rates the same way
> >
> > So I feel less and less that reciprocal_divide() is a good fit.
> > But perhaps I am mistaken.
> >
> > In the meantime I will take a look to see if a helper common function can
> > be made to do (64 bit) reciprocal divides for the packet and byte rate
> > use-cases. I.e. the common code in psched_ppscfg_precompute() and
> > psched_ratecfg_precompute().
>
> No strong feelings, I'll just ask to document the reasoning in the
> commit message or the comment above.
Thanks. I'll include some text explaining this when reposting.
next prev parent reply other threads:[~2021-01-28 12:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 15:18 [PATCH RFC net-next] net/sched: act_police: add support for packet-per-second policing Simon Horman
2021-01-27 2:38 ` Jakub Kicinski
2021-01-27 11:02 ` Simon Horman
2021-01-27 20:59 ` Jakub Kicinski
2021-01-28 12:02 ` Simon Horman [this message]
2021-01-28 12:08 ` Simon Horman
2021-01-28 16:19 ` Ido Schimmel
2021-02-01 12:31 ` Simon Horman
2021-02-01 12:38 ` Simon Horman
2021-02-01 17:41 ` Ido Schimmel
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=20210128120233.GA8059@netronome.com \
--to=simon.horman@netronome.com \
--cc=baowen.zheng@corigine.com \
--cc=jhs@mojatatu.com \
--cc=jiri@mellanox.com \
--cc=kuba@kernel.org \
--cc=louis.peens@netronome.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
--cc=xiyou.wangcong@gmail.com \
/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.