aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorMaxim Uvarov <maxim.uvarov@linaro.org>2015-08-11 16:36:34 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-08-11 16:36:34 +0300
commitd8b3ffe6552ef72f6d6dd4ff35ef541c2c5d1393 (patch)
treea57471d538b7629e095b7066c4ce019f57ee3ea6 /example
parent1a7daf45862ab3a8785b9f5e6d6950eff6637c63 (diff)
parent4450e0a0e9f6ac7f63e6b30b94f456386e07011b (diff)
Merge branch 'master' into api-next
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Conflicts: example/timer/odp_timer_test.c
Diffstat (limited to 'example')
-rw-r--r--example/classifier/odp_classifier.c18
-rw-r--r--example/generator/odp_generator.c14
-rw-r--r--example/timer/odp_timer_test.c45
3 files changed, 52 insertions, 25 deletions
diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c
index 3a16279..ac204af 100644
--- a/example/classifier/odp_classifier.c
+++ b/example/classifier/odp_classifier.c
@@ -122,7 +122,7 @@ void print_cls_statistics(appl_args_t *args)
printf("-");
printf("\n");
for (i = 0; i < args->policy_count; i++)
- printf("%s\t", args->stats[i].queue_name);
+ printf("%-12s ", args->stats[i].queue_name);
printf("Total Packets");
printf("\n");
@@ -135,17 +135,19 @@ void print_cls_statistics(appl_args_t *args)
for (; timeout > 0 || infinite; timeout--) {
for (i = 0; i < args->policy_count; i++)
- printf("%"PRIu64"\t",
+ printf("%-12" PRIu64 " ",
odp_atomic_load_u64(&args->stats[i]
.packet_count));
- printf("\t%"PRIu64"\t", odp_atomic_load_u64(&args->
- total_packets));
+ printf("%-" PRIu64, odp_atomic_load_u64(&args->
+ total_packets));
sleep(1);
printf("\r");
fflush(stdout);
}
+
+ printf("\n");
}
static inline
@@ -608,10 +610,12 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *argv[], char *optarg)
switch (term) {
case ODP_PMR_SIP_ADDR:
token = strtok(NULL, ":");
- strncpy(stats[policy_count].value, token, DISPLAY_STRING_LEN);
+ strncpy(stats[policy_count].value, token,
+ DISPLAY_STRING_LEN - 1);
parse_ipv4_addr(token, &stats[policy_count].rule.val);
token = strtok(NULL, ":");
- strncpy(stats[policy_count].mask, token, DISPLAY_STRING_LEN);
+ strncpy(stats[policy_count].mask, token,
+ DISPLAY_STRING_LEN - 1);
parse_ipv4_mask(token, &stats[policy_count].rule.mask);
stats[policy_count].val_sz = 4;
break;
@@ -623,7 +627,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *argv[], char *optarg)
/* Queue Name */
token = strtok(NULL, ":");
- strncpy(stats[policy_count].queue_name, token, ODP_QUEUE_NAME_LEN);
+ strncpy(stats[policy_count].queue_name, token, ODP_QUEUE_NAME_LEN - 1);
appl_args->policy_count++;
free(pmr_str);
return 0;
diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 2c0aa76..35a6fa8 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -26,6 +26,7 @@
#define MAX_WORKERS 32 /**< max number of works */
#define SHM_PKT_POOL_SIZE (512*2048) /**< pkt pool size */
#define SHM_PKT_POOL_BUF_SIZE 1856 /**< pkt pool buf size */
+#define DEFAULT_PKT_INTERVAL 1000 /**< interval btw each pkt */
#define APPL_MODE_UDP 0 /**< UDP mode */
#define APPL_MODE_PING 1 /**< ping mode */
@@ -375,6 +376,7 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool)
static void *gen_send_thread(void *arg)
{
int thr;
+ uint64_t start, now, diff;
odp_pktio_t pktio;
thread_args_t *thr_args;
odp_queue_t outq_def;
@@ -396,6 +398,7 @@ static void *gen_send_thread(void *arg)
return NULL;
}
+ start = odp_time_cycles();
printf(" [%02i] created mode: SEND\n", thr);
for (;;) {
int err;
@@ -436,6 +439,15 @@ static void *gen_send_thread(void *arg)
>= (unsigned int)args->appl.number) {
break;
}
+
+ now = odp_time_cycles();
+ diff = odp_time_diff_cycles(start, now);
+ if (odp_time_cycles_to_ns(diff) > 20 * ODP_TIME_SEC) {
+ start = odp_time_cycles();
+ printf(" [%02i] total send: %ju\n",
+ thr, odp_atomic_load_u64(&counters.seq));
+ fflush(stdout);
+ }
}
/* receive number of reply pks until timeout */
@@ -444,7 +456,7 @@ static void *gen_send_thread(void *arg)
if (odp_atomic_load_u64(&counters.icmp) >=
(unsigned int)args->appl.number)
break;
- millisleep(1000,
+ millisleep(DEFAULT_PKT_INTERVAL,
thr_args->tp,
thr_args->tim,
thr_args->tq,
diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 5d362ec..49630b0 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -21,6 +21,7 @@
#define MAX_WORKERS 32 /**< Max worker threads */
#define NUM_TMOS 10000 /**< Number of timers */
+#define WAIT_NUM 10 /**< Max tries to rx last tmo per worker */
/** Test arguments */
@@ -47,6 +48,7 @@ typedef struct {
odp_timer_pool_t tp; /**< Timer pool handle*/
odp_atomic_u32_t remain; /**< Number of timeouts to receive*/
struct test_timer tt[256]; /**< Array of all timer helper structs*/
+ uint32_t num_workers; /**< Number of threads */
} test_globals_t;
/** @private Timer set status ASCII strings */
@@ -87,6 +89,7 @@ static void test_abs_timeouts(int thr, test_globals_t *gbls)
uint64_t tick;
struct test_timer *ttp;
odp_timeout_t tmo;
+ uint32_t num_workers = gbls->num_workers;
EXAMPLE_DBG(" [%i] test_timeouts\n", thr);
@@ -115,16 +118,19 @@ static void test_abs_timeouts(int thr, test_globals_t *gbls)
ttp->ev = odp_timeout_to_event(tmo);
tick = odp_timer_current_tick(gbls->tp);
- while ((int)odp_atomic_load_u32(&gbls->remain) > 0) {
+ while (1) {
+ int wait = 0;
odp_event_t ev;
odp_timer_set_t rc;
- tick += period;
- rc = odp_timer_set_abs(ttp->tim, tick, &ttp->ev);
- if (odp_unlikely(rc != ODP_TIMER_SUCCESS)) {
- /* Too early or too late timeout requested */
- EXAMPLE_ABORT("odp_timer_set_abs() failed: %s\n",
- timerset2str(rc));
+ if (ttp) {
+ tick += period;
+ rc = odp_timer_set_abs(ttp->tim, tick, &ttp->ev);
+ if (odp_unlikely(rc != ODP_TIMER_SUCCESS)) {
+ /* Too early or too late timeout requested */
+ EXAMPLE_ABORT("odp_timer_set_abs() failed: %s\n",
+ timerset2str(rc));
+ }
}
/* Get the next expired timeout.
@@ -139,6 +145,9 @@ static void test_abs_timeouts(int thr, test_globals_t *gbls)
ev = odp_schedule(&queue, sched_tmo);
/* Check if odp_schedule() timed out, possibly there
* are no remaining timeouts to receive */
+ if (++wait > WAIT_NUM &&
+ odp_atomic_load_u32(&gbls->remain) < num_workers)
+ EXAMPLE_ABORT("At least one TMO was lost\n");
} while (ev == ODP_EVENT_INVALID &&
(int)odp_atomic_load_u32(&gbls->remain) > 0);
@@ -161,18 +170,18 @@ static void test_abs_timeouts(int thr, test_globals_t *gbls)
}
EXAMPLE_DBG(" [%i] timeout, tick %"PRIu64"\n", thr, tick);
- odp_atomic_dec_u32(&gbls->remain);
- }
+ uint32_t rx_num = odp_atomic_fetch_dec_u32(&gbls->remain);
+
+ if (!rx_num)
+ EXAMPLE_ABORT("Unexpected timeout received (timer %x, tick %"PRIu64")\n",
+ ttp->tim, tick);
+ else if (rx_num > num_workers)
+ continue;
- /* Cancel and free last timer used */
- (void)odp_timer_cancel(ttp->tim, &ttp->ev);
- if (ttp->ev != ODP_EVENT_INVALID)
odp_event_free(ttp->ev);
- else
- EXAMPLE_ERR("Lost timeout event at timer cancel\n");
- /* Since we have cancelled the timer, there is no timeout event to
- * return from odp_timer_free() */
- (void)odp_timer_free(ttp->tim);
+ odp_timer_free(ttp->tim);
+ ttp = NULL;
+ }
/* Remove any prescheduled events */
remove_prescheduled_events();
@@ -457,6 +466,8 @@ int main(int argc, char *argv[])
printf("\n");
+ gbls->num_workers = num_workers;
+
/* Initialize number of timeouts to receive */
odp_atomic_init_u32(&gbls->remain, gbls->args.tmo_count * num_workers);