examples/quota_watermark: use ring space for watermarks
[dpdk.git] / examples / quota_watermark / qw / main.c
index 2dcddea..bdb8a43 100644 (file)
@@ -67,6 +67,7 @@ struct ether_fc_frame {
 
 int *quota;
 unsigned int *low_watermark;
+unsigned int *high_watermark;
 
 uint8_t port_pairs[RTE_MAX_ETHPORTS];
 
@@ -158,6 +159,7 @@ receive_stage(__attribute__((unused)) void *args)
        uint16_t nb_rx_pkts;
 
        unsigned int lcore_id;
+       unsigned int free;
 
        struct rte_mbuf *pkts[MAX_PKT_QUOTA];
        struct rte_ring *ring;
@@ -189,13 +191,13 @@ receive_stage(__attribute__((unused)) void *args)
                        nb_rx_pkts = rte_eth_rx_burst(port_id, 0, pkts,
                                        (uint16_t) *quota);
                        ret = rte_ring_enqueue_bulk(ring, (void *) pkts,
-                                       nb_rx_pkts);
-                       if (ret == -EDQUOT) {
+                                       nb_rx_pkts, &free);
+                       if (RING_SIZE - free > *high_watermark) {
                                ring_state[port_id] = RING_OVERLOADED;
                                send_pause_frame(port_id, 1337);
                        }
 
-                       else if (ret == -ENOBUFS) {
+                       if (ret == 0) {
 
                                /*
                                 * Return  mbufs to the pool,
@@ -217,6 +219,7 @@ pipeline_stage(__attribute__((unused)) void *args)
        uint8_t port_id;
 
        unsigned int lcore_id, previous_lcore_id;
+       unsigned int free;
 
        void *pkts[MAX_PKT_QUOTA];
        struct rte_ring *rx, *tx;
@@ -253,11 +256,12 @@ pipeline_stage(__attribute__((unused)) void *args)
                                continue;
 
                        /* Enqueue them on tx */
-                       ret = rte_ring_enqueue_bulk(tx, pkts, nb_dq_pkts);
-                       if (ret == -EDQUOT)
+                       ret = rte_ring_enqueue_bulk(tx, pkts,
+                                       nb_dq_pkts, &free);
+                       if (RING_SIZE - free > *high_watermark)
                                ring_state[port_id] = RING_OVERLOADED;
 
-                       else if (ret == -ENOBUFS) {
+                       if (ret == 0) {
 
                                /*
                                 * Return  mbufs to the pool,