xref: /OK3568_Linux_fs/kernel/net/rds/stats.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2006 Oracle.  All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This software is available to you under a choice of one of two
5*4882a593Smuzhiyun  * licenses.  You may choose to be licensed under the terms of the GNU
6*4882a593Smuzhiyun  * General Public License (GPL) Version 2, available from the file
7*4882a593Smuzhiyun  * COPYING in the main directory of this source tree, or the
8*4882a593Smuzhiyun  * OpenIB.org BSD license below:
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *     Redistribution and use in source and binary forms, with or
11*4882a593Smuzhiyun  *     without modification, are permitted provided that the following
12*4882a593Smuzhiyun  *     conditions are met:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *      - Redistributions of source code must retain the above
15*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
16*4882a593Smuzhiyun  *        disclaimer.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  *      - Redistributions in binary form must reproduce the above
19*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
20*4882a593Smuzhiyun  *        disclaimer in the documentation and/or other materials
21*4882a593Smuzhiyun  *        provided with the distribution.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26*4882a593Smuzhiyun  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30*4882a593Smuzhiyun  * SOFTWARE.
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun #include <linux/percpu.h>
34*4882a593Smuzhiyun #include <linux/seq_file.h>
35*4882a593Smuzhiyun #include <linux/proc_fs.h>
36*4882a593Smuzhiyun #include <linux/export.h>
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #include "rds.h"
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun DEFINE_PER_CPU_SHARED_ALIGNED(struct rds_statistics, rds_stats);
41*4882a593Smuzhiyun EXPORT_PER_CPU_SYMBOL_GPL(rds_stats);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /* :.,$s/unsigned long\>.*\<s_\(.*\);/"\1",/g */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun static const char *const rds_stat_names[] = {
46*4882a593Smuzhiyun 	"conn_reset",
47*4882a593Smuzhiyun 	"recv_drop_bad_checksum",
48*4882a593Smuzhiyun 	"recv_drop_old_seq",
49*4882a593Smuzhiyun 	"recv_drop_no_sock",
50*4882a593Smuzhiyun 	"recv_drop_dead_sock",
51*4882a593Smuzhiyun 	"recv_deliver_raced",
52*4882a593Smuzhiyun 	"recv_delivered",
53*4882a593Smuzhiyun 	"recv_queued",
54*4882a593Smuzhiyun 	"recv_immediate_retry",
55*4882a593Smuzhiyun 	"recv_delayed_retry",
56*4882a593Smuzhiyun 	"recv_ack_required",
57*4882a593Smuzhiyun 	"recv_rdma_bytes",
58*4882a593Smuzhiyun 	"recv_ping",
59*4882a593Smuzhiyun 	"send_queue_empty",
60*4882a593Smuzhiyun 	"send_queue_full",
61*4882a593Smuzhiyun 	"send_lock_contention",
62*4882a593Smuzhiyun 	"send_lock_queue_raced",
63*4882a593Smuzhiyun 	"send_immediate_retry",
64*4882a593Smuzhiyun 	"send_delayed_retry",
65*4882a593Smuzhiyun 	"send_drop_acked",
66*4882a593Smuzhiyun 	"send_ack_required",
67*4882a593Smuzhiyun 	"send_queued",
68*4882a593Smuzhiyun 	"send_rdma",
69*4882a593Smuzhiyun 	"send_rdma_bytes",
70*4882a593Smuzhiyun 	"send_pong",
71*4882a593Smuzhiyun 	"page_remainder_hit",
72*4882a593Smuzhiyun 	"page_remainder_miss",
73*4882a593Smuzhiyun 	"copy_to_user",
74*4882a593Smuzhiyun 	"copy_from_user",
75*4882a593Smuzhiyun 	"cong_update_queued",
76*4882a593Smuzhiyun 	"cong_update_received",
77*4882a593Smuzhiyun 	"cong_send_error",
78*4882a593Smuzhiyun 	"cong_send_blocked",
79*4882a593Smuzhiyun 	"recv_bytes_added_to_sock",
80*4882a593Smuzhiyun 	"recv_bytes_freed_fromsock",
81*4882a593Smuzhiyun 	"send_stuck_rm",
82*4882a593Smuzhiyun };
83*4882a593Smuzhiyun 
rds_stats_info_copy(struct rds_info_iterator * iter,uint64_t * values,const char * const * names,size_t nr)84*4882a593Smuzhiyun void rds_stats_info_copy(struct rds_info_iterator *iter,
85*4882a593Smuzhiyun 			 uint64_t *values, const char *const *names, size_t nr)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun 	struct rds_info_counter ctr;
88*4882a593Smuzhiyun 	size_t i;
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	for (i = 0; i < nr; i++) {
91*4882a593Smuzhiyun 		BUG_ON(strlen(names[i]) >= sizeof(ctr.name));
92*4882a593Smuzhiyun 		strncpy(ctr.name, names[i], sizeof(ctr.name) - 1);
93*4882a593Smuzhiyun 		ctr.name[sizeof(ctr.name) - 1] = '\0';
94*4882a593Smuzhiyun 		ctr.value = values[i];
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 		rds_info_copy(iter, &ctr, sizeof(ctr));
97*4882a593Smuzhiyun 	}
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(rds_stats_info_copy);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun  * This gives global counters across all the transports.  The strings
103*4882a593Smuzhiyun  * are copied in so that the tool doesn't need knowledge of the specific
104*4882a593Smuzhiyun  * stats that we're exporting.  Some are pretty implementation dependent
105*4882a593Smuzhiyun  * and may change over time.  That doesn't stop them from being useful.
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  * This is the only function in the chain that knows about the byte granular
108*4882a593Smuzhiyun  * length in userspace.  It converts it to number of stat entries that the
109*4882a593Smuzhiyun  * rest of the functions operate in.
110*4882a593Smuzhiyun  */
rds_stats_info(struct socket * sock,unsigned int len,struct rds_info_iterator * iter,struct rds_info_lengths * lens)111*4882a593Smuzhiyun static void rds_stats_info(struct socket *sock, unsigned int len,
112*4882a593Smuzhiyun 			   struct rds_info_iterator *iter,
113*4882a593Smuzhiyun 			   struct rds_info_lengths *lens)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun 	struct rds_statistics stats = {0, };
116*4882a593Smuzhiyun 	uint64_t *src;
117*4882a593Smuzhiyun 	uint64_t *sum;
118*4882a593Smuzhiyun 	size_t i;
119*4882a593Smuzhiyun 	int cpu;
120*4882a593Smuzhiyun 	unsigned int avail;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	avail = len / sizeof(struct rds_info_counter);
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	if (avail < ARRAY_SIZE(rds_stat_names)) {
125*4882a593Smuzhiyun 		avail = 0;
126*4882a593Smuzhiyun 		goto trans;
127*4882a593Smuzhiyun 	}
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	for_each_online_cpu(cpu) {
130*4882a593Smuzhiyun 		src = (uint64_t *)&(per_cpu(rds_stats, cpu));
131*4882a593Smuzhiyun 		sum = (uint64_t *)&stats;
132*4882a593Smuzhiyun 		for (i = 0; i < sizeof(stats) / sizeof(uint64_t); i++)
133*4882a593Smuzhiyun 			*(sum++) += *(src++);
134*4882a593Smuzhiyun 	}
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	rds_stats_info_copy(iter, (uint64_t *)&stats, rds_stat_names,
137*4882a593Smuzhiyun 			    ARRAY_SIZE(rds_stat_names));
138*4882a593Smuzhiyun 	avail -= ARRAY_SIZE(rds_stat_names);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun trans:
141*4882a593Smuzhiyun 	lens->each = sizeof(struct rds_info_counter);
142*4882a593Smuzhiyun 	lens->nr = rds_trans_stats_info_copy(iter, avail) +
143*4882a593Smuzhiyun 		   ARRAY_SIZE(rds_stat_names);
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
rds_stats_exit(void)146*4882a593Smuzhiyun void rds_stats_exit(void)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun 	rds_info_deregister_func(RDS_INFO_COUNTERS, rds_stats_info);
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun 
rds_stats_init(void)151*4882a593Smuzhiyun int rds_stats_init(void)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun 	rds_info_register_func(RDS_INFO_COUNTERS, rds_stats_info);
154*4882a593Smuzhiyun 	return 0;
155*4882a593Smuzhiyun }
156