Changeset 796

Show
Ignore:
Timestamp:
01/01/08 11:31:39 (14 years ago)
Author:
ppalmers
Message:

- move #define constants to config.h.in
- switch receive handler over to packet-per-buffer mode to improve latency performance

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/config.h.in

    r756 r796  
    3636#define SHAREDIR "$sharedir" 
    3737 
     38#define MINIMUM_INTERRUPTS_PER_PERIOD   4U 
     39#define MAX_ISO_XMIT_BUFFER_FILL_PCT    70 
     40 
     41#define ISOHANDLER_PER_HANDLER_THREAD   0 
     42#define ISOHANDLER_USE_POLL             0 
     43 
     44#define ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT         16 
     45 
     46// allows to add some processing margin. This shifts the time 
     47// at which the buffer is transfer()'ed, making things somewhat 
     48// more robust. It should be noted though that shifting the transfer 
     49// time to a later time instant also causes the xmit buffer fill to be 
     50// lower on average. 
     51#define STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS           (3072*1) 
     52 
     53#define STREAMPROCESSORMANAGER_CYCLES_FOR_DRYRUN            40000 
     54#define STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP           2000 
     55#define STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT     20 
     56#define STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV     0 
     57#define STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC      200 
     58#define STREAMPROCESSORMANAGER_NB_ALIGN_TRIES               40 
     59 
     60 
     61// FIXME: note that it will probably be better to use a DLL bandwidth that is  
     62//        dependant on the sample rate 
     63#define TIMESTAMPEDBUFFER_DLL_BANDWIDTH                     (0.01) 
     64 
     65// in ticks 
     66// as per AMDTP2.1: 
     67// 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks 
     68#define AMDTP_TRANSMIT_TRANSFER_DELAY   (11776U) 
     69 
     70#define MOTU_TRANSMIT_TRANSFER_DELAY    (11776U) 
     71 
    3872#endif // CONFIG_H 
  • trunk/libffado/src/libieee1394/IsoHandler.cpp

    r791 r796  
    2222 */ 
    2323 
    24 //#define PER_HANDLER_THREAD 
     24#include "config.h" 
    2525 
    2626#include "IsoHandler.h" 
     
    183183    } 
    184184 
    185 #ifdef DO_POLL 
     185#if ISOHANDLER_USE_POLL 
    186186    uint64_t poll_enter = m_manager.get1394Service().getCurrentTimeAsUsecs(); 
    187187    err = poll(&m_poll_fd, 1, m_poll_timeout); 
     
    228228bool 
    229229IsoHandler::iterate() { 
    230     flush(); 
     230    //flush(); 
    231231    if(raw1394_loop_iterate(m_handle)) { 
    232232        debugOutput( DEBUG_LEVEL_VERBOSE, 
     
    288288    } 
    289289 
    290 #ifdef THREAD_PER_ISOHANDLER 
     290#if ISOHANDLER_PER_HANDLER_THREAD 
    291291    // create a thread to iterate ourselves 
    292292    debugOutput( DEBUG_LEVEL_VERBOSE, "Start thread for %p...\n", this); 
     
    471471                                    m_max_packet_size, 
    472472                                    m_Client->getChannel(), 
    473                                     RAW1394_DMA_BUFFERFILL, 
     473//                                     RAW1394_DMA_BUFFERFILL, 
     474                                    RAW1394_DMA_PACKET_PER_BUFFER, 
    474475                                    m_irq_interval)) { 
    475476                debugFatal("Could not do receive initialisation (DMA_BUFFERFILL)!\n" ); 
  • trunk/libffado/src/libieee1394/IsoHandlerManager.cpp

    r791 r796  
    2222 */ 
    2323 
     24#include "config.h" 
    2425#include "IsoHandlerManager.h" 
    2526#include "ieee1394service.h"  
     
    3233 
    3334#include <assert.h> 
    34  
    35 #define MINIMUM_INTERRUPTS_PER_PERIOD  4U 
    3635 
    3736IMPL_DEBUG_MODULE( IsoHandlerManager, IsoHandlerManager, DEBUG_LEVEL_NORMAL ); 
     
    101100    unsigned int i; 
    102101    m_poll_nfds_shadow = m_IsoHandlers.size(); 
    103     if(m_poll_nfds_shadow > FFADO_MAX_ISO_HANDLERS_PER_PORT) { 
     102    if(m_poll_nfds_shadow > ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT) { 
    104103        debugWarning("Too much ISO Handlers in manager...\n"); 
    105         m_poll_nfds_shadow = FFADO_MAX_ISO_HANDLERS_PER_PORT; 
     104        m_poll_nfds_shadow = ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT; 
    106105    } 
    107106    for (i = 0; i < m_poll_nfds_shadow; i++) { 
     
    209208    } 
    210209 
    211 #ifndef THREAD_PER_ISOHANDLER 
     210#if ISOHANDLER_PER_HANDLER_THREAD 
     211#else 
    212212    // create a thread to iterate our handlers 
    213213    debugOutput( DEBUG_LEVEL_VERBOSE, "Start thread for %p...\n", this); 
     
    368368        } 
    369369 
    370         //unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
    371         //if(irq_interval <= 0) irq_interval=1; 
    372         unsigned int irq_interval=2; // this is not the HW IRQ interval 
     370        unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
     371        if(irq_interval <= 0) irq_interval=1; 
     372//         unsigned int irq_interval=2; // this is not the HW IRQ interval 
    373373         
    374374        // the receive buffer size doesn't matter for the latency, 
  • trunk/libffado/src/libieee1394/IsoHandlerManager.h

    r795 r796  
    2525#define __FFADO_ISOHANDLERMANAGER__ 
    2626 
     27#include "config.h" 
     28 
    2729#include "debugmodule/debugmodule.h" 
    2830 
     
    3436#include <vector> 
    3537 
    36 //#define THREAD_PER_ISOHANDLER 
    37  
    38 #define FFADO_MAX_ISO_HANDLERS_PER_PORT 16 
    39  
    40 #define USLEEP_AFTER_UPDATE_FAILURE 10 
    41 #define USLEEP_AFTER_UPDATE 100 
    42 #define MAX_UPDATE_TRIES 10 
    4338class Ieee1394Service; 
    4439 
     
    7469    private: 
    7570        // shadow variables 
    76         struct pollfd m_poll_fds_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT]; 
    77         IsoHandler *m_IsoHandler_map_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT]; 
     71        struct pollfd m_poll_fds_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT]; 
     72        IsoHandler *m_IsoHandler_map_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT]; 
    7873        unsigned int m_poll_nfds_shadow; 
    7974 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r790 r796  
    3737#include <assert.h> 
    3838 
    39 // in ticks 
    40 // as per AMDTP2.1: 
    41 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks 
    42 #define DEFAULT_TRANSFER_DELAY (11776U) 
    43  
    44 #define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY 
    45  
    4639namespace Streaming 
    4740{ 
     
    9083    // a packet ahead of the presentation time. The nominal time 
    9184    // the packet is transmitted ahead of the presentation time is 
    92     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 
     85    // given by AMDTP_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 
    9386    // are too late for that, this constant defines how late we can 
    9487    // be. 
     
    9891    // a packet ahead of the ideal transmit time. The nominal time 
    9992    // the packet is transmitted ahead of the presentation time is 
    100     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 
     93    // given by AMDTP_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 
    10194    // packets early if we want to. (not completely according to spec) 
    10295    const int max_cycles_to_transmit_early = 2; 
     
    114107 
    115108    // now we calculate the time when we have to transmit the sample block 
    116     transmit_at_time = substractTicks ( presentation_time, TRANSMIT_TRANSFER_DELAY ); 
     109    transmit_at_time = substractTicks ( presentation_time, AMDTP_TRANSMIT_TRANSFER_DELAY ); 
    117110 
    118111    // calculate the cycle this block should be presented in 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp

    r795 r796  
    2121 * 
    2222 */ 
     23 
     24#include "config.h" 
    2325 
    2426#include "StreamProcessor.h" 
     
    112114    // in the transmit buffer (the others are still to be put into the xmit frame buffer) 
    113115    unsigned int packets_to_prebuffer = (getPacketsPerPeriod() * (m_StreamProcessorManager.getNbBuffers()-1)); 
     116    debugOutput(DEBUG_LEVEL_VERBOSE, "Nominal prebuffer: %u\n", packets_to_prebuffer); 
    114117     
    115     // however we have to take into account the fact that there is some sync delay (unknown at this point) 
    116     packets_to_prebuffer -= 16; //FIXME: magic 
     118    // however we have to take into account the fact that there is some sync delay 
     119    // we assume that the SPM has indicated 
     120    // HACK: this counts on the fact that the latency for this stream will be the same as the 
     121    //       latency for the receive sync source 
     122    unsigned int est_sync_delay = getPacketsPerPeriod() / MINIMUM_INTERRUPTS_PER_PERIOD; 
     123    est_sync_delay += STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS / TICKS_PER_CYCLE; 
     124    packets_to_prebuffer -= est_sync_delay; 
     125    debugOutput(DEBUG_LEVEL_VERBOSE, " correct for sync delay (%d): %u\n", 
     126                                     est_sync_delay, 
     127                                     packets_to_prebuffer); 
    117128     
    118     // only queue a part (80%) of the theoretical max in order not to have too much 'not ready' cycles 
    119     packets_to_prebuffer = (packets_to_prebuffer * 7000) / 10000; 
     129    // only queue a part (70%) of the theoretical max in order not to have too much 'not ready' cycles 
     130    packets_to_prebuffer = (packets_to_prebuffer * MAX_ISO_XMIT_BUFFER_FILL_PCT * 1000) / 100000; 
     131    debugOutput(DEBUG_LEVEL_VERBOSE, " reduce to %d%%: %u\n", 
     132                                     MAX_ISO_XMIT_BUFFER_FILL_PCT, packets_to_prebuffer); 
    120133     
    121134    return packets_to_prebuffer; 
  • trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

    r753 r796  
    2323 */ 
    2424 
     25#include "config.h" 
     26 
    2527#include "MotuTransmitStreamProcessor.h" 
    2628#include "MotuPort.h" 
     
    3436#include <netinet/in.h> 
    3537#include <assert.h> 
    36  
    37 // in ticks 
    38 // as per AMDTP2.1: 
    39 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks 
    40 #define DEFAULT_TRANSFER_DELAY (11776U) 
    41  
    42 #define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY 
    4338 
    4439// Set to 1 to enable the generation of a 1 kHz test tone in analog output 1 
     
    110105    // a packet ahead of the presentation time. The nominal time 
    111106    // the packet is transmitted ahead of the presentation time is 
    112     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 
     107    // given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 
    113108    // are too late for that, this constant defines how late we can 
    114109    // be. 
     
    118113    // a packet ahead of the ideal transmit time. The nominal time 
    119114    // the packet is transmitted ahead of the presentation time is 
    120     // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 
     115    // given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 
    121116    // packets early if we want to. (not completely according to spec) 
    122117    const int max_cycles_to_transmit_early = 2; 
     
    135130 
    136131    // now we calculate the time when we have to transmit the sample block 
    137     transmit_at_time = substractTicks ( presentation_time, TRANSMIT_TRANSFER_DELAY ); 
     132    transmit_at_time = substractTicks ( presentation_time, MOTU_TRANSMIT_TRANSFER_DELAY ); 
    138133 
    139134    // calculate the cycle this block should be presented in 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r795 r796  
    2121 * 
    2222 */ 
     23#include "config.h" 
    2324 
    2425#include "StreamProcessorManager.h" 
     
    3233#include <assert.h> 
    3334#include <math.h> 
    34  
    35 #define RUNNING_TIMEOUT_MSEC 4000 
    36 #define PREPARE_TIMEOUT_MSEC 4000 
    37 #define ENABLE_TIMEOUT_MSEC 4000 
    38  
    39 // allows to add some processing margin. This shifts the time 
    40 // at which the buffer is transfer()'ed, making things somewhat 
    41 // more robust. It should be noted though that shifting the transfer 
    42 // time to a later time instant also causes the xmit buffer fill to be 
    43 // lower on average. 
    44 #define FFADO_SIGNAL_DELAY_TICKS (3072*1) 
    4535 
    4636namespace Streaming { 
     
    257247    // wait for the syncsource to start running. 
    258248    // that will block the waitForPeriod call until everyone has started (theoretically) 
    259     #define CYCLES_FOR_DRYRUN 40000 
    260     int cnt = CYCLES_FOR_DRYRUN; // by then it should have started 
     249    int cnt = STREAMPROCESSORMANAGER_CYCLES_FOR_DRYRUN; // by then it should have started 
    261250    bool all_dry_running = false; 
    262251    while (!all_dry_running && cnt) { 
     
    319308    // time to a later time instant also causes the xmit buffer fill to be 
    320309    // lower on average. 
    321     max_of_min_delay += FFADO_SIGNAL_DELAY_TICKS; 
     310    max_of_min_delay += STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS; 
    322311    debugOutput( DEBUG_LEVEL_VERBOSE, " sync delay = %d ticks (%03us %04uc %04ut)...\n",  
    323312        max_of_min_delay, 
     
    361350        (unsigned int)TICKS_TO_OFFSET(time_of_first_sample)); 
    362351 
    363     #define CYCLES_FOR_STARTUP 2000 
    364     // start wet-running in CYCLES_FOR_STARTUP cycles 
     352    // start wet-running in STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP cycles 
    365353    // this is the time window we have to setup all SP's such that they  
    366354    // can start wet-running correctly. 
    367355    time_of_first_sample = addTicks(time_of_first_sample, 
    368                                     CYCLES_FOR_STARTUP * TICKS_PER_CYCLE); 
     356                                    STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP * TICKS_PER_CYCLE); 
    369357 
    370358    debugOutput( DEBUG_LEVEL_VERBOSE, "  => first sample at TS=%011llu (%03us %04uc %04ut)...\n",  
     
    376364    // we should start wet-running the transmit SP's some cycles in advance 
    377365    // such that we know it is wet-running when it should output its first sample 
    378     #define PRESTART_CYCLES_FOR_XMIT 20 
    379366    uint64_t time_to_start_xmit = substractTicks(time_of_first_sample,  
    380                                                  PRESTART_CYCLES_FOR_XMIT * TICKS_PER_CYCLE); 
    381  
    382     #define PRESTART_CYCLES_FOR_RECV 0 
     367                                                 STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT * TICKS_PER_CYCLE); 
     368 
    383369    uint64_t time_to_start_recv = substractTicks(time_of_first_sample, 
    384                                                  PRESTART_CYCLES_FOR_RECV * TICKS_PER_CYCLE); 
     370                                                 STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV * TICKS_PER_CYCLE); 
    385371    debugOutput( DEBUG_LEVEL_VERBOSE, "  => xmit starts at  TS=%011llu (%03us %04uc %04ut)...\n",  
    386372        time_to_start_xmit, 
     
    421407    // wait for the syncsource to start running. 
    422408    // that will block the waitForPeriod call until everyone has started (theoretically) 
    423     int cnt = CYCLES_FOR_STARTUP * 20; // by then it should have started 
     409    int cnt = STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP * 20; // by then it should have started 
    424410    while (!m_SyncSource->isRunning() && cnt) { 
    425411        SleepRelativeUsec(125); 
     
    444430{ 
    445431    if(m_SyncSource == NULL) return false; 
    446     #define ALIGN_AVERAGE_TIME_MSEC 200 
    447     #define NB_ALIGN_TRIES 40 
    448432    debugOutput( DEBUG_LEVEL_VERBOSE, "Aligning received streams...\n"); 
    449433    unsigned int nb_sync_runs; 
     
    454438    unsigned int i; 
    455439 
    456     unsigned int periods_per_align_try = (ALIGN_AVERAGE_TIME_MSEC * getNominalRate()); 
     440    unsigned int periods_per_align_try = (STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC * getNominalRate()); 
    457441    periods_per_align_try /= 1000; 
    458442    periods_per_align_try /= getPeriodSize(); 
     
    460444 
    461445    bool aligned = false; 
    462     int cnt = NB_ALIGN_TRIES; 
     446    int cnt = STREAMPROCESSORMANAGER_NB_ALIGN_TRIES; 
    463447    while (!aligned && cnt--) { 
    464448        nb_sync_runs = periods_per_align_try; 
  • trunk/libffado/src/libutil/TimestampedBuffer.cpp

    r795 r796  
    2222 */ 
    2323 
     24#include "config.h" 
     25 
    2426#include "libutil/Atomic.h" 
    2527#include "libieee1394/cycletimer.h" 
     
    2931#include "errno.h" 
    3032 
    31 // FIXME: note that it will probably be better to use a DLL bandwidth that is  
    32 //        dependant on the sample rate 
    33  
    34  
    35 // #define DLL_BANDWIDTH (4800/48000.0) 
    36 #define DLL_BANDWIDTH (0.01) 
     33 
    3734#define DLL_PI        (3.141592653589793238) 
    3835#define DLL_SQRT2     (1.414213562373095049) 
    39 #define DLL_OMEGA     (2.0*DLL_PI*DLL_BANDWIDTH) 
     36#define DLL_OMEGA     (2.0*DLL_PI*TIMESTAMPEDBUFFER_DLL_BANDWIDTH) 
    4037#define DLL_COEFF_B   (DLL_SQRT2 * DLL_OMEGA) 
    4138#define DLL_COEFF_C   (DLL_OMEGA * DLL_OMEGA)