18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2006 Oracle.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#include <linux/percpu.h>
348c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
358c2ecf20Sopenharmony_ci#include <linux/proc_fs.h>
368c2ecf20Sopenharmony_ci#include <linux/export.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include "rds.h"
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciDEFINE_PER_CPU_SHARED_ALIGNED(struct rds_statistics, rds_stats);
418c2ecf20Sopenharmony_ciEXPORT_PER_CPU_SYMBOL_GPL(rds_stats);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* :.,$s/unsigned long\>.*\<s_\(.*\);/"\1",/g */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic const char *const rds_stat_names[] = {
468c2ecf20Sopenharmony_ci	"conn_reset",
478c2ecf20Sopenharmony_ci	"recv_drop_bad_checksum",
488c2ecf20Sopenharmony_ci	"recv_drop_old_seq",
498c2ecf20Sopenharmony_ci	"recv_drop_no_sock",
508c2ecf20Sopenharmony_ci	"recv_drop_dead_sock",
518c2ecf20Sopenharmony_ci	"recv_deliver_raced",
528c2ecf20Sopenharmony_ci	"recv_delivered",
538c2ecf20Sopenharmony_ci	"recv_queued",
548c2ecf20Sopenharmony_ci	"recv_immediate_retry",
558c2ecf20Sopenharmony_ci	"recv_delayed_retry",
568c2ecf20Sopenharmony_ci	"recv_ack_required",
578c2ecf20Sopenharmony_ci	"recv_rdma_bytes",
588c2ecf20Sopenharmony_ci	"recv_ping",
598c2ecf20Sopenharmony_ci	"send_queue_empty",
608c2ecf20Sopenharmony_ci	"send_queue_full",
618c2ecf20Sopenharmony_ci	"send_lock_contention",
628c2ecf20Sopenharmony_ci	"send_lock_queue_raced",
638c2ecf20Sopenharmony_ci	"send_immediate_retry",
648c2ecf20Sopenharmony_ci	"send_delayed_retry",
658c2ecf20Sopenharmony_ci	"send_drop_acked",
668c2ecf20Sopenharmony_ci	"send_ack_required",
678c2ecf20Sopenharmony_ci	"send_queued",
688c2ecf20Sopenharmony_ci	"send_rdma",
698c2ecf20Sopenharmony_ci	"send_rdma_bytes",
708c2ecf20Sopenharmony_ci	"send_pong",
718c2ecf20Sopenharmony_ci	"page_remainder_hit",
728c2ecf20Sopenharmony_ci	"page_remainder_miss",
738c2ecf20Sopenharmony_ci	"copy_to_user",
748c2ecf20Sopenharmony_ci	"copy_from_user",
758c2ecf20Sopenharmony_ci	"cong_update_queued",
768c2ecf20Sopenharmony_ci	"cong_update_received",
778c2ecf20Sopenharmony_ci	"cong_send_error",
788c2ecf20Sopenharmony_ci	"cong_send_blocked",
798c2ecf20Sopenharmony_ci	"recv_bytes_added_to_sock",
808c2ecf20Sopenharmony_ci	"recv_bytes_freed_fromsock",
818c2ecf20Sopenharmony_ci	"send_stuck_rm",
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_civoid rds_stats_info_copy(struct rds_info_iterator *iter,
858c2ecf20Sopenharmony_ci			 uint64_t *values, const char *const *names, size_t nr)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	struct rds_info_counter ctr;
888c2ecf20Sopenharmony_ci	size_t i;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	for (i = 0; i < nr; i++) {
918c2ecf20Sopenharmony_ci		BUG_ON(strlen(names[i]) >= sizeof(ctr.name));
928c2ecf20Sopenharmony_ci		strncpy(ctr.name, names[i], sizeof(ctr.name) - 1);
938c2ecf20Sopenharmony_ci		ctr.name[sizeof(ctr.name) - 1] = '\0';
948c2ecf20Sopenharmony_ci		ctr.value = values[i];
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci		rds_info_copy(iter, &ctr, sizeof(ctr));
978c2ecf20Sopenharmony_ci	}
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(rds_stats_info_copy);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/*
1028c2ecf20Sopenharmony_ci * This gives global counters across all the transports.  The strings
1038c2ecf20Sopenharmony_ci * are copied in so that the tool doesn't need knowledge of the specific
1048c2ecf20Sopenharmony_ci * stats that we're exporting.  Some are pretty implementation dependent
1058c2ecf20Sopenharmony_ci * and may change over time.  That doesn't stop them from being useful.
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * This is the only function in the chain that knows about the byte granular
1088c2ecf20Sopenharmony_ci * length in userspace.  It converts it to number of stat entries that the
1098c2ecf20Sopenharmony_ci * rest of the functions operate in.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_cistatic void rds_stats_info(struct socket *sock, unsigned int len,
1128c2ecf20Sopenharmony_ci			   struct rds_info_iterator *iter,
1138c2ecf20Sopenharmony_ci			   struct rds_info_lengths *lens)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	struct rds_statistics stats = {0, };
1168c2ecf20Sopenharmony_ci	uint64_t *src;
1178c2ecf20Sopenharmony_ci	uint64_t *sum;
1188c2ecf20Sopenharmony_ci	size_t i;
1198c2ecf20Sopenharmony_ci	int cpu;
1208c2ecf20Sopenharmony_ci	unsigned int avail;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	avail = len / sizeof(struct rds_info_counter);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	if (avail < ARRAY_SIZE(rds_stat_names)) {
1258c2ecf20Sopenharmony_ci		avail = 0;
1268c2ecf20Sopenharmony_ci		goto trans;
1278c2ecf20Sopenharmony_ci	}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	for_each_online_cpu(cpu) {
1308c2ecf20Sopenharmony_ci		src = (uint64_t *)&(per_cpu(rds_stats, cpu));
1318c2ecf20Sopenharmony_ci		sum = (uint64_t *)&stats;
1328c2ecf20Sopenharmony_ci		for (i = 0; i < sizeof(stats) / sizeof(uint64_t); i++)
1338c2ecf20Sopenharmony_ci			*(sum++) += *(src++);
1348c2ecf20Sopenharmony_ci	}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	rds_stats_info_copy(iter, (uint64_t *)&stats, rds_stat_names,
1378c2ecf20Sopenharmony_ci			    ARRAY_SIZE(rds_stat_names));
1388c2ecf20Sopenharmony_ci	avail -= ARRAY_SIZE(rds_stat_names);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_citrans:
1418c2ecf20Sopenharmony_ci	lens->each = sizeof(struct rds_info_counter);
1428c2ecf20Sopenharmony_ci	lens->nr = rds_trans_stats_info_copy(iter, avail) +
1438c2ecf20Sopenharmony_ci		   ARRAY_SIZE(rds_stat_names);
1448c2ecf20Sopenharmony_ci}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_civoid rds_stats_exit(void)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	rds_info_deregister_func(RDS_INFO_COUNTERS, rds_stats_info);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ciint rds_stats_init(void)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	rds_info_register_func(RDS_INFO_COUNTERS, rds_stats_info);
1548c2ecf20Sopenharmony_ci	return 0;
1558c2ecf20Sopenharmony_ci}
156