From 757ae9401ae161e374ae1c6cb3c30fa1f29cb6f4 Mon Sep 17 00:00:00 2001 From: Xuan Zhuo Date: Thu, 21 May 2020 14:28:07 +0800 Subject: [PATCH 1720/2944] alinux: tcp_rt module: change real to stats to #27804112 Uniformly modify "check" "statis" to stats. Since some users do not use the stats function, and the stats function takes up some resources, modifying stats is not enabled by default. Signed-off-by: Xuan Zhuo Acked-by: Dust Li Reviewed-by: Ya Zhao Reviewed-by: Cambda Zhu --- net/ipv4/tcp_rt/core.c | 54 ++++++++++++------------ net/ipv4/tcp_rt/output.c | 105 ++++++++++++++++++++++++----------------------- net/ipv4/tcp_rt/tcp_rt.h | 6 +-- 3 files changed, 82 insertions(+), 83 deletions(-) diff --git a/net/ipv4/tcp_rt/core.c b/net/ipv4/tcp_rt/core.c index f323b8a..d563d84 100644 --- a/net/ipv4/tcp_rt/core.c +++ b/net/ipv4/tcp_rt/core.c @@ -2,25 +2,25 @@ #include "tcp_rt.h" -static int ports_number; -static int ports_peer_number; -static int ports_range_number; +static int ports_number; +static int ports_peer_number; +static int ports_range_number; -static int ports[PORT_MAX_NUM]; -static int ports_peer[PORT_MAX_NUM]; -static int ports_range[PORT_MAX_NUM]; +static int ports[PORT_MAX_NUM]; +static int ports_peer[PORT_MAX_NUM]; +static int ports_range[PORT_MAX_NUM]; -static int log_buf_num = 8; -static int real_buf_num = 2; +static int log_buf_num = 8; +static int stats_buf_num = 2; -static int check = 1; -static int check_interval = 60; +static int stats; +static int stats_interval = 60; -module_param(check, int, 0644); -MODULE_PARM_DESC(check, "whether check the init_cwnd is ok"); +module_param(stats, int, 0644); +MODULE_PARM_DESC(stats, "stats is enable"); -module_param(check_interval, int, 0644); -MODULE_PARM_DESC(check_interval, "how many seconds later do stats"); +module_param(stats_interval, int, 0644); +MODULE_PARM_DESC(stats_interval, "how many seconds later do stats"); module_param_array(ports, int, &ports_number, 0644); MODULE_PARM_DESC(ports, "local port array. config: ports=80,3306."); @@ -33,14 +33,14 @@ module_param(log_buf_num, int, 0644); MODULE_PARM_DESC(log_buf_num, "the num of buffers for every cpu log buffer. unit is 256k. just work when module load."); -module_param(real_buf_num, int, 0644); -MODULE_PARM_DESC(real_buf_num, "the num of buffers for every cpu real buffer. unit is 16k. just work when module load."); +module_param(stats_buf_num, int, 0644); +MODULE_PARM_DESC(stats_buf_num, "the num of buffers for every cpu stats buffer. unit is 16k. just work when module load."); struct timer_list tcp_rt_timer; static void tcp_rt_timer_handler(struct timer_list *t) { - if (check) { + if (stats) { int i, port; for (i = 0; i < ports_number; i++) @@ -56,7 +56,7 @@ static void tcp_rt_timer_handler(struct timer_list *t) for (i = 0; i < ports_peer_number; i++) tcp_rt_timer_output(i, ports_peer[i], "P"); } - mod_timer(&tcp_rt_timer, jiffies + check_interval * HZ); + mod_timer(&tcp_rt_timer, jiffies + stats_interval * HZ); } static void tcp_rt_sk_send_data_peer(const struct sock *sk, struct tcp_rt *rt, @@ -64,7 +64,7 @@ static void tcp_rt_sk_send_data_peer(const struct sock *sk, struct tcp_rt *rt, { switch (rt->stage_peer) { case TCPRT_STAGE_PEER_RESPONSE: - tcp_rt_log_printk(sk, LOG_STATUS_P, false, check); + tcp_rt_log_printk(sk, LOG_STATUS_P, false, stats); /* fall through */ case TCPRT_STAGE_PEER_NONE: @@ -139,7 +139,7 @@ static void tcp_rt_sk_recv_data_local(const struct sock *sk, struct tcp_rt *rt, */ ktime_get_real_ts64(&rt->end_time); } - tcp_rt_log_printk(sk, LOG_STATUS_R, false, check); + tcp_rt_log_printk(sk, LOG_STATUS_R, false, stats); /* fall through */ @@ -185,7 +185,7 @@ static void tcp_rt_sk_release_peer(const struct sock *sk, struct tcp_rt *rt, return; case TCPRT_STAGE_PEER_RESPONSE: - tcp_rt_log_printk(sk, LOG_STATUS_P, false, check); + tcp_rt_log_printk(sk, LOG_STATUS_P, false, stats); return; } } @@ -199,7 +199,7 @@ static void tcp_rt_sk_release_local(const struct sock *sk, struct tcp_rt *rt, case TCPRT_STAGE_REQUEST: /* closed when receiving data */ - tcp_rt_log_printk(sk, LOG_STATUS_N, false, check); + tcp_rt_log_printk(sk, LOG_STATUS_N, false, stats); break; case TCPRT_STAGE_RESPONSE: @@ -210,12 +210,10 @@ static void tcp_rt_sk_release_local(const struct sock *sk, struct tcp_rt *rt, if (after(tp->snd_una, rt->last_update_seq + 1)) ktime_get_real_ts64(&rt->end_time); - tcp_rt_log_printk(sk, LOG_STATUS_R, true, - check); + tcp_rt_log_printk(sk, LOG_STATUS_R, true, stats); } else { /* closed when sending data */ - tcp_rt_log_printk(sk, LOG_STATUS_W, false, - check); + tcp_rt_log_printk(sk, LOG_STATUS_W, false, stats); } break; @@ -236,7 +234,7 @@ static void tcp_rt_sk_release(struct sock *sk) tcp_rt_sk_release_local(sk, rt, tp); /* closed, 1 record per connection */ - tcp_rt_log_printk(sk, LOG_STATUS_E, false, check); + tcp_rt_log_printk(sk, LOG_STATUS_E, false, stats); free: kfree(rt); @@ -364,7 +362,7 @@ static int __init tcp_rt_module_init(void) { int ret; - ret = tcp_rt_output_init(log_buf_num, real_buf_num, &fops); + ret = tcp_rt_output_init(log_buf_num, stats_buf_num, &fops); if (ret) return ret; diff --git a/net/ipv4/tcp_rt/output.c b/net/ipv4/tcp_rt/output.c index 0540b5e..7c21e95 100644 --- a/net/ipv4/tcp_rt/output.c +++ b/net/ipv4/tcp_rt/output.c @@ -4,26 +4,27 @@ #include "tcp_rt.h" #define CHUNK_SIZE (4096) -#define PORTS_PER_CHUNK (CHUNK_SIZE / sizeof(struct tcp_rt_real)) +#define PORTS_PER_CHUNK (CHUNK_SIZE / sizeof(struct tcp_rt_stats)) #define PORT_TOTAL_NUM (U16_MAX + 1) #define CHUNK_COUNT (PORT_TOTAL_NUM / PORTS_PER_CHUNK + 1) static struct rchan *relay_log; static struct rchan *relay_stats; static struct dentry *tcprt_dir; -static struct tcp_rt_real *statis_local[CHUNK_COUNT]; -static struct tcp_rt_real statis_peer[PORT_MAX_NUM]; -#define statis_local_inc(item) atomic64_inc(&(item)) -#define statis_local_add(item, val) atomic64_add(val, &(item)) +static struct tcp_rt_stats *stats_local[CHUNK_COUNT]; +static struct tcp_rt_stats stats_peer[PORT_MAX_NUM]; -#define statis_peer_inc(rt, item) \ - atomic64_inc(&statis_peer[(rt)->index].item) -#define statis_peer_add(rt, item, val) \ - atomic64_add(val, &statis_peer[(rt)->index].item) +#define stats_local_inc(item) atomic64_inc(&(item)) +#define stats_local_add(item, val) atomic64_add(val, &(item)) -#define tcp_rt_get_local_statis_sk(sk) \ - tcp_rt_get_local_statis(ntohs(inet_sk(sk)->inet_sport), true) +#define stats_peer_inc(rt, item) \ + atomic64_inc(&stats_peer[(rt)->index].item) +#define stats_peer_add(rt, item, val) \ + atomic64_add(val, &stats_peer[(rt)->index].item) + +#define tcp_rt_get_local_stats_sk(sk) \ + tcp_rt_get_local_stats(ntohs(inet_sk(sk)->inet_sport), true) static int64_t timespec64_dec(struct timespec64 tv1, struct timespec64 tv2) { @@ -76,14 +77,14 @@ static int ip_format2(char *buf, u32 addr, char end) return idx; } -static struct tcp_rt_real *tcp_rt_get_local_statis(int port, bool alloc) +static struct tcp_rt_stats *tcp_rt_get_local_stats(int port, bool alloc) { int chunkid; - struct tcp_rt_real *p; + struct tcp_rt_stats *p; chunkid = port / PORTS_PER_CHUNK; - p = statis_local[chunkid]; + p = stats_local[chunkid]; if (unlikely(!p)) { if (!alloc) @@ -95,9 +96,9 @@ static struct tcp_rt_real *tcp_rt_get_local_statis(int port, bool alloc) memset(p, 0, CHUNK_SIZE); - if (cmpxchg(&statis_local[chunkid], NULL, p)) { + if (cmpxchg(&stats_local[chunkid], NULL, p)) { vfree(p); - p = READ_ONCE(statis_local[chunkid]); + p = READ_ONCE(stats_local[chunkid]); } } @@ -129,11 +130,11 @@ static int bufheader(char *buf, int size, char flag, return n; } -void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check) +void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool stats) { #define MAX_BUF_SIZE 512 - struct tcp_rt_real *r; + struct tcp_rt_stats *r; struct tcp_sock *tp = tcp_sk(sk); struct tcp_rt *rt = TCP_SK_RT(sk); char buf[MAX_BUF_SIZE]; @@ -176,21 +177,21 @@ void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check) size += bufappend(buf, size, tp->mss_cache); buf[size++] = '\n'; - if (check && t_seq > 0) { - r = tcp_rt_get_local_statis_sk(sk); + if (stats && t_seq > 0) { + r = tcp_rt_get_local_stats_sk(sk); if (!r) break; - statis_local_inc(r->number); + stats_local_inc(r->number); - statis_local_add(r->rt, t_rt); - statis_local_add(r->bytes, t_seq); - statis_local_add(r->drop, t_retrans); - statis_local_add(r->packets, - t_seq / tp->mss_cache + 1); - statis_local_add(r->server_time, rt->server_time); - statis_local_add(r->upload_time, rt->upload_time); - statis_local_add(r->upload_data, rt->upload_data); + stats_local_add(r->rt, t_rt); + stats_local_add(r->bytes, t_seq); + stats_local_add(r->drop, t_retrans); + stats_local_add(r->packets, + t_seq / tp->mss_cache + 1); + stats_local_add(r->server_time, rt->server_time); + stats_local_add(r->upload_time, rt->upload_time); + stats_local_add(r->upload_data, rt->upload_data); } break; @@ -213,12 +214,12 @@ void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check) size += bufappend(buf, size, tp->mss_cache); buf[size++] = '\n'; - if (check && t_rt > HZ / 10) { - r = tcp_rt_get_local_statis_sk(sk); + if (stats && t_rt > HZ / 10) { + r = tcp_rt_get_local_stats_sk(sk); if (!r) break; - statis_local_inc(r->fail); + stats_local_inc(r->fail); } break; @@ -248,12 +249,12 @@ void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check) buf[size++] = '\n'; if (mrtt > 0) { - r = tcp_rt_get_local_statis_sk(sk); + r = tcp_rt_get_local_stats_sk(sk); if (!r) break; - statis_local_inc(r->con_num); - statis_local_add(r->rtt, mrtt); + stats_local_inc(r->con_num); + stats_local_add(r->rtt, mrtt); } break; @@ -270,13 +271,13 @@ void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check) size += bufappend(buf, size, tp->mss_cache); buf[size++] = '\n'; - if (check) { - statis_peer_inc(rt, number); - statis_peer_inc(rt, con_num); - statis_peer_add(rt, bytes, t_seq); - statis_peer_add(rt, rtt, mrtt); - statis_peer_add(rt, packets, t_seq / tp->mss_cache + 1); - statis_peer_add(rt, drop, t_retrans); + if (stats) { + stats_peer_inc(rt, number); + stats_peer_inc(rt, con_num); + stats_peer_add(rt, bytes, t_seq); + stats_peer_add(rt, rtt, mrtt); + stats_peer_add(rt, packets, t_seq / tp->mss_cache + 1); + stats_peer_add(rt, drop, t_retrans); } break; } @@ -287,25 +288,25 @@ void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check) void tcp_rt_timer_output(int index, int port, char *flag) { - struct tcp_rt_real *r; - struct _tcp_rt_real t; - struct _tcp_rt_real avg = {0}; + struct tcp_rt_stats *r; + struct _tcp_rt_stats t; + struct _tcp_rt_stats avg = {0}; int size; char buf[MAX_BUF_SIZE]; if (*flag == 'L') { if (index == PORT_MAX_NUM) - r = tcp_rt_get_local_statis(port, false); + r = tcp_rt_get_local_stats(port, false); else - r = tcp_rt_get_local_statis(port, true); + r = tcp_rt_get_local_stats(port, true); if (!r) return; flag = ""; } else { - r = statis_peer + index; + r = stats_peer + index; } t.number = atomic64_read(&r->number); @@ -380,7 +381,7 @@ static int remove_buf_file_handler(struct dentry *dentry) .remove_buf_file = remove_buf_file_handler, }; -int tcp_rt_output_init(int log_buf_num, int real_buf_num, +int tcp_rt_output_init(int log_buf_num, int stats_buf_num, const struct file_operations *fops) { tcprt_dir = debugfs_create_dir("tcp-rt", NULL); @@ -404,7 +405,7 @@ int tcp_rt_output_init(int log_buf_num, int real_buf_num, pr_info("tcp-rt: relay_log ready!\n"); relay_stats = relay_open("rt-network-real", NULL, STATS_SUBBUF_SIZE, - real_buf_num, &relay_callbacks, NULL); + stats_buf_num, &relay_callbacks, NULL); if (!relay_stats) { relay_close(relay_log); relay_log = NULL; @@ -426,8 +427,8 @@ void tcp_rt_output_released(void) relay_close(relay_stats); debugfs_remove_recursive(tcprt_dir); - for (i = 0; i < ARRAY_SIZE(statis_local); ++i) - kfree(statis_local[i]); + for (i = 0; i < ARRAY_SIZE(stats_local); ++i) + kfree(stats_local[i]); pr_info("tcp-rt: output released\n"); } diff --git a/net/ipv4/tcp_rt/tcp_rt.h b/net/ipv4/tcp_rt/tcp_rt.h index 18c382f..6414aca 100644 --- a/net/ipv4/tcp_rt/tcp_rt.h +++ b/net/ipv4/tcp_rt/tcp_rt.h @@ -80,7 +80,7 @@ struct tcp_rt { enum tcp_rt_stage_peer stage_peer; }; -struct tcp_rt_real { +struct tcp_rt_stats { atomic64_t rt; atomic64_t number; atomic64_t drop; @@ -94,7 +94,7 @@ struct tcp_rt_real { atomic64_t con_num; }; -struct _tcp_rt_real { +struct _tcp_rt_stats { u32 rt; u32 number; u32 drop; @@ -108,7 +108,7 @@ struct _tcp_rt_real { u32 con_num; }; -int tcp_rt_output_init(int log_buf_num, int real_buf_num, +int tcp_rt_output_init(int log_buf_num, int stats_buf_num, const struct file_operations *fops); void tcp_rt_output_released(void); void tcp_rt_log_printk(const struct sock *sk, char flag, bool fin, bool check); -- 1.8.3.1