Ray | 3a9b5d9 | 2016-08-09 18:35:13 +0100 | [diff] [blame^] | 1 | From 3432c140c9c51e671a4d58bb428d5852426add1f Mon Sep 17 00:00:00 2001 |
| 2 | From: "Todd Foggoa (tfoggoa)" <tfoggoa@cisco.com> |
| 3 | Date: Wed, 3 Feb 2016 08:35:27 -0800 |
| 4 | Subject: [PATCH 5/6] Allow applications to override rte_delay_us() |
| 5 | |
| 6 | Some applications may wish to define their own implentation of |
| 7 | usec delay other than the existing blocking one. The default |
| 8 | behavior remains unchanged. |
| 9 | |
| 10 | Signed-off-by: Todd Foggoa (tfoggoa) <tfoggoa@cisco.com> |
| 11 | --- |
| 12 | lib/librte_eal/common/eal_common_timer.c | 12 ++++++++++++ |
| 13 | 1 file changed, 12 insertions(+) |
| 14 | |
| 15 | diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c |
| 16 | index c4227cd..cc26b91 100644 |
| 17 | --- a/lib/librte_eal/common/eal_common_timer.c |
| 18 | +++ b/lib/librte_eal/common/eal_common_timer.c |
| 19 | @@ -47,9 +47,21 @@ |
| 20 | /* The frequency of the RDTSC timer resolution */ |
| 21 | static uint64_t eal_tsc_resolution_hz; |
| 22 | |
| 23 | +/* Allow an override of the rte_delay_us function */ |
| 24 | +int rte_delay_us_override (unsigned us) __attribute__((weak)); |
| 25 | + |
| 26 | +int |
| 27 | +rte_delay_us_override(__attribute__((unused)) unsigned us) |
| 28 | +{ |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | void |
| 33 | rte_delay_us(unsigned us) |
| 34 | { |
| 35 | + if (rte_delay_us_override(us)) |
| 36 | + return; |
| 37 | + |
| 38 | const uint64_t start = rte_get_timer_cycles(); |
| 39 | const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6; |
| 40 | while ((rte_get_timer_cycles() - start) < ticks) |
| 41 | -- |
| 42 | 2.7.4 |
| 43 | |