Skip to contentSkip to conversation

iproute2-next: police: support 64bit rate and peakrate in tc utility

PATCH Applied David Dai 2 participants 2 messages Sep 4, 2019 – Sep 15, 2019

Subsystems (3)
lore
Share & tools
lore

David Dai

author
#0 lore raw

PATCH v3 1/1 iproute2-next: police: support 64bit rate and peakrate in tc utility

For high speed adapter like Mellanox CX-5 card, it can reach upto 100 Gbits per second bandwidth. Currently htb already supports 64bit rate in tc utility. However police action rate and peakrate are still limited to 32bit value (upto 32 Gbits per second). Taking advantage of the 2 new attributes TCA_POLICE_RATE64 and TCA_POLICE_PEAKRATE64 from kernel, tc can use them to break the 32bit limit, and still keep the backward binary compatibility.

---
Changelog:
v1->v2:
- Change patch submit component from iproute2 to iproute2-next
- Move 2 attributes TCA_POLICE_RATE64 TCA_POLICE_PEAKRATE64 after TCA_POLICE_PAD in pkt_cls.h header to be consistent with kernel's pkt_cls.h header.
v2->v3:
- Use common functions of duparg and invarg in police filter.

---
 include/uapi/linux/pkt_cls.h |    2 +
 tc/m_police.c                |  149 +++++++++++++++++++-----------------------
 tc/tc_core.c                 |   29 ++++++++
 tc/tc_core.h                 |    3 +
 4 files changed, 102 insertions(+), 81 deletions(-)
include/uapi/linux/pkt_cls.h +2 -0
index b057aee..a6aa466 100644
@@ -160,6 +160,8 @@ enum {
 	TCA_POLICE_RESULT,
 	TCA_POLICE_TM,
 	TCA_POLICE_PAD,
+	TCA_POLICE_RATE64,
+	TCA_POLICE_PEAKRATE64,
 	__TCA_POLICE_MAX
 #define TCA_POLICE_RESULT TCA_POLICE_RESULT
 };
tc/m_police.c +68 -81

249 lines not on this page · raw message

tc/tc_core.c +29 -0
index 8eb1122..498d35d 100644
@@ -152,6 +152,35 @@ int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab,
 	return cell_log;
 }
 
+int tc_calc_rtable_64(struct tc_ratespec *r, __u32 *rtab,
+		   int cell_log, unsigned int mtu,
+		   enum link_layer linklayer, __u64 rate)
+{
+	int i;
+	unsigned int sz;
+	__u64 bps = rate;
+	unsigned int mpu = r->mpu;
+
+	if (mtu == 0)
+		mtu = 2047;
+
+	if (cell_log < 0) {
+		cell_log = 0;
+		while ((mtu >> cell_log) > 255)
+			cell_log++;
+	}
+
+	for (i = 0; i < 256; i++) {
+		sz = tc_adjust_size((i + 1) << cell_log, mpu, linklayer);
+		rtab[i] = tc_calc_xmittime(bps, sz);
+	}
+
+	r->cell_align =  -1;
+	r->cell_log = cell_log;
+	r->linklayer = (linklayer & TC_LINKLAYER_MASK);
+	return cell_log;
+}
+
 /*
    stab[pkt_len>>cell_log] = pkt_xmit_size>>size_log
  */
tc/tc_core.h +3 -0
index bd4a99f..6dab272 100644
@@ -21,6 +21,9 @@ unsigned tc_calc_xmittime(__u64 rate, unsigned size);
 unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks);
 int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab,
 		   int cell_log, unsigned mtu, enum link_layer link_layer);
+int tc_calc_rtable_64(struct tc_ratespec *r, __u32 *rtab,
+			int cell_log, unsigned mtu, enum link_layer link_layer,
+			__u64 rate);
 int tc_calc_size_table(struct tc_sizespec *s, __u16 **stab);
 
 int tc_setup_estimator(unsigned A, unsigned time_const, struct tc_estimator *est);
Signature · 1 line
1.7.1
Applied
#1 lore raw
Quoted 19 lines · David Dai

For high speed adapter like Mellanox CX-5 card, it can reach upto 100 Gbits per second bandwidth. Currently htb already supports 64bit rate in tc utility. However police action rate and peakrate are still limited to 32bit value (upto 32 Gbits per second). Taking advantage of the 2 new attributes TCA_POLICE_RATE64 and TCA_POLICE_PEAKRATE64 from kernel, tc can use them to break the 32bit limit, and still keep the backward binary compatibility.

---
Changelog:
v1->v2:
- Change patch submit component from iproute2 to iproute2-next
- Move 2 attributes TCA_POLICE_RATE64 TCA_POLICE_PEAKRATE64 after TCA_POLICE_PAD in pkt_cls.h header to be consistent with kernel's pkt_cls.h header.
v2->v3:
- Use common functions of duparg and invarg in police filter.

Quoted 7 lines
---
 include/uapi/linux/pkt_cls.h |    2 +
 tc/m_police.c                |  149 +++++++++++++++++++-----------------------
 tc/tc_core.c                 |   29 ++++++++
 tc/tc_core.h                 |    3 +
 4 files changed, 102 insertions(+), 81 deletions(-)

applied to iproute2-next.