Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Change StreamTiming::TxRxKey format
Browse files Browse the repository at this point in the history
The format now matches the ttag list format input in recordTxTime() making
that API a little more optimized.
  • Loading branch information
pstavirs committed Jun 17, 2023
1 parent 5ec7010 commit ee45aaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions server/streamtiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int StreamTiming::processRecords()
struct timespec diff;
timespecsub(&rxTime, &txTime, &diff);

uint guid = i.key() >> 8;
uint guid = guidFromKey(i.key());
uint portId = i.value().portId;

if (!timing_.contains(portId))
Expand All @@ -132,7 +132,7 @@ int StreamTiming::processRecords()
count++;

timingDebug("[%u/%u/%u] diff %ld.%09ld (%ld.%09ld - %ld.%09ld)",
i.value().portId, guid, i.key() & 0xFF,
i.value().portId, guid, ttagIdFromKey(i.key()),
diff.tv_sec, diff.tv_nsec,
rxTime.tv_sec, rxTime.tv_nsec,
txTime.tv_sec, txTime.tv_nsec);
Expand Down
28 changes: 16 additions & 12 deletions server/streamtiming.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ public slots:
int processRecords();
int deleteStaleRecords();

quint32 makeKey(uint guid, uint ttagId) {
return guid << 8 | (ttagId & 0xFF);
}

// XXX: use only time intervals, not absolute time
quint64 timespecToNsecs(const struct timespec &interval) {
return interval.tv_nsec + interval.tv_sec*1e9;
Expand All @@ -83,16 +79,26 @@ public slots:

QSet<uint> activePortSet_;

// XXX: TxRxKey = guid (24 bit MSB) + ttagid (8 bit LSB)
// TODO: encode tx port in in packet and use as part of key
// XXX: TxRxKey = ttagid (8 bit MSB) + guid (24 bit LSB)
// TODO: encode tx port in packet and use as part of key
typedef quint32 TxRxKey;
TxRxKey makeKey(uint guid, uint ttagId) {
return (ttagId << 24 ) | (guid & 0x00FFFFFF);
}
uint guidFromKey(TxRxKey key) {
return uint(key) & 0x00FFFFFF;
}
uint ttagIdFromKey(TxRxKey key) {
return uint(key) >> 24;
}

QHash<TxRxKey, TtagData> txHash_;
QHash<TxRxKey, TtagData> rxHash_;
QMutex txHashLock_;
QMutex rxHashLock_;

typedef uint PortIdKey;
typedef uint GuidKey;
typedef uint GuidKey; // guid only, no ttagid
typedef QHash<GuidKey, Timing> PortTiming;
QHash<PortIdKey, PortTiming*> timing_;
QMutex timingLock_;
Expand Down Expand Up @@ -163,14 +169,12 @@ bool StreamTiming::recordTxTime(uint portId, uint *ttagList, int count,
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);
TxRxKey key = TxRxKey(ttagList[i]);

timingDebug("[%d TX] %ld:%ld ttag %u guid %u", portId,
timestamp.tv_sec, long(timestamp.tv_nsec), ttagId, guid);
timestamp.tv_sec, long(timestamp.tv_nsec),
ttagIdFromKey(key), guidFromKey(key));

txHash_.insert(key, value);
}
Expand Down

0 comments on commit ee45aaf

Please sign in to comment.