mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-08 10:35:54 -04:00
net/sched: act_police: add support for packet-per-second policing
Allow a policer action to enforce a rate-limit based on packets-per-second,
configurable using a packet-per-second rate and burst parameters.
e.g.
tc filter add dev tap1 parent ffff: u32 match \
u32 0 0 police pkts_rate 3000 pkts_burst 1000
Testing was unable to uncover a performance impact of this change on
existing features.
Signed-off-by: Baowen Zheng <baowen.zheng@corigine.com>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: Louis Peens <louis.peens@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
6a56e19902
commit
2ffe039528
@@ -1242,6 +1242,20 @@ static inline void psched_ratecfg_getrate(struct tc_ratespec *res,
|
||||
res->linklayer = (r->linklayer & TC_LINKLAYER_MASK);
|
||||
}
|
||||
|
||||
struct psched_pktrate {
|
||||
u64 rate_pkts_ps; /* packets per second */
|
||||
u32 mult;
|
||||
u8 shift;
|
||||
};
|
||||
|
||||
static inline u64 psched_pkt2t_ns(const struct psched_pktrate *r,
|
||||
unsigned int pkt_num)
|
||||
{
|
||||
return ((u64)pkt_num * r->mult) >> r->shift;
|
||||
}
|
||||
|
||||
void psched_ppscfg_precompute(struct psched_pktrate *r, u64 pktrate64);
|
||||
|
||||
/* Mini Qdisc serves for specific needs of ingress/clsact Qdisc.
|
||||
* The fast path only needs to access filter list and to update stats
|
||||
*/
|
||||
|
||||
@@ -10,10 +10,13 @@ struct tcf_police_params {
|
||||
s64 tcfp_burst;
|
||||
u32 tcfp_mtu;
|
||||
s64 tcfp_mtu_ptoks;
|
||||
s64 tcfp_pkt_burst;
|
||||
struct psched_ratecfg rate;
|
||||
bool rate_present;
|
||||
struct psched_ratecfg peak;
|
||||
bool peak_present;
|
||||
struct psched_pktrate ppsrate;
|
||||
bool pps_present;
|
||||
struct rcu_head rcu;
|
||||
};
|
||||
|
||||
@@ -24,6 +27,7 @@ struct tcf_police {
|
||||
spinlock_t tcfp_lock ____cacheline_aligned_in_smp;
|
||||
s64 tcfp_toks;
|
||||
s64 tcfp_ptoks;
|
||||
s64 tcfp_pkttoks;
|
||||
s64 tcfp_t_c;
|
||||
};
|
||||
|
||||
@@ -99,14 +103,50 @@ static inline u32 tcf_police_burst(const struct tc_action *act)
|
||||
|
||||
static inline u64 tcf_police_rate_pkt_ps(const struct tc_action *act)
|
||||
{
|
||||
/* Not implemented */
|
||||
return 0;
|
||||
struct tcf_police *police = to_police(act);
|
||||
struct tcf_police_params *params;
|
||||
|
||||
params = rcu_dereference_protected(police->params,
|
||||
lockdep_is_held(&police->tcf_lock));
|
||||
return params->ppsrate.rate_pkts_ps;
|
||||
}
|
||||
|
||||
static inline u32 tcf_police_burst_pkt(const struct tc_action *act)
|
||||
{
|
||||
/* Not implemented */
|
||||
return 0;
|
||||
struct tcf_police *police = to_police(act);
|
||||
struct tcf_police_params *params;
|
||||
u32 burst;
|
||||
|
||||
params = rcu_dereference_protected(police->params,
|
||||
lockdep_is_held(&police->tcf_lock));
|
||||
|
||||
/*
|
||||
* "rate" pkts "burst" nanoseconds
|
||||
* ------------ * -------------------
|
||||
* 1 second 2^6 ticks
|
||||
*
|
||||
* ------------------------------------
|
||||
* NSEC_PER_SEC nanoseconds
|
||||
* ------------------------
|
||||
* 2^6 ticks
|
||||
*
|
||||
* "rate" pkts "burst" nanoseconds 2^6 ticks
|
||||
* = ------------ * ------------------- * ------------------------
|
||||
* 1 second 2^6 ticks NSEC_PER_SEC nanoseconds
|
||||
*
|
||||
* "rate" * "burst"
|
||||
* = ---------------- pkts/nanosecond
|
||||
* NSEC_PER_SEC^2
|
||||
*
|
||||
*
|
||||
* "rate" * "burst"
|
||||
* = ---------------- pkts/second
|
||||
* NSEC_PER_SEC
|
||||
*/
|
||||
burst = div_u64(params->tcfp_pkt_burst * params->ppsrate.rate_pkts_ps,
|
||||
NSEC_PER_SEC);
|
||||
|
||||
return burst;
|
||||
}
|
||||
|
||||
static inline u32 tcf_police_tcfp_mtu(const struct tc_action *act)
|
||||
|
||||
@@ -190,6 +190,8 @@ enum {
|
||||
TCA_POLICE_PAD,
|
||||
TCA_POLICE_RATE64,
|
||||
TCA_POLICE_PEAKRATE64,
|
||||
TCA_POLICE_PKTRATE64,
|
||||
TCA_POLICE_PKTBURST64,
|
||||
__TCA_POLICE_MAX
|
||||
#define TCA_POLICE_RESULT TCA_POLICE_RESULT
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user