From 81be6f9d9b51f093870677e4c32daeb3db70ad8a Mon Sep 17 00:00:00 2001 From: Xuan Zhuo Date: Thu, 4 Jun 2020 10:50:45 +0800 Subject: [PATCH 1726/2944] alinux: tcp_rt module: use atomic64_xchg replace atomic64_read and atomic64_set to #27804112 1. Call atomic_read first and then atomic_set which will cause some statistics to be lost 2. The instruction of atomic class is relatively slow, and calling it twice for each variable in succession is a big harm to performance. Signed-off-by: Xuan Zhuo Acked-by: Dust Li Reviewed-by: Ya Zhao Reviewed-by: Cambda Zhu --- net/ipv4/tcp_rt/output.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/net/ipv4/tcp_rt/output.c b/net/ipv4/tcp_rt/output.c index 16927bd..55a9a46 100644 --- a/net/ipv4/tcp_rt/output.c +++ b/net/ipv4/tcp_rt/output.c @@ -305,20 +305,20 @@ void tcp_rt_timer_output(int index, int port, char *flag) r = stats_peer + index; } - t.number = atomic64_read(&r->number); + t.number = atomic64_xchg(&r->number, 0); if (!t.number && index == PORT_MAX_NUM) return; - t.rt = atomic64_read(&r->rt); - t.bytes = atomic64_read(&r->bytes); - t.drop = atomic64_read(&r->drop); - t.fail = atomic64_read(&r->fail); - t.server_time = atomic64_read(&r->server_time); - t.packets = atomic64_read(&r->packets); - t.con_num = atomic64_read(&r->con_num); - t.rtt = atomic64_read(&r->rtt); - t.upload_time = atomic64_read(&r->upload_time); - t.upload_data = atomic64_read(&r->upload_data); + t.server_time = atomic64_xchg(&r->server_time, 0); + t.rt = atomic64_xchg(&r->rt, 0); + t.bytes = atomic64_xchg(&r->bytes, 0); + t.drop = atomic64_xchg(&r->drop, 0); + t.fail = atomic64_xchg(&r->fail, 0); + t.packets = atomic64_xchg(&r->packets, 0); + t.con_num = atomic64_xchg(&r->con_num, 0); + t.rtt = atomic64_xchg(&r->rtt, 0); + t.upload_time = atomic64_xchg(&r->upload_time, 0); + t.upload_data = atomic64_xchg(&r->upload_data, 0); if (t.number > 0) { avg.rt = t.rt / t.number; @@ -340,18 +340,6 @@ void tcp_rt_timer_output(int index, int port, char *flag) if (relay_stats) relay_write(relay_stats, buf, size); - - atomic64_set(&r->rt, 0); - atomic64_set(&r->number, 0); - atomic64_set(&r->bytes, 0); - atomic64_set(&r->drop, 0); - atomic64_set(&r->fail, 0); - atomic64_set(&r->server_time, 0); - atomic64_set(&r->packets, 0); - atomic64_set(&r->con_num, 0); - atomic64_set(&r->rtt, 0); - atomic64_set(&r->upload_time, 0); - atomic64_set(&r->upload_data, 0); } static struct dentry *create_buf_file_handler(const char *filename, -- 1.8.3.1