Changeset 2167

Show
Ignore:
Timestamp:
06/19/12 05:10:51 (8 years ago)
Author:
jwoithe
Message:

Possibly address ticket #242. Libraw1394 2.1.0 will introduce a new raw1394_read_cycle_timer_and_clock() which permits a choice of the clock to use. If this function is available, use it in preference to raw1394_read_cycle_timer(). By using CLOCK_MONOTONIC_RAW we should avoid timing glitches induced by NTP.
This patch exploits weak linkage to permit ffado to compile and run against all versions libraw1394 regardless of which is present on the runtime system. Correct behaviour with pre-2.1.0 libraw1394 has been verified. Testing with libraw1394 2.1.0 (when it's released) will be needed to confirm that the logic of this patch works as expected.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r2164 r2167  
    4747#include <iostream> 
    4848#include <iomanip> 
     49 
     50// Permit linking against older libraw1394 which didn't include this 
     51// function. 
     52#ifdef __GNUC__ 
     53  #ifdef __APPLE__ 
     54  #define WEAK_ATTRIBUTE weak_import 
     55  #else 
     56  #define WEAK_ATTRIBUTE __weak__ 
     57  #endif 
     58  int raw1394_read_cycle_timer_and_clock(raw1394handle_t handle, 
     59      u_int32_t *cycle_timer, u_int64_t *local_time, clockid_t clk_id) 
     60      __attribute__((WEAK_ATTRIBUTE)); 
     61#endif 
    4962 
    5063using namespace std; 
     
    318331    uint32_t cycle_timer; 
    319332    uint64_t local_time; 
     333    m_have_read_ctr_and_clock = false; 
    320334    err = raw1394_read_cycle_timer(m_util_handle, &cycle_timer, &local_time); 
    321335    if(err) { 
     
    330344        m_have_new_ctr_read = false; 
    331345    } else { 
    332         debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n"); 
    333346        m_have_new_ctr_read = true; 
     347 
     348        // Only if raw1394_read_cycle_timer() is present is it worth even 
     349        // considering the option that raw1394_read_cycle_timer_and_clock() 
     350        // might be available. 
     351        if (raw1394_read_cycle_timer_and_clock != NULL) { 
     352            err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC_RAW); 
     353            if (!err) 
     354                m_have_read_ctr_and_clock = true; 
     355        } 
     356 
     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 { 
     360            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"); 
     362            debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n"); 
     363            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"); 
     365        } 
    334366    } 
    335367 
     
    504536Ieee1394Service::readCycleTimerReg(uint32_t *cycle_timer, uint64_t *local_time) 
    505537{ 
     538    if (m_have_read_ctr_and_clock) { 
     539        int err; 
     540        err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time, CLOCK_MONOTONIC_RAW); 
     541        if(err) { 
     542            debugWarning("raw1394_read_cycle_timer_and_clock: %s\n", strerror(err)); 
     543            return false; 
     544        } 
     545        return true; 
     546    } else 
    506547    if(m_have_new_ctr_read) { 
    507548        int err; 
  • trunk/libffado/src/libieee1394/ieee1394service.h

    r1660 r2167  
    461461    CycleTimerHelper*       m_pCTRHelper; 
    462462    bool                    m_have_new_ctr_read; 
     463    bool                    m_have_read_ctr_and_clock; 
    463464 
    464465    bool            m_filterFCPResponse;