Index: trunk/libffado/src/libieee1394/ieee1394service.cpp =================================================================== --- trunk/libffado/src/libieee1394/ieee1394service.cpp (revision 2167) +++ trunk/libffado/src/libieee1394/ieee1394service.cpp (revision 2171) @@ -2,4 +2,5 @@ * Copyright (C) 2005-2008 by Daniel Wagner * Copyright (C) 2005-2008 by Pieter Palmers + * Copyright (C) 2012 by Jonathan Woithe * * This file is part of FFADO @@ -351,16 +352,19 @@ if (raw1394_read_cycle_timer_and_clock != NULL) { err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC_RAW); - if (!err) + if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC_RAW)==true) m_have_read_ctr_and_clock = true; } - if (m_have_read_ctr_and_clock) - debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call, using it.\n"); - else { + if (m_have_read_ctr_and_clock) { + debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call and the\n"); + debugOutput(DEBUG_LEVEL_VERBOSE, "CLOCK_MONOTONIC_RAW clock source; using them.\n"); + } else { debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n"); - debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call is not available.\n"); + debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC_RAW\n"); + debugOutput(DEBUG_LEVEL_NORMAL, "clock source is not available.\n"); debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n"); debugOutput(DEBUG_LEVEL_NORMAL, "FFADO may be susceptible to NTP-induced clock discontinuities.\n"); - debugOutput(DEBUG_LEVEL_NORMAL, "Upgrade libraw1394 to version 2.1.0 or later if this is an issue.\n"); + debugOutput(DEBUG_LEVEL_NORMAL, "If this is an issue, upgrade libraw1394 to version 2.1.0 or later and/or\n"); + debugOutput(DEBUG_LEVEL_NORMAL, "kernel 2.6.28 or later.\n"); } } @@ -538,5 +542,6 @@ if (m_have_read_ctr_and_clock) { int err; - err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time, CLOCK_MONOTONIC_RAW); + err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time, + Util::SystemTimeSource::getSource()); if(err) { debugWarning("raw1394_read_cycle_timer_and_clock: %s\n", strerror(err)); Index: trunk/libffado/src/libieee1394/IsoHandlerManager.cpp =================================================================== --- trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 2076) +++ trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 2171) @@ -398,5 +398,5 @@ int result; - if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { + if (Util::SystemTimeSource::clockGettime(&ts) == -1) { debugError("clock_gettime failed\n"); return eAR_Error; Index: trunk/libffado/src/libstreaming/StreamProcessorManager.cpp =================================================================== --- trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (revision 2107) +++ trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (revision 2171) @@ -164,5 +164,5 @@ if (m_activity_wait_timeout_nsec >= 0) { - if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { + if (Util::SystemTimeSource::clockGettime(&ts) == -1) { debugError("clock_gettime failed\n"); return eAR_Error; Index: trunk/libffado/src/debugmodule/debugmodule.cpp =================================================================== --- trunk/libffado/src/debugmodule/debugmodule.cpp (revision 1999) +++ trunk/libffado/src/debugmodule/debugmodule.cpp (revision 2171) @@ -27,4 +27,5 @@ #include #include "libutil/ByteSwap.h" +#include "libutil/Time.h" #include @@ -180,5 +181,5 @@ // add a timing timestamp struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); + Util::SystemTimeSource::clockGettime(&ts); uint64_t ts_usec=(uint64_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL); Index: trunk/libffado/src/libutil/PosixMessageQueue.cpp =================================================================== --- trunk/libffado/src/libutil/PosixMessageQueue.cpp (revision 1255) +++ trunk/libffado/src/libutil/PosixMessageQueue.cpp (revision 2171) @@ -26,4 +26,5 @@ #include "Functors.h" #include "PosixMutex.h" +#include "Time.h" #include @@ -197,5 +198,5 @@ while(countMessages()) { struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); + Util::SystemTimeSource::clockGettime(&timeout); timeout.tv_sec += m_timeout.tv_sec; timeout.tv_nsec += m_timeout.tv_nsec; @@ -247,5 +248,5 @@ struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); + Util::SystemTimeSource::clockGettime(&timeout); timeout.tv_sec += m_timeout.tv_sec; timeout.tv_nsec += m_timeout.tv_nsec; @@ -293,5 +294,5 @@ struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); + Util::SystemTimeSource::clockGettime(&timeout); timeout.tv_sec += m_timeout.tv_sec; timeout.tv_nsec += m_timeout.tv_nsec; Index: trunk/libffado/src/libutil/SystemTimeSource.cpp =================================================================== --- trunk/libffado/src/libutil/SystemTimeSource.cpp (revision 1763) +++ trunk/libffado/src/libutil/SystemTimeSource.cpp (revision 2171) @@ -1,4 +1,5 @@ /* * Copyright (C) 2005-2008 by Pieter Palmers + * Copytight (C) 2012 by Jonathan Woithe * * This file is part of FFADO @@ -37,4 +38,31 @@ namespace Util { +static clockid_t clock_id = CLOCK_REALTIME; + +bool +SystemTimeSource::setSource(clockid_t id) +{ + struct timespec tp; + // Determine at runtime whether the kernel has support for the + // requested clock source. + if (clock_gettime(id, &tp) == 0) { + clock_id = id; + return true; + } + return false; +} + +clockid_t +SystemTimeSource::getSource(void) +{ + return clock_id; +} + +int +SystemTimeSource::clockGettime(struct timespec *tp) +{ + return clock_gettime(clock_id, tp); +} + void SystemTimeSource::SleepUsecRelative(ffado_microsecs_t usecs) @@ -44,5 +72,5 @@ ts.tv_sec = usecs / (1000000LL); ts.tv_nsec = (usecs % (1000000LL)) * 1000LL; - clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); + clock_nanosleep(clock_id, 0, &ts, NULL); } @@ -57,5 +85,5 @@ "clock_nanosleep until %"PRId64" sec, %"PRId64" nanosec\n", (int64_t)ts.tv_sec, (int64_t)ts.tv_nsec); - int err = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL); + int err = clock_nanosleep(clock_id, TIMER_ABSTIME, &ts, NULL); if(err) { // maybe signal occurred, but we're going to ignore that @@ -95,5 +123,5 @@ { struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); + clock_gettime(clock_id, &ts); return (ffado_microsecs_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL); } Index: trunk/libffado/src/libutil/SystemTimeSource.h =================================================================== --- trunk/libffado/src/libutil/SystemTimeSource.h (revision 1568) +++ trunk/libffado/src/libutil/SystemTimeSource.h (revision 2171) @@ -1,4 +1,5 @@ /* * Copyright (C) 2005-2008 by Pieter Palmers + * Copyright (C) 2012 by Jonathan Woithe * * This file is part of FFADO @@ -31,4 +32,10 @@ typedef uint64_t ffado_microsecs_t; +// Ensure this is defined even for kernels/glib versions which don't include +// it. This allows compile-time testing for the feature. +#ifndef CLOCK_MONOTONIC_RAW +#define CLOCK_MONOTONIC_RAW 4 +#endif + namespace Util { @@ -40,4 +47,8 @@ public: + static bool setSource(clockid_t id); + static clockid_t getSource(void); + static int clockGettime(struct timespec *tp); + static ffado_microsecs_t getCurrentTime(); static ffado_microsecs_t getCurrentTimeAsUsecs(); Index: trunk/libffado/src/bebob/bebob_dl_mgr.cpp =================================================================== --- trunk/libffado/src/bebob/bebob_dl_mgr.cpp (revision 2019) +++ trunk/libffado/src/bebob/bebob_dl_mgr.cpp (revision 2171) @@ -575,5 +575,5 @@ struct timespec timeout; int retcode; - clock_gettime(CLOCK_REALTIME, &timeout); + Util::SystemTimeSource::clockGettime(&timeout); do { printf(".");