Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refax: removed m_iRcvLastSkipAck and its dependencies #2546

Merged
merged 13 commits into from
Nov 29, 2022

Conversation

ethouris
Copy link
Collaborator

Removed the m_iRcvLastSkipAck field. This field was different to m_iRcvLastAck in case when a drop was done and was used as a base sequence pinned in the old receiver buffer to the "end pointer" that was pointing to the end of the initial contiguous region. With the defined sequence number of the first cell in the new receiver buffer this field was only duplicating the information as well as the convention where the acknowledgement signs off packets for retrieval in live mode as well has been dismissed (this is still valid in file mode, but relies on only signaling the CV and setting read ready; both these things are being done by the TSBPD thread in live mode). The value of this field can be determined from m_iRcvLastAck and m_pRcvBuffer->getStartSeqNo(), whichever is later, however the way how this value was used in comparisons had to be changed as well, as the check if a sequence is within the buffer can be now done more straighforward way.

@ethouris ethouris added Priority: High Type: Maintenance Work required to maintain or clean up the code [core] Area: Changes in SRT library core labels Nov 22, 2022
@ethouris ethouris changed the title Refax: removed m_RcvLastSkipAck and its dependencies Refax: removed m_iRcvLastSkipAck and its dependencies Nov 22, 2022
srtcore/core.cpp Outdated Show resolved Hide resolved
@codecov-commenter

This comment was marked as off-topic.

@gou4shi1
Copy link
Contributor

gou4shi1 commented Nov 22, 2022

Great refactor!
I just curious about will this PR be merged before #2535?Or this PR replaced #2535
I noticed that the new packet insertion check is similar to #2535, so I'm OK to close #2535.

@@ -1050,13 +1050,13 @@ void CRcvBuffer::updateTsbPdTimeBase(uint32_t usPktTimestamp)

string CRcvBuffer::strFullnessState(bool enable_debug_log, int iFirstUnackSeqNo, const time_point& tsNow) const
{
if (!enable_debug_log)
Copy link
Contributor

@gou4shi1 gou4shi1 Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason of this enable_debug_log check: #2463 (comment)
If return empty string, why not just check enable_debug_log in the caller site? i.e. qrlog.Debug.CheckEnabled() ? strFullnessState() : ""

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the idea is to avoid the lengthy evaluation when the resulting string will be ignored anyway. The instruction for logging will not result in a printed log if the log isn't enabled, but all the arguments will be evaluated anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lengthy evaluation

Does it mean qrlog.Debug.CheckEnabled() ? strFullnessState() : "" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would work as well. @maxsharabayko what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean qrlog.Debug.CheckEnabled() ? strFullnessState() : "" ?

Good suggestion. And get rid of the enable_debug_log argument.

Copy link
Collaborator Author

@ethouris ethouris Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe even this way? At least this improves reliability over the explicit version:

                        << LOGEVAL_IF(qrlog.Warn, m_pRcvBuffer->strFullnessState(m_iRcvLastAck, steady_clock::now()))

Copy link
Contributor

@gou4shi1 gou4shi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments about logs.

<< " m_iStartPos=" << m_iStartPos << " m_iMaxPosInc=" << m_iMaxPosInc << ". ";
}
ss << "iFirstUnackSeqNo=" << iFirstUnackSeqNo << " m_iStartSeqNo=" << m_iStartSeqNo
<< " m_iStartPos=" << m_iStartPos << " m_iMaxPosInc=" << m_iMaxPosInc << ". ";

ss << "Space avail " << getAvailSize(iFirstUnackSeqNo) << "/" << m_szSize << " pkts. ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the no room check has nothing to do with getAvailSize(ack), this "Space avail..." log should also be changed or removed, e.g. https://github.com/Haivision/srt/pull/2535/files#diff-45454334aff81b7e3327c5453befe97eb41e7ec0c3bdfc695e25949ba9f463adL1061

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't understand what is happening here. I raised some concerns already about the way how the "avail space" is calculated. I didn't trace that before, but that all depends on what you're going to use this value for. The sequence of acknowledgement is only a marker of the part of the buffer not yet retrieved by the application. But rest of the buffer contains two ranges: working range (packets that are there, maybe with losses, but haven't been yet acknowledged) and available range (no packet with such a sequence has come even for the first time). A sender that is about to decide as to whether it can send the packet and count on that the receiver has a place to store it, should be given only this last "available" range. But also the sender should regard this free space value only when going to send the new packets, not when retransmitting. Retransmission should use the "working range" which should always be available. But now I'm not exactly sure how to best display it.

srtcore/core.cpp Outdated
// Remove [from,to-inclusive]
dropFromLossLists(m_iRcvLastSkipAck, CSeqNo::decseq(seqno));
m_iRcvLastSkipAck = seqno;
LOGC(tslog.Error, log << CONID() << "IPE: drop request up to %" << seqno << " while last received is %"
Copy link
Contributor

@gou4shi1 gou4shi1 Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an IPE in group mode, it will happen frequently if it's called from dropToGroupRecvBase() in broadcast mode, IIRC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Forgot that this function is also being used from the group synchronization code, and in this case this sequence may exceed the last received sequence. Still, AFAIR this last received sequence has to be synchronized as well. Fortunately this will remain only temporarily, until the common receiver buffer is ready.

Copy link
Contributor

@gou4shi1 gou4shi1 Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this last received sequence has to be synchronized as well

I tried, this may break senders' check:

if (CSeqNo::seqcmp(ackdata_seqno, CSeqNo::incseq(m_iSndCurrSeqNo)) > 0)
{
    leaveCS(m_RecvAckLock);
    // this should not happen: attack or bug

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I'd simply leave it as is for now. The common receiver code will approach this part differently.

srtcore/core.cpp Outdated Show resolved Hide resolved
@@ -9749,14 +9763,12 @@ int srt::CUDT::handleSocketPacketReception(const vector<CUnit*>& incoming, bool&
m_stats.rcvr.recvdBelated.count(rpkt.getLength());
leaveCS(m_StatsLock);
HLOGC(qrlog.Debug,
log << CONID() << "RECEIVED: seq=" << rpkt.m_iSeqNo << " offset=" << offset << " (BELATED/"
log << CONID() << "RECEIVED: %" << rpkt.m_iSeqNo << " bufidx=" << bufidx << " (BELATED/"

This comment was marked as resolved.

<< "+" << CSeqNo::incseq(m_iRcvLastSkipAck, int(m_pRcvBuffer->capacity()) - 1)
<< "), " << (offset-avail_bufsize+1)
" %" << rpkt.m_iSeqNo
<< " buffer=(%" << bufseq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<< "buffer=(%" << bufseq
<< ":%" << m_iRcvCurrSeqNo
<< "+%" << CSeqNo::incseq(bufseq, int(m_pRcvBuffer->capacity()) - 1)
<< ")"

This code block was repeated many times, maybe add a dedicated function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be, but I'd postpone it until the common receiver as things may change there a lot. In case of a common receiver there will be a different buffer where data come from.

srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
Comment on lines +7748 to +7749
// [[using locked(m_RcvBufferLock)]]
bool srt::CUDT::getFirstNoncontSequence(int32_t& w_seq, string& w_log_reason)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the function return value is always true and thus can be ignored, might make sense to return the w_seq instead of passing it as a reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is consistent with the future implementation of it where it returns false in case when it neither has a receiver buffer nor is a group member. This situation should never happen and therefore for this it's a sanity check. I can change it, but this will cause merge problems in the future.

srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated
<< ":" << m_iRcvCurrSeqNo // -1 = size to last index
<< "+" << CSeqNo::incseq(m_iRcvLastSkipAck, m_pRcvBuffer->capacity()-1)
// XXX Fix this when the end of contiguous region detection is added.
int ackidx = CSeqNo::seqoff(m_pRcvBuffer->getStartSeqNo(), m_iRcvLastAck);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int ackidx = CSeqNo::seqoff(m_pRcvBuffer->getStartSeqNo(), m_iRcvLastAck);
const int ackidx = CSeqNo::seqoff(m_pRcvBuffer->getStartSeqNo(), m_iRcvLastAck);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instruction two lines below this will not compile.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be converted into a single line using the std::max(0, CSeqNo...).

srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Priority: High Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants