TCP拥塞控制算法 — CUBIC的补丁(三)
生活随笔
收集整理的這篇文章主要介紹了
TCP拥塞控制算法 — CUBIC的补丁(三)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
描述
?
以下是提交者Stephen Hemminger對(duì)這個(gè)patch的描述:
fix clock dependency
The hystart code was written with assumption that HZ=1000.
Replace the use of jiffies with bictcp_clock as a millisecond real time clock.
?
代碼
?
--- a/net/ipv4/tcp_cubic.c +++ b/net/ipv4/tcp_cubic.c @@ -88,7 +88,7 @@ struct bictcp {u32 last_time; /* time when updated last_cwnd */u32 bic_origin_point;/* origin point of bic function */u32 bic_K; /* time to origin point from the beginning of the current epoch */ - u32 delay_min; /* min delay,以前的單位為jiffies*/ + u32 delay_min; /* min delay (msec << 3),現(xiàn)在的單位為毫秒*/u32 epoch_start; /* beginning of an epoch */u32 ack_cnt; /* number of acks */u32 tcp_cwnd; /* estimated tcp cwnd */ @@ -98,7 +98,7 @@ struct bictcp {u8 found; /* the exit point is found? */u32 round_start; /* beginning of each round */u32 end_seq; /* end_seq of the round */ - u32 last_jiffies; /* last time when the ACK spacing is close,單位為jiffies */ + u32 last_ack; /* last time when the ACK spacing is close,單位為毫秒 */u32 curr_rtt; /* the minimum rtt of current round */};@@ -119,12 +119,21 @@ static inline void bictcp_reset(struct bictcp *ca)ca->found = 0;}+static inline u32 bictcp_clock(void) +{ +#if HZ < 1000 /* NZ小于1000,返回的是實(shí)際時(shí)間,單位為毫秒 */ + return ktime_to_ms(ktime_get_real()); +#else + return jiffies_to_msecs(jiffies); /* 返回的是jiffies時(shí)間,單位為毫秒*/ +#endif +} +static inline void bictcp_hystart_reset(struct sock *sk){struct tcp_sock *tp = tcp_sk(sk);struct bictcp *ca = inet_csk_ca(sk);- ca->round_start = ca->last_jiffies = jiffies; + ca->round_start = ca->last_ack = bictcp_clock();ca->end_seq = tp->snd_nxt;ca->curr_rtt = 0;ca->sample_cnt = 0; @@ -239,8 +248,8 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd)*//* change the unit from HZ to bictcp_HZ */ - t = ((tcp_time_stamp + (ca->delay_min>>3) - ca->epoch_start) - << BICTCP_HZ) / HZ; + t = ((tcp_time_stamp + msecs_to_jiffies(ca->delay_min>>3) + - ca->epoch_start) << BICTCP_HZ) / HZ;if (t < ca->bic_K) /* t - K */offs = ca->bic_K - t; @@ -342,14 +351,12 @@ static void hystart_update(struct sock *sk, u32 delay)struct bictcp *ca = inet_csk_ca(sk);if (!(ca->found & hystart_detect)) { - u32 curr_jiffies = jiffies; + u32 now = bictcp_clock();/* first detection parameter - ack-train detection */ - if ((s32)(curr_jiffies - ca->last_jiffies) <= - msecs_to_jiffies(hystart_ack_delta)) { - ca->last_jiffies = curr_jiffies; - if ((s32) (curr_jiffies - ca->round_start) > - ca->delay_min >> 4) + if ((s32)(now - ca->last_ack) <= hystart_ack_delta) { + ca->last_ack = now; + if ((s32)(now - ca->round_start) > ca->delay_min >> 4)ca->found |= HYSTART_ACK_TRAIN;}@@ -396,7 +403,7 @@ static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)if ((s32)(tcp_time_stamp - ca->epoch_start) < HZ)return;- delay = usecs_to_jiffies(rtt_us) << 3; + delay = (rtt_us << 3) / USEC_PER_MSEC;if (delay == 0)delay = 1;?
分析
?
#ifndef _STRUCT_TIMESPEC #define _STRUCT_TIMESPEC struct timespec {__kernel_time_t tv_sec; /* seconds,long*/long tv_nsec; /* nanoseconds */ }; #endifunion ktime {s64 tv64;#if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR)struct { #ifdef __BIG_ENDIANs32 sec, nsec; #elses32 nsec, sec; #endif} tv; #endif };typedef union ktime ktime_t;/*** ktime_get_real - get the real (wall) time in ktime_t format* returns the time in ktime_t format*/ ktime_t ktime_get_real(void) {struct timespec now;getnstimeofday(&now);return timespec_to_ktime(now); }static inline s64 ktime_to_ms(const ktime_t kt) {struct timeval tv = ktime_to_timeval(kt);return (s64) tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC; }/*** ktime_to_timeval - convert a ktime_t variable to timeval format* @kt: the ktime_t variable to convert* Returns the timeval representation of the ktime value*/ static inline struct timeval ktime_to_timeval (const ktime_t kt) {return (struct timeval) {.tv_sec = (time_t) kt.tv.sec,.tv_usec = (suseconds_t) (kt.tv.nsec / NSEC_PER_USEC) }; }?
評(píng)價(jià)
?
原來(lái)的bictcp結(jié)構(gòu)中的round_start、delay_min和last_jiffies的單位為jiffies,現(xiàn)在考慮到1jiffies不
一定代表1ms(如果HZ不為1000),所以這三個(gè)變量就采用毫秒為單位來(lái)計(jì)算。原來(lái)的版本也沒(méi)
有錯(cuò)誤,現(xiàn)在只是改了下度量單位。
?
Author
?
zhangskd @ csdn blog
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/aiwz/archive/2013/03/02/6333351.html
總結(jié)
以上是生活随笔為你收集整理的TCP拥塞控制算法 — CUBIC的补丁(三)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Sql server 事务的两种用法
- 下一篇: Ajax-基础篇(02)