Changeset 783

Show
Ignore:
Timestamp:
12/29/07 02:18:54 (15 years ago)
Author:
ppalmers
Message:

cleanup time/wait/sleep code

Files:

Legend:

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

    r742 r783  
    3030 
    3131#include "libutil/cmd_serialize.h" 
     32#include "libutil/Time.h" 
    3233 
    3334#include <netinet/in.h> 
     
    436437            break; 
    437438        } 
    438         usleep( 100 ); 
     439        SleepRelativeUsec( 100 ); 
    439440 
    440441        if ( !readResponse( ccBlock ) ) { 
  • trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp

    r750 r783  
    2525#include "focusrite_cmd.h" 
    2626 
     27#include "libutil/Time.h" 
     28 
    2729namespace BeBoB { 
    2830namespace Focusrite { 
     
    385387 
    386388                // the device needs quite some time to reboot 
    387                 usleep(2 * 1000 * 1000); 
     389                SleepRelativeUsec(2 * 1000 * 1000); 
    388390 
    389391                int timeout = 5; // multiples of 1s 
     
    393395                { 
    394396                    // wait for a while 
    395                     usleep(1000 * 1000); 
     397                    SleepRelativeUsec(1000 * 1000); 
    396398                } 
    397399                if (!timeout) { 
     
    400402 
    401403                    // the device needs quite some time to reboot 
    402                     usleep(2 * 1000 * 1000); 
     404                    SleepRelativeUsec(2 * 1000 * 1000); 
    403405 
    404406                    // wait for the device to finish the reboot 
     
    408410                    { 
    409411                        // wait for a while 
    410                         usleep(1000 * 1000); 
     412                        SleepRelativeUsec(1000 * 1000); 
    411413                    } 
    412414                    if (!timeout) { 
     
    425427 
    426428                    // wait for a while 
    427                     usleep(4 * 1000 * 1000); 
     429                    SleepRelativeUsec(4 * 1000 * 1000); 
    428430                } while (gen_current != get1394Service().getGeneration() 
    429431                         && --timeout); 
     
    438440 
    439441                // wait some more 
    440                 usleep(1 * 1000 * 1000); 
     442                SleepRelativeUsec(1 * 1000 * 1000); 
    441443 
    442444                // we have to rediscover the device 
  • trunk/libffado/src/bounce/bounce_slave_avdevice.cpp

    r742 r783  
    2727#include "libieee1394/configrom.h" 
    2828#include "libieee1394/ieee1394service.h" 
     29 
     30#include "libutil/Time.h" 
    2931 
    3032#include "bounce_slave_avdevice.h" 
     
    313315            return false; 
    314316        } 
    315         usleep(100000); 
     317        SleepRelativeUsec(100000); 
    316318    } 
    317319 
  • trunk/libffado/src/libavc/general/avc_generic.cpp

    r742 r783  
    2727 
    2828#include "debugmodule/debugmodule.h" 
     29 
     30#include "libutil/Time.h" 
    2931 
    3032#include <netinet/in.h> 
     
    265267    m_p1394Service->transactionBlockClose(); 
    266268 
    267     usleep( m_time ); 
     269    SleepRelativeUsec( m_time ); 
    268270 
    269271    return result; 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r779 r783  
    2828#include "devicemanager.h" 
    2929 
     30#include "libutil/Time.h" 
     31 
    3032#include "libieee1394/ieee1394service.h" 
    3133#include "libieee1394/IsoHandlerManager.h" 
     
    180182 
    181183            // for example: 
    182             // usleep(125); // one cycle 
     184            // SleepRelativeUsec(125); // one cycle 
    183185            // goto try_block_of_frames; 
    184186 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp

    r776 r783  
    3030#include "libieee1394/IsoHandlerManager.h" 
    3131#include "libieee1394/cycletimer.h" 
     32 
     33#include "libutil/Time.h" 
    3234 
    3335#include "libutil/Atomic.h" 
     
    923925    int cnt = timeout_ms; 
    924926    while (m_state != state && cnt) { 
    925         usleep(1000); 
     927        SleepRelativeUsec(1000); 
    926928        cnt--; 
    927929    } 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r776 r783  
    2626#include "generic/Port.h" 
    2727#include "libieee1394/cycletimer.h" 
     28 
     29#include "libutil/Time.h" 
    2830 
    2931#include <errno.h> 
     
    263265        } 
    264266 
    265         usleep(125); 
     267        SleepRelativeUsec(125); 
    266268        cnt--; 
    267269    } 
     
    332334        if(time_till_next_period > 0) { 
    333335            // wait for the period 
    334             usleep(time_till_next_period); 
     336            SleepRelativeUsec(time_till_next_period); 
    335337        } 
    336338    } 
     
    412414    int cnt = CYCLES_FOR_STARTUP * 20; // by then it should have started 
    413415    while (!m_SyncSource->isRunning() && cnt) { 
    414         usleep(125); 
     416        SleepRelativeUsec(125); 
    415417        cnt--; 
    416418    } 
     
    557559            ready &= ((*it)->isDryRunning() || (*it)->isStopped()); 
    558560        } 
    559         usleep(125); 
     561        SleepRelativeUsec(125); 
    560562        cnt--; 
    561563    } 
     
    597599            ready &= (*it)->isStopped(); 
    598600        } 
    599         usleep(125); 
     601        SleepRelativeUsec(125); 
    600602        cnt--; 
    601603    } 
     
    670672 
    671673        // wait for the period 
    672         usleep(time_till_next_period); 
     674        SleepRelativeUsec(time_till_next_period); 
    673675 
    674676        // check for underruns on the ISO side, 
     
    737739        if (!ready_for_transfer) { 
    738740             
    739             usleep(125); // MAGIC: one cycle sleep... 
     741            SleepRelativeUsec(125); // MAGIC: one cycle sleep... 
    740742 
    741743            // in order to avoid this in the future, we increase the sync delay of the sync source SP 
  • trunk/libffado/src/libutil/SystemTimeSource.cpp

    r742 r783  
    3838 
    3939ffado_microsecs_t SystemTimeSource::getCurrentTime() { 
    40     struct timeval tv; 
    41     gettimeofday(&tv, NULL); 
    42     return tv.tv_sec * 1000000ULL + tv.tv_usec; 
    43  
    44 //     return GetMicroSeconds(); 
     40//     struct timeval tv; 
     41//     gettimeofday(&tv, NULL); 
     42//     return tv.tv_sec * 1000000ULL + tv.tv_usec; 
     43    struct timespec ts; 
     44    clock_gettime(CLOCK_MONOTONIC, &ts); 
     45    return (ffado_microsecs_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL); 
    4546} 
    4647 
  • trunk/libffado/src/libutil/Time.c

    r742 r783  
    2222 */ 
    2323 
    24 /* 
    25  * Copied from the jackd/jackdmp sources 
    26  * function names changed in order to avoid naming problems when using this in 
    27  * a jackd backend. 
    28  */ 
    29  
    30 /* Original license: 
    31  * 
    32  *  Copyright (C) 2001 Paul Davis 
    33  *  Copyright (C) 2004-2006 Grame 
    34  * 
    35  *  This program is free software; you can redistribute it and/or modify 
    36  *  it under the terms of the GNU General Public License as published by 
    37  *  the Free Software Foundation; either version 2 of the License, or 
    38  *  (at your option) any later version. 
    39  * 
    40  *  This program is distributed in the hope that it will be useful, 
    41  *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    42  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    43  *  GNU General Public License for more details. 
    44  * 
    45  *  You should have received a copy of the GNU General Public License 
    46  *  along with this program; if not, write to the Free Software 
    47  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
    48  * 
    49  */ 
    5024#include "Time.h" 
    5125 
    52 #ifdef GETCYCLE_TIME 
    53  
    54 #include <stdio.h> 
    55 freebob_microsecs_t GetMhz(void) 
    56 { 
    57         FILE *f = fopen("/proc/cpuinfo", "r"); 
    58         if (f == 0) 
    59         { 
    60                 perror("can't open /proc/cpuinfo\n"); 
    61                 exit(1); 
    62         } 
    63  
    64         for ( ; ; ) 
    65         { 
    66                 freebob_microsecs_t mhz; 
    67                 int ret; 
    68                 char buf[1000]; 
    69  
    70                 if (fgets(buf, sizeof(buf), f) == NULL) { 
    71                         fprintf (stderr,"FATAL: cannot locate cpu MHz in " 
    72                                     "/proc/cpuinfo\n"); 
    73                         exit(1); 
    74                 } 
    75  
    76 #if defined(__powerpc__) 
    77                 ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz); 
    78 #elif defined( __i386__ ) || defined (__hppa__)  || defined (__ia64__) || \ 
    79       defined(__x86_64__) 
    80                 ret = sscanf(buf, "cpu MHz         : %" SCNu64, &mhz); 
    81 #elif defined( __sparc__ ) 
    82                 ret = sscanf(buf, "Cpu0Bogo        : %" SCNu64, &mhz); 
    83 #elif defined( __mc68000__ ) 
    84                 ret = sscanf(buf, "Clocking:       %" SCNu64, &mhz); 
    85 #elif defined( __s390__  ) 
    86                 ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz); 
    87 #else /* MIPS, ARM, alpha */ 
    88                 ret = sscanf(buf, "BogoMIPS        : %" SCNu64, &mhz); 
    89 #endif  
    90                 if (ret == 1) 
    91                 { 
    92                         fclose(f); 
    93                         return (freebob_microsecs_t)mhz; 
    94                 } 
    95         } 
    96 } 
    97  
    98 freebob_microsecs_t __freebob_cpu_mhz; 
    99  
    100 void InitTime() 
    101 { 
    102         __freebob_cpu_mhz = GetMhz(); 
    103 } 
    104  
    105 #else 
    106 void InitTime() 
    107 {} 
    108  
    109 #endif  
    110  
  • trunk/libffado/src/libutil/Time.h

    r742 r783  
    2222 */ 
    2323 
    24 /* 
    25  * Copied from the jackd/jackdmp sources 
    26  * function names changed in order to avoid naming problems when using this in 
    27  * a jackd backend. 
    28  */ 
    29  
    30 /* Original license: 
    31  * 
    32  *  Copyright (C) 2001-2003 Paul Davis 
    33  *  Copyright (C) 2004-2006 Grame 
    34  * 
    35  *  This program is free software; you can redistribute it and/or modify 
    36  *  it under the terms of the GNU General Public License as published by 
    37  *  the Free Software Foundation; either version 2 of the License, or 
    38  *  (at your option) any later version. 
    39  * 
    40  *  This program is distributed in the hope that it will be useful, 
    41  *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    42  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    43  *  GNU General Public License for more details. 
    44  * 
    45  *  You should have received a copy of the GNU General Public License 
    46  *  along with this program; if not, write to the Free Software 
    47  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
    48  * 
    49  */ 
    50  
    5124#ifndef __Time__ 
    5225#define __Time__ 
     
    5427#include <stdio.h> 
    5528#include <inttypes.h> 
     29#include <unistd.h> 
    5630 
    57 // #define GETCYCLE_TIME 
     31#include <time.h> 
    5832 
    5933/** 
     
    6135 * monotonic clock with units of microseconds. 
    6236 */ 
    63  
    6437typedef uint64_t ffado_microsecs_t; 
    6538 
    66  
    67 #ifdef __cplusplus 
    68 extern "C" 
    69 
    70 #endif 
    71  
    72  
    73 #include <unistd.h> 
    74  
    75     static inline void FFADOSleep(long usec) { 
    76         usleep(usec); 
    77     } 
    78  
    79 #ifdef GETCYCLE_TIME 
    80     #include "cycles.h" 
    81     extern ffado_microsecs_t __ffado_cpu_mhz; 
    82     extern ffado_microsecs_t GetMhz(); 
    83     extern void InitTime(); 
    84     static inline ffado_microsecs_t GetMicroSeconds (void) { 
    85         return get_cycles() / __ffado_cpu_mhz; 
    86     } 
    87 #else 
    88     #include <time.h> 
    89     extern void InitTime(); 
    90     static inline ffado_microsecs_t GetMicroSeconds (void) { 
    91         struct timespec ts; 
    92         clock_gettime(CLOCK_MONOTONIC, &ts); 
    93         return (ffado_microsecs_t)ts.tv_sec * 1000000LL + ts.tv_nsec / 1000; 
    94     } 
    95 #endif 
    96  
    97  
    98 #ifdef __cplusplus 
     39static inline void SleepRelativeUsec(unsigned long usec) { 
     40    usleep(usec); 
    9941} 
    10042#endif 
    10143 
    10244 
    103 #endif 
    10445 
    105  
    106  
  • trunk/libffado/src/motu/motu_avdevice.cpp

    r750 r783  
    3737 
    3838#include "libutil/DelayLockedLoop.h" 
     39#include "libutil/Time.h" 
    3940 
    4041#include <string> 
     
    959960  } 
    960961 
    961   usleep(100); 
     962  SleepRelativeUsec(100); 
    962963  return (err==0)?0:-1; 
    963964} 
  • trunk/libffado/support/dbus/controlserver.cpp

    r742 r783  
    2626#include "libcontrol/BasicElements.h" 
    2727#include "libcontrol/MatrixMixer.h" 
     28#include "libutil/Time.h" 
    2829 
    2930namespace DBusControl { 
     
    172173    m_Slave.setValue(value); 
    173174/*     
    174     usleep(1000*500); 
     175    SleepRelativeUsec(1000*500); 
    175176     
    176177    debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%lf) => %lf\n", value, m_Slave.getValue() ); 
     
    202203    m_Slave.setValue(value); 
    203204     
    204 /*    usleep(1000*500); 
     205/*    SleepRelativeUsec(1000*500); 
    205206    debugOutput( DEBUG_LEVEL_VERBOSE, "setValue(%d) => %d\n", value, m_Slave.getValue() ); 
    206207     
  • trunk/libffado/tests/streaming/teststreaming3.c

    r750 r783  
    3737 
    3838#include <signal.h> 
     39#include <sched.h> 
    3940 
    4041#include "libffado/ffado.h" 
     
    4748{ 
    4849        run = 0; 
     50        set_realtime_priority(0); 
     51} 
     52 
     53int set_realtime_priority(unsigned int prio) 
     54{ 
     55  if (prio > 0) { 
     56    struct sched_param schp; 
     57    /* 
     58     * set the process to realtime privs 
     59     */ 
     60    memset(&schp, 0, sizeof(schp)); 
     61    schp.sched_priority = prio; 
     62     
     63    if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { 
     64      perror("sched_setscheduler"); 
     65      exit(1); 
     66    } 
     67  } else { 
     68        struct sched_param schp; 
     69        /* 
     70        * set the process to realtime privs 
     71        */ 
     72        memset(&schp, 0, sizeof(schp)); 
     73        schp.sched_priority = prio; 
     74         
     75        if (sched_setscheduler(0, SCHED_OTHER, &schp) != 0) { 
     76        perror("sched_setscheduler"); 
     77        exit(1); 
     78        } 
     79     
     80  } 
     81  return 0; 
    4982} 
    5083 
     
    69102        run=1; 
    70103 
    71         printf("Ffado streaming test application (3)\n"); 
     104        printf("FFADO streaming test application (3)\n"); 
    72105 
    73106        signal (SIGINT, sighandler); 
     
    86119 
    87120        dev_options.realtime=1; 
    88         dev_options.packetizer_priority=70; 
     121        dev_options.packetizer_priority=60; 
    89122         
    90123        dev_options.verbose = 6; 
     
    203236        start_flag = ffado_streaming_start(dev); 
    204237 
     238        set_realtime_priority(dev_options.packetizer_priority-1); 
    205239        fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 
    206240        while(run && start_flag==0) { 
  • trunk/libffado/tests/test-echo.cpp

    r742 r783  
    2626#include <libiec61883/iec61883.h> 
    2727#include <libavc1394/avc1394.h> 
     28#include "libutil/Time.h" 
    2829 
    2930#include <argp.h> 
     
    145146//     cmd[1] = 0x01FF0000; 
    146147//     avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); 
    147 //     usleep(100000);  
     148//     SleepRelativeUsec(100000);  
    148149//      
    149150//     cerr << "Reading descriptor" << endl; 
     
    156157//       
    157158//     avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 3, &response_len, 10); 
    158 //     usleep(100000); 
     159//     SleepRelativeUsec(100000); 
    159160//      
    160161//     cerr << "Closing descriptor" << endl; 
     
    162163//     cmd[1] = 0x00FF0000; 
    163164//     avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); 
    164 //     usleep(100000); 
     165//     SleepRelativeUsec(100000); 
    165166 
    166167    cerr << "getting signal source" << endl; 
     
    196197    cmd[1] = 0xFFFE6000; 
    197198    avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); 
    198 //     usleep(100000); 
     199//     SleepRelativeUsec(100000); 
    199200     
    200201    cmd[0] = 0x01FF1AFF; 
    201202    cmd[1] = 0xFFFEFF00; 
    202203    avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); 
    203     usleep(100000); 
     204    SleepRelativeUsec(100000); 
    204205 
    205206 
  • trunk/libffado/tests/test-focusrite.cpp

    r742 r783  
    3232#include "libutil/cmd_serialize.h" 
    3333#include "libavc/general/avc_generic.h" 
     34#include "libutil/Time.h" 
    3435 
    3536#include "bebob/focusrite/focusrite_cmd.h" 
     
    191192            } 
    192193        } 
    193         usleep(1000000); 
     194        SleepRelativeUsec(1000000); 
    194195    } 
    195196 
  • trunk/libffado/tests/test-ieee1394service.cpp

    r752 r783  
    4444 
    4545#include <libraw1394/raw1394.h> 
     46#include "libutil/Time.h" 
    4647 
    4748DECLARE_GLOBAL_DEBUG_MODULE; 
     
    130131        fflush(stderr); 
    131132        fflush(stdout); 
    132         usleep(900*1000); 
     133        SleepRelativeUsec(900*1000); 
    133134 
    134135        uint32_t cycle_timer; 
  • trunk/libffado/tests/test-timestampedbuffer.cpp

    r748 r783  
    4040 
    4141#include "src/libutil/TimestampedBuffer.h" 
     42#include "libutil/Time.h" 
    4243 
    4344#include <pthread.h> 
     
    297298    t->prepare(); 
    298299 
    299     usleep(1000); 
     300    SleepRelativeUsec(1000); 
    300301 
    301302    debugOutput(DEBUG_LEVEL_NORMAL, "Start setBufferHeadTimestamp test...\n"); 
     
    365366 
    366367            // allow for the messagebuffer thread to catch up 
    367             usleep(200); 
     368            SleepRelativeUsec(200); 
    368369 
    369370            if(!run) break; 
     
    480481 
    481482            // allow for the messagebuffer thread to catch up 
    482             usleep(200); 
     483            SleepRelativeUsec(200); 
    483484 
    484485            if(!run) break; 
     
    580581 
    581582            // allow for the messagebuffer thread to catch up 
    582             usleep(200); 
     583            SleepRelativeUsec(200); 
    583584 
    584585            if(!run) break;