Skip to content

Commit

Permalink
Merge branch 'v3_6' into v3_7
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Sep 13, 2024
2 parents 7e4448f + dd18553 commit 5ed04f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/ptp/ptpd2/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct {
sfptpd_time_t offset;
bool have_timestamp;
bool have_offset;
bool two_step;
UInteger16 seq;
} ForeignSyncSnapshot;

Expand Down Expand Up @@ -95,6 +96,7 @@ typedef struct

/* Snapshot of Sync for use with discriminator */
ForeignSyncSnapshot syncSnapshot;
ForeignSyncSnapshot nextSyncSnapshot;
} ForeignMasterRecord;

typedef struct {
Expand Down
37 changes: 21 additions & 16 deletions src/ptp/ptpd2/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ calculateForeignOffset(ForeignSyncSnapshot *syncSnapshot, const Timestamp *syncO
ForeignMasterRecord *record, PtpClock *ptpClock)
{
struct timespec sync_time;
/* sync_time will store the sync origin timestamp, which is from the foreign
/* sync_time will store the sync origin timestamp, which is from the foreign
master under scrutiny and has NOT had the UTC offset applied to it.
This timestamp could be in UTC or it could be in TAI.
Expand All @@ -350,11 +350,12 @@ calculateForeignOffset(ForeignSyncSnapshot *syncSnapshot, const Timestamp *syncO
The sync message may arrive before the announce message. In that case,
we must wait until the announce message arrives, which is why we check
for record->announceTimesCount in order to decide whether to return a
result or not.
*/
result or not. */

struct timespec foreign_offset; /* foreign_offset holds the result. */

struct timespec local_time;
/* local_time will hold the local timestamp from the NIC that has already
/* local_time will hold the local timestamp from the NIC that has already
had the applyUtcOffset function called on it.
This means it may or may not have had a UTC offset added to it. If a
Expand All @@ -381,8 +382,7 @@ calculateForeignOffset(ForeignSyncSnapshot *syncSnapshot, const Timestamp *syncO
before it has had the applyUtcOffset function called on it.
This approach was considered cleaner as it keeps the special code for this
feature in as few places as possible.
*/
feature in as few places as possible. */

assert(syncSnapshot != NULL);
assert(syncOriginTimestamp != NULL);
Expand Down Expand Up @@ -419,20 +419,21 @@ recordForeignSync(const MsgHeader *header, PtpClock *ptpClock, TimeInternal *tim
if (ptpClock->discriminator_valid) {
ForeignMasterRecord *record = findForeignMasterRecord(header, &ptpClock->foreign);
if (record) {
ForeignSyncSnapshot *snapshot = &record->syncSnapshot;
ForeignSyncSnapshot *snapshot = &record->nextSyncSnapshot;

snapshot->have_timestamp = true;
snapshot->seq = header->sequenceId;
*snapshot = (ForeignSyncSnapshot) {
.have_timestamp = true,
.seq = header->sequenceId,
.two_step = header->flagField0 & PTPD_FLAG_TWO_STEP,
};
internalTime_to_ts(timestamp, &snapshot->timestamp);

if ((header->flagField0 & PTPD_FLAG_TWO_STEP) == 0) {
if (!snapshot->two_step) {
calculateForeignOffset(snapshot,
&ptpClock->interface->msgTmp.sync.originTimestamp,
record,
ptpClock);

} else {
snapshot->have_offset = false;
record->syncSnapshot = *snapshot;
}
}
}
Expand All @@ -445,15 +446,19 @@ recordForeignFollowUp(const MsgHeader *header, PtpClock *ptpClock, const MsgFoll
if (ptpClock->discriminator_valid) {
ForeignMasterRecord *record = findForeignMasterRecord(header, &ptpClock->foreign);
if (record) {
ForeignSyncSnapshot *snapshot = &record->syncSnapshot;
ForeignSyncSnapshot *snapshot = &record->nextSyncSnapshot;

if (header->sequenceId == snapshot->seq) {
if (snapshot->two_step &&
!snapshot->have_offset &&
header->sequenceId == snapshot->seq) {
calculateForeignOffset(snapshot,
&payload->preciseOriginTimestamp,
record,
ptpClock);
record->syncSnapshot = *snapshot;
} else {
/* Invalidate snapshot if sequence ID of FollowUp does not match Sync */
/* Invalidate pending snapshot if sequence ID of FollowUp
* does not match Sync */
snapshot->have_timestamp = false;
snapshot->have_offset = false;
}
Expand Down

0 comments on commit 5ed04f1

Please sign in to comment.