diff options
author | Jack Lloyd <[email protected]> | 2018-12-23 14:42:49 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-12-23 14:42:49 -0500 |
commit | f7f42d07187b357dc5b4c3de53f29af88bd07eb6 (patch) | |
tree | 2979a79abf3446a5c231da8707f084bb685998ae /src | |
parent | 716005aa4283c962dfe1478e4ee85bef5cfda293 (diff) |
Rename OS::get_processor_timestamp to OS::get_cpu_cycle_counter
Using phrase "timestamp" makes it sound like it has some relation
to wall clock which it does not.
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/speed.cpp | 2 | ||||
-rw-r--r-- | src/lib/utils/os_utils.cpp | 6 | ||||
-rw-r--r-- | src/lib/utils/os_utils.h | 2 | ||||
-rw-r--r-- | src/lib/utils/timer.cpp | 5 | ||||
-rw-r--r-- | src/tests/test_os_utils.cpp | 14 |
5 files changed, 15 insertions, 14 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index d18cab99a..84d8d5679 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -440,7 +440,7 @@ class Speed final : public Command m_clock_cycle_ratio = 1.0 / m_clock_cycle_ratio; - if(m_clock_speed != 0 && Botan::OS::get_processor_timestamp() != 0) + if(m_clock_speed != 0 && Botan::OS::get_cpu_cycle_counter() != 0) { error_output() << "The --cpu-clock-speed option is only intended to be used on " "platforms without access to a cycle counter.\n" diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 77be98dc6..946a2c297 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -100,7 +100,7 @@ bool OS::running_in_privileged_state() #endif } -uint64_t OS::get_processor_timestamp() +uint64_t OS::get_cpu_cycle_counter() { uint64_t rtc = 0; @@ -153,7 +153,7 @@ uint64_t OS::get_processor_timestamp() asm volatile("mfctl 16,%0" : "=r" (rtc)); // 64-bit only? #else - //#warning "OS::get_processor_timestamp not implemented" + //#warning "OS::get_cpu_cycle_counter not implemented" #endif #endif @@ -163,7 +163,7 @@ uint64_t OS::get_processor_timestamp() uint64_t OS::get_high_resolution_clock() { - if(uint64_t cpu_clock = OS::get_processor_timestamp()) + if(uint64_t cpu_clock = OS::get_cpu_cycle_counter()) return cpu_clock; #if defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) diff --git a/src/lib/utils/os_utils.h b/src/lib/utils/os_utils.h index 39e30fcb7..24cbdd5a3 100644 --- a/src/lib/utils/os_utils.h +++ b/src/lib/utils/os_utils.h @@ -46,7 +46,7 @@ bool running_in_privileged_state(); * Currently supported processors are x86, PPC, Alpha, SPARC, IA-64, S/390x, and HP-PA. * If no CPU cycle counter is available on this system, returns zero. */ -uint64_t BOTAN_TEST_API get_processor_timestamp(); +uint64_t BOTAN_TEST_API get_cpu_cycle_counter(); /* * @return best resolution timestamp available diff --git a/src/lib/utils/timer.cpp b/src/lib/utils/timer.cpp index 5196397b9..1b4f3068c 100644 --- a/src/lib/utils/timer.cpp +++ b/src/lib/utils/timer.cpp @@ -5,6 +5,7 @@ */ #include <botan/internal/timer.h> +#include <botan/internal/os_utils.h> #include <algorithm> #include <sstream> #include <iomanip> @@ -15,7 +16,7 @@ void Timer::start() { stop(); m_timer_start = OS::get_system_timestamp_ns(); - m_cpu_cycles_start = OS::get_processor_timestamp(); + m_cpu_cycles_start = OS::get_cpu_cycle_counter(); } void Timer::stop() @@ -24,7 +25,7 @@ void Timer::stop() { if(m_cpu_cycles_start != 0) { - const uint64_t cycles_taken = OS::get_processor_timestamp() - m_cpu_cycles_start; + const uint64_t cycles_taken = OS::get_cpu_cycle_counter() - m_cpu_cycles_start; if(cycles_taken > 0) { m_cpu_cycles_used += static_cast<size_t>(cycles_taken * m_clock_cycle_ratio); diff --git a/src/tests/test_os_utils.cpp b/src/tests/test_os_utils.cpp index 1cf1d4d65..f8d55edba 100644 --- a/src/tests/test_os_utils.cpp +++ b/src/tests/test_os_utils.cpp @@ -19,7 +19,7 @@ namespace { /* uint32_t get_process_id(); -uint64_t get_processor_timestamp(); +uint64_t get_cpu_cycle_counter(); uint64_t get_system_timestamp_ns(); size_t get_memory_locking_limit(); void* allocate_locked_pages(size_t length); @@ -35,7 +35,7 @@ class OS_Utils_Tests final : public Test std::vector<Test::Result> results; results.push_back(test_get_process_id()); - results.push_back(test_get_processor_timestamp()); + results.push_back(test_get_cpu_cycle_counter()); results.push_back(test_get_high_resolution_clock()); results.push_back(test_get_system_timestamp()); results.push_back(test_memory_locking()); @@ -64,21 +64,21 @@ class OS_Utils_Tests final : public Test return result; } - Test::Result test_get_processor_timestamp() + Test::Result test_get_cpu_cycle_counter() { - Test::Result result("OS::get_processor_timestamp"); + Test::Result result("OS::get_cpu_cycle_counter"); - const uint64_t proc_ts1 = Botan::OS::get_processor_timestamp(); + const uint64_t proc_ts1 = Botan::OS::get_cpu_cycle_counter(); if(proc_ts1 == 0) { - const uint64_t proc_ts2 = Botan::OS::get_processor_timestamp(); + const uint64_t proc_ts2 = Botan::OS::get_cpu_cycle_counter(); result.test_is_eq("Disabled processor timestamp stays at zero", proc_ts1, proc_ts2); return result; } size_t counts = 0; - while(counts < 100 && (Botan::OS::get_processor_timestamp() == proc_ts1)) + while(counts < 100 && (Botan::OS::get_cpu_cycle_counter() == proc_ts1)) ++counts; result.test_lt("CPU cycle counter eventually changes value", counts, 10); |