xref: /illumos-gate/usr/src/uts/common/io/ib/clients/rdsv3/ib_stats.c (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
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 ib_stats.c
7  * Oracle elects to have and use the contents of ib_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 #include <sys/ib/clients/rdsv3/ib.h>
48 #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
49 
50 struct rdsv3_ib_statistics	*rdsv3_ib_stats = NULL;
51 
52 static char *rdsv3_ib_stat_names[] = {
53 	"ib_connect_raced",
54 	"ib_listen_closed_stale",
55 	"ib_evt_handler_call",
56 	"ib_tasklet_call",
57 	"ib_tx_cq_event",
58 	"ib_tx_ring_full",
59 	"ib_tx_throttle",
60 	"ib_tx_sg_mapping_failure",
61 	"ib_tx_stalled",
62 	"ib_tx_credit_updates",
63 	"ib_rx_cq_event",
64 	"ib_rx_ring_empty",
65 	"ib_rx_refill_from_cq",
66 	"ib_rx_refill_from_thread",
67 	"ib_rx_alloc_limit",
68 	"ib_rx_credit_updates",
69 	"ib_ack_sent",
70 	"ib_ack_send_failure",
71 	"ib_ack_send_delayed",
72 	"ib_ack_send_piggybacked",
73 	"ib_ack_received",
74 	"ib_rdma_mr_alloc",
75 	"ib_rdma_mr_free",
76 	"ib_rdma_mr_used",
77 	"ib_rdma_mr_pool_flush",
78 	"ib_rdma_mr_pool_wait",
79 	"ib_rdma_mr_pool_depleted",
80 };
81 
82 unsigned int
rdsv3_ib_stats_info_copy(struct rdsv3_info_iterator * iter,unsigned int avail)83 rdsv3_ib_stats_info_copy(struct rdsv3_info_iterator *iter,
84     unsigned int avail)
85 {
86 	struct rdsv3_ib_statistics stats = {0, };
87 	uint64_t *src;
88 	uint64_t *sum;
89 	size_t i;
90 	int cpu;
91 
92 	RDSV3_DPRINTF4("rdsv3_ib_stats_info_copy", "iter: %p, avail: %d",
93 	    iter, avail);
94 
95 	if (avail < ARRAY_SIZE(rdsv3_ib_stat_names))
96 		goto out;
97 
98 	for (cpu = 0; cpu < nr_cpus; cpu++) {
99 		src = (uint64_t *)&(rdsv3_per_cpu(rdsv3_ib_stats, cpu));
100 		sum = (uint64_t *)&stats;
101 		for (i = 0; i < sizeof (stats) / sizeof (uint64_t); i++)
102 			*(sum++) += *(src++);
103 	}
104 
105 	rdsv3_stats_info_copy(iter, (uint64_t *)&stats, rdsv3_ib_stat_names,
106 	    ARRAY_SIZE(rdsv3_ib_stat_names));
107 
108 	RDSV3_DPRINTF4("rdsv3_ib_stats_info_copy",
109 	    "Return: iter: %p, avail: %d", iter, avail);
110 out:
111 	return (ARRAY_SIZE(rdsv3_ib_stat_names));
112 }
113