[dpdk-dev] [PATCH] examples/timer: fix incorrect time interval

Chengchang Tang tangchengchang at huawei.com
Thu May 6 04:06:26 CEST 2021



On 2021/5/6 5:37, Thomas Monjalon wrote:
> 15/04/2021 09:12, Min Hu (Connor):
>> From: Chengchang Tang <tangchengchang at huawei.com>
>>
>> Timer sample example assumes that the frequency of the timer is about
>> 2Ghz to control the period of calling rte_timer_manage(). But this
>> assumption is easy to fail. For example. the frequency of tsc on ARM64
>> is much less than 2Ghz.
>>
>> This patch uses the frequency of the current timer to calculate the
>> correct time interval to ensure consistent result on all platforms.
>>
>> In addition, the rte_rdtsc() is replaced with the more recommended
>> rte_get_timer_cycles function in this patch.
>>
>> Fixes: af75078fece3 ("first public release")
>> Cc: stable at dpdk.org
>>
>> Signed-off-by: Chengchang Tang <tangchengchang at huawei.com>
>> Signed-off-by: Min Hu (Connor) <humin29 at huawei.com>
> [...]
>>  		/*
>> -		 * Call the timer handler on each core: as we don't
>> -		 * need a very precise timer, so only call
>> -		 * rte_timer_manage() every ~10ms (at 2Ghz). In a real
>> -		 * application, this will enhance performances as
>> -		 * reading the HPET timer is not efficient.
>> +		 * Call the timer handler on each core: as we don't need a
>> +		 * very precise timer, so only call rte_timer_manage()
>> +		 * every ~10ms. since rte_eal_hpet_init() has not been
>> +		 * called, the rte_rdtsc() will be used at runtime.
> 
> I don't understand this last sentence.
> 

This is explaining why we can use rte_get_timer_cycles() instead of rte_rdtsc().
In this example, we call tsc to improve its performance. So, we invoked rte_rdtsc()
here. Now the function rte_get_timer_cycles() encapsulates these counters. It will
invoke the corresponding counter according to the user's initialization of the counter.

>> +		 * In a real application, this will enhance performances
>> +		 * as reading the HPET timer is not efficient.
>>  		 */
>> -		cur_tsc = rte_rdtsc();
>> +		cur_tsc = rte_get_timer_cycles();
> 
> 
> 
> 
> .
> 



More information about the dev mailing list