diff options
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/utils/CMakeLists.txt | 62 | ||||
-rw-r--r-- | host/lib/utils/system_time.cpp | 54 | ||||
-rw-r--r-- | host/tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | host/tests/system_time_test.cpp | 2 |
4 files changed, 15 insertions, 109 deletions
diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 5c4478909..4369a8f11 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -132,68 +132,6 @@ set_source_files_properties( ) ######################################################################## -# Setup defines for high resolution timing -######################################################################## -message(STATUS "") -message(STATUS "Configuring high resolution timing...") -include(CheckCXXSourceCompiles) - -set(CMAKE_REQUIRED_LIBRARIES -lrt) -CHECK_CXX_SOURCE_COMPILES(" - #include <ctime> - int main(){ - timespec ts; - return clock_gettime(CLOCK_MONOTONIC, &ts); - } - " HAVE_CLOCK_GETTIME -) -set(CMAKE_REQUIRED_LIBRARIES) - -include(CheckCXXSourceCompiles) -CHECK_CXX_SOURCE_COMPILES(" - #include <mach/mach_time.h> - int main(){ - mach_timebase_info_data_t info; - mach_timebase_info(&info); - mach_absolute_time(); - return 0; - } - " HAVE_MACH_ABSOLUTE_TIME -) - -CHECK_CXX_SOURCE_COMPILES(" - #include <Windows.h> - int main(){ - LARGE_INTEGER value; - QueryPerformanceCounter(&value); - QueryPerformanceFrequency(&value); - return 0; - } - " HAVE_QUERY_PERFORMANCE_COUNTER -) - - -if(HAVE_CLOCK_GETTIME) - message(STATUS " High resolution timing supported through clock_gettime.") - set(SYSTEM_TIME_DEFS HAVE_CLOCK_GETTIME) - LIBUHD_APPEND_LIBS("-lrt") -elseif(HAVE_MACH_ABSOLUTE_TIME) - message(STATUS " High resolution timing supported through mach_absolute_time.") - set(SYSTEM_TIME_DEFS HAVE_MACH_ABSOLUTE_TIME) -elseif(HAVE_QUERY_PERFORMANCE_COUNTER) - message(STATUS " High resolution timing supported through QueryPerformanceCounter.") - set(SYSTEM_TIME_DEFS HAVE_QUERY_PERFORMANCE_COUNTER) -else() - message(STATUS " High resolution timing supported though microsec_clock.") - set(SYSTEM_TIME_DEFS HAVE_MICROSEC_CLOCK) -endif() - -set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/system_time.cpp - PROPERTIES COMPILE_DEFINITIONS "${SYSTEM_TIME_DEFS}" -) - -######################################################################## # Setup defines for module loading ######################################################################## message(STATUS "") diff --git a/host/lib/utils/system_time.cpp b/host/lib/utils/system_time.cpp index 20b6dc429..71fcd3fff 100644 --- a/host/lib/utils/system_time.cpp +++ b/host/lib/utils/system_time.cpp @@ -5,50 +5,12 @@ // #include <uhdlib/utils/system_time.hpp> - -using namespace uhd; - -#ifdef HAVE_CLOCK_GETTIME -#include <time.h> -time_spec_t uhd::get_system_time(void){ - timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return time_spec_t(ts.tv_sec, ts.tv_nsec, 1e9); -} -#endif /* HAVE_CLOCK_GETTIME */ - - -#ifdef HAVE_MACH_ABSOLUTE_TIME -#include <mach/mach_time.h> -time_spec_t uhd::get_system_time(void){ - mach_timebase_info_data_t info; mach_timebase_info(&info); - intmax_t nanosecs = mach_absolute_time()*info.numer/info.denom; - return time_spec_t::from_ticks(nanosecs, 1e9); -} -#endif /* HAVE_MACH_ABSOLUTE_TIME */ - - -#ifdef HAVE_QUERY_PERFORMANCE_COUNTER -#include <Windows.h> -time_spec_t uhd::get_system_time(void){ - LARGE_INTEGER counts, freq; - QueryPerformanceCounter(&counts); - QueryPerformanceFrequency(&freq); - return time_spec_t::from_ticks(counts.QuadPart, double(freq.QuadPart)); -} -#endif /* HAVE_QUERY_PERFORMANCE_COUNTER */ - - -#ifdef HAVE_MICROSEC_CLOCK -#include <boost/date_time/posix_time/posix_time.hpp> -namespace pt = boost::posix_time; -time_spec_t uhd::get_system_time(void){ - pt::ptime time_now = pt::microsec_clock::universal_time(); - pt::time_duration time_dur = time_now - pt::from_time_t(0); - return time_spec_t( - int64_t(time_dur.total_seconds()), - long(time_dur.fractional_seconds()), - double(pt::time_duration::ticks_per_second()) - ); +#include <chrono> + +uhd::time_spec_t uhd::get_system_time(void) +{ + const auto now = std::chrono::steady_clock::now().time_since_epoch(); + const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(now); + const auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(now-seconds); + return uhd::time_spec_t(seconds.count(), nanoseconds.count(), 1e9); } -#endif /* HAVE_MICROSEC_CLOCK */ - diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 769c09796..e476eb61b 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -157,6 +157,12 @@ UHD_ADD_NONAPI_TEST( ) UHD_ADD_NONAPI_TEST( + TARGET "system_time_test.cpp" + EXTRA_SOURCES + "${CMAKE_SOURCE_DIR}/lib/utils/system_time.cpp" +) + +UHD_ADD_NONAPI_TEST( TARGET "nocscript_ftable_test.cpp" EXTRA_SOURCES ${CMAKE_SOURCE_DIR}/lib/rfnoc/nocscript/function_table.cpp diff --git a/host/tests/system_time_test.cpp b/host/tests/system_time_test.cpp index 3f4f8a814..5e39604c8 100644 --- a/host/tests/system_time_test.cpp +++ b/host/tests/system_time_test.cpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: GPL-3.0+ // -#include "system_time.hpp" #include <uhd/types/time_spec.hpp> +#include <uhdlib/utils/system_time.hpp> #include <boost/test/unit_test.hpp> #include <chrono> #include <cstdint> |