I would drop the "__" suffix from the function names. Otherwise this looks good to me
Thanks, Daniele 2016-05-10 2:19 GMT-07:00 Ian Stokes <ian.sto...@intel.com>: > Add generic policer functions to avoid code duplication. > > Policing can be implemented on both egress and ingress paths. > Currently the QoS egress-policer implementation uses it's own specific run > and packet handle policer functions. This patch makes the policer functions > generic so that they can be used regardless of whether the policer is > egress > or ingress by just requiring a pointer to the rte_meter used for policing > to be passed. > > Signed-off-by: Ian Stokes <ian.sto...@intel.com> > --- > > v2: > - Rebased to master. > > v1: > > *netdev-dpdk.c > - Add netdev_dpdk_policer_pkt_handle__() function. > - Add netdev_dpdk_policer_run__() function. > - Modify egress_policer_run() to call netdev_dpdk_policer_run__(). > --- > lib/netdev-dpdk.c | 65 > ++++++++++++++++++++++++++++++---------------------- > 1 files changed, 37 insertions(+), 28 deletions(-) > > diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c > index af86d19..0ed909c 100644 > --- a/lib/netdev-dpdk.c > +++ b/lib/netdev-dpdk.c > @@ -1163,6 +1163,41 @@ dpdk_queue_flush(struct netdev_dpdk *dev, int qid) > dpdk_queue_flush__(dev, qid); > } > > +static inline bool > +netdev_dpdk_policer_pkt_handle__(struct rte_meter_srtcm *meter, > + struct rte_mbuf *pkt, uint64_t time) > +{ > + uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) - sizeof(struct > ether_hdr); > + > + return rte_meter_srtcm_color_blind_check(meter, time, pkt_len) == > + e_RTE_METER_GREEN; > +} > + > +static int > +netdev_dpdk_policer_run__(struct rte_meter_srtcm *meter, > + struct rte_mbuf **pkts, int pkt_cnt) > +{ > + int i = 0; > + int cnt = 0; > + struct rte_mbuf *pkt = NULL; > + uint64_t current_time = rte_rdtsc(); > + > + for (i = 0; i < pkt_cnt; i++) { > + pkt = pkts[i]; > + /* Handle current packet */ > + if (netdev_dpdk_policer_pkt_handle__(meter, pkt, current_time)) { > + if (cnt != i) { > + pkts[cnt] = pkt; > + } > + cnt++; > + } else { > + rte_pktmbuf_free(pkt); > + } > + } > + > + return cnt; > +} > + > static bool > is_vhost_running(struct virtio_net *virtio_dev) > { > @@ -2735,39 +2770,13 @@ egress_policer_qos_set(struct netdev *netdev, > const struct smap *details) > return err; > } > > -static inline bool > -egress_policer_pkt_handle__(struct rte_meter_srtcm *meter, > - struct rte_mbuf *pkt, uint64_t time) > -{ > - uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) - sizeof(struct > ether_hdr); > - > - return rte_meter_srtcm_color_blind_check(meter, time, pkt_len) == > - e_RTE_METER_GREEN; > -} > - > static int > -egress_policer_run(struct netdev *netdev, struct rte_mbuf **pkts, > - int pkt_cnt) > +egress_policer_run(struct netdev *netdev, struct rte_mbuf **pkts, int > pkt_cnt) > { > - int i = 0; > int cnt = 0; > struct egress_policer *policer = egress_policer_get__(netdev); > - struct rte_mbuf *pkt = NULL; > - uint64_t current_time = rte_rdtsc(); > > - for(i = 0; i < pkt_cnt; i++) { > - pkt = pkts[i]; > - /* Handle current packet */ > - if (egress_policer_pkt_handle__(&policer->egress_meter, pkt, > - current_time)) { > - if (cnt != i) { > - pkts[cnt] = pkt; > - } > - cnt++; > - } else { > - rte_pktmbuf_free(pkt); > - } > - } > + cnt = netdev_dpdk_policer_run__(&policer->egress_meter, pkts, > pkt_cnt); > > return cnt; > } > -- > 1.7.4.1 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > http://openvswitch.org/mailman/listinfo/dev > _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev