-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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(); | ||
|
@@ -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"); | ||
} | ||
} | ||
} | ||
|
||
uint64_t dp_timers_get_manage_interval_cycles(void) | ||
{ | ||
return dp_timer_manage_interval_cycles; | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.