From: Roman Pen <[email protected]>

This introduces set of functions used on server side to account
statistics of RDMA data sent/received.

Signed-off-by: Danil Kipnis <[email protected]>
Signed-off-by: Jack Wang <[email protected]>
---
 .../infiniband/ulp/ibtrs/ibtrs-srv-stats.c    | 103 ++++++++++++++++++
 1 file changed, 103 insertions(+)
 create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-srv-stats.c

diff --git a/drivers/infiniband/ulp/ibtrs/ibtrs-srv-stats.c 
b/drivers/infiniband/ulp/ibtrs/ibtrs-srv-stats.c
new file mode 100644
index 000000000000..47f8d6d2d88d
--- /dev/null
+++ b/drivers/infiniband/ulp/ibtrs/ibtrs-srv-stats.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * InfiniBand Transport Layer
+ *
+ * Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved.
+ * Authors: Fabian Holler <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Kleber Souza <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ *          Roman Penyaev <[email protected]>
+ *          Milind Dumbare <[email protected]>
+ *
+ * Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved.
+ * Authors: Danil Kipnis <[email protected]>
+ *          Roman Penyaev <[email protected]>
+ *
+ * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
+ * Authors: Roman Penyaev <[email protected]>
+ *          Jack Wang <[email protected]>
+ *          Danil Kipnis <[email protected]>
+ */
+
+#undef pr_fmt
+#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
+
+#include "ibtrs-srv.h"
+
+void ibtrs_srv_update_rdma_stats(struct ibtrs_srv_stats *s,
+                                size_t size, int d)
+{
+       atomic64_inc(&s->rdma_stats.dir[d].cnt);
+       atomic64_add(size, &s->rdma_stats.dir[d].size_total);
+}
+
+void ibtrs_srv_update_wc_stats(struct ibtrs_srv_stats *s)
+{
+       atomic64_inc(&s->wc_comp.calls);
+       atomic64_inc(&s->wc_comp.total_wc_cnt);
+}
+
+int ibtrs_srv_reset_rdma_stats(struct ibtrs_srv_stats *stats, bool enable)
+{
+       if (enable) {
+               struct ibtrs_srv_stats_rdma_stats *r = &stats->rdma_stats;
+
+               memset(r, 0, sizeof(*r));
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+ssize_t ibtrs_srv_stats_rdma_to_str(struct ibtrs_srv_stats *stats,
+                                   char *page, size_t len)
+{
+       struct ibtrs_srv_stats_rdma_stats *r = &stats->rdma_stats;
+       struct ibtrs_srv_sess *sess;
+
+       sess = container_of(stats, typeof(*sess), stats);
+
+       return scnprintf(page, len, "%lld %lld %lld %lld %u\n",
+                        (s64)atomic64_read(&r->dir[READ].cnt),
+                        (s64)atomic64_read(&r->dir[READ].size_total),
+                        (s64)atomic64_read(&r->dir[WRITE].cnt),
+                        (s64)atomic64_read(&r->dir[WRITE].size_total),
+                        atomic_read(&sess->ids_inflight));
+}
+
+int ibtrs_srv_reset_wc_completion_stats(struct ibtrs_srv_stats *stats,
+                                       bool enable)
+{
+       if (enable) {
+               memset(&stats->wc_comp, 0, sizeof(stats->wc_comp));
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+int ibtrs_srv_stats_wc_completion_to_str(struct ibtrs_srv_stats *stats,
+                                        char *buf, size_t len)
+{
+       return snprintf(buf, len, "%lld %lld\n",
+                       (s64)atomic64_read(&stats->wc_comp.total_wc_cnt),
+                       (s64)atomic64_read(&stats->wc_comp.calls));
+}
+
+ssize_t ibtrs_srv_reset_all_help(struct ibtrs_srv_stats *stats,
+                                char *page, size_t len)
+{
+       return scnprintf(page, PAGE_SIZE, "echo 1 to reset all statistics\n");
+}
+
+int ibtrs_srv_reset_all_stats(struct ibtrs_srv_stats *stats, bool enable)
+{
+       if (enable) {
+               ibtrs_srv_reset_wc_completion_stats(stats, enable);
+               ibtrs_srv_reset_rdma_stats(stats, enable);
+               return 0;
+       }
+
+       return -EINVAL;
+}
-- 
2.17.1

Reply via email to