xref: /onnv-gate/usr/src/uts/common/io/ib/clients/rdsv3/stats.c (revision 13118:e192495818d4)
112198SEiji.Ota@Sun.COM /*
212198SEiji.Ota@Sun.COM  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
312198SEiji.Ota@Sun.COM  */
412198SEiji.Ota@Sun.COM 
512198SEiji.Ota@Sun.COM /*
612763SGiri.Adari@Sun.COM  * This file contains code imported from the OFED rds source file stats.c
712763SGiri.Adari@Sun.COM  * Oracle elects to have and use the contents of stats.c under and governed
812763SGiri.Adari@Sun.COM  * by the OpenIB.org BSD license (see below for full license text). However,
912763SGiri.Adari@Sun.COM  * the following notice accompanied the original version of this file:
1012763SGiri.Adari@Sun.COM  */
1112763SGiri.Adari@Sun.COM 
1212763SGiri.Adari@Sun.COM /*
1312198SEiji.Ota@Sun.COM  * Copyright (c) 2006 Oracle.  All rights reserved.
1412198SEiji.Ota@Sun.COM  *
1512198SEiji.Ota@Sun.COM  * This software is available to you under a choice of one of two
1612198SEiji.Ota@Sun.COM  * licenses.  You may choose to be licensed under the terms of the GNU
1712198SEiji.Ota@Sun.COM  * General Public License (GPL) Version 2, available from the file
1812198SEiji.Ota@Sun.COM  * COPYING in the main directory of this source tree, or the
1912198SEiji.Ota@Sun.COM  * OpenIB.org BSD license below:
2012198SEiji.Ota@Sun.COM  *
2112198SEiji.Ota@Sun.COM  *     Redistribution and use in source and binary forms, with or
2212198SEiji.Ota@Sun.COM  *     without modification, are permitted provided that the following
2312198SEiji.Ota@Sun.COM  *     conditions are met:
2412198SEiji.Ota@Sun.COM  *
2512198SEiji.Ota@Sun.COM  *      - Redistributions of source code must retain the above
2612198SEiji.Ota@Sun.COM  *        copyright notice, this list of conditions and the following
2712198SEiji.Ota@Sun.COM  *        disclaimer.
2812198SEiji.Ota@Sun.COM  *
2912198SEiji.Ota@Sun.COM  *      - Redistributions in binary form must reproduce the above
3012198SEiji.Ota@Sun.COM  *        copyright notice, this list of conditions and the following
3112198SEiji.Ota@Sun.COM  *        disclaimer in the documentation and/or other materials
3212198SEiji.Ota@Sun.COM  *        provided with the distribution.
3312198SEiji.Ota@Sun.COM  *
3412198SEiji.Ota@Sun.COM  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
3512198SEiji.Ota@Sun.COM  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3612198SEiji.Ota@Sun.COM  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
3712198SEiji.Ota@Sun.COM  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
3812198SEiji.Ota@Sun.COM  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3912198SEiji.Ota@Sun.COM  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4012198SEiji.Ota@Sun.COM  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4112198SEiji.Ota@Sun.COM  * SOFTWARE.
4212198SEiji.Ota@Sun.COM  *
4312198SEiji.Ota@Sun.COM  */
4412198SEiji.Ota@Sun.COM #include <sys/rds.h>
4512198SEiji.Ota@Sun.COM 
4612198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3.h>
4712198SEiji.Ota@Sun.COM 
4812922SGiri.Adari@Sun.COM struct rdsv3_statistics *rdsv3_stats = NULL;
4912922SGiri.Adari@Sun.COM uint_t	nr_cpus;
5012198SEiji.Ota@Sun.COM 
5112198SEiji.Ota@Sun.COM static char *rdsv3_stat_names[] = {
5212198SEiji.Ota@Sun.COM 	"conn_reset",
5312198SEiji.Ota@Sun.COM 	"recv_drop_bad_checksum",
5412198SEiji.Ota@Sun.COM 	"recv_drop_old_seq",
5512198SEiji.Ota@Sun.COM 	"recv_drop_no_sock",
5612198SEiji.Ota@Sun.COM 	"recv_drop_dead_sock",
5712198SEiji.Ota@Sun.COM 	"recv_deliver_raced",
5812198SEiji.Ota@Sun.COM 	"recv_delivered",
5912198SEiji.Ota@Sun.COM 	"recv_queued",
6012198SEiji.Ota@Sun.COM 	"recv_immediate_retry",
6112198SEiji.Ota@Sun.COM 	"recv_delayed_retry",
6212198SEiji.Ota@Sun.COM 	"recv_ack_required",
6312198SEiji.Ota@Sun.COM 	"recv_rdma_bytes",
6412198SEiji.Ota@Sun.COM 	"recv_ping",
6512198SEiji.Ota@Sun.COM 	"send_queue_empty",
6612198SEiji.Ota@Sun.COM 	"send_queue_full",
6712198SEiji.Ota@Sun.COM 	"send_sem_contention",
6812198SEiji.Ota@Sun.COM 	"send_sem_queue_raced",
6912198SEiji.Ota@Sun.COM 	"send_immediate_retry",
7012198SEiji.Ota@Sun.COM 	"send_delayed_retry",
7112198SEiji.Ota@Sun.COM 	"send_drop_acked",
7212198SEiji.Ota@Sun.COM 	"send_ack_required",
7312198SEiji.Ota@Sun.COM 	"send_queued",
7412198SEiji.Ota@Sun.COM 	"send_rdma",
7512198SEiji.Ota@Sun.COM 	"send_rdma_bytes",
7612198SEiji.Ota@Sun.COM 	"send_pong",
7712198SEiji.Ota@Sun.COM 	"page_remainder_hit",
7812198SEiji.Ota@Sun.COM 	"page_remainder_miss",
7912198SEiji.Ota@Sun.COM 	"copy_to_user",
8012198SEiji.Ota@Sun.COM 	"copy_from_user",
8112198SEiji.Ota@Sun.COM 	"cong_update_queued",
8212198SEiji.Ota@Sun.COM 	"cong_update_received",
8312198SEiji.Ota@Sun.COM 	"cong_send_error",
8412198SEiji.Ota@Sun.COM 	"cong_send_blocked",
8512198SEiji.Ota@Sun.COM };
8612198SEiji.Ota@Sun.COM 
8712198SEiji.Ota@Sun.COM void
rdsv3_stats_info_copy(struct rdsv3_info_iterator * iter,uint64_t * values,char ** names,size_t nr)8812198SEiji.Ota@Sun.COM rdsv3_stats_info_copy(struct rdsv3_info_iterator *iter,
8912198SEiji.Ota@Sun.COM     uint64_t *values, char **names, size_t nr)
9012198SEiji.Ota@Sun.COM {
9112863SEiji.Ota@Sun.COM 	struct rds_info_counter ctr;
9212198SEiji.Ota@Sun.COM 	size_t i;
9312198SEiji.Ota@Sun.COM 
9412198SEiji.Ota@Sun.COM 	for (i = 0; i < nr; i++) {
9512198SEiji.Ota@Sun.COM 		ASSERT(!(strlen(names[i]) >= sizeof (ctr.name)));
9612198SEiji.Ota@Sun.COM 		(void) strncpy((char *)ctr.name, names[i],
9712198SEiji.Ota@Sun.COM 		    sizeof (ctr.name) - 1);
9812198SEiji.Ota@Sun.COM 		ctr.value = values[i];
9912198SEiji.Ota@Sun.COM 
10012198SEiji.Ota@Sun.COM 		rdsv3_info_copy(iter, &ctr, sizeof (ctr));
10112198SEiji.Ota@Sun.COM 	}
10212198SEiji.Ota@Sun.COM }
10312198SEiji.Ota@Sun.COM 
10412198SEiji.Ota@Sun.COM /*
10512198SEiji.Ota@Sun.COM  * This gives global counters across all the transports.  The strings
10612198SEiji.Ota@Sun.COM  * are copied in so that the tool doesn't need knowledge of the specific
10712198SEiji.Ota@Sun.COM  * stats that we're exporting.  Some are pretty implementation dependent
10812198SEiji.Ota@Sun.COM  * and may change over time.  That doesn't stop them from being useful.
10912198SEiji.Ota@Sun.COM  *
11012198SEiji.Ota@Sun.COM  * This is the only function in the chain that knows about the byte granular
11112198SEiji.Ota@Sun.COM  * length in userspace.  It converts it to number of stat entries that the
11212198SEiji.Ota@Sun.COM  * rest of the functions operate in.
11312198SEiji.Ota@Sun.COM  */
11412198SEiji.Ota@Sun.COM /* ARGSUSED */
11512198SEiji.Ota@Sun.COM static void
rdsv3_stats_info(struct rsock * sock,unsigned int len,struct rdsv3_info_iterator * iter,struct rdsv3_info_lengths * lens)11612198SEiji.Ota@Sun.COM rdsv3_stats_info(struct rsock *sock, unsigned int len,
11712198SEiji.Ota@Sun.COM     struct rdsv3_info_iterator *iter,
11812198SEiji.Ota@Sun.COM     struct rdsv3_info_lengths *lens)
11912198SEiji.Ota@Sun.COM {
12012580SGiri.Adari@Sun.COM 	struct rdsv3_statistics stats;
12112198SEiji.Ota@Sun.COM 	uint64_t *src;
12212198SEiji.Ota@Sun.COM 	uint64_t *sum;
12312198SEiji.Ota@Sun.COM 	size_t i;
12412198SEiji.Ota@Sun.COM 	int cpu;
12512198SEiji.Ota@Sun.COM 	unsigned int avail;
12612198SEiji.Ota@Sun.COM 
12712863SEiji.Ota@Sun.COM 	avail = len / sizeof (struct rds_info_counter);
12812198SEiji.Ota@Sun.COM 
12912198SEiji.Ota@Sun.COM 	if (avail < ARRAY_SIZE(rdsv3_stat_names)) {
13012198SEiji.Ota@Sun.COM 		avail = 0;
13112198SEiji.Ota@Sun.COM 		goto trans;
13212198SEiji.Ota@Sun.COM 	}
13312198SEiji.Ota@Sun.COM 
13412580SGiri.Adari@Sun.COM 	bzero(&stats, sizeof (struct rdsv3_statistics));
13512580SGiri.Adari@Sun.COM 
13612922SGiri.Adari@Sun.COM 	for (cpu = 0; cpu < nr_cpus; cpu++) {
13712198SEiji.Ota@Sun.COM 		src = (uint64_t *)&(rdsv3_per_cpu(rdsv3_stats, cpu));
13812198SEiji.Ota@Sun.COM 		sum = (uint64_t *)&stats;
13912580SGiri.Adari@Sun.COM 		for (i = 0;
14012580SGiri.Adari@Sun.COM 		    i < sizeof (struct rdsv3_statistics) / sizeof (uint64_t);
14112580SGiri.Adari@Sun.COM 		    i++)
14212198SEiji.Ota@Sun.COM 			*(sum++) += *(src++);
14312198SEiji.Ota@Sun.COM 	}
14412198SEiji.Ota@Sun.COM 
14512198SEiji.Ota@Sun.COM 	rdsv3_stats_info_copy(iter, (uint64_t *)&stats, rdsv3_stat_names,
14612198SEiji.Ota@Sun.COM 	    ARRAY_SIZE(rdsv3_stat_names));
14712198SEiji.Ota@Sun.COM 	avail -= ARRAY_SIZE(rdsv3_stat_names);
14812198SEiji.Ota@Sun.COM 
14912198SEiji.Ota@Sun.COM trans:
15012863SEiji.Ota@Sun.COM 	lens->each = sizeof (struct rds_info_counter);
15112198SEiji.Ota@Sun.COM 	lens->nr = rdsv3_trans_stats_info_copy(iter, avail) +
15212198SEiji.Ota@Sun.COM 	    ARRAY_SIZE(rdsv3_stat_names);
15312198SEiji.Ota@Sun.COM }
15412198SEiji.Ota@Sun.COM 
15512198SEiji.Ota@Sun.COM void
rdsv3_stats_exit(void)15612198SEiji.Ota@Sun.COM rdsv3_stats_exit(void)
15712198SEiji.Ota@Sun.COM {
15812863SEiji.Ota@Sun.COM 	rdsv3_info_deregister_func(RDS_INFO_COUNTERS, rdsv3_stats_info);
15912922SGiri.Adari@Sun.COM 
16012922SGiri.Adari@Sun.COM 	ASSERT(rdsv3_stats);
16112922SGiri.Adari@Sun.COM 	kmem_free(rdsv3_stats,
16212922SGiri.Adari@Sun.COM 	    nr_cpus * sizeof (struct rdsv3_statistics));
16312922SGiri.Adari@Sun.COM 	rdsv3_stats = NULL;
16412198SEiji.Ota@Sun.COM }
16512198SEiji.Ota@Sun.COM 
16612198SEiji.Ota@Sun.COM int
rdsv3_stats_init(void)16712198SEiji.Ota@Sun.COM rdsv3_stats_init(void)
16812198SEiji.Ota@Sun.COM {
16912922SGiri.Adari@Sun.COM 	/*
170*13118SEiji.Ota@Sun.COM 	 * Note the max number of cpus that this system can have at most.
17112922SGiri.Adari@Sun.COM 	 */
17212922SGiri.Adari@Sun.COM 	nr_cpus = max_ncpus;
17312922SGiri.Adari@Sun.COM 	ASSERT(rdsv3_stats == NULL);
17412922SGiri.Adari@Sun.COM 	rdsv3_stats = kmem_zalloc(nr_cpus *
17512922SGiri.Adari@Sun.COM 	    sizeof (struct rdsv3_statistics), KM_SLEEP);
17612922SGiri.Adari@Sun.COM 
17712863SEiji.Ota@Sun.COM 	rdsv3_info_register_func(RDS_INFO_COUNTERS, rdsv3_stats_info);
17812198SEiji.Ota@Sun.COM 	return (0);
17912198SEiji.Ota@Sun.COM }
180