Skip to content

Commit

Permalink
[Bug Fix] NF Advanced Ring Thread Process NF Shutdown Messages (#111)
Browse files Browse the repository at this point in the history
Before, when running the advanced rings mode in speed tester and scaling, closing the manager would not kill the NF running.

This adds a message handler in the advanced rings loop that listens for the MSG_STOP macro sent by the manager.

Closes #105 

Commit log:

* Listen for stop message

* Removing extra line

* Style fixes

* Avoiding memleak

* Style updates

* Style fixes

* Style nits

* Style nits

* Style nits
  • Loading branch information
dennisafa authored and nks5295 committed May 16, 2019
1 parent 095869d commit 20941c6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/scaling_example/scaling.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ run_advanced_rings(struct onvm_nf_info *nf_info) {
int tx_batch_size;
struct rte_ring *rx_ring;
struct rte_ring *tx_ring;
struct onvm_nf_msg *msg;
struct rte_ring *msg_q;
struct rte_mempool *nf_msg_pool;
volatile struct onvm_nf *nf;
static uint8_t spawned_nfs = 0;

Expand All @@ -263,6 +266,8 @@ run_advanced_rings(struct onvm_nf_info *nf_info) {
nf = onvm_nflib_get_nf(nf_info->instance_id);
rx_ring = nf->rx_q;
tx_ring = nf->tx_q;
msg_q = nf->msg_q;
nf_msg_pool = rte_mempool_lookup(_NF_MSG_POOL_NAME);

/* Testing NF scaling */
if (spawned_nfs == 0) {
Expand All @@ -289,6 +294,18 @@ run_advanced_rings(struct onvm_nf_info *nf_info) {
}

while (keep_running && rx_ring && tx_ring && nf) {
/* Check for a stop message from the manager. */
if (unlikely(rte_ring_count(msg_q) > 0)) {
msg = NULL;
rte_ring_dequeue(msg_q, (void **)(&msg));
if (msg->msg_type == MSG_STOP) {
keep_running = 0;
} else {
printf("Received message %d, ignoring", msg->msg_type);
}
rte_mempool_put(nf_msg_pool, (void *)msg);
}

tx_batch_size = 0;
/* Dequeue all packets in ring up to max possible. */
nb_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE, NULL);
Expand Down
17 changes: 17 additions & 0 deletions examples/speed_tester/speed_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ run_advanced_rings(struct onvm_nf_info *nf_info) {
uint64_t start_time;
struct rte_ring *rx_ring;
struct rte_ring *tx_ring;
struct onvm_nf_msg *msg;
struct rte_ring *msg_q;
struct rte_mempool *nf_msg_pool;
volatile struct onvm_nf *nf;

printf("Process %d handling packets using advanced rings\n", nf_info->instance_id);
Expand All @@ -329,10 +332,24 @@ run_advanced_rings(struct onvm_nf_info *nf_info) {
nf = onvm_nflib_get_nf(nf_info->instance_id);
rx_ring = nf->rx_q;
tx_ring = nf->tx_q;
msg_q = nf->msg_q;
nf_msg_pool = rte_mempool_lookup(_NF_MSG_POOL_NAME);

start_time = rte_get_tsc_cycles();

while (keep_running && rx_ring && tx_ring && nf) {
/* Check for a stop message from the manager. */
if (unlikely(rte_ring_count(msg_q) > 0)) {
msg = NULL;
rte_ring_dequeue(msg_q, (void **)(&msg));
if (msg->msg_type == MSG_STOP) {
keep_running = 0;
} else {
printf("Received message %d, ignoring", msg->msg_type);
}
rte_mempool_put(nf_msg_pool, (void *)msg);
}

tx_batch_size = 0;
/* Dequeue all packets in ring up to max possible. */
nb_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE, NULL);
Expand Down

0 comments on commit 20941c6

Please sign in to comment.