xref: /illumos-gate/usr/src/uts/common/io/ib/clients/rdsv3/stats.c (revision 16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347)
1 /*
2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 
5 /*
6  * This file contains code imported from the OFED rds source file stats.c
7  * Oracle elects to have and use the contents of stats.c under and governed
8  * by the OpenIB.org BSD license (see below for full license text). However,
9  * the following notice accompanied the original version of this file:
10  */
11 
12 /*
13  * Copyright (c) 2006 Oracle.  All rights reserved.
14  *
15  * This software is available to you under a choice of one of two
16  * licenses.  You may choose to be licensed under the terms of the GNU
17  * General Public License (GPL) Version 2, available from the file
18  * COPYING in the main directory of this source tree, or the
19  * OpenIB.org BSD license below:
20  *
21  *     Redistribution and use in source and binary forms, with or
22  *     without modification, are permitted provided that the following
23  *     conditions are met:
24  *
25  *      - Redistributions of source code must retain the above
26  *        copyright notice, this list of conditions and the following
27  *        disclaimer.
28  *
29  *      - Redistributions in binary form must reproduce the above
30  *        copyright notice, this list of conditions and the following
31  *        disclaimer in the documentation and/or other materials
32  *        provided with the distribution.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
38  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
39  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41  * SOFTWARE.
42  *
43  */
44 #include <sys/rds.h>
45 
46 #include <sys/ib/clients/rdsv3/rdsv3.h>
47 
48 RDSV3_DEFINE_PER_CPU(struct rdsv3_statistics, rdsv3_stats);
49 
50 static char *rdsv3_stat_names[] = {
51 	"conn_reset",
52 	"recv_drop_bad_checksum",
53 	"recv_drop_old_seq",
54 	"recv_drop_no_sock",
55 	"recv_drop_dead_sock",
56 	"recv_deliver_raced",
57 	"recv_delivered",
58 	"recv_queued",
59 	"recv_immediate_retry",
60 	"recv_delayed_retry",
61 	"recv_ack_required",
62 	"recv_rdma_bytes",
63 	"recv_ping",
64 	"send_queue_empty",
65 	"send_queue_full",
66 	"send_sem_contention",
67 	"send_sem_queue_raced",
68 	"send_immediate_retry",
69 	"send_delayed_retry",
70 	"send_drop_acked",
71 	"send_ack_required",
72 	"send_queued",
73 	"send_rdma",
74 	"send_rdma_bytes",
75 	"send_pong",
76 	"page_remainder_hit",
77 	"page_remainder_miss",
78 	"copy_to_user",
79 	"copy_from_user",
80 	"cong_update_queued",
81 	"cong_update_received",
82 	"cong_send_error",
83 	"cong_send_blocked",
84 };
85 
86 void
87 rdsv3_stats_info_copy(struct rdsv3_info_iterator *iter,
88     uint64_t *values, char **names, size_t nr)
89 {
90 	struct rdsv3_info_counter ctr;
91 	size_t i;
92 
93 	for (i = 0; i < nr; i++) {
94 		ASSERT(!(strlen(names[i]) >= sizeof (ctr.name)));
95 		(void) strncpy((char *)ctr.name, names[i],
96 		    sizeof (ctr.name) - 1);
97 		ctr.value = values[i];
98 
99 		rdsv3_info_copy(iter, &ctr, sizeof (ctr));
100 	}
101 }
102 
103 /*
104  * This gives global counters across all the transports.  The strings
105  * are copied in so that the tool doesn't need knowledge of the specific
106  * stats that we're exporting.  Some are pretty implementation dependent
107  * and may change over time.  That doesn't stop them from being useful.
108  *
109  * This is the only function in the chain that knows about the byte granular
110  * length in userspace.  It converts it to number of stat entries that the
111  * rest of the functions operate in.
112  */
113 /* ARGSUSED */
114 static void
115 rdsv3_stats_info(struct rsock *sock, unsigned int len,
116     struct rdsv3_info_iterator *iter,
117     struct rdsv3_info_lengths *lens)
118 {
119 	struct rdsv3_statistics stats;
120 	uint64_t *src;
121 	uint64_t *sum;
122 	size_t i;
123 	int cpu;
124 	unsigned int avail;
125 
126 	avail = len / sizeof (struct rdsv3_info_counter);
127 
128 	if (avail < ARRAY_SIZE(rdsv3_stat_names)) {
129 		avail = 0;
130 		goto trans;
131 	}
132 
133 	bzero(&stats, sizeof (struct rdsv3_statistics));
134 
135 	for (cpu = 0; cpu < NR_CPUS; cpu++) {
136 		src = (uint64_t *)&(rdsv3_per_cpu(rdsv3_stats, cpu));
137 		sum = (uint64_t *)&stats;
138 		for (i = 0;
139 		    i < sizeof (struct rdsv3_statistics) / sizeof (uint64_t);
140 		    i++)
141 			*(sum++) += *(src++);
142 	}
143 
144 	rdsv3_stats_info_copy(iter, (uint64_t *)&stats, rdsv3_stat_names,
145 	    ARRAY_SIZE(rdsv3_stat_names));
146 	avail -= ARRAY_SIZE(rdsv3_stat_names);
147 
148 trans:
149 	lens->each = sizeof (struct rdsv3_info_counter);
150 	lens->nr = rdsv3_trans_stats_info_copy(iter, avail) +
151 	    ARRAY_SIZE(rdsv3_stat_names);
152 }
153 
154 void
155 rdsv3_stats_exit(void)
156 {
157 	rdsv3_info_deregister_func(RDSV3_INFO_COUNTERS, rdsv3_stats_info);
158 }
159 
160 int
161 rdsv3_stats_init(void)
162 {
163 	rdsv3_info_register_func(RDSV3_INFO_COUNTERS, rdsv3_stats_info);
164 	return (0);
165 }
166