LCOV - code coverage report
Current view: top level - core/src/arch - timer.h Hit Total Coverage
Test: ROOT-Sim master Documentation Coverage Lines: 2 2 100.0 %
Date: 2021-03-25 15:11:55

          Line data    Source code
       1           1 : /**
       2             :  * @file arch/timer.h
       3             :  *
       4             :  * @brief Timers
       5             :  *
       6             :  * This header defines the timers which the simulator uses to monitor its
       7             :  * internal behaviour
       8             :  *
       9             :  * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com>
      10             :  * SPDX-License-Identifier: GPL-3.0-only
      11             :  */
      12             : #pragma once
      13             : 
      14             : #include <arch/platform.h>
      15             : 
      16             : #include <stdint.h>
      17             : #include <time.h>
      18             : 
      19             : /** The type used to store results of timer related calls */
      20           1 : typedef uint_fast64_t timer_uint;
      21             : 
      22             : #ifdef __POSIX
      23             : #include <sys/time.h>
      24             : 
      25             : inline timer_uint timer_new(void)
      26             : {
      27             :         struct timeval tmptv;
      28             :         gettimeofday(&tmptv, NULL);
      29             :         return (timer_uint) tmptv.tv_sec * 1000000U + tmptv.tv_usec;
      30             : }
      31             : 
      32             : inline timer_uint timer_value(timer_uint start)
      33             : {
      34             :         return timer_new() - start;
      35             : }
      36             : 
      37             : #endif
      38             : 
      39             : #ifdef __WINDOWS
      40             : #include <windows.h>
      41             : 
      42             : extern timer_uint timer_perf_freq;
      43             : 
      44             : inline timer_uint timer_new(void)
      45             : {
      46             :         LARGE_INTEGER __start_time;
      47             :         QueryPerformanceCounter(&__start_time);
      48             :         return (timer_uint)__start_time.QuadPart;
      49             : }
      50             : 
      51             : 
      52             : inline timer_uint timer_value(timer_uint start)
      53             : {
      54             :         if (unlikely(timer_perf_freq == 0)) {
      55             :                 LARGE_INTEGER __perf;
      56             :                 QueryPerformanceFrequency(&__perf);
      57             :                 timer_perf_freq = __perf.QuadPart;
      58             :         }
      59             :         return (timer_new() - start) / timer_perf_freq;
      60             : }
      61             : 
      62             : #endif
      63             : 

Generated by: LCOV version 1.14