Skip to content

Commit

Permalink
Optionally use CLOCK_BOOTTIME for monotonic time
Browse files Browse the repository at this point in the history
  • Loading branch information
mitza-oci committed Feb 26, 2024
1 parent d139fe7 commit 8506a96
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
10 changes: 8 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ my @specs = # Array of array-refs, each inner array is an option group which
'macros=s@', 'Extra text for platform_macros.GNU',
'features=s@', 'Extra text for default.features',
'mpcopts=s@', 'Extra command-line args for MPC',
'boottime|boottime!', 'Use CLOCK_BOOTTIME as the monotonic time source',
],
['Optional dependencies for OpenDDS (disabled by default unless noted otherwise):',
'java:s', 'Java development kit (use JAVA_HOME)',
Expand Down Expand Up @@ -1344,10 +1345,15 @@ sub write_opendds_configh {
my $CFGIN = new FileHandle;
open($CFGIN, 'dds/OpenDDSConfig.h.in') or die("Can't open OpenDDSConfig.h.in for reading: $!\nStopped");

my %config = (
'OPENDDS_CONFIG_AUTO_STATIC_INCLUDES' => 0,
'OPENDDS_CONFIG_MONOTONIC_USES_BOOTTIME' => $opts{'boottime'} // 0,
);

sub replace_value {
my $var = shift;
return '0' if $var eq 'OPENDDS_CONFIG_AUTO_STATIC_INCLUDES';
return 'UNDEFINED';
return 'UNDEFINED_NEED_TO_UPDATE_CONFIGURE_SCRIPT' unless exists $config{$var};
return $config{$var};
}

while (<$CFGIN>) {
Expand Down
27 changes: 27 additions & 0 deletions dds/DCPS/TimeTypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <DCPS/DdsDcps_pch.h> // Only the _pch include should start with DCPS/

#include "TimeTypes.h"

#include <ace/os_include/os_time.h>

OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
namespace OpenDDS {
namespace DCPS {

#if OPENDDS_CONFIG_MONOTONIC_USES_BOOTTIME

ACE_Time_Value_T<BootTimePolicy> BootTimePolicy::operator()() const
{
timespec ts;
if (0 == ::clock_gettime(CLOCK_BOOTTIME, &ts)) {
return ACE_Time_Value_T<BootTimePolicy>(ts);
}

return ACE_Time_Value_T<BootTimePolicy>(ACE_Time_Value::zero);
}

#endif

}
}
OPENDDS_END_VERSIONED_NAMESPACE_DECL
18 changes: 16 additions & 2 deletions dds/DCPS/TimeTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef OPENDDS_DCPS_TIMETYPES_H
#define OPENDDS_DCPS_TIMETYPES_H

#include "Definitions.h"
#include "TimeDuration.h"
#include "TimePoint_T.h"

Expand Down Expand Up @@ -35,15 +36,28 @@ typedef TimePoint_T<SystemClock> SystemTimePoint;
/**
* ACE_Time_Policy that OpenDDS uses for internal timing.
*
* ACE_Monotonic_Time_Policy protects OpenDDS from being effected by changes to
* MonotonicClock protects OpenDDS from being affected by changes to
* the system clock to a certain degree.
*
* CLOCK_BOOTTIME is a monotonic clock that includes the time the system is suspended.
* If OPENDDS_CONFIG_MONOTONIC_USES_BOOTTIME is true, CLOCK_BOOTTIME will be
* used in place of CLOCK_MONOTONIC on platforms that support it. The types
* used by OpenDDS are still named MonotonicClock and MonotonicTimePoint.
*/
///@{
#if defined(ACE_HAS_MONOTONIC_TIME_POLICY) && defined(ACE_HAS_MONOTONIC_CONDITIONS)
# define OPENDDS_USES_MONOTONIC_TIME
#endif

#ifdef OPENDDS_USES_MONOTONIC_TIME
#if OPENDDS_CONFIG_MONOTONIC_USES_BOOTTIME

struct BootTimePolicy {
ACE_Time_Value_T<BootTimePolicy> operator()() const;
void set_gettimeofday(ACE_Time_Value (*)()) {} // see comment in ace/Monotonic_Time_Policy.h
};

typedef BootTimePolicy MonotonicClock;
#elif defined OPENDDS_USES_MONOTONIC_TIME
typedef ACE_Monotonic_Time_Policy MonotonicClock;
#else
typedef SystemClock MonotonicClock;
Expand Down
2 changes: 2 additions & 0 deletions dds/OpenDDSConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@

#define OPENDDS_CONFIG_AUTO_STATIC_INCLUDES @OPENDDS_CONFIG_AUTO_STATIC_INCLUDES@

#define OPENDDS_CONFIG_MONOTONIC_USES_BOOTTIME @OPENDDS_CONFIG_MONOTONIC_USES_BOOTTIME@

#endif

0 comments on commit 8506a96

Please sign in to comment.