MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_tsc_freq

Function get_tsc_freq

dpdk/lib/eal/linux/eal_timer.c:194–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192#endif
193
194uint64_t
195get_tsc_freq(void)
196{
197#ifdef CLOCK_MONOTONIC_RAW
198#define NS_PER_SEC 1E9
199#define CYC_PER_10MHZ 1E7
200
201 struct timespec sleeptime = {.tv_nsec = NS_PER_SEC / 10 }; /* 1/10 second */
202
203 struct timespec t_start, t_end;
204 uint64_t tsc_hz;
205
206 if (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) {
207 uint64_t ns, end, start = rte_rdtsc();
208 nanosleep(&sleeptime,NULL);
209 clock_gettime(CLOCK_MONOTONIC_RAW, &t_end);
210 end = rte_rdtsc();
211 ns = ((t_end.tv_sec - t_start.tv_sec) * NS_PER_SEC);
212 ns += (t_end.tv_nsec - t_start.tv_nsec);
213
214 double secs = (double)ns/NS_PER_SEC;
215 tsc_hz = (uint64_t)((end - start)/secs);
216 /* Round up to 10Mhz. 1E7 ~ 10Mhz */
217 return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ);
218 }
219#endif
220 return 0;
221}
222
223int
224rte_eal_timer_init(void)

Callers 1

set_tsc_freqFunction · 0.50

Calls 1

rte_rdtscFunction · 0.50

Tested by

no test coverage detected