netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@netronome.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: David Miller <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@mellanox.com>,
	Linux Kernel Network Developers <netdev@vger.kernel.org>,
	oss-drivers@netronome.com,
	Baowen Zheng <baowen.zheng@corigine.com>
Subject: Re: [PATCH net-next v2] net/sched: act_police: add support for packet-per-second policing
Date: Mon, 1 Feb 2021 14:02:43 +0100	[thread overview]
Message-ID: <20210201130242.GC25935@netronome.com> (raw)
In-Reply-To: <CAM_iQpVnd9s6rpNOSNLTBHzLH7BtKvdZmWMhZdFps8udfCyikQ@mail.gmail.com>

Hi Cong,

On Fri, Jan 29, 2021 at 03:04:51PM -0800, Cong Wang wrote:
> On Fri, Jan 29, 2021 at 2:29 AM Simon Horman <simon.horman@netronome.com> wrote:
> > +/**
> > + * psched_ratecfg_precompute__() - Pre-compute values for reciprocal division
> > + * @rate:   Rate to compute reciprocal division values of
> > + * @mult:   Multiplier for reciprocal division
> > + * @shift:  Shift for reciprocal division
> > + *
> > + * The multiplier and shift for reciprocal division by rate are stored
> > + * in mult and shift.
> > + *
> > + * 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 * len) / rate_bps
> > + *
> > + * 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.
> > + *
> > + * reciprocal_value() is not used here it doesn't handle 64-bit values.
> > + */
> > +static void psched_ratecfg_precompute__(u64 rate, u32 *mult, u8 *shift)
> 
> Am I the only one who thinks "foo__()" is an odd name? We usually use
> "__foo()" for helper or unlocked version of "foo()".

Sorry, I will fix that.

> And, you probably want to move the function doc to its exported variant
> instead, right?

Would something like this incremental change your concerns?

diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 44991ea726fc..63cb69df4240 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -1325,14 +1325,7 @@ void dev_shutdown(struct net_device *dev)
 	WARN_ON(timer_pending(&dev->watchdog_timer));
 }
 
-/**
- * psched_ratecfg_precompute__() - Pre-compute values for reciprocal division
- * @rate:   Rate to compute reciprocal division values of
- * @mult:   Multiplier for reciprocal division
- * @shift:  Shift for reciprocal division
- *
- * The multiplier and shift for reciprocal division by rate are stored
- * in mult and shift.
+/* Pre-compute values for reciprocol division for a rate limit.
  *
  * The deal here is to replace a divide by a reciprocal one
  * in fast path (a reciprocal divide is a multiply and a shift)
@@ -1348,7 +1341,7 @@ void dev_shutdown(struct net_device *dev)
  *
  * reciprocal_value() is not used here it doesn't handle 64-bit values.
  */
-static void psched_ratecfg_precompute__(u64 rate, u32 *mult, u8 *shift)
+static void __psched_ratecfg_precompute(u64 rate, u32 *mult, u8 *shift)
 {
 	u64 factor = NSEC_PER_SEC;
 
@@ -1367,6 +1360,15 @@ static void psched_ratecfg_precompute__(u64 rate, u32 *mult, u8 *shift)
 	}
 }
 
+/**
+ * psched_ratecfg_precompute() - Pre-compute values for byte rate limiting
+ * @r:      Byte-per-second rate struct to store configuration in
+ * @conf:   Rate specification
+ * @rate64: Rate in bytes-per-second
+ *
+ * Pre-compute configuration, including values for reciprocal division,
+ * for a byte-per-second rate limit.
+ */
 void psched_ratecfg_precompute(struct psched_ratecfg *r,
 			       const struct tc_ratespec *conf,
 			       u64 rate64)
@@ -1375,14 +1377,22 @@ void psched_ratecfg_precompute(struct psched_ratecfg *r,
 	r->overhead = conf->overhead;
 	r->rate_bytes_ps = max_t(u64, conf->rate, rate64);
 	r->linklayer = (conf->linklayer & TC_LINKLAYER_MASK);
-	psched_ratecfg_precompute__(r->rate_bytes_ps, &r->mult, &r->shift);
+	__psched_ratecfg_precompute(r->rate_bytes_ps, &r->mult, &r->shift);
 }
 EXPORT_SYMBOL(psched_ratecfg_precompute);
 
+/**
+ * psched_ppscfg_precompute() - Pre-compute values for packet rate limiting
+ * @r:         Packet-per-second rate struct to store configuration in
+ * @pktrate64: Rate in packets-per-second
+ *
+ * Pre-compute configuration, including values for reciprocal division,
+ * for a packet-per-second rate limit.
+ */
 void psched_ppscfg_precompute(struct psched_pktrate *r, u64 pktrate64)
 {
 	r->rate_pkts_ps = pktrate64;
-	psched_ratecfg_precompute__(r->rate_pkts_ps, &r->mult, &r->shift);
+	__psched_ratecfg_precompute(r->rate_pkts_ps, &r->mult, &r->shift);
 }
 EXPORT_SYMBOL(psched_ppscfg_precompute);
 

  parent reply	other threads:[~2021-02-01 13:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210129102856.6225-1-simon.horman@netronome.com>
2021-01-29 23:04 ` [PATCH net-next v2] net/sched: act_police: add support for packet-per-second policing Cong Wang
2021-01-30 14:57   ` Ido Schimmel
2021-02-01 13:07     ` Simon Horman
2021-02-01 13:02   ` Simon Horman [this message]
2021-02-02  5:26     ` Cong Wang
     [not found] ` <0c47b7d7-dc2b-3422-62ff-92fea8300036@mojatatu.com>
2021-02-01 12:33   ` Simon Horman
2021-02-02 13:59     ` Jamal Hadi Salim

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=20210201130242.GC25935@netronome.com \
    --to=simon.horman@netronome.com \
    --cc=baowen.zheng@corigine.com \
    --cc=davem@davemloft.net \
    --cc=jhs@mojatatu.com \
    --cc=jiri@mellanox.com \
    --cc=kuba@kernel.org \
    --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 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).