Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce an one-shot timer which runs more often after init() call #340

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_signal_initialization(void);

#ifdef __cplusplus
}
Expand Down
39 changes: 36 additions & 3 deletions src/dp_timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

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

// timer for stats printing
#define TIMER_STATS_INTERVAL 1

static int dp_maintenance_interval = TIMER_DP_MAINTENANCE_STARTUP_INTERVAL;

static struct rte_timer dp_flow_aging_timer;
static struct rte_timer dp_maintenance_timer;
Expand All @@ -35,7 +38,7 @@ 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 inline void dp_maintenance_timer_cb_core(void)
{
if (dp_conf_is_ipv6_overlay_enabled()) {
trigger_nd_ra();
Expand All @@ -44,6 +47,31 @@ static void dp_maintenance_timer_cb(__rte_unused struct rte_timer *timer, __rte_
trigger_garp();
}

static void dp_maintenance_timer_cb(__rte_unused struct rte_timer *timer, __rte_unused void *arg)
{
dp_maintenance_timer_cb_core();
}

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

dp_maintenance_timer_cb_core();

// This is a simple back-off of the maintenance timer. Only at the beginning of the timer life time,
// do it every TIMER_DP_MAINTENANCE_STARTUP_INTERVAL seconds. After TIMER_DP_MAINTENANCE_STARTUP_CYCLES times
// and dp_maintenance_interval is set to a greater value, reset the timer with the greater value.
if ((dp_maintenance_interval > TIMER_DP_MAINTENANCE_STARTUP_INTERVAL) && (counter <= TIMER_DP_MAINTENANCE_STARTUP_CYCLES)) {
counter++;
if (counter == TIMER_DP_MAINTENANCE_STARTUP_CYCLES) {
cycles = dp_maintenance_interval * rte_get_timer_hz();
if (DP_FAILED(rte_timer_reset(timer, cycles, PERIODICAL, rte_lcore_id(), dp_maintenance_timer_cb, NULL)))
DPS_LOG_ERR("Cannot start maintenance timer");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now due to the asynchronous implementation though, I think this needs the two-callback imeplementation, otherwise the whole condition will get evaluated for eternity, since interval will be always big and then counter will always be small and there are two unneeded comparisons.

So I would create a startup callbak that does what is above, but then sets the callback to the old function.

}

uint64_t dp_timers_get_manage_interval_cycles(void)
{
return dp_timer_manage_interval_cycles;
Expand All @@ -63,6 +91,11 @@ static inline int dp_timers_add(struct rte_timer *timer, int period, rte_timer_c
return rte_timer_reset(timer, cycles, PERIODICAL, rte_lcore_id(), callback, NULL);
}

void dp_timers_signal_initialization(void)
{
dp_maintenance_interval = TIMER_DP_MAINTENANCE_INTERVAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now quite elegant actually, you made it asynchronous.

}

int dp_timers_init(void)
{
int ret;
Expand All @@ -84,8 +117,8 @@ int dp_timers_init(void)
return DP_ERROR;
}

if (DP_FAILED(dp_timers_add(&dp_maintenance_timer, TIMER_DP_MAINTENANCE_INTERVAL, dp_maintenance_timer_cb))) {
DPS_LOG_ERR("Cannot start maintenance timer");
if (DP_FAILED(dp_timers_add(&dp_maintenance_timer, dp_maintenance_interval, dp_maintenance_startup_timer_cb))) {
DPS_LOG_ERR("Cannot start maintenance startup 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_signal_initialization();
initialized = status;
}

Expand Down