Changeset 2186

Show
Ignore:
Timestamp:
07/17/12 05:57:11 (8 years ago)
Author:
jwoithe
Message:

More tweaks in the interests of ticket #242. If the monotonic and monotonic-raw clock rates differ significantly, relative sleeps using the monotonic clock will not necessarily give the sleep time expected from the rest of the system if the montonic-raw clock is in use. Therefore we'll try using just CLOCK_MONOTONIC and see how that goes. This patch also enables the ABS_TIMER sleep mode if available and selected via config.h. Note that even before it was unconditionally disabled in r2173 the ABS_TIMER functionality wasn't being used because config.h wasn't included until r2174.

Files:

Legend:

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

    r2177 r2186  
    351351        // might be available. 
    352352        if (raw1394_read_cycle_timer_and_clock != NULL) { 
    353             err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC_RAW); 
    354             if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC_RAW)==true) 
     353            err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC); 
     354            if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC)==true) 
    355355                m_have_read_ctr_and_clock = true; 
    356356        } 
     
    358358        if (m_have_read_ctr_and_clock) { 
    359359            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"); 
     360            debugOutput(DEBUG_LEVEL_VERBOSE, "CLOCK_MONOTONIC clock source; using them.\n"); 
    361361        } else { 
    362362            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n"); 
    363             debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC_RAW\n"); 
     363            debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC\n"); 
    364364            debugOutput(DEBUG_LEVEL_NORMAL, "clock source is not available.\n"); 
    365365            debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n"); 
  • trunk/libffado/src/libutil/SystemTimeSource.cpp

    r2174 r2186  
    8585SystemTimeSource::SleepUsecAbsolute(ffado_microsecs_t wake_at_usec) 
    8686{ 
    87 // If the system time is based on CLOCK_MONOTONIC_RAW we can't use 
    88 // TIMER_ABSTIME because wake_at_usec will be in terms of 
    89 // CLOCK_MONOTONIC_RAW while clock_nanosleep() can at best use only 
    90 // CLOCK_MONOTONIC.  There is, AFAIK, no guarantee that the two are even 
    91 // remotely related.  For now, resolve this problem by unconditionally 
    92 // disabling the use of TIMER_ABSTIME here, regardless of the setting of 
    93 // USE_ABSOLUTE_NANOSLEEP.  Jonathan Woithe, 25 June 2012. 
    94 #if USE_ABSOLUTE_NANOSLEEP && 0 
    95     // CLOCK_MONOTONIC_RAW isn't supported by clock_nanosleep() 
    96     clockid_t clk = (clock_id==CLOCK_MONOTONIC_RAW)?CLOCK_MONOTONIC:clock_id; 
    97     struct timespec ts; 
    98     ts.tv_sec = wake_at_usec / (1000000LL); 
    99     ts.tv_nsec = (wake_at_usec % (1000000LL)) * 1000LL; 
    100     debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
     87#if USE_ABSOLUTE_NANOSLEEP 
     88    // If the system time is based on CLOCK_MONOTONIC_RAW we can't use 
     89    // TIMER_ABSTIME even if it is available because wake_at_usec will be in 
     90    // terms of CLOCK_MONOTONIC_RAW while clock_nanosleep() can at best use 
     91    // only CLOCK_MONOTONIC.  There is, AFAIK, no guarantee that the two are 
     92    // even remotely related.  For now, resolve this problem by only using 
     93    // TIMER_ABSTIME when CLOCK_MONOTONIC_RAW is not in use. 
     94    if (clock_id != CLOCK_MONOTONIC_RAW) { 
     95        struct timespec ts; 
     96        ts.tv_sec = wake_at_usec / (1000000LL); 
     97        ts.tv_nsec = (wake_at_usec % (1000000LL)) * 1000LL; 
     98        debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
    10199                       "clock_nanosleep until %"PRId64" sec, %"PRId64" nanosec\n", 
    102100                       (int64_t)ts.tv_sec, (int64_t)ts.tv_nsec); 
    103     int err = clock_nanosleep(clk, TIMER_ABSTIME, &ts, NULL); 
    104     if(err) { 
    105         // maybe signal occurred, but we're going to ignore that 
     101        int err = clock_nanosleep(clock_id, TIMER_ABSTIME, &ts, NULL); 
     102        if(err) { 
     103            // maybe signal occurred, but we're going to ignore that 
     104        } 
     105        debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "back with err=%d\n", err); 
     106    } else 
     107#endif 
     108    { 
     109        // only sleep if needed 
     110        ffado_microsecs_t now = getCurrentTime(); 
     111        if(wake_at_usec >= now) { 
     112            ffado_microsecs_t to_sleep = wake_at_usec - now; 
     113            SleepUsecRelative(to_sleep); 
     114        } 
    106115    } 
    107     debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
    108                 "back with err=%d\n", 
    109                 err); 
    110 #else 
    111     // only sleep if needed 
    112     ffado_microsecs_t now = getCurrentTime(); 
    113     if(wake_at_usec >= now) { 
    114         ffado_microsecs_t to_sleep = wake_at_usec - now; 
    115         SleepUsecRelative(to_sleep); 
    116     } 
    117 #endif 
    118116} 
    119117 
  • trunk/libffado/src/libutil/SystemTimeSource.h

    r2171 r2186  
    3333 
    3434// Ensure this is defined even for kernels/glib versions which don't include 
    35 // it.  This allows compile-time testing for the feature. 
     35// it.  This allows runtime-time testing for the feature. 
    3636#ifndef CLOCK_MONOTONIC_RAW 
    3737#define CLOCK_MONOTONIC_RAW 4