^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2006 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * licenses. You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "rds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) DEFINE_PER_CPU_SHARED_ALIGNED(struct rds_statistics, rds_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) EXPORT_PER_CPU_SYMBOL_GPL(rds_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* :.,$s/unsigned long\>.*\<s_\(.*\);/"\1",/g */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const char *const rds_stat_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) "conn_reset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) "recv_drop_bad_checksum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) "recv_drop_old_seq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) "recv_drop_no_sock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) "recv_drop_dead_sock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "recv_deliver_raced",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) "recv_delivered",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) "recv_queued",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "recv_immediate_retry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) "recv_delayed_retry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) "recv_ack_required",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) "recv_rdma_bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) "recv_ping",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) "send_queue_empty",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) "send_queue_full",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) "send_lock_contention",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) "send_lock_queue_raced",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) "send_immediate_retry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) "send_delayed_retry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) "send_drop_acked",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) "send_ack_required",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) "send_queued",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) "send_rdma",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) "send_rdma_bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) "send_pong",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) "page_remainder_hit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) "page_remainder_miss",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) "copy_to_user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) "copy_from_user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) "cong_update_queued",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "cong_update_received",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) "cong_send_error",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) "cong_send_blocked",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) "recv_bytes_added_to_sock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) "recv_bytes_freed_fromsock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) "send_stuck_rm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void rds_stats_info_copy(struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) uint64_t *values, const char *const *names, size_t nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct rds_info_counter ctr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) for (i = 0; i < nr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) BUG_ON(strlen(names[i]) >= sizeof(ctr.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) strncpy(ctr.name, names[i], sizeof(ctr.name) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ctr.name[sizeof(ctr.name) - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ctr.value = values[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) rds_info_copy(iter, &ctr, sizeof(ctr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) EXPORT_SYMBOL_GPL(rds_stats_info_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * This gives global counters across all the transports. The strings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * are copied in so that the tool doesn't need knowledge of the specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * stats that we're exporting. Some are pretty implementation dependent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * and may change over time. That doesn't stop them from being useful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * This is the only function in the chain that knows about the byte granular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * length in userspace. It converts it to number of stat entries that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * rest of the functions operate in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void rds_stats_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct rds_statistics stats = {0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) uint64_t *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) uint64_t *sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) avail = len / sizeof(struct rds_info_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (avail < ARRAY_SIZE(rds_stat_names)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) avail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) goto trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) for_each_online_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) src = (uint64_t *)&(per_cpu(rds_stats, cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) sum = (uint64_t *)&stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) for (i = 0; i < sizeof(stats) / sizeof(uint64_t); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *(sum++) += *(src++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) rds_stats_info_copy(iter, (uint64_t *)&stats, rds_stat_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ARRAY_SIZE(rds_stat_names));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) avail -= ARRAY_SIZE(rds_stat_names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) trans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) lens->each = sizeof(struct rds_info_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) lens->nr = rds_trans_stats_info_copy(iter, avail) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ARRAY_SIZE(rds_stat_names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void rds_stats_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) rds_info_deregister_func(RDS_INFO_COUNTERS, rds_stats_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int rds_stats_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) rds_info_register_func(RDS_INFO_COUNTERS, rds_stats_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }