From d4031f89f77ea0725765766f697d298693257d54 Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Sat, 8 Mar 2025 23:03:12 +0800 Subject: Some changes by lvchao --- include/linux/tcp.h | 6 + include/net/tcp.h | 7 +- net/ipv4/tcp_cong.c | 1 + net/ipv4/tcp_input.c | 7 + net/ipv4/tcp_mytcp.c | 372 +++++++++++++++++++++++++++++++++++++++++---------- net/ipv4/tcp_mytcp.h | 0 6 files changed, 321 insertions(+), 72 deletions(-) mode change 100644 => 100755 net/ipv4/tcp_mytcp.c mode change 100644 => 100755 net/ipv4/tcp_mytcp.h diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 5feb49ee9..f2be9dbaa 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -471,12 +471,18 @@ struct tcp_sock { u32 mytcp_bytes_send; u32 mytcp_acked_bytes; u32 mytcp_acked_seq_last; + + // add + int exit_slow_start_flag; // new u32 my_ip_rtt; + u32 mytcp_average_rtt; + u32 my_last_ack; u32 my_ack_seq_gap; + u32 mytcp_this_rtt_count; // new ended }; diff --git a/include/net/tcp.h b/include/net/tcp.h index 7a8f950f5..69417ebf6 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1210,7 +1210,12 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) static inline bool tcp_in_slow_start(const struct tcp_sock *tp) { - return tp->snd_cwnd < tp->snd_ssthresh; + // return tp->snd_cwnd < tp->snd_ssthresh; + if(tp->exit_slow_start_flag!=1){ + return tp->snd_cwnd < tp->snd_ssthresh; + }else{ + return 0; + } } static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp) diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c index be24f070c..949fe9df3 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -409,6 +409,7 @@ u32 tcp_slow_start(struct tcp_sock *tp, u32 acked) else{ cwnd_full = min((cwnd + tp->mytcp_stopped_cwnd), tp->snd_ssthresh); tp->snd_cwnd = min(cwnd_full, tp->snd_cwnd_clamp); + tp->mytcp_stopped_cwnd = 0; // printk(KERN_DEBUG "full_pipe_flag == 0, the cwnd is %u, the mytcp_stopped_cwnd is %u\n",tp->snd_cwnd, tp->mytcp_stopped_cwnd); tp->mytcp_stopped_cwnd = 0; } diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 2e878f392..c934446f3 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -3098,6 +3098,13 @@ static bool tcp_ack_update_rtt(struct sock *sk, const int flag, /* RFC6298: only reset backoff on valid RTT measurement. */ inet_csk(sk)->icsk_backoff = 0; + //打印RTT + struct inet_sock *inet2; + inet2 = inet_sk(sk); + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "in tcp_ack_update_rtt now RTT is %ld\n",rs->rtt_us); + // printk(KERN_DEBUG "in tcp_ack_update_rtt cwnd is %u\n", tp->snd_cwnd); + } return true; } diff --git a/net/ipv4/tcp_mytcp.c b/net/ipv4/tcp_mytcp.c old mode 100644 new mode 100755 index 6e9bb84e5..56cf935a3 --- a/net/ipv4/tcp_mytcp.c +++ b/net/ipv4/tcp_mytcp.c @@ -9,8 +9,8 @@ #include #include // for gettimeofday() #include -#include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/drivers/net/wireless/ath/ath10k/core.h" #include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/include/net/mac80211.h" +#include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/drivers/net/wireless/ath/ath10k/core.h" #include "tcp_vegas.h" #include "tcp_mytcp.h" @@ -29,7 +29,7 @@ //int this_flow_num; static int gamma = 2; -static int RQ_allow = 40; +static int RQ_allow = 10; module_param(gamma, int, 0644); MODULE_PARM_DESC(gamma, "limit on increase (scale by 2)"); @@ -113,11 +113,13 @@ void tcp_mytcp_pkts_acked(struct sock *sk, const struct ack_sample *sample) vrtt = sample->rtt_us + 1; // mytcp->rtt_of_this_packet = sample->rtt_us; - tp->my_ip_rtt = sample->rtt_us; + tp->my_ip_rtt = sample->rtt_us;//目前的rtt buffer_queue = tp->write_seq - tp->snd_una; //sndbuffer中的当前队列长度,单位为byte // printk(KERN_DEBUG "packets inflight are %u\n", tp->packets_out); - printk(KERN_DEBUG "the mytcp RTT is %u\n",sample->rtt_us); + // printk(KERN_DEBUG "the mytcp RTT is %u\n",sample->rtt_us); + // printk(KERN_DEBUG "in mytcp, the cubic cwnd is %u\n",tp->snd_cwnd); + /* Filter to find propagation delay: */ @@ -202,6 +204,19 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) int buffer_queue; int min_inflight; + struct inet_sock *inet2; + inet2 = inet_sk(sk); + + + + // if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + // printk(KERN_DEBUG "cubictcp_cong_avoid has receive acked is %u\n", acked); + // printk(KERN_DEBUG "cubictcp_cong_avoid the ack is %u\n", ack); + // printk(KERN_DEBUG "cubictcp_cong_avoid tp->snd_nxt %u\n", tp->snd_nxt); + + // } + + mytcp->inflight_2pre = mytcp->inflight_1pre; mytcp->inflight_1pre = mytcp->inflight_now; @@ -230,12 +245,25 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) // mytcp->min_queue = mytcp_min_tx_queue; mytcp->min_queue_within_t = tp->mytcp_est_rq; + + + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + // printk(KERN_DEBUG "min_queue_within_t is %u\n", mytcp->min_queue_within_t); + // printk(KERN_DEBUG "the mytcp RTT is %u\n",sample->rtt_us); + printk(KERN_DEBUG "in mytcp the cwnd is %u\n", tp->snd_cwnd); + + } + mytcp->min_queue = tp->mytcp_est_rq; if ((mytcp->min_queue_within_t > 0) && (mytcp->max_queue_within_t > mytcp->min_queue_within_t)){ mytcp->one_full_ronund_send = mytcp->max_queue_within_t - mytcp->min_queue_within_t; mytcp->threshold = (mytcp->one_full_ronund_send * 5) / 100; - mytcp->threshold = max(mytcp->threshold,RQ_allow); + // mytcp->threshold = max(mytcp->threshold,RQ_allow); + if(RQ_allow > mytcp->threshold){ + mytcp->threshold = RQ_allow; + } +// mytcp->threshold = max(mytcp->threshold,1); } else{ mytcp->threshold = RQ_allow; @@ -253,24 +281,32 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) } - if (tcp_in_slow_start(tp)) { + if (tcp_in_slow_start(tp) && tp->exit_slow_start_flag != 1) { tcp_slow_start(tp, acked); mytcp->cwnd_hold = tp->snd_cwnd; } + if((tp->mytcp_average_rtt != 0) &&((tp->mytcp_average_rtt - mytcp->min_rtt) > 20000)){ + tp->exit_slow_start_flag = 1; + } + + + //当没有显式拥塞的信息返回时,按照正常的QCC逻辑利用驱动残余队列调整cwnd if (!tp->mytcp_ece_flag){ //与BBR类似,当连续三轮网卡发送检测出超过阈值的堆积时,才判定占满带宽,退出慢启动。 - if(/*mytcp_round_count*/ tp->mytcp_round_flag >= 1 && tcp_in_slow_start(tp)){ + if(/*mytcp_round_count*/ tp->mytcp_round_flag >= 1 && tcp_in_slow_start(tp) && tp->exit_slow_start_flag != 1){ //mytcp_round_count = 0; tp->mytcp_round_flag = 0; if (tcp_in_slow_start(tp)) { + printk(KERN_DEBUG "qcc in slow start and slow start\n"); int flag_count = 0; mytcp->full_flag_3 = mytcp->full_flag_2; mytcp->full_flag_2 = mytcp->full_flag_1; mytcp->min_queue_within_t = tp->mytcp_est_rq; mytcp->full_flag_1 = mytcp->min_queue_within_t; + if(mytcp->full_flag_1 > mytcp->threshold){ flag_count ++; tp->mytcp_full_pipe_flag = 1; @@ -287,19 +323,38 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) // printk(KERN_DEBUG "in slow start, the flag1 is %d, the flag2 is %d, the flag3 is %d\n", mytcp->full_flag_1, mytcp->full_flag_2, mytcp->full_flag_3); //判定占满的条件是残余队列连续三轮大于阈值,或者一旦超过50(表明此时堆积很大) //50这个参数取的经验值,调试分析发现这一个值可以有一定变化影响也不大,因为于拥塞避免阶段也具有调整能力 - if ((flag_count >= 3 && /*mytcp_round_max*/tp->mytcp_est_max_queue_real > 50) || (mytcp->full_flag_1 > 80) || (mytcp->loss_cnt > 3)) - { + if ( ((tp->mytcp_average_rtt != 0) &&((tp->mytcp_average_rtt - mytcp->min_rtt) > 20000))|| (flag_count >= 3 && /*mytcp_round_max*/tp->mytcp_est_max_queue_real > 50) || (mytcp->full_flag_1 > 80) || (mytcp->loss_cnt > 3)) + { + + if((tp->mytcp_average_rtt - mytcp->min_rtt) > 20000){ + printk(KERN_DEBUG " mytcp->min_rtt is %u\n",mytcp->min_rtt); + printk(KERN_DEBUG " tp->mytcp_average_rtt is %u\n",tp->mytcp_average_rtt); + printk(KERN_DEBUG "exit slow start because rtt is too big\n"); + } + // mytcp->time_last = ktime_get_real_ns(); // mytcp->cwnd_first = tp->snd_cwnd - mytcp->full_flag_1; mytcp->cwnd_first = tp->snd_cwnd; + + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "exit slow start flag_count >=3 cwnd_first is %u\n", mytcp->cwnd_first); + } // tp->snd_cwnd = mytcp->cwnd_first; // tp->snd_ssthresh = tcp_mytcp_ssthresh(tp)/2; + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "in slow start, full, before ssthresh change the snd_cwnd is %d, the ssh is %d\n", mytcp->cwnd_first, tp->snd_ssthresh); + } tp->snd_ssthresh = mytcp->cwnd_first/2; mytcp->time_last = ktime_get_real_ns(); mytcp->beg_snd_nxt = tp->snd_nxt; tp->mytcp_bytes_send = 0; tp->mytcp_acked_seq_last = ack; - printk(KERN_DEBUG "in slow start, full, the snd_cwnd is %d, the ssh is %d\n", mytcp->cwnd_first, tp->snd_ssthresh); + tp->exit_slow_start_flag = 1; + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "dport is %u and sport is %u\n", ntohs(inet2->inet_dport), ntohs(inet2->inet_dport)); + printk(KERN_DEBUG "exit slow start\n"); + printk(KERN_DEBUG "in slow start, full, after ssthresh change the snd_cwnd is %d, the ssh is %d\n", mytcp->cwnd_first, tp->snd_ssthresh); + } } // printk(KERN_DEBUG "in slow start, the source port is %d, the snd_cwnd is %d, \n", tp->myfast_source, tp->snd_cwnd); } @@ -327,7 +382,11 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) tp->mytcp_round_flag = 0; // mytcp->cwnd_last = tp->snd_cwnd; if (mytcp->cong_flag == 3){ - tp->snd_cwnd = mytcp->cwnd_first; + printk(KERN_DEBUG "mytcp->cong_flag ==3\n"); + if (tp->exit_slow_start_flag==1 && mytcp->cwnd_first > 0){ + tp->snd_cwnd = mytcp->cwnd_first; + } + if(mytcp->max_queue_within_t > /*mytcp_round_max*/tp->mytcp_est_max_queue_real){ mytcp->max_queue_first = mytcp->max_queue_within_t; } @@ -342,16 +401,41 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) } else if (mytcp->cong_flag < 3){ - tp->snd_cwnd = mytcp->cwnd_first; + printk(KERN_DEBUG "mytcp->cong_flag = %u the cwnd will be cwnd_first and cwnd is %u\n",mytcp->cong_flag,tp->snd_cwnd); + printk(KERN_DEBUG "the cwnd_first is %d\n",mytcp->cwnd_first); + printk(KERN_DEBUG "the ssthresh is %u\n",tp->snd_ssthresh); + if (tp->exit_slow_start_flag==1 && mytcp->cwnd_first > 0){ + tp->snd_cwnd = mytcp->cwnd_first; + } mytcp->cong_flag ++; -// printk(KERN_DEBUG "mytcp->cong_flag < 3, snd_cwnd is %u\n", tp->snd_cwnd); + printk(KERN_DEBUG "mytcp->cong_flag < 3, the cwnd is %u\n", tp->snd_cwnd); } else{ + + ////////////// + + // if (mytcp->throughput_now > 0 && (tp->mytcp_average_rtt - mytcp->min_rtt) > 20000){ + + // printk(KERN_DEBUG "the cwnd_last will change now it is %u\n",mytcp->cwnd_last); + // u32 more_rtt = tp->mytcp_average_rtt - mytcp->min_rtt - 20000; + + // u32 more_cwnd_in_air = (((mytcp->throughput_now * 2)/1) * more_rtt)/(tp->mss_cache*8); + // printk(KERN_DEBUG "the more_cwnd_in_air is %u\n",more_cwnd_in_air); + // if(mytcp->cwnd_last > more_cwnd_in_air/2) + // { + // mytcp->cwnd_last = max(mytcp->cwnd_last - more_cwnd_in_air/2,mytcp->cwnd_last/2); + // } + // printk(KERN_DEBUG "the cwnd_last has change it is %u\n",mytcp->cwnd_last); + + // } + mytcp->queue_last = mytcp->queue_now; if(mytcp->min_last == 0 && mytcp->min_queue_within_t == 0){ //连续n轮最小队列长度为0,则cwnd增长步长变为n*10 // mytcp->cwnd_last = mytcp->cwnd_last + mytcp->threshold; - mytcp->cwnd_last = mytcp->cwnd_last + RQ_allow; + // mytcp->cwnd_last = mytcp->cwnd_last + RQ_allow; + mytcp->cwnd_last = mytcp->cwnd_last; + } else { @@ -361,20 +445,78 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) mytcp->min_last = mytcp->min_queue_within_t; if(mytcp->min_queue_within_t > 0 && mytcp->min_queue_within_t < mytcp->threshold){ + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "RQ is suitable cwnd will not change, snd_cwnd is %u\n", tp->snd_cwnd); + } tp->snd_cwnd = tp->snd_cwnd; mytcp->cwnd_first = tp->snd_cwnd; mytcp->max_queue_first = mytcp->max_queue_now; + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "RQ is suitable cwnd not change, snd_cwnd is %u\n", tp->snd_cwnd); + printk(KERN_DEBUG "cwnd_first is %u\n", mytcp->cwnd_first); + } // printk(KERN_DEBUG "suitable, snd_cwnd is %u\n", tp->snd_cwnd); // printk(KERN_DEBUG "111111111111111111111111111, into the update, snd_cwnd is %u\n", tp->snd_cwnd); } // else if(/*mytcp->max_queue_now > 10 && */mytcp->queue_now > 5){ //确保队列中至少有5个包的进出 else{ if(mytcp->min_queue_within_t > mytcp->threshold){ - tp->snd_cwnd = mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold); + + if (mytcp->throughput_now > 0 && (tp->mytcp_average_rtt - mytcp->min_rtt) > 20000){ + printk(KERN_DEBUG "the cwnd_last will change now it is %u\n",mytcp->cwnd_last); + u32 more_rtt = tp->mytcp_average_rtt - mytcp->min_rtt - 20000; + u32 more_cwnd_in_air = (((mytcp->throughput_now * 2)/1) * more_rtt)/(tp->mss_cache*8); + printk(KERN_DEBUG "the more_cwnd_in_air is %u\n",more_cwnd_in_air); + if(mytcp->cwnd_last > more_cwnd_in_air/2) + { + mytcp->cwnd_last = max(mytcp->cwnd_last - more_cwnd_in_air/2,mytcp->cwnd_last/2); + } + printk(KERN_DEBUG "the cwnd_last has change it is %u\n",mytcp->cwnd_last); + } + + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "long,the cwnd will down now the snd_cwnd is %u\n", tp->snd_cwnd); + printk(KERN_DEBUG "RQ is %u\n", mytcp->min_queue_within_t); + printk(KERN_DEBUG "mytcp->threshold is %u\n", mytcp->threshold); + // printk(KERN_DEBUG "cwnd will be mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold); is %u\n", mytcp->threshold); + } + // u32 more_cwnd = ((mytcp->min_queue_within_t - mytcp->threshold)*(mytcp->min_queue_within_t - mytcp->threshold/2))/mytcp->threshold;//此时残余队列长度减阈值 + u32 more_cwnd = mytcp->min_queue_within_t - mytcp->threshold; + printk(KERN_DEBUG "the more_cwnd is %u\n", more_cwnd); + + if(more_cwnd < mytcp->cwnd_last){ + // tp->snd_cwnd = mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold); + + tp->snd_cwnd = mytcp->cwnd_last - more_cwnd; + if(tp->snd_cwnd < 10){ + // printk(KERN_DEBUG "now cwnd < 10 so make it 10 \n"); + tp->snd_cwnd = 10; + } + // printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd); + }else{ + tp->snd_cwnd -= 10; + // printk(KERN_DEBUG "too_long, mytcp->cwnd_last is %u\n", mytcp->cwnd_last); + // printk(KERN_DEBUG "too_long, mytcp->min_queue_within_t is %u\n", mytcp->min_queue_within_t); + // printk(KERN_DEBUG "too_long, mytcp->threshold is %u\n", mytcp->threshold); + // printk(KERN_DEBUG "too_long, mytcp->min_queue_within_t - mytcp->threshold is %u\n", mytcp->min_queue_within_t - mytcp->threshold); + // printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd); + // printk(KERN_DEBUG "now cwnd < 0 so make it 10\n"); + } + + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "long,the cwnd has down now the snd_cwnd is %u\n", tp->snd_cwnd); + } + // tp->snd_cwnd = mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold); // printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd); } if(mytcp->min_queue_within_t == 0){ + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "RQ is 0 cwnd will change + 步长, snd_cwnd is %u\n", tp->snd_cwnd); + } tp->snd_cwnd = mytcp->cwnd_last + mytcp->threshold; + if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){ + printk(KERN_DEBUG "RQ is 0 cwnd has change, snd_cwnd is %u\n", tp->snd_cwnd); + } // printk(KERN_DEBUG "empty, snd_cwnd is %u\n", tp->snd_cwnd); } } @@ -389,8 +531,8 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) } - printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, tp->snd_cwnd is %u\n", tp->snd_cwnd); - printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, min_queue_within_t is %d\n", mytcp->min_queue_within_t); + // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, tp->snd_cwnd is %u\n", tp->snd_cwnd); + // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, min_queue_within_t is %d\n", mytcp->min_queue_within_t); // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, queue last is %d\n", mytcp->queue_last); // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, queue now is %d\n", mytcp->queue_now); @@ -401,8 +543,10 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) tp->mytcp_est_max_queue_real = 0; // mytcp->min_queue_within_t = 1000; // mytcp_actual_min_queue = 1000; - if (tp->snd_cwnd < 10) + if (tp->snd_cwnd < 10){ tp->snd_cwnd = 10; + printk(KERN_DEBUG "snd_cwnd < 10 so make cwnd is 10\n"); + } // if (tp->snd_cwnd > 30) // tp->snd_cwnd = 30; else if (tp->snd_cwnd > tp->snd_cwnd_clamp) @@ -419,73 +563,158 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) } } +// // 每一个rtt统计一次有线瓶颈的场景 +// if (after(ack, mytcp->beg_snd_nxt) && !tcp_in_slow_start(tp)){ //瓶颈为有线部分时的处理 + +// int packets_in_air; +// int RQ_wire; +// int RQ_wire2; +// int extra_cwnd; +// int throughput2; + +// mytcp->beg_snd_nxt = tp->snd_nxt; +// mytcp->time_now = ktime_get_real_ns(); + +// //从确认占满链路后100ms再开始计算吞吐量,避免慢启动发送窗口耗尽对带宽估算的影响。 +// // if ((mytcp->time_now - mytcp->time_last)>(100*1000)){ + +// tp->mytcp_acked_bytes = ack - tp->mytcp_acked_seq_last; +// mytcp->throughput_now = (tp->mytcp_bytes_send * 8) / ((mytcp->time_now - mytcp->time_last)/1000); +// throughput2 = (tp->mytcp_acked_bytes * 8) / ((mytcp->time_now - mytcp->time_last)/1000); + +// if (mytcp->throughput_now > 0){ +// packets_in_air = (((mytcp->throughput_now * 2)/1) * mytcp->min_rtt)/(tp->mss_cache*8); +// RQ_wire = tp->packets_out - mytcp->min_queue - packets_in_air; +// } + +// else { +// RQ_wire = 0; +// } + +// if(RQ_wire < 0){ +// RQ_wire = 0; +// } + +// if(RQ_wire > mytcp->threshold){ +// extra_cwnd = RQ_wire - mytcp->threshold; +// // tp->snd_cwnd = mytcp->cwnd_last - (RQ_wire - mytcp->threshold); +// } + +// else{ +// extra_cwnd = 0; +// // tp->snd_cwnd = tp->snd_cwnd; +// } + +// // tp->snd_cwnd = mytcp->cwnd_last - max(tp->mytcp_ece_count, extra_cwnd); +// tp->snd_cwnd = mytcp->cwnd_last -extra_cwnd; + +// if (tp->snd_cwnd > (2*packets_in_air)){ +// tp->snd_cwnd = (2*packets_in_air); +// } + +// // printk(KERN_DEBUG "the bytes ackes is %llu, time interval is %llu\n", tp->bytes_acked, mytcp->time_now - mytcp->time_last); +// printk(KERN_DEBUG "the throughput is %u, throughput2 is %u, RQ_wire is %u\n", mytcp->throughput_now, throughput2, RQ_wire); +// printk(KERN_DEBUG "wired bottle, the packets out is %u, min queue is %u, packets in air is %d, the RQ wire is %d\n", +// tp->packets_out, mytcp->min_queue, packets_in_air, RQ_wire); +// // printk(KERN_DEBUG "wired bottle, the mytcp_ece_count is %u, extra_cwnd is %u\n",tp->mytcp_ece_count, extra_cwnd); +// printk(KERN_DEBUG ",wired bottle, into the cong_avoid, the cwnd is %u\n", tp->snd_cwnd); +// // } +// //将ece计数器置0,重新开始统计下一轮rtt内的ece数量 +// tp->mytcp_ece_count = 0; +// tp->mytcp_bytes_send = 0; +// tp->mytcp_acked_seq_last = ack; +// mytcp->time_last = mytcp->time_now; +// mytcp->cwnd_hold = tp->snd_cwnd; +// } + +// else{ +// tp->snd_cwnd = mytcp->cwnd_hold; +// // printk(KERN_DEBUG "111111111111111111111111111, else, the cwnd is %u\n", tp->snd_cwnd); +// } // 每一个rtt统计一次有线瓶颈的场景 - if (after(ack, mytcp->beg_snd_nxt) && !tcp_in_slow_start(tp)){ //瓶颈为有线部分时的处理 - - int packets_in_air; - int RQ_wire; - int RQ_wire2; - int extra_cwnd; - int throughput2; - + if (after(ack, mytcp->beg_snd_nxt)){ //瓶颈为有线部分时的处理 + printk(KERN_DEBUG "此时经历了一轮RTT\n"); mytcp->beg_snd_nxt = tp->snd_nxt; - mytcp->time_now = ktime_get_real_ns(); + tp->mytcp_this_rtt_count = 0; + if(!tcp_in_slow_start(tp)){ + int packets_in_air; + int RQ_wire; + int RQ_wire2; + int extra_cwnd; + int throughput2; - //从确认占满链路后100ms再开始计算吞吐量,避免慢启动发送窗口耗尽对带宽估算的影响。 -// if ((mytcp->time_now - mytcp->time_last)>(100*1000)){ + + mytcp->time_now = ktime_get_real_ns(); - tp->mytcp_acked_bytes = ack - tp->mytcp_acked_seq_last; - mytcp->throughput_now = (tp->mytcp_bytes_send * 8) / ((mytcp->time_now - mytcp->time_last)/1000); - throughput2 = (tp->mytcp_acked_bytes * 8) / ((mytcp->time_now - mytcp->time_last)/1000); + //从确认占满链路后100ms再开始计算吞吐量,避免慢启动发送窗口耗尽对带宽估算的影响。 + // if ((mytcp->time_now - mytcp->time_last)>(100*1000)){ - if (mytcp->throughput_now > 0){ - packets_in_air = (((mytcp->throughput_now * 2)/1) * mytcp->min_rtt)/(tp->mss_cache*8); - RQ_wire = tp->packets_out - mytcp->min_queue - packets_in_air; - } + tp->mytcp_acked_bytes = ack - tp->mytcp_acked_seq_last; + mytcp->throughput_now = (tp->mytcp_bytes_send * 8) / ((mytcp->time_now - mytcp->time_last)/1000); + throughput2 = (tp->mytcp_acked_bytes * 8) / ((mytcp->time_now - mytcp->time_last)/1000); - else { - RQ_wire = 0; - } + if (mytcp->throughput_now > 0){ + packets_in_air = (((mytcp->throughput_now * 2)/1) * mytcp->min_rtt)/(tp->mss_cache*8); + printk(KERN_DEBUG "the mytcp->throughput_now is > 0\n"); + RQ_wire = tp->packets_out - mytcp->min_queue - packets_in_air; + } - if(RQ_wire < 0){ - RQ_wire = 0; - } + else { + RQ_wire = 0; + } - if(RQ_wire > mytcp->threshold){ - extra_cwnd = RQ_wire - mytcp->threshold; -// tp->snd_cwnd = mytcp->cwnd_last - (RQ_wire - mytcp->threshold); - } + if(RQ_wire < 0){ + RQ_wire = 0; + } - else{ - extra_cwnd = 0; -// tp->snd_cwnd = tp->snd_cwnd; - } + if(RQ_wire > mytcp->threshold){ + extra_cwnd = RQ_wire - mytcp->threshold; + // tp->snd_cwnd = mytcp->cwnd_last - (RQ_wire - mytcp->threshold); + } - tp->snd_cwnd = mytcp->cwnd_last - max(tp->mytcp_ece_count, extra_cwnd); + else{ + extra_cwnd = 0; + // tp->snd_cwnd = tp->snd_cwnd; + } - if (tp->snd_cwnd > (2*packets_in_air)){ - tp->snd_cwnd = (2*packets_in_air); - } + // tp->snd_cwnd = mytcp->cwnd_last - max(tp->mytcp_ece_count, extra_cwnd); + tp->snd_cwnd = mytcp->cwnd_last -extra_cwnd; -// printk(KERN_DEBUG "the bytes ackes is %llu, time interval is %llu\n", tp->bytes_acked, mytcp->time_now - mytcp->time_last); - printk(KERN_DEBUG "the throughput is %u, throughput2 is %u, RQ_wire is %u\n", mytcp->throughput_now, throughput2, RQ_wire); - printk(KERN_DEBUG "wired bottle, the packets out is %u, min queue is %u, packets in air is %d, the RQ wire is %d\n", - tp->packets_out, mytcp->min_queue, packets_in_air, RQ_wire); -// printk(KERN_DEBUG "wired bottle, the mytcp_ece_count is %u, extra_cwnd is %u\n",tp->mytcp_ece_count, extra_cwnd); - printk(KERN_DEBUG "111111111111111111111111111, wired bottle, into the cong_avoid, the cwnd is %u\n", tp->snd_cwnd); -// } - //将ece计数器置0,重新开始统计下一轮rtt内的ece数量 - tp->mytcp_ece_count = 0; - tp->mytcp_bytes_send = 0; - tp->mytcp_acked_bytes = ack; - mytcp->time_last = mytcp->time_now; - mytcp->cwnd_hold = tp->snd_cwnd; - } + tp->snd_cwnd = max(mytcp->cwnd_last - extra_cwnd,tp->snd_cwnd/2);//吕超加的,为了控制保证吞吐量不会过低 - else{ + if (tp->snd_cwnd > (2*packets_in_air)){ + tp->snd_cwnd = (2*packets_in_air); + } + if(tp->snd_cwnd < 10){ + tp->snd_cwnd = 10; + } + + // printk(KERN_DEBUG "the bytes ackes is %llu, time interval is %llu\n", tp->bytes_acked, mytcp->time_now - mytcp->time_last); + printk(KERN_DEBUG "the throughput is %u, throughput2 is %u, RQ_wire is %u\n", mytcp->throughput_now, throughput2, RQ_wire); + printk(KERN_DEBUG "wired bottle, the packets out is %u, min queue is %u, packets in air is %d, the RQ wire is %d\n", + tp->packets_out, mytcp->min_queue, packets_in_air, RQ_wire); + // printk(KERN_DEBUG "wired bottle, the mytcp_ece_count is %u, extra_cwnd is %u\n",tp->mytcp_ece_count, extra_cwnd); + printk(KERN_DEBUG ",wired bottle, into the cong_avoid, the cwnd is %u\n", tp->snd_cwnd); + // } + //将ece计数器置0,重新开始统计下一轮rtt内的ece数量 + tp->mytcp_ece_count = 0; + tp->mytcp_bytes_send = 0; + tp->mytcp_acked_seq_last = ack; + mytcp->time_last = mytcp->time_now; + mytcp->cwnd_hold = tp->snd_cwnd; + } + else{ tp->snd_cwnd = mytcp->cwnd_hold; -// printk(KERN_DEBUG "111111111111111111111111111, else, the cwnd is %u\n", tp->snd_cwnd); } + } + else{//本轮rtt没有结束 + tp->mytcp_average_rtt = ((tp->mytcp_average_rtt)*(tp->mytcp_this_rtt_count)+tp->my_ip_rtt)/(tp->mytcp_this_rtt_count+1); + printk(KERN_DEBUG "now average RTT is %u\n",tp->mytcp_average_rtt); + tp->mytcp_this_rtt_count += 1; + + tp->snd_cwnd = mytcp->cwnd_hold; +// printk(KERN_DEBUG "111111111111111111111111111, else, the cwnd is %u\n", tp->snd_cwnd); + } @@ -496,6 +725,8 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked) + + /* Extract info for Tcp socket info provided via netlink. */ size_t tcp_mytcp_get_info(struct sock *sk, u32 ext, int *attr, union tcp_cc_info *info) @@ -550,4 +781,3 @@ MODULE_DESCRIPTION("TCP mytcp"); - diff --git a/net/ipv4/tcp_mytcp.h b/net/ipv4/tcp_mytcp.h old mode 100644 new mode 100755 -- cgit v1.2.3-70-g09d2