xref: /linux/drivers/infiniband/ulp/rtrs/rtrs-srv-stats.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * RDMA Transport Layer
4  *
5  * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
6  * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
7  * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
8  */
9 #undef pr_fmt
10 #define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
11 
12 #include "rtrs-srv.h"
13 
rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats * stats,bool enable)14 int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable)
15 {
16 	if (enable) {
17 		int cpu;
18 		struct rtrs_srv_stats_rdma_stats *r;
19 
20 		for_each_possible_cpu(cpu) {
21 			r = per_cpu_ptr(stats->rdma_stats, cpu);
22 			memset(r, 0, sizeof(*r));
23 		}
24 
25 		return 0;
26 	}
27 
28 	return -EINVAL;
29 }
30 
rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats * stats,char * page)31 ssize_t rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats *stats, char *page)
32 {
33 	int cpu;
34 	struct rtrs_srv_stats_rdma_stats sum;
35 	struct rtrs_srv_stats_rdma_stats *r;
36 
37 	memset(&sum, 0, sizeof(sum));
38 
39 	for_each_possible_cpu(cpu) {
40 		r = per_cpu_ptr(stats->rdma_stats, cpu);
41 
42 		sum.dir[READ].cnt	  += r->dir[READ].cnt;
43 		sum.dir[READ].size_total  += r->dir[READ].size_total;
44 		sum.dir[WRITE].cnt	  += r->dir[WRITE].cnt;
45 		sum.dir[WRITE].size_total += r->dir[WRITE].size_total;
46 	}
47 
48 	return sysfs_emit(page, "%llu %llu %llu %llu\n",
49 			  sum.dir[READ].cnt, sum.dir[READ].size_total,
50 			  sum.dir[WRITE].cnt, sum.dir[WRITE].size_total);
51 }
52