Skip to content

Commit

Permalink
[core] Minor ACK variables clean up.
Browse files Browse the repository at this point in the history
* m_ullACKInt_tk used at initialization
* FileCC does not use m_iACKPeriod
* ACK event variant type changed to signed integer
  • Loading branch information
maxsharabayko committed Sep 3, 2019
1 parent f426e9d commit 66d87ff
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
6 changes: 3 additions & 3 deletions srtcore/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct EventVariant
union U
{
CPacket* packet;
uint32_t ack;
int32_t ack;
struct
{
int32_t* ptr;
Expand Down Expand Up @@ -238,7 +238,7 @@ struct EventVariant
}

void operator=(CPacket* arg) { Assign<PACKET>(arg); };
void operator=(uint32_t arg) { Assign<ACK>(arg); };
void operator=(int32_t arg) { Assign<ACK>(arg); };
void operator=(ECheckTimerStage arg) { Assign<STAGE>(arg); };
void operator=(EInitEvent arg) { Assign<INIT>(arg); };

Expand Down Expand Up @@ -323,7 +323,7 @@ template<> struct EventVariant::VariantFor<EventVariant::PACKET>

template<> struct EventVariant::VariantFor<EventVariant::ACK>
{
typedef uint32_t type;
typedef int32_t type;
static type U::*field() { return &U::ack; }
};

Expand Down
4 changes: 0 additions & 4 deletions srtcore/congctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ class FileCC: public SrtCongestionControlBase
{
typedef FileCC Me; // Required by SSLOT macro

// Fields from CCC not used by LiveCC
int m_iACKPeriod;

// Fields from CUDTCC
int m_iRCInterval; // UDT Rate control interval
uint64_t m_LastRCTime; // last rate increase time
Expand All @@ -270,7 +267,6 @@ class FileCC: public SrtCongestionControlBase

FileCC(CUDT* parent)
: SrtCongestionControlBase(parent)
, m_iACKPeriod(CUDT::COMM_SYN_INTERVAL_US)
, m_iRCInterval(CUDT::COMM_SYN_INTERVAL_US)
, m_LastRCTime(CTimer::getTime())
, m_bSlowStart(true)
Expand Down
20 changes: 9 additions & 11 deletions srtcore/congctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,17 @@ class SrtCongestionControlBase
// If not, it will be internally calculated.
virtual int RTO() { return 0; }

// How many packets to send one ACK, in packets.
// If user-defined, will return nonzero value. It can enforce extra ACKs
// beside those calculated by ACK, sent only when the number of packets
// received since the last EXP that fired "fat" ACK does not exceed this
// value.
virtual int ACKInterval() { return 0; }

// Periodical timer to send an ACK, in microseconds.
// If user-defined, this value in microseconds will be used to calculate
// ACK interval in packets.
// Specifies the number of packets to receive before sending the ACK.
// Used by CUDT together with ACKIntervalMicrosec() to trigger ACK packet sending.
virtual int ACKIntervalPkts() const { return 0; }

// Periodical interval to send an ACK, in microseconds.
// If user-defined, this value will be used to calculate
// the next ACK time every time ACK is considered to be sent (see CUDT::checkTimers).
// Otherwise this will be calculated internally in CUDT, normally taken
// from CPacket::SYN_INTERVAL.
virtual int ACKPeriod() { return 0; }
// from CUDT::COMM_SYN_INTERVAL_US.
virtual int ACKIntervalMicrosec() const { return 0; }

// Called when the settings concerning m_llMaxBW were changed.
// Arg 1: value of CUDT::m_llMaxBW
Expand Down
25 changes: 12 additions & 13 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,6 @@ void CUDT::open()
m_iRTTVar = m_iRTT >> 1;
m_ullCPUFrequency = CTimer::getCPUFrequency();

// set up the timers
m_ullSYNInt_tk = COMM_SYN_INTERVAL_US * m_ullCPUFrequency;

// set minimum NAK and EXP timeout to 300ms
/*
Expand All @@ -1303,16 +1301,17 @@ void CUDT::open()
else
#endif
*/
// Set up timers
m_ullMinNakInt_tk = 300000 * m_ullCPUFrequency;
m_ullMinExpInt_tk = 300000 * m_ullCPUFrequency;

m_ullACKInt_tk = m_ullSYNInt_tk;
m_ullACKInt_tk = COMM_SYN_INTERVAL_US * m_ullCPUFrequency;
m_ullNAKInt_tk = m_ullMinNakInt_tk;

uint64_t currtime_tk;
CTimer::rdtsc(currtime_tk);
m_ullLastRspTime_tk = currtime_tk;
m_ullNextACKTime_tk = currtime_tk + m_ullSYNInt_tk;
m_ullNextACKTime_tk = currtime_tk + m_ullACKInt_tk;
m_ullNextNAKTime_tk = currtime_tk + m_ullNAKInt_tk;
m_ullLastRspAckTime_tk = currtime_tk;
m_ullLastSndTime_tk = currtime_tk;
Expand Down Expand Up @@ -4788,7 +4787,7 @@ void CUDT::setupCC()
uint64_t currtime_tk;
CTimer::rdtsc(currtime_tk);
m_ullLastRspTime_tk = currtime_tk;
m_ullNextACKTime_tk = currtime_tk + m_ullSYNInt_tk;
m_ullNextACKTime_tk = currtime_tk + m_ullACKInt_tk;
m_ullNextNAKTime_tk = currtime_tk + m_ullNAKInt_tk;
m_ullLastRspAckTime_tk = currtime_tk;
m_ullLastSndTime_tk = currtime_tk;
Expand Down Expand Up @@ -6628,7 +6627,8 @@ void CUDT::sendCtrl(UDTMessageType pkttype, void* lparam, void* rparam, int size
if (data[ACKD_BUFFERLEFT] < 2)
data[ACKD_BUFFERLEFT] = 2;

if (currtime_tk - m_ullLastAckTime_tk > m_ullSYNInt_tk)
// NOTE: m_CongCtl->ACKIntervalMicrosec() should be taken into account.
if (currtime_tk - m_ullLastAckTime_tk > m_ullACKInt_tk)
{
int rcvRate;
int ctrlsz = ACKD_TOTAL_SIZE_UDTBASE * ACKD_FIELD_SIZE; // Minimum required size
Expand All @@ -6648,7 +6648,6 @@ void CUDT::sendCtrl(UDTMessageType pkttype, void* lparam, void* rparam, int size
// Normal, currently expected version.
data[ACKD_RCVRATE] = rcvRate; //bytes/sec
ctrlsz = ACKD_FIELD_SIZE * ACKD_TOTAL_SIZE_VER101;

}
// ELSE: leave the buffer with ...UDTBASE size.

Expand Down Expand Up @@ -8666,17 +8665,17 @@ void CUDT::addLossRecord(std::vector<int32_t>& lr, int32_t lo, int32_t hi)
void CUDT::checkACKTimer(uint64_t currtime_tk)
{
if (currtime_tk > m_ullNextACKTime_tk // ACK time has come
// OR the number of sent packets since last ACK has reached
// the congctl-defined value of ACK Interval
// (note that none of the builtin congctls defines ACK Interval)
|| (m_CongCtl->ACKInterval() > 0 && m_iPktCount >= m_CongCtl->ACKInterval()))
// OR the number of sent packets since last ACK has reached
// the congctl-defined value of ACK Interval
// (note that none of the builtin congctls defines ACK Interval)
|| (m_CongCtl->ACKIntervalPkts() > 0 && m_iPktCount >= m_CongCtl->ACKIntervalPkts()))
{
// ACK timer expired or ACK interval is reached
sendCtrl(UMSG_ACK);
CTimer::rdtsc(currtime_tk);

const int ack_interval_tk = m_CongCtl->ACKPeriod() > 0
? m_CongCtl->ACKPeriod() * m_ullCPUFrequency
const int ack_interval_tk = m_CongCtl->ACKIntervalMicrosec() > 0
? m_CongCtl->ACKIntervalMicrosec() * m_ullCPUFrequency
: m_ullACKInt_tk;
m_ullNextACKTime_tk = currtime_tk + ack_interval_tk;

Expand Down
1 change: 0 additions & 1 deletion srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ class CUDT
uint64_t m_ullNextACKTime_tk; // Next ACK time, in CPU clock cycles, same below
uint64_t m_ullNextNAKTime_tk; // Next NAK time

volatile uint64_t m_ullSYNInt_tk; // SYN interval
volatile uint64_t m_ullACKInt_tk; // ACK interval
volatile uint64_t m_ullNAKInt_tk; // NAK interval
volatile uint64_t m_ullLastRspTime_tk; // time stamp of last response from the peer
Expand Down
2 changes: 1 addition & 1 deletion srtcore/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ friend class CRcvQueue;
int32_t& m_iSeqNo; // alias: sequence number
int32_t& m_iMsgNo; // alias: message number
int32_t& m_iTimeStamp; // alias: timestamp
int32_t& m_iID; // alias: socket ID
int32_t& m_iID; // alias: socket ID
char*& m_pcData; // alias: data/control information

//static const int m_iPktHdrSize; // packet header size
Expand Down
1 change: 0 additions & 1 deletion test/test_epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ TEST(CEPoll, NotifyConnectionBreak)
SRTSOCKET client_sock = srt_socket(AF_INET, SOCK_DGRAM, 0);
ASSERT_NE(client_sock, SRT_ERROR);

const int yes = 1;
const int no = 0;
ASSERT_NE(srt_setsockopt(client_sock, 0, SRTO_RCVSYN, &no, sizeof no), SRT_ERROR); // for async connect
ASSERT_NE(srt_setsockopt(client_sock, 0, SRTO_SNDSYN, &no, sizeof no), SRT_ERROR); // for async connect
Expand Down

0 comments on commit 66d87ff

Please sign in to comment.