Agora
1.2.0
Agora project
|
Go to the documentation of this file.
7 static inline size_t rdtsc() {
10 asm volatile(
"rdtsc" :
"=a"(rax),
"=d"(rdx));
11 return static_cast<size_t>((rdx << 32) | rax);
20 size_t upp =
static_cast<size_t>(
freq_ghz * ns);
26 clock_gettime(CLOCK_REALTIME, &
start);
27 uint64_t rdtsc_start =
rdtsc();
32 for (uint64_t
i = 0;
i < 1000000;
i++) {
33 sum +=
i + (sum +
i) * (
i % sum);
36 if (sum != 13580802877818827968ull) {
37 throw std::runtime_error(
"measure_rdtsc_freq is incorrect");
40 clock_gettime(CLOCK_REALTIME, &
end);
42 static_cast<uint64_t
>(
end.tv_sec -
start.tv_sec) * 1000000000 +
43 static_cast<uint64_t
>(
end.tv_nsec -
start.tv_nsec);
44 uint64_t rdtsc_cycles =
rdtsc() - rdtsc_start;
46 double _freq_ghz = rdtsc_cycles * 1.0 / clock_ns;
52 return (cycles / (
freq_ghz * 1000000000));
57 return (cycles / (
freq_ghz * 1000000));
66 return static_cast<size_t>(us * 1000 *
freq_ghz);
70 return static_cast<size_t>(ns *
freq_ghz);
79 static double sec_since(
const struct timespec& t0) {
81 clock_gettime(CLOCK_REALTIME, &t1);
82 return (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1000000000.0;
86 static double ns_since(
const struct timespec& t0) {
88 clock_gettime(CLOCK_REALTIME, &t1);
89 return (t1.tv_sec - t0.tv_sec) * 1000000000.0 + (t1.tv_nsec - t0.tv_nsec);
119 if (var_ms < 0)
return 0.0;
double freq_ghz
Definition: bench.cc:10
std::vector< double > ms_duration_vec
Definition: timer.h:114
double stddev_msec()
Definition: timer.h:110
double avg_msec()
Definition: timer.h:124
static double sec_since(const struct timespec &t0)
Return seconds elapsed since timestamp t0.
Definition: timer.h:79
void start()
Definition: timer.h:103
size_t start_tsc
Definition: timer.h:112
static size_t us_to_cycles(double us, double freq_ghz)
Definition: timer.h:65
void stop()
Definition: timer.h:104
static double to_usec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to usec.
Definition: timer.h:61
static size_t rdtsc()
Return the TSC.
Definition: timer.h:7
static double to_nsec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to nsec.
Definition: timer.h:74
for i
Definition: generate_data.m:107
static const auto & dpath_rdtsc
An alias for rdtsc() to distinguish calls on the critical path.
Definition: timer.h:15
end start
Definition: inspect_agora_results.m:95
TscTimer(size_t n_timestamps, double freq_ghz)
Definition: timer.h:99
double freq_ghz
Definition: timer.h:113
static double to_msec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to msec.
Definition: timer.h:56
static size_t ns_to_cycles(double ns, double freq_ghz)
Definition: timer.h:69
static double measure_rdtsc_freq()
Definition: timer.h:24
void reset()
Definition: timer.h:108
static void nano_sleep(size_t ns, double freq_ghz)
Definition: timer.h:17
Simple time that uses RDTSC.
Definition: timer.h:110
static double ns_since(const struct timespec &t0)
Return nanoseconds elapsed since timestamp t0.
Definition: timer.h:86
static double to_sec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to seconds.
Definition: timer.h:51