+static volatile int cb_count = 0;
+
+/* callback for second stress test. will only be called
+ * on master lcore */
+static void
+timer_stress2_cb(struct rte_timer *tim __rte_unused, void *arg __rte_unused)
+{
+ cb_count++;
+}
+
+#define NB_STRESS2_TIMERS 8192
+
+static int
+timer_stress2_main_loop(__attribute__((unused)) void *arg)
+{
+ static struct rte_timer *timers;
+ int i;
+ static volatile int ready = 0;
+ uint64_t delay = rte_get_timer_hz() / 4;
+ unsigned lcore_id = rte_lcore_id();
+
+ if (lcore_id == rte_get_master_lcore()) {
+ timers = rte_malloc(NULL, sizeof(*timers) * NB_STRESS2_TIMERS, 0);
+ if (timers == NULL) {
+ printf("Test Failed\n");
+ printf("- Cannot allocate memory for timers\n" );
+ return -1;
+ }
+ for (i = 0; i < NB_STRESS2_TIMERS; i++)
+ rte_timer_init(&timers[i]);
+ ready = 1;
+ } else {
+ while (!ready)
+ rte_pause();
+ }
+
+ /* have all cores schedule all timers on master lcore */
+ for (i = 0; i < NB_STRESS2_TIMERS; i++)
+ rte_timer_reset(&timers[i], delay, SINGLE, rte_get_master_lcore(),
+ timer_stress2_cb, NULL);
+
+ ready = 0;
+ rte_delay_ms(500);
+
+ /* now check that we get the right number of callbacks */
+ if (lcore_id == rte_get_master_lcore()) {
+ rte_timer_manage();
+ if (cb_count != NB_STRESS2_TIMERS) {
+ printf("Test Failed\n");
+ printf("- Stress test 2, part 1 failed\n");
+ printf("- Expected %d callbacks, got %d\n", NB_STRESS2_TIMERS,
+ cb_count);
+ return -1;
+ }
+ ready = 1;
+ } else {
+ while (!ready)
+ rte_pause();
+ }
+
+ /* now test again, just stop and restart timers at random after init*/
+ for (i = 0; i < NB_STRESS2_TIMERS; i++)
+ rte_timer_reset(&timers[i], delay, SINGLE, rte_get_master_lcore(),
+ timer_stress2_cb, NULL);
+ cb_count = 0;
+
+ /* pick random timer to reset, stopping them first half the time */
+ for (i = 0; i < 100000; i++) {
+ int r = rand() % NB_STRESS2_TIMERS;
+ if (i % 2)
+ rte_timer_stop(&timers[r]);
+ rte_timer_reset(&timers[r], delay, SINGLE, rte_get_master_lcore(),
+ timer_stress2_cb, NULL);
+ }
+
+ rte_delay_ms(500);
+
+ /* now check that we get the right number of callbacks */
+ if (lcore_id == rte_get_master_lcore()) {
+ rte_timer_manage();
+ if (cb_count != NB_STRESS2_TIMERS) {
+ printf("Test Failed\n");
+ printf("- Stress test 2, part 2 failed\n");
+ printf("- Expected %d callbacks, got %d\n", NB_STRESS2_TIMERS,
+ cb_count);
+ return -1;
+ }
+ printf("Test OK\n");
+ }
+
+ return 0;
+}
+