Changeset 2171

Show
Ignore:
Timestamp:
06/23/12 07:03:54 (8 years ago)
Author:
jwoithe
Message:

A second pass at addressing ticket #242. Define a global clock source within the SystemTimeSource? object and use this whenever clock_gettime() is called. On systems which support the new raw1394_read_cycle_timer_and_clock() libraw1394 call and CLOCK_MONOTONIC_RAW, these changes should ensure that all timing-sensitive parts of FFADO are using the same clock source. System tests under tests/systemtests/ have not been converted to use this new framework because they exist for different purposes and are not using the FFADO streaming infrastructure.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/bebob/bebob_dl_mgr.cpp

    r2019 r2171  
    575575    struct timespec timeout; 
    576576    int retcode; 
    577     clock_gettime(CLOCK_REALTIME, &timeout); 
     577    Util::SystemTimeSource::clockGettime(&timeout); 
    578578    do { 
    579579        printf("."); 
  • trunk/libffado/src/debugmodule/debugmodule.cpp

    r1999 r2171  
    2727#include <stdarg.h> 
    2828#include "libutil/ByteSwap.h" 
     29#include "libutil/Time.h" 
    2930 
    3031#include <iostream> 
     
    180181    // add a timing timestamp 
    181182    struct timespec ts; 
    182     clock_gettime(CLOCK_MONOTONIC, &ts); 
     183    Util::SystemTimeSource::clockGettime(&ts); 
    183184    uint64_t ts_usec=(uint64_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL); 
    184185 
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r2167 r2171  
    22 * Copyright (C) 2005-2008 by Daniel Wagner 
    33 * Copyright (C) 2005-2008 by Pieter Palmers 
     4 * Copyright (C) 2012 by Jonathan Woithe 
    45 * 
    56 * This file is part of FFADO 
     
    351352        if (raw1394_read_cycle_timer_and_clock != NULL) { 
    352353            err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC_RAW); 
    353             if (!err
     354            if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC_RAW)==true
    354355                m_have_read_ctr_and_clock = true; 
    355356        } 
    356357 
    357         if (m_have_read_ctr_and_clock) 
    358             debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call, using it.\n"); 
    359         else { 
     358        if (m_have_read_ctr_and_clock) { 
     359            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call and the\n"); 
     360            debugOutput(DEBUG_LEVEL_VERBOSE, "CLOCK_MONOTONIC_RAW clock source; using them.\n"); 
     361        } else { 
    360362            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n"); 
    361             debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call is not available.\n"); 
     363            debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC_RAW\n"); 
     364            debugOutput(DEBUG_LEVEL_NORMAL, "clock source is not available.\n"); 
    362365            debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n"); 
    363366            debugOutput(DEBUG_LEVEL_NORMAL, "FFADO may be susceptible to NTP-induced clock discontinuities.\n"); 
    364             debugOutput(DEBUG_LEVEL_NORMAL, "Upgrade libraw1394 to version 2.1.0 or later if this is an issue.\n"); 
     367            debugOutput(DEBUG_LEVEL_NORMAL, "If this is an issue, upgrade libraw1394 to version 2.1.0 or later and/or\n"); 
     368            debugOutput(DEBUG_LEVEL_NORMAL, "kernel 2.6.28 or later.\n"); 
    365369        } 
    366370    } 
     
    538542    if (m_have_read_ctr_and_clock) { 
    539543        int err; 
    540         err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time, CLOCK_MONOTONIC_RAW); 
     544        err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time,  
     545                  Util::SystemTimeSource::getSource()); 
    541546        if(err) { 
    542547            debugWarning("raw1394_read_cycle_timer_and_clock: %s\n", strerror(err)); 
  • trunk/libffado/src/libieee1394/IsoHandlerManager.cpp

    r2076 r2171  
    398398    int result; 
    399399 
    400     if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { 
     400    if (Util::SystemTimeSource::clockGettime(&ts) == -1) { 
    401401        debugError("clock_gettime failed\n"); 
    402402        return eAR_Error; 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r2107 r2171  
    164164    if (m_activity_wait_timeout_nsec >= 0) { 
    165165 
    166         if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { 
     166        if (Util::SystemTimeSource::clockGettime(&ts) == -1) { 
    167167            debugError("clock_gettime failed\n"); 
    168168            return eAR_Error; 
  • trunk/libffado/src/libutil/PosixMessageQueue.cpp

    r1255 r2171  
    2626#include "Functors.h" 
    2727#include "PosixMutex.h" 
     28#include "Time.h" 
    2829 
    2930#include <errno.h> 
     
    197198    while(countMessages()) { 
    198199        struct timespec timeout; 
    199         clock_gettime(CLOCK_REALTIME, &timeout); 
     200        Util::SystemTimeSource::clockGettime(&timeout); 
    200201        timeout.tv_sec += m_timeout.tv_sec; 
    201202        timeout.tv_nsec += m_timeout.tv_nsec; 
     
    247248 
    248249    struct timespec timeout; 
    249     clock_gettime(CLOCK_REALTIME, &timeout); 
     250    Util::SystemTimeSource::clockGettime(&timeout); 
    250251    timeout.tv_sec += m_timeout.tv_sec; 
    251252    timeout.tv_nsec += m_timeout.tv_nsec; 
     
    293294 
    294295    struct timespec timeout; 
    295     clock_gettime(CLOCK_REALTIME, &timeout); 
     296    Util::SystemTimeSource::clockGettime(&timeout); 
    296297    timeout.tv_sec += m_timeout.tv_sec; 
    297298    timeout.tv_nsec += m_timeout.tv_nsec; 
  • trunk/libffado/src/libutil/SystemTimeSource.cpp

    r1763 r2171  
    11/* 
    22 * Copyright (C) 2005-2008 by Pieter Palmers 
     3 * Copytight (C) 2012 by Jonathan Woithe 
    34 * 
    45 * This file is part of FFADO 
     
    3738namespace Util { 
    3839 
     40static clockid_t clock_id = CLOCK_REALTIME; 
     41 
     42bool 
     43SystemTimeSource::setSource(clockid_t id) 
     44{ 
     45    struct timespec tp; 
     46    // Determine at runtime whether the kernel has support for the 
     47    // requested clock source. 
     48    if (clock_gettime(id, &tp) == 0) { 
     49        clock_id = id; 
     50        return true; 
     51    } 
     52    return false; 
     53} 
     54 
     55clockid_t 
     56SystemTimeSource::getSource(void) 
     57{ 
     58    return clock_id; 
     59} 
     60 
     61int 
     62SystemTimeSource::clockGettime(struct timespec *tp) 
     63{ 
     64    return clock_gettime(clock_id, tp); 
     65} 
     66 
    3967void 
    4068SystemTimeSource::SleepUsecRelative(ffado_microsecs_t usecs) 
     
    4472    ts.tv_sec = usecs / (1000000LL); 
    4573    ts.tv_nsec = (usecs % (1000000LL)) * 1000LL; 
    46     clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); 
     74    clock_nanosleep(clock_id, 0, &ts, NULL); 
    4775} 
    4876 
     
    5785                       "clock_nanosleep until %"PRId64" sec, %"PRId64" nanosec\n", 
    5886                       (int64_t)ts.tv_sec, (int64_t)ts.tv_nsec); 
    59     int err = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL); 
     87    int err = clock_nanosleep(clock_id, TIMER_ABSTIME, &ts, NULL); 
    6088    if(err) { 
    6189        // maybe signal occurred, but we're going to ignore that 
     
    95123{ 
    96124    struct timespec ts; 
    97     clock_gettime(CLOCK_REALTIME, &ts); 
     125    clock_gettime(clock_id, &ts); 
    98126    return (ffado_microsecs_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL); 
    99127} 
  • trunk/libffado/src/libutil/SystemTimeSource.h

    r1568 r2171  
    11/* 
    22 * Copyright (C) 2005-2008 by Pieter Palmers 
     3 * Copyright (C) 2012 by Jonathan Woithe 
    34 * 
    45 * This file is part of FFADO 
     
    3132typedef uint64_t ffado_microsecs_t; 
    3233 
     34// Ensure this is defined even for kernels/glib versions which don't include 
     35// it.  This allows compile-time testing for the feature. 
     36#ifndef CLOCK_MONOTONIC_RAW 
     37#define CLOCK_MONOTONIC_RAW 4 
     38#endif 
     39 
    3340namespace Util { 
    3441 
     
    4047 
    4148public: 
     49    static bool setSource(clockid_t id); 
     50    static clockid_t getSource(void); 
     51    static int clockGettime(struct timespec *tp); 
     52 
    4253    static ffado_microsecs_t getCurrentTime(); 
    4354    static ffado_microsecs_t getCurrentTimeAsUsecs();