Skip to content

Commit

Permalink
Introduce an one-shot timer which runs more often after init() call
Browse files Browse the repository at this point in the history
One shot timer gets kicked after the init() grpc call and sends the
ARP requests more often for the first 30 seconds. After that the
normal interval is used. (30 seconds)

Signed-off-by: Guvenc Gulce <[email protected]>
  • Loading branch information
guvenc committed Jul 19, 2023
1 parent 4540b99 commit c4557ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/dp_timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void dp_timers_free(void);
int dp_timers_add_stats(rte_timer_cb_t stats_cb);

uint64_t dp_timers_get_manage_interval_cycles(void);
void dp_timers_kick_one_shot_timer(void);

#ifdef __cplusplus
}
Expand Down
29 changes: 23 additions & 6 deletions src/dp_timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

// how often to perform network maintenance tasks (ND, GARP, ...)
#define TIMER_DP_MAINTENANCE_INTERVAL 30
#define TIMER_DP_MAINTENANCE_STARTUP_INTERVAL 5

// timer for stats printing
#define TIMER_STATS_INTERVAL 1


static struct rte_timer dp_flow_aging_timer;
static struct rte_timer dp_maintenance_timer;
static struct rte_timer dp_maintenance_oneshot_timer;
static struct rte_timer dp_stats_timer;
static uint64_t dp_timer_manage_interval_cycles;

Expand All @@ -35,21 +37,30 @@ static void dp_flow_aging_timer_cb(__rte_unused struct rte_timer *timer, __rte_u
DPS_LOG_WARNING("Cannot send flow aging event", DP_LOG_RET(ret));
}

static void dp_maintenance_timer_cb(__rte_unused struct rte_timer *timer, __rte_unused void *arg)
static void dp_maintenance_timer_cb(struct rte_timer *timer, __rte_unused void *arg)
{
static unsigned int counter = 0;
uint64_t cycles;

if (dp_conf_is_ipv6_overlay_enabled()) {
trigger_nd_ra();
trigger_nd_unsol_adv();
}
trigger_garp();

if ((timer->period == SINGLE) && (counter < 4)) {
counter++;
cycles = timer->period * rte_get_timer_hz();
rte_timer_reset(timer, cycles, SINGLE, rte_lcore_id(), dp_maintenance_timer_cb, NULL);
}
}

uint64_t dp_timers_get_manage_interval_cycles(void)
{
return dp_timer_manage_interval_cycles;
}

static inline int dp_timers_add(struct rte_timer *timer, int period, rte_timer_cb_t callback)
static inline int dp_timers_add(struct rte_timer *timer, int period, enum rte_timer_type type, rte_timer_cb_t callback)
{
uint64_t cycles = period * rte_get_timer_hz();

Expand All @@ -60,7 +71,13 @@ static inline int dp_timers_add(struct rte_timer *timer, int period, rte_timer_c
rte_timer_init(timer);

// there is no errno for this call, so log the failure in caller for better call stack
return rte_timer_reset(timer, cycles, PERIODICAL, rte_lcore_id(), callback, NULL);
return rte_timer_reset(timer, cycles, type, rte_lcore_id(), callback, NULL);
}

void dp_timers_kick_one_shot_timer(void)
{
if (DP_FAILED(dp_timers_add(&dp_maintenance_oneshot_timer, TIMER_DP_MAINTENANCE_STARTUP_INTERVAL, SINGLE, dp_maintenance_timer_cb)))
DPS_LOG_ERR("Cannot start maintenance one shot timer");
}

int dp_timers_init(void)
Expand All @@ -79,12 +96,12 @@ int dp_timers_init(void)
return ret;
}

if (DP_FAILED(dp_timers_add(&dp_flow_aging_timer, flow_aging_interval, dp_flow_aging_timer_cb))) {
if (DP_FAILED(dp_timers_add(&dp_flow_aging_timer, flow_aging_interval, PERIODICAL, dp_flow_aging_timer_cb))) {
DPS_LOG_ERR("Cannot start flow aging timer");
return DP_ERROR;
}

if (DP_FAILED(dp_timers_add(&dp_maintenance_timer, TIMER_DP_MAINTENANCE_INTERVAL, dp_maintenance_timer_cb))) {
if (DP_FAILED(dp_timers_add(&dp_maintenance_timer, TIMER_DP_MAINTENANCE_INTERVAL, PERIODICAL, dp_maintenance_timer_cb))) {
DPS_LOG_ERR("Cannot start maintenance timer");
return DP_ERROR;
}
Expand All @@ -99,7 +116,7 @@ void dp_timers_free(void)

int dp_timers_add_stats(rte_timer_cb_t stats_cb)
{
if (DP_FAILED(dp_timers_add(&dp_stats_timer, TIMER_STATS_INTERVAL, stats_cb))) {
if (DP_FAILED(dp_timers_add(&dp_stats_timer, TIMER_STATS_INTERVAL, PERIODICAL, stats_cb))) {
DPS_LOG_ERR("Cannot start stats timer");
return DP_ERROR;
}
Expand Down
2 changes: 2 additions & 0 deletions src/grpc/dp_grpc_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "dpdk_layer.h"
#include <rte_mbuf.h>
#include "dp_log.h"
#include "dp_timers.h"


GRPCService::GRPCService()
Expand Down Expand Up @@ -43,6 +44,7 @@ char* GRPCService::GetUUID()

void GRPCService::SetInitStatus(bool status)
{
dp_timers_kick_one_shot_timer();
initialized = status;
}

Expand Down

0 comments on commit c4557ea

Please sign in to comment.