Changeset 782

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

fix mutex macro's; don't run thread in old_style mode

Files:

Legend:

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

    r767 r782  
    4242*/ 
    4343#define ENTER_CRITICAL_SECTION { \ 
    44     ENTER_CRITICAL_SECTION; \ 
     44    pthread_mutex_lock(&m_compute_vars_lock); \ 
    4545    } 
    4646#define EXIT_CRITICAL_SECTION { \ 
    47     EXIT_CRITICAL_SECTION; \ 
    48     } 
    49  
     47    pthread_mutex_unlock(&m_compute_vars_lock); \ 
     48    } 
     49 
     50#define OLD_STYLE 
    5051 
    5152IMPL_DEBUG_MODULE( CycleTimerHelper, CycleTimerHelper, DEBUG_LEVEL_NORMAL ); 
     
    99100{ 
    100101    debugOutput( DEBUG_LEVEL_VERBOSE, "Start %p...\n", this); 
     102#ifndef OLD_STYLE 
    101103    m_Thread = new Util::PosixThread(this, m_realtime, m_priority,  
    102104                                     PTHREAD_CANCEL_DEFERRED); 
     
    109111        return false; 
    110112    } 
     113#endif 
    111114    return true; 
    112115} 
     
    127130    m_priority = priority; 
    128131 
     132#ifndef OLD_STYLE 
    129133    if (m_Thread) { 
    130134        if (m_realtime) { 
     
    134138        } 
    135139    } 
     140#endif 
    136141    return true; 
    137142} 
     
    152157} 
    153158 
    154 #define OLD_STYLE 
    155159#ifdef OLD_STYLE 
    156160 
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r777 r782  
    5757    , m_base_priority ( 0 ) 
    5858    , m_pIsoManager( new IsoHandlerManager( *this ) ) 
    59     , m_pCTRHelper ( new CycleTimerHelper( *this, 1000 ) ) 
     59    , m_pCTRHelper ( new CycleTimerHelper( *this, 10000 ) ) 
    6060    , m_have_new_ctr_read ( false ) 
    6161    , m_pTimeSource ( new Util::SystemTimeSource() ) 
     
    100100Ieee1394Service::~Ieee1394Service() 
    101101{ 
     102    delete m_pIsoManager; 
    102103    delete m_pCTRHelper; 
    103     delete m_pIsoManager; 
    104104    stopRHThread(); 
    105105    for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); 
  • trunk/libffado/src/libieee1394/IsoHandlerManager.cpp

    r776 r782  
    330330        // setup the optimal parameters for the raw1394 ISO buffering 
    331331        unsigned int packets_per_period = stream->getPacketsPerPeriod(); 
    332  
    333 #if 1 
    334         // hardware interrupts occur when one DMA block is full, and the size of one DMA 
    335         // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq 
    336         // occurs at a period boundary (optimal CPU use) 
    337  
    338         // NOTE: try and use MINIMUM_INTERRUPTS_PER_PERIOD hardware interrupts 
    339         //       per period for better latency. 
    340         unsigned int max_packet_size=(MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize()/2) / packets_per_period; 
    341  
    342         if (max_packet_size < stream->getMaxPacketSize()) { 
    343             debugWarning("calculated max packet size (%u) < stream max packet size (%u)\n", 
    344                          max_packet_size ,(unsigned int)stream->getMaxPacketSize()); 
    345             max_packet_size = stream->getMaxPacketSize(); 
     332        unsigned int max_packet_size = stream->getMaxPacketSize(); 
     333        unsigned int page_size = getpagesize() - 2; // for one reason or another this is necessary 
     334 
     335        // hardware interrupts can only occur when one DMA descriptor is full,  
     336        // and the size of one DMA descriptor in bufferfill mode is PAGE_SIZE. 
     337        // the number of packets that fits into this descriptor is dependent on 
     338        // the max_packet_size parameter:  
     339        // packets_per_descriptor = PAGE_SIZE / max_packet_size 
     340        // 
     341        // Hence if we want N hardware IRQ's in one period, we have to ensure that 
     342        // there are at least N descriptors for one period worth of packets 
     343        // hence: 
     344        // packets_per_interrupt = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD 
     345        // packets_per_descriptor <= packets_per_interrupt 
     346        // 
     347        // or: 
     348        // => PAGE_SIZE / max_packet_size <= packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD 
     349        // => PAGE_SIZE * MINIMUM_INTERRUPTS_PER_PERIOD / packets_per_period <= max_packet_size 
     350 
     351        unsigned int min_max_packet_size=(MINIMUM_INTERRUPTS_PER_PERIOD * page_size) / packets_per_period; 
     352 
     353        if (max_packet_size < min_max_packet_size) { 
     354            debugOutput(DEBUG_LEVEL_VERBOSE, "correcting stream max packet size (%u) to (%u) to ensure enough interrupts\n", 
     355                         max_packet_size, min_max_packet_size); 
     356            max_packet_size = min_max_packet_size; 
    346357        } 
    347358 
    348359        // Ensure we don't request a packet size bigger than the 
    349360        // kernel-enforced maximum which is currently 1 page. 
    350         if (max_packet_size > (unsigned int)getpagesize()/2) { 
    351             debugError("max packet size (%u) > page size (%u)\n", max_packet_size, (unsigned int)getpagesize()/2); 
     361        if (max_packet_size > page_size) { 
     362            debugError("max packet size (%u) > page size (%u)\n", max_packet_size, page_size); 
    352363            return false; 
    353364        } 
     
    355366        unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
    356367        if(irq_interval <= 0) irq_interval=1; 
    357         // FIXME: test 
    358 //        irq_interval=1; 
    359  
    360 #else 
    361         // hardware interrupts occur when one DMA block is full, and the size of one DMA 
    362         // block = PAGE_SIZE. Setting the max_packet_size enables control over the IRQ 
    363         // frequency, as the controller uses max_packet_size, and not the effective size 
    364         // when writing to the DMA buffer. 
    365  
    366         // configure it such that we have an irq for every PACKETS_PER_INTERRUPT packets 
    367         unsigned int irq_interval = packets_per_period/MINIMUM_INTERRUPTS_PER_PERIOD; 
    368         if(irq_interval <= 0) irq_interval = 1; 
    369  
    370         unsigned int max_packet_size = getpagesize()/2; 
    371  
    372         if (max_packet_size < stream->getMaxPacketSize()) { 
    373             debugError("Stream max packet size too large: %d\n", stream->getMaxPacketSize()); 
    374             return false; 
    375         } 
    376  
    377 #endif 
    378         /* the receive buffer size doesn't matter for the latency, 
    379            but it has a minimal value in order for libraw to operate correctly (300) */ 
     368 
     369        // the receive buffer size doesn't matter for the latency, 
     370        // but it has a minimal value in order for libraw to operate correctly (300) 
    380371        int buffers=400; 
    381         //max_packet_size = getpagesize(); // HACK 
    382         //irq_interval=2; // HACK 
     372 
    383373        // create the actual handler 
    384374        h = new IsoHandler(*this, IsoHandler::eHT_Receive, 
     
    395385        // setup the optimal parameters for the raw1394 ISO buffering 
    396386        unsigned int packets_per_period = stream->getPacketsPerPeriod(); 
    397  
    398 #if 0 
    399         // hardware interrupts occur when one DMA block is full, and the size of one DMA 
    400         // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq 
    401         // occurs at a period boundary (optimal CPU use) 
    402         // NOTE: try and use MINIMUM_INTERRUPTS_PER_PERIOD interrupts per period 
    403         //       for better latency. 
    404         unsigned int max_packet_size=MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize() / packets_per_period; 
    405         if (max_packet_size < stream->getMaxPacketSize()) { 
    406             max_packet_size = stream->getMaxPacketSize(); 
     387        unsigned int max_packet_size = stream->getMaxPacketSize(); 
     388        unsigned int page_size = getpagesize() - 2; // for one reason or another this is necessary 
     389 
     390        // hardware interrupts can only occur when one DMA descriptor is full,  
     391        // and the size of one DMA descriptor in bufferfill mode is PAGE_SIZE. 
     392        // the number of packets that fits into this descriptor is dependent on 
     393        // the max_packet_size parameter:  
     394        // packets_per_descriptor = PAGE_SIZE / max_packet_size 
     395        // 
     396        // Hence if we want N hardware IRQ's in one period, we have to ensure that 
     397        // there are at least N descriptors for one period worth of packets 
     398        // hence: 
     399        // packets_per_interrupt = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD 
     400        // packets_per_descriptor <= packets_per_interrupt 
     401        // 
     402        // or: 
     403        // => PAGE_SIZE / max_packet_size <= packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD 
     404        // => PAGE_SIZE * MINIMUM_INTERRUPTS_PER_PERIOD / packets_per_period <= max_packet_size 
     405 
     406        unsigned int min_max_packet_size=(MINIMUM_INTERRUPTS_PER_PERIOD * page_size) / packets_per_period; 
     407 
     408        if (max_packet_size < min_max_packet_size) { 
     409            debugOutput(DEBUG_LEVEL_VERBOSE, "correcting stream max packet size (%u) to (%u) to ensure enough interrupts\n", 
     410                         max_packet_size, min_max_packet_size); 
     411            max_packet_size = min_max_packet_size; 
    407412        } 
    408413 
    409414        // Ensure we don't request a packet size bigger than the 
    410415        // kernel-enforced maximum which is currently 1 page. 
    411         if (max_packet_size > (unsigned int)getpagesize()) 
    412                     max_packet_size = getpagesize(); 
    413  
    414          unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
    415          if(irq_interval <= 0) irq_interval = 1; 
    416  
    417         // the transmit buffer size should be as low as possible for latency. 
    418         // note however that the raw1394 subsystem tries to keep this buffer 
    419         // full, so we have to make sure that we have enough events in our 
    420         // event buffers 
    421  
    422         // FIXME: latency spoiler 
    423         // every irq_interval packets an interrupt will occur. that is when 
    424         // buffers get transfered, meaning that we should have at least some 
    425         // margin here 
    426         //irq_interval=2; 
    427         //int buffers=30; 
    428         //max_packet_size = getpagesize(); // HACK 
    429 #else 
    430         // configure it such that we have an irq for every PACKETS_PER_INTERRUPT packets 
    431         unsigned int irq_interval = packets_per_period/MINIMUM_INTERRUPTS_PER_PERIOD; 
    432         if(irq_interval <= 0) irq_interval = 1; 
    433  
    434         unsigned int max_packet_size=MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize() / packets_per_period; 
    435         if (max_packet_size < stream->getMaxPacketSize()) { 
    436             max_packet_size = stream->getMaxPacketSize(); 
    437         } 
    438  
    439         if (max_packet_size < stream->getMaxPacketSize()) { 
    440             debugError("Max packet size too large! (%d)\n", stream->getMaxPacketSize()); 
    441         } 
    442   //      irq_interval=2; 
    443 #endif 
    444         // the SP specifies how many packets to buffer 
     416        if (max_packet_size > page_size) { 
     417            debugError("max packet size (%u) > page size (%u)\n", max_packet_size, page_size); 
     418            return false; 
     419        } 
     420 
     421        unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
     422        if(irq_interval <= 0) irq_interval=1; 
     423 
     424        // the SP specifies how many packets to ISO-buffer 
    445425        int buffers = stream->getNbPacketsIsoXmitBuffer(); 
    446426