Proposed improvement to non-interactive loop timing
https://bugs.dpdk.org/show_bug.cgi?id=435
Bug ID: 435
Summary: Proposed improvement to non-interactive loop timing
Product: DPDK
Version: 20.02
Hardware: All
OS: Linux
Status: UNCONFIRMED
Severity: enhancement
Priority: Normal
Component: testpmd
Assignee: [email protected]
Reporter: [email protected]Target Milestone: ---
When running testpmd in non-interactive mode, and using a stats period value, the current loop delay is less than ideal.
The current code:
if (stats_period != 0) {
uint64_t prev_time = 0, cur_time, diff_time = 0;
uint64_t timer_period;
/* Convert to number of cycles */
timer_period = stats_period * rte_get_timer_hz();
while (f_quit == 0) {
cur_time = rte_get_timer_cycles();
diff_time += cur_time - prev_time;
if (diff_time >= timer_period) {
print_stats();
/* Reset the timer */
diff_time = 0;
}
/* Sleep to avoid unnecessary checks */
prev_time = cur_time;
sleep(1);
}
}Compares the difference in time, and if the time has not expired, will sleep for one second before checking again. The problem with this is when the difference is close, but not at the timer period. This will result in an additional second being added to the update period. (e.g. a one second period becomes almost 2 seconds.)
Ideally, the sleep value would be based on the amount of time left (cur_time - prev_time).
Using usleep(), it is possible to create delays that are closer to the desired delay.
The following code appears to work for me, and takes into account the time required for the print_stats() call, but there may be a better solution:
if (stats_period != 0) {
uint64_t cur_time, ticks_per_usec;
uint64_t timer_period;
/* Convert to number of usecs */
timer_period = stats_period * 1000000;
/* How many CPU ticks per usec */
ticks_per_usec = rte_get_timer_hz() / 1000000;
while (f_quit == 0) {
/* Get the current CPU ticks */
cur_time = rte_get_timer_cycles();
print_stats();
/* Get the tick count again and sleep for the
difference */
usleep(timer_period - (rte_get_timer_cycles() -
cur_time) / ticks_per_usec);
}
}Signature · 2 lines
You are receiving this mail because: You are the assignee for the bug.
https://bugs.dpdk.org/show_bug.cgi?id=435
Zhang, RobinX ([email protected]) changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |WONTFIX
Status|UNCONFIRMED |RESOLVED
CC| |[email protected]--- Comment #1 from Zhang, RobinX ([email protected]) --- Hi Charlie, you can send your proposal to community for further discussion. Here's the contributor's guideline:
https://doc.dpdk.org/guides/contributing/index.html
For this bugzilla, due to it's not a bug, I will close it, thanks.
Signature · 2 lines
You are receiving this mail because: You are the assignee for the bug.