Merge changes made in base code for turbo/latency

This commit is contained in:
Srivats P 2023-06-15 12:32:20 +05:30
parent 63ed64a9d2
commit 598e6bf243
13 changed files with 72 additions and 48 deletions

View File

@ -285,7 +285,9 @@ bool SignProtocol::packetTtagId(const uchar *pkt, int pktLen, uint *ttagId, uint
} else if (*p == kTypeLenGuid) {
*guid = qFromBigEndian<quint32>(p - 3) >> 8;
} else if (*p == kTypeLenTxPort) {
#ifdef Q_OS_WIN32
*ttagId |= uint(*(p - 1)) << 8;
#endif
}
p -= 1 + (*p >> 5); // move to next TLV
}

View File

@ -41,12 +41,19 @@ TLVs are encoded as
Len does NOT include the one byte of TypeLen
Size of the value field varies between 0 to 7 bytes
Defined TLVs
Defined TLVs
Type = 0, Len = 0 (0x00): End of TLVs
Type = 1, Len = 3 (0x61): Stream GUID
Type = 2, Len = 1 (0x22): T-Tag Placeholder (0 value)
Type = 3, Len = 1 (0x23): T-Tag with actual value
Type = 4, Len = 1 (0x24): Tx Port Id
Order of TLVs from end of packet towards beginning [Offset, Size]
[ -4, 4 bytes] Magic
[ -6, 2 bytes] TTag (Placeholder or actual)
[-10, 4 bytes] Stream Guid
[-12, 2 bytes] Tx Port Id
[-13, 1 byte ] End
*/
class SignProtocol : public AbstractProtocol

View File

@ -245,6 +245,7 @@ int AbstractPort::updatePacketListSequential()
quint64 duration = 0; // in nanosec
quint64 totalPkts = 0;
QList<uint> ttagMarkers;
uint ttagRepeatInterval;
FrameValueAttrib packetListAttrib;
long sec = 0;
long nsec = 0;
@ -443,12 +444,17 @@ int AbstractPort::updatePacketListSequential()
} // if (stream is enabled)
} // for (numStreams)
_out_of_memory:
_stop_no_more_pkts:
// See comments in updatePacketListInterleaved() for calc explanation
setPacketListTtagMarkers(ttagMarkers, ttagMarkers.isEmpty() ? 0 :
qMax(uint(kTtagTimeInterval_*1e9/(duration)),
1U) * totalPkts);
ttagRepeatInterval = ttagMarkers.isEmpty() ? 0 :
qMax(uint(kTtagTimeInterval_*1e9/(duration)), 1U)
* totalPkts;
if (!setPacketListTtagMarkers(ttagMarkers, ttagRepeatInterval)) {
clearPacketList(); // don't leave it half baked/inconsitent
packetListAttrib.errorFlags |= FrameValueAttrib::OutOfMemoryError;
}
_out_of_memory:
isSendQueueDirty_ = false;
qDebug("PacketListAttrib = %x",
@ -657,12 +663,11 @@ int AbstractPort::updatePacketListInterleaved()
// Count total packets we are going to add, so that we can create
// an explicit packet set first
// TODO: Find less expensive way to do this counting
// FIXME: Turbo still thinks it has to create implicit packet set for
// interleaved mode - Turbo code should be changed once this is validated
quint64 totalPkts = 0;
QVector<ulong> ttagSchedSec(numStreams, 0);
QVector<ulong> ttagSchedNsec(numStreams, 0);
QList<uint> ttagMarkers;
uint ttagRepeatInterval;
do
{
@ -817,10 +822,13 @@ int AbstractPort::updatePacketListInterleaved()
// CASE 2. pktListDuration > kTtagTimeInterval:
// e.g. if pktListDuration is 7sec and TtagTimerInterval is 5s, we
// skip repeat markers every pktList iteration
setPacketListTtagMarkers(ttagMarkers, ttagMarkers.isEmpty() ? 0 :
qMax(uint(kTtagTimeInterval_*1e9
/(durSec*1e9+durNsec)),
1U) * totalPkts);
ttagRepeatInterval = ttagMarkers.isEmpty() ? 0 :
qMax(uint(kTtagTimeInterval_*1e9/(durSec*1e9+durNsec)), 1U)
* totalPkts;
if (!setPacketListTtagMarkers(ttagMarkers, ttagRepeatInterval)) {
clearPacketList(); // don't leave it half baked/inconsitent
packetListAttrib.errorFlags |= FrameValueAttrib::OutOfMemoryError;
}
_out_of_memory:
isSendQueueDirty_ = false;

View File

@ -107,7 +107,7 @@ public:
int length) = 0;
virtual void setPacketListLoopMode(bool loop,
quint64 secDelay, quint64 nsecDelay) = 0;
virtual void setPacketListTtagMarkers(QList<uint> markers,
virtual bool setPacketListTtagMarkers(QList<uint> markers,
uint repeatInterval) = 0;
int updatePacketList();

View File

@ -63,10 +63,10 @@ public:
{
transmitter_->setPacketListLoopMode(loop, secDelay, nsecDelay);
}
virtual void setPacketListTtagMarkers(QList<uint> markers,
virtual bool setPacketListTtagMarkers(QList<uint> markers,
uint repeatInterval)
{
transmitter_->setPacketListTtagMarkers(markers, repeatInterval);
return transmitter_->setPacketListTtagMarkers(markers, repeatInterval);
}
virtual void startTransmit() {
@ -173,6 +173,8 @@ protected:
PortMonitor *monitorRx_;
PortMonitor *monitorTx_;
PcapRxStats *rxStatsPoller_;
void updateNotes();
private:
@ -183,7 +185,6 @@ private:
PortCapturer *capturer_;
EmulationTransceiver *emulXcvr_;
PcapTxTtagStats *txTtagStatsPoller_;
PcapRxStats *rxStatsPoller_;
static pcap_if_t *deviceList_;
};

View File

@ -134,14 +134,10 @@ _skip_filter:
&& (ttagId >> 8 != uint(portId_))) {
ttagId &= 0xFF;
timing_->recordRxTime(portId_, guid, ttagId, hdr->ts);
timingDebug("[%d RX] %ld:%ld ttag %u guid %u", portId_,
hdr->ts.tv_sec, long(hdr->ts.tv_usec), ttagId, guid);
}
#else
if (SignProtocol::packetTtagId(data, hdr->caplen, &ttagId, &guid)) {
timing_->recordRxTime(portId_, guid, ttagId, hdr->ts);
timingDebug("[%d RX] %ld:%ld ttag %u guid %u", portId_,
hdr->ts.tv_sec, long(hdr->ts.tv_usec), ttagId, guid);
}
#endif
if (guid != SignProtocol::kInvalidGuid) {

View File

@ -88,11 +88,11 @@ void PcapTransmitter::setPacketListLoopMode(
txThread_.setPacketListLoopMode(loop, secDelay, nsecDelay);
}
void PcapTransmitter::setPacketListTtagMarkers(
bool PcapTransmitter::setPacketListTtagMarkers(
QList<uint> markers,
uint repeatInterval)
{
txThread_.setPacketListTtagMarkers(markers, repeatInterval);
return txThread_.setPacketListTtagMarkers(markers, repeatInterval);
}
void PcapTransmitter::useExternalStats(AbstractPort::PortStats *stats)

View File

@ -42,7 +42,7 @@ public:
bool appendToPacketList(long sec, long usec, const uchar *packet,
int length);
void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay);
void setPacketListTtagMarkers(QList<uint> markers, uint repeatInterval);
bool setPacketListTtagMarkers(QList<uint> markers, uint repeatInterval);
void setHandle(pcap_t *handle);
void useExternalStats(AbstractPort::PortStats *stats);

View File

@ -112,25 +112,6 @@ void PcapTxThread::clearPacketList()
void PcapTxThread::loopNextPacketSet(qint64 size, qint64 repeats,
long repeatDelaySec, long repeatDelayNsec)
{
#if 0 // Don't let implicit packet sets be created
// XXX: The below change was done as part of Turbo code
// implementation alongwith calls to this function from
// AbstractPort::updatePacketListSequential(). Turbo to
// have clean code requires explicit packet sets for all
// cases (except interleaved streams). The below change
// was done so that the base code should not be affected
// after the explict packet set creation calls.
// XXX: Since we create implicit packetset for this case, skip
// This case =>
// 1. Packet set for y when x = 0
// 2. n==1 in n*x+y
// These two cases were the result of the changes in
// updatePacketListSequential() as part of Turbo changes
// mentioned above
if (repeats == 1)
return;
#endif
currentPacketSequence_ = new PacketSequence(trackStreamStats_);
currentPacketSequence_->repeatCount_ = repeats;
currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6)
@ -221,7 +202,7 @@ void PcapTxThread::setPacketListLoopMode(
loopDelay_ = secDelay*long(1e6) + nsecDelay/1000;
}
void PcapTxThread::setPacketListTtagMarkers(
bool PcapTxThread::setPacketListTtagMarkers(
QList<uint> markers,
uint repeatInterval)
{
@ -239,7 +220,7 @@ void PcapTxThread::setPacketListTtagMarkers(
qDebug() << "FirstTtagPkt:" << firstTtagPkt_;
qDebug() << "TtagMarkers:" << ttagDeltaMarkers_;
}
return true;
}
void PcapTxThread::setHandle(pcap_t *handle)

View File

@ -42,7 +42,7 @@ public:
bool appendToPacketList(long sec, long usec, const uchar *packet,
int length);
void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay);
void setPacketListTtagMarkers(QList<uint> markers, uint repeatInterval);
bool setPacketListTtagMarkers(QList<uint> markers, uint repeatInterval);
void setHandle(pcap_t *handle);

View File

@ -115,8 +115,6 @@ _skip_filter:
ttagId &= 0xFF;
#endif
timing_->recordTxTime(portId_, guid, ttagId, hdr->ts);
timingDebug("[%d TX] %ld:%ld ttag %u guid %u", portId_,
hdr->ts.tv_sec, long(hdr->ts.tv_usec), ttagId, guid);
}
break;
}

View File

@ -69,6 +69,9 @@ bool StreamTiming::recordTxTime(uint portId, uint guid, uint ttagId,
TxRxKey key = makeKey(guid, ttagId);
TtagData value = { .timeStamp = timestamp, .portId = portId};
timingDebug("[%d TX] %ld:%ld ttag %u guid %u", portId,
timestamp.tv_sec, long(timestamp.tv_nsec), ttagId, guid);
QMutexLocker locker(&txHashLock_);
txHash_.insert(key, value);
@ -81,6 +84,9 @@ bool StreamTiming::recordRxTime(uint portId, uint guid, uint ttagId,
TxRxKey key = makeKey(guid, ttagId);
TtagData value = { .timeStamp = timestamp, .portId = portId};
timingDebug("[%d RX] %ld:%ld ttag %u guid %u", portId,
timestamp.tv_sec, long(timestamp.tv_nsec), ttagId, guid);
QMutexLocker locker(&rxHashLock_);
rxHash_.insert(key, value);
@ -107,6 +113,28 @@ bool StreamTiming::recordRxTime(uint portId, uint guid, uint ttagId,
return recordRxTime(portId, guid, ttagId, ts);
}
// TTagList contains 32-bit ttags formatted as ttagId (8msb) + guid (24lsb)
bool StreamTiming::recordTxTime(uint portId, uint *ttagList, int count,
const struct timespec &timestamp)
{
TtagData value = { .timeStamp = timestamp, .portId = portId};
QMutexLocker locker(&txHashLock_);
// FIXME: Change TxRxKey to match the format passed to this function
for (int i = 0; i < count; i++) {
uint guid = ttagList[i] & 0x00FFFFFF;
uint ttagId = ttagList[i] >> 24;
TxRxKey key = makeKey(guid, ttagId);
timingDebug("[%d TX] %ld:%ld ttag %u guid %u", portId,
timestamp.tv_sec, long(timestamp.tv_nsec), ttagId, guid);
txHash_.insert(key, value);
}
return true;
}
quint64 StreamTiming::delay(uint portId, uint guid)
{
Q_ASSERT(guid <= SignProtocol::kMaxGuid);
@ -181,8 +209,8 @@ int StreamTiming::processRecords()
diff.tv_sec, diff.tv_nsec,
rxTime.tv_sec, rxTime.tv_nsec,
txTime.tv_sec, txTime.tv_nsec);
timingDebug("%d:[%u/%u] total %ld.%09ld count %u",
count, i.value().portId, guid,
timingDebug("[%u/%u](%d) total %ld.%09ld count %u",
i.value().portId, guid, count,
guidTiming.sumDelays.tv_sec, guidTiming.sumDelays.tv_nsec,
guidTiming.countDelays);
}

View File

@ -43,6 +43,9 @@ public:
bool recordRxTime(uint portId, uint guid, uint ttagId,
const struct timeval &timestamp);
bool recordTxTime(uint portId, uint *ttagList, int count,
const struct timespec &timestamp);
quint64 delay(uint portId, uint guid);
void clear(uint portId, uint guid = SignProtocol::kInvalidGuid);