stats.c revision 12198:4db936bda957
1226026Sdelphij/*
2226026Sdelphij * CDDL HEADER START
3226026Sdelphij *
4226026Sdelphij * The contents of this file are subject to the terms of the
5226026Sdelphij * Common Development and Distribution License (the "License").
6226026Sdelphij * You may not use this file except in compliance with the License.
7226026Sdelphij *
8226026Sdelphij * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9226026Sdelphij * or http://www.opensolaris.org/os/licensing.
10226026Sdelphij * See the License for the specific language governing permissions
11226026Sdelphij * and limitations under the License.
12226026Sdelphij *
13226026Sdelphij * When distributing Covered Code, include this CDDL HEADER in each
14226026Sdelphij * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15226026Sdelphij * If applicable, add the following below this CDDL HEADER, with the
16226026Sdelphij * fields enclosed by brackets "[]" replaced with your own identifying
17226026Sdelphij * information: Portions Copyright [yyyy] [name of copyright owner]
18226026Sdelphij *
19226026Sdelphij * CDDL HEADER END
20226026Sdelphij */
21226026Sdelphij/*
22226026Sdelphij * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23226026Sdelphij */
24226026Sdelphij
25226026Sdelphij/*
26226026Sdelphij * Copyright (c) 2006 Oracle.  All rights reserved.
27226026Sdelphij *
28226026Sdelphij * This software is available to you under a choice of one of two
29226026Sdelphij * licenses.  You may choose to be licensed under the terms of the GNU
30226026Sdelphij * General Public License (GPL) Version 2, available from the file
31226026Sdelphij * COPYING in the main directory of this source tree, or the
32226026Sdelphij * OpenIB.org BSD license below:
33226026Sdelphij *
34226026Sdelphij *     Redistribution and use in source and binary forms, with or
35226026Sdelphij *     without modification, are permitted provided that the following
36226026Sdelphij *     conditions are met:
37226026Sdelphij *
38226026Sdelphij *      - Redistributions of source code must retain the above
39226026Sdelphij *        copyright notice, this list of conditions and the following
40226026Sdelphij *        disclaimer.
41226026Sdelphij *
42226026Sdelphij *      - Redistributions in binary form must reproduce the above
43226026Sdelphij *        copyright notice, this list of conditions and the following
44226026Sdelphij *        disclaimer in the documentation and/or other materials
45226026Sdelphij *        provided with the distribution.
46226026Sdelphij *
47226026Sdelphij * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48226026Sdelphij * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49226026Sdelphij * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50226026Sdelphij * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
51226026Sdelphij * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
52226026Sdelphij * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53226026Sdelphij * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54226026Sdelphij * SOFTWARE.
55226026Sdelphij *
56226026Sdelphij */
57226026Sdelphij#include <sys/rds.h>
58226026Sdelphij
59226026Sdelphij#include <sys/ib/clients/rdsv3/rdsv3.h>
60226026Sdelphij
61226026SdelphijRDSV3_DEFINE_PER_CPU(struct rdsv3_statistics, rdsv3_stats);
62226026Sdelphij
63226026Sdelphijstatic char *rdsv3_stat_names[] = {
64226026Sdelphij	"conn_reset",
65226026Sdelphij	"recv_drop_bad_checksum",
66226026Sdelphij	"recv_drop_old_seq",
67226026Sdelphij	"recv_drop_no_sock",
68226026Sdelphij	"recv_drop_dead_sock",
69226026Sdelphij	"recv_deliver_raced",
70226026Sdelphij	"recv_delivered",
71226026Sdelphij	"recv_queued",
72226026Sdelphij	"recv_immediate_retry",
73226026Sdelphij	"recv_delayed_retry",
74226026Sdelphij	"recv_ack_required",
75226026Sdelphij	"recv_rdma_bytes",
76226026Sdelphij	"recv_ping",
77226026Sdelphij	"send_queue_empty",
78226026Sdelphij	"send_queue_full",
79226026Sdelphij	"send_sem_contention",
80226026Sdelphij	"send_sem_queue_raced",
81226026Sdelphij	"send_immediate_retry",
82226026Sdelphij	"send_delayed_retry",
83226026Sdelphij	"send_drop_acked",
84226026Sdelphij	"send_ack_required",
85226026Sdelphij	"send_queued",
86226026Sdelphij	"send_rdma",
87226026Sdelphij	"send_rdma_bytes",
88226026Sdelphij	"send_pong",
89226026Sdelphij	"page_remainder_hit",
90226026Sdelphij	"page_remainder_miss",
91226026Sdelphij	"copy_to_user",
92226026Sdelphij	"copy_from_user",
93226026Sdelphij	"cong_update_queued",
94226026Sdelphij	"cong_update_received",
95226026Sdelphij	"cong_send_error",
96226026Sdelphij	"cong_send_blocked",
97226026Sdelphij};
98226026Sdelphij
99226026Sdelphijvoid
100226026Sdelphijrdsv3_stats_info_copy(struct rdsv3_info_iterator *iter,
101226026Sdelphij    uint64_t *values, char **names, size_t nr)
102226026Sdelphij{
103226026Sdelphij	struct rdsv3_info_counter ctr;
104226026Sdelphij	size_t i;
105226026Sdelphij
106226026Sdelphij	for (i = 0; i < nr; i++) {
107226026Sdelphij		ASSERT(!(strlen(names[i]) >= sizeof (ctr.name)));
108226026Sdelphij		(void) strncpy((char *)ctr.name, names[i],
109226026Sdelphij		    sizeof (ctr.name) - 1);
110226026Sdelphij		ctr.value = values[i];
111226026Sdelphij
112226026Sdelphij		rdsv3_info_copy(iter, &ctr, sizeof (ctr));
113226026Sdelphij	}
114226026Sdelphij}
115226026Sdelphij
116226026Sdelphij/*
117226026Sdelphij * This gives global counters across all the transports.  The strings
118226026Sdelphij * are copied in so that the tool doesn't need knowledge of the specific
119226026Sdelphij * stats that we're exporting.  Some are pretty implementation dependent
120226026Sdelphij * and may change over time.  That doesn't stop them from being useful.
121226026Sdelphij *
122226026Sdelphij * This is the only function in the chain that knows about the byte granular
123226026Sdelphij * length in userspace.  It converts it to number of stat entries that the
124226026Sdelphij * rest of the functions operate in.
125226026Sdelphij */
126226026Sdelphij/* ARGSUSED */
127226026Sdelphijstatic void
128226026Sdelphijrdsv3_stats_info(struct rsock *sock, unsigned int len,
129226026Sdelphij    struct rdsv3_info_iterator *iter,
130226026Sdelphij    struct rdsv3_info_lengths *lens)
131226026Sdelphij{
132226026Sdelphij	struct rdsv3_statistics stats = {0, };
133226026Sdelphij	uint64_t *src;
134226026Sdelphij	uint64_t *sum;
135226026Sdelphij	size_t i;
136226026Sdelphij	int cpu;
137226026Sdelphij	unsigned int avail;
138226026Sdelphij
139226026Sdelphij	avail = len / sizeof (struct rdsv3_info_counter);
140226026Sdelphij
141226026Sdelphij	if (avail < ARRAY_SIZE(rdsv3_stat_names)) {
142226026Sdelphij		avail = 0;
143226026Sdelphij		goto trans;
144226026Sdelphij	}
145226026Sdelphij
146226026Sdelphij	for (cpu = 0; cpu < NR_CPUS; cpu++) {
147226026Sdelphij		src = (uint64_t *)&(rdsv3_per_cpu(rdsv3_stats, cpu));
148226026Sdelphij		sum = (uint64_t *)&stats;
149226026Sdelphij		for (i = 0; i < sizeof (stats) / sizeof (uint64_t); i++)
150226026Sdelphij			*(sum++) += *(src++);
151226026Sdelphij	}
152226026Sdelphij
153226026Sdelphij	rdsv3_stats_info_copy(iter, (uint64_t *)&stats, rdsv3_stat_names,
154226026Sdelphij	    ARRAY_SIZE(rdsv3_stat_names));
155226026Sdelphij	avail -= ARRAY_SIZE(rdsv3_stat_names);
156226026Sdelphij
157226026Sdelphijtrans:
158226026Sdelphij	lens->each = sizeof (struct rdsv3_info_counter);
159226026Sdelphij	lens->nr = rdsv3_trans_stats_info_copy(iter, avail) +
160226026Sdelphij	    ARRAY_SIZE(rdsv3_stat_names);
161226026Sdelphij}
162226026Sdelphij
163226026Sdelphijvoid
164226026Sdelphijrdsv3_stats_exit(void)
165226026Sdelphij{
166226026Sdelphij	rdsv3_info_deregister_func(RDSV3_INFO_COUNTERS, rdsv3_stats_info);
167226026Sdelphij}
168226026Sdelphij
169226026Sdelphijint
170226026Sdelphijrdsv3_stats_init(void)
171226026Sdelphij{
172226026Sdelphij	rdsv3_info_register_func(RDSV3_INFO_COUNTERS, rdsv3_stats_info);
173226026Sdelphij	return (0);
174226026Sdelphij}
175226026Sdelphij