vSMC
vSMC: Scalable Monte Carlo
Public Member Functions | List of all members
vsmc::RDTSCPCounter Class Reference

CPU clock cycle counter using rdtscp More...

#include <vsmc/utility/rdtsc.hpp>

Public Member Functions

 RDTSCPCounter ()
 
uint64_t cycles () const
 Return the accumulated elapsed cycle count. More...
 
void reset ()
 Stop and reset the elapsed cycle count to zero. More...
 
bool running () const
 If the counter is running. More...
 
bool start ()
 Start the counter, no effect if already started. More...
 
bool stop ()
 Stop the counter, no effect if already stopped. More...
 

Detailed Description

CPU clock cycle counter using rdtscp

This class shall only be used if RDTSCP is supported. For example,

RDTSCCouner c1;
RDTSCPCouner c2;
CPUID::has_feature<CPUIDFeatureExtRDTSCP>() ? c2.start() : c1.start();

Definition at line 169 of file rdtsc.hpp.

Constructor & Destructor Documentation

vsmc::RDTSCPCounter::RDTSCPCounter ( )
inline

Definition at line 173 of file rdtsc.hpp.

Member Function Documentation

uint64_t vsmc::RDTSCPCounter::cycles ( ) const
inline

Return the accumulated elapsed cycle count.

Definition at line 234 of file rdtsc.hpp.

void vsmc::RDTSCPCounter::reset ( )
inline

Stop and reset the elapsed cycle count to zero.

Definition at line 227 of file rdtsc.hpp.

bool vsmc::RDTSCPCounter::running ( ) const
inline

If the counter is running.

If start() has been called and no stop() call since, then it is running, otherwise it is stoped.

Definition at line 180 of file rdtsc.hpp.

bool vsmc::RDTSCPCounter::start ( )
inline

Start the counter, no effect if already started.

Returns
true if it is started by this call, and the elapsed cycle count will be incremented next time stop() is called. The increment will be relative to the time point of this call. false if it is already started earlier.

Definition at line 188 of file rdtsc.hpp.

bool vsmc::RDTSCPCounter::stop ( )
inline

Stop the counter, no effect if already stopped.

Returns
true if it is stoped by this call, and the elapsed cycle count has been incremented. false in one of the following situations. In all these situations, the elapsed cycle count will not be incremented.
  • It already stopped or wasn't started before.
  • The logical processor has changed since the last successful start() call. The user is repsonsible for assure threads affinity.
  • The cycle count appears to decrease. This is most likely in the case that the TSC MSR has been reset.

Definition at line 210 of file rdtsc.hpp.