Fixed burst mode timing problem by taking into account overhead

This commit is contained in:
Srivats P. 2011-06-26 10:33:06 +05:30
parent 955be71082
commit aae32eb510
2 changed files with 33 additions and 14 deletions

View File

@ -314,13 +314,13 @@ bool PcapPort::PortTransmitter::appendToPacketList(long sec, long usec,
if ((sendQ == NULL) || if ((sendQ == NULL) ||
(sendQ->len + 2*sizeof(pcap_pkthdr) + length) > sendQ->maxlen) (sendQ->len + 2*sizeof(pcap_pkthdr) + length) > sendQ->maxlen)
{ {
// Add a zero len packet at end of sendQ for inter-sendQ timing // Add a zero len packet at end of sendQ for inter-sendQ timing
if (sendQ) if (sendQ)
{ {
pcap_pkthdr hdr = pktHdr; pcap_pkthdr hdr = pktHdr;
hdr.caplen = 0; hdr.caplen = 0;
pcap_sendqueue_queue(sendQ, &hdr, (u_char*)packet); pcap_sendqueue_queue(sendQ, &hdr, (u_char*)packet);
} }
//! \todo (LOW): calculate sendqueue size //! \todo (LOW): calculate sendqueue size
sendQ = pcap_sendqueue_alloc(1*1024*1024); sendQ = pcap_sendqueue_alloc(1*1024*1024);
sendQueueList_.append(sendQ); sendQueueList_.append(sendQ);
@ -369,6 +369,7 @@ void PcapPort::PortTransmitter::run()
const int kSyncTransmit = 1; const int kSyncTransmit = 1;
int i; int i;
long overHead = 0;
qDebug("sendQueueList_.size = %d", sendQueueList_.size()); qDebug("sendQueueList_.size = %d", sendQueueList_.size());
if (sendQueueList_.size() <= 0) if (sendQueueList_.size() <= 0)
@ -378,11 +379,13 @@ void PcapPort::PortTransmitter::run()
{ {
int ret; int ret;
_restart: _restart:
ret = sendQueueTransmit(handle_, sendQueueList_.at(i), kSyncTransmit); ret = sendQueueTransmit(handle_, sendQueueList_.at(i), overHead,
kSyncTransmit);
if (ret < 0) if (ret < 0)
{ {
qDebug("error %d in sendQueueTransmit()", ret); qDebug("error %d in sendQueueTransmit()", ret);
qDebug("overHead = %ld", overHead);
stop_ = false; stop_ = false;
return; return;
} }
@ -390,10 +393,17 @@ _restart:
if (returnToQIdx_ >= 0) if (returnToQIdx_ >= 0)
{ {
i = returnToQIdx_; long usecs = loopDelay_ + overHead;
if (loopDelay_) if (usecs > 0)
udelay(loopDelay_); {
udelay(usecs);
overHead = 0;
}
else
overHead = usecs;
i = returnToQIdx_;
goto _restart; goto _restart;
} }
} }
@ -405,7 +415,7 @@ void PcapPort::PortTransmitter::stop()
} }
int PcapPort::PortTransmitter::sendQueueTransmit(pcap_t *p, int PcapPort::PortTransmitter::sendQueueTransmit(pcap_t *p,
pcap_send_queue *queue, int sync) pcap_send_queue *queue, long &overHead, int sync)
{ {
TimeStamp ovrStart, ovrEnd; TimeStamp ovrStart, ovrEnd;
struct timeval ts; struct timeval ts;
@ -427,9 +437,15 @@ int PcapPort::PortTransmitter::sendQueueTransmit(pcap_t *p,
getTimeStamp(&ovrEnd); getTimeStamp(&ovrEnd);
usec -= udiffTimeStamp(&ovrStart, &ovrEnd); overHead -= udiffTimeStamp(&ovrStart, &ovrEnd);
usec += overHead;
if (usec > 0) if (usec > 0)
{
udelay(usec); udelay(usec);
overHead = 0;
}
else
overHead = usec;
ts = hdr->ts; ts = hdr->ts;
getTimeStamp(&ovrStart); getTimeStamp(&ovrStart);
@ -471,6 +487,8 @@ void PcapPort::PortTransmitter::udelay(long usec)
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
struct timeval delay, target, now; struct timeval delay, target, now;
//qDebug("usec delay = %ld", usec);
delay.tv_sec = 0; delay.tv_sec = 0;
delay.tv_usec = usec; delay.tv_usec = usec;

View File

@ -107,7 +107,8 @@ protected:
void stop(); void stop();
private: private:
void udelay(long usec); void udelay(long usec);
int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue, int sync); int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue, long &overHead,
int sync);
quint64 ticksFreq_; quint64 ticksFreq_;
QList<pcap_send_queue*> sendQueueList_; QList<pcap_send_queue*> sendQueueList_;