Skip to content

Commit

Permalink
app/pipeline: add sigint handler
Browse files Browse the repository at this point in the history
[ upstream commit f6897b23f70b84742129a215ea2be17c8843adb8 ]

For test-pipeline, if the main core receive SIGINT signal, it will kill
all the threads immediately and not wait other threads to finish their
jobs.

To fix this, add 'signal_handler' function.

Fixes: 48f31ca ("app/pipeline: packet framework benchmark")

Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Matthew Dirba <matthew.dirba@arm.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
  • Loading branch information
Feifeiarm authored and kevintraynor committed Nov 23, 2023
1 parent 25bb8f0 commit fab24e7
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 124 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ Mateusz Rusinski <mateusz.rusinski@intel.com>
Matias Elo <matias.elo@nokia.com>
Mats Liljegren <mats.liljegren@enea.com>
Matteo Croce <mcroce@redhat.com>
Matthew Dirba <matthew.dirba@arm.com>
Matthew Hall <mhall@mhcomputing.net>
Matthew Smith <mgsmith@netgate.com>
Matthew Vick <matthew.vick@intel.com>
Expand Down
14 changes: 14 additions & 0 deletions app/test-pipeline/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string.h>
#include <sys/queue.h>
#include <stdarg.h>
#include <signal.h>
#include <errno.h>
#include <getopt.h>
#include <unistd.h>
Expand Down Expand Up @@ -41,6 +42,15 @@

#include "main.h"

bool force_quit;

static void
signal_handler(int signum)
{
if (signum == SIGINT || signum == SIGTERM)
force_quit = true;
}

int
main(int argc, char **argv)
{
Expand All @@ -54,6 +64,10 @@ main(int argc, char **argv)
argc -= ret;
argv += ret;

force_quit = false;
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);

/* Parse application arguments (after the EAL ones) */
ret = app_parse_args(argc, argv);
if (ret < 0) {
Expand Down
2 changes: 2 additions & 0 deletions app/test-pipeline/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct app_params {

extern struct app_params app;

extern bool force_quit;

int app_parse_args(int argc, char **argv);
void app_print_usage(void);
void app_init(void);
Expand Down
6 changes: 4 additions & 2 deletions app/test-pipeline/pipeline_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ app_main_loop_worker_pipeline_acl(void) {

/* Run-time */
#if APP_FLUSH == 0
for ( ; ; )
while (!force_quit)
rte_pipeline_run(p);
#else
for (i = 0; ; i++) {
i = 0;
while (!force_quit) {
rte_pipeline_run(p);

if ((i & APP_FLUSH) == 0)
rte_pipeline_flush(p);
i++;
}
#endif
}
110 changes: 57 additions & 53 deletions app/test-pipeline/pipeline_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,16 @@ app_main_loop_worker_pipeline_hash(void) {

/* Run-time */
#if APP_FLUSH == 0
for ( ; ; )
while (!force_quit)
rte_pipeline_run(p);
#else
for (i = 0; ; i++) {
i = 0;
while (!force_quit) {
rte_pipeline_run(p);

if ((i & APP_FLUSH) == 0)
rte_pipeline_flush(p);
i++;
}
#endif
}
Expand Down Expand Up @@ -411,59 +413,61 @@ app_main_loop_rx_metadata(void) {
RTE_LOG(INFO, USER1, "Core %u is doing RX (with meta-data)\n",
rte_lcore_id());

for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
uint16_t n_mbufs;

n_mbufs = rte_eth_rx_burst(
app.ports[i],
0,
app.mbuf_rx.array,
app.burst_size_rx_read);

if (n_mbufs == 0)
continue;

for (j = 0; j < n_mbufs; j++) {
struct rte_mbuf *m;
uint8_t *m_data, *key;
struct rte_ipv4_hdr *ip_hdr;
struct rte_ipv6_hdr *ipv6_hdr;
uint32_t ip_dst;
uint8_t *ipv6_dst;
uint32_t *signature, *k32;

m = app.mbuf_rx.array[j];
m_data = rte_pktmbuf_mtod(m, uint8_t *);
signature = RTE_MBUF_METADATA_UINT32_PTR(m,
APP_METADATA_OFFSET(0));
key = RTE_MBUF_METADATA_UINT8_PTR(m,
APP_METADATA_OFFSET(32));

if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
ip_hdr = (struct rte_ipv4_hdr *)
&m_data[sizeof(struct rte_ether_hdr)];
ip_dst = ip_hdr->dst_addr;

k32 = (uint32_t *) key;
k32[0] = ip_dst & 0xFFFFFF00;
} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
ipv6_hdr = (struct rte_ipv6_hdr *)
&m_data[sizeof(struct rte_ether_hdr)];
ipv6_dst = ipv6_hdr->dst_addr;

memcpy(key, ipv6_dst, 16);
} else
while (!force_quit) {
for (i = 0; i < app.n_ports; i++) {
uint16_t n_mbufs;

n_mbufs = rte_eth_rx_burst(
app.ports[i],
0,
app.mbuf_rx.array,
app.burst_size_rx_read);

if (n_mbufs == 0)
continue;

*signature = test_hash(key, NULL, 0, 0);
for (j = 0; j < n_mbufs; j++) {
struct rte_mbuf *m;
uint8_t *m_data, *key;
struct rte_ipv4_hdr *ip_hdr;
struct rte_ipv6_hdr *ipv6_hdr;
uint32_t ip_dst;
uint8_t *ipv6_dst;
uint32_t *signature, *k32;

m = app.mbuf_rx.array[j];
m_data = rte_pktmbuf_mtod(m, uint8_t *);
signature = RTE_MBUF_METADATA_UINT32_PTR(m,
APP_METADATA_OFFSET(0));
key = RTE_MBUF_METADATA_UINT8_PTR(m,
APP_METADATA_OFFSET(32));

if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
ip_hdr = (struct rte_ipv4_hdr *)
&m_data[sizeof(struct rte_ether_hdr)];
ip_dst = ip_hdr->dst_addr;

k32 = (uint32_t *) key;
k32[0] = ip_dst & 0xFFFFFF00;
} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
ipv6_hdr = (struct rte_ipv6_hdr *)
&m_data[sizeof(struct rte_ether_hdr)];
ipv6_dst = ipv6_hdr->dst_addr;

memcpy(key, ipv6_dst, 16);
} else
continue;

*signature = test_hash(key, NULL, 0, 0);
}

do {
ret = rte_ring_sp_enqueue_bulk(
app.rings_rx[i],
(void **) app.mbuf_rx.array,
n_mbufs,
NULL);
} while (ret == 0 && !force_quit);
}

do {
ret = rte_ring_sp_enqueue_bulk(
app.rings_rx[i],
(void **) app.mbuf_rx.array,
n_mbufs,
NULL);
} while (ret == 0);
}
}
6 changes: 4 additions & 2 deletions app/test-pipeline/pipeline_lpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ app_main_loop_worker_pipeline_lpm(void) {

/* Run-time */
#if APP_FLUSH == 0
for ( ; ; )
while (!force_quit)
rte_pipeline_run(p);
#else
for (i = 0; ; i++) {
i = 0;
while (!force_quit) {
rte_pipeline_run(p);

if ((i & APP_FLUSH) == 0)
rte_pipeline_flush(p);
i++;
}
#endif
}
6 changes: 4 additions & 2 deletions app/test-pipeline/pipeline_lpm_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ app_main_loop_worker_pipeline_lpm_ipv6(void) {

/* Run-time */
#if APP_FLUSH == 0
for ( ; ; )
while (!force_quit)
rte_pipeline_run(p);
#else
for (i = 0; ; i++) {
i = 0;
while (!force_quit) {
rte_pipeline_run(p);

if ((i & APP_FLUSH) == 0)
rte_pipeline_flush(p);
i++;
}
#endif
}
6 changes: 4 additions & 2 deletions app/test-pipeline/pipeline_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ app_main_loop_worker_pipeline_stub(void) {

/* Run-time */
#if APP_FLUSH == 0
for ( ; ; )
while (!force_quit)
rte_pipeline_run(p);
#else
for (i = 0; ; i++) {
i = 0;
while (!force_quit) {
rte_pipeline_run(p);

if ((i & APP_FLUSH) == 0)
rte_pipeline_flush(p);
i++;
}
#endif
}

0 comments on commit fab24e7

Please sign in to comment.