Commit f4e13571 authored by Santosh Kumar Pradhan's avatar Santosh Kumar Pradhan Committed by Leon Romanovsky

RDMA/rtrs-srv: Use per-cpu variables for rdma stats

Convert server stat counters from atomic to per-cpu variables.

Link: https://lore.kernel.org/r/20220712103113.617754-4-haris.iqbal@ionos.comSigned-off-by: default avatarSantosh Kumar Pradhan <santosh.pradhan@ionos.com>
Signed-off-by: default avatarJack Wang <jinpu.wang@ionos.com>
Signed-off-by: default avatarMd Haris Iqbal <haris.iqbal@ionos.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent 861703b4
...@@ -14,9 +14,14 @@ ...@@ -14,9 +14,14 @@
int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable) int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable)
{ {
if (enable) { if (enable) {
struct rtrs_srv_stats_rdma_stats *r = &stats->rdma_stats; int cpu;
struct rtrs_srv_stats_rdma_stats *r;
for_each_possible_cpu(cpu) {
r = per_cpu_ptr(stats->rdma_stats, cpu);
memset(r, 0, sizeof(*r));
}
memset(r, 0, sizeof(*r));
return 0; return 0;
} }
...@@ -25,11 +30,22 @@ int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable) ...@@ -25,11 +30,22 @@ int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable)
ssize_t rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats *stats, char *page) ssize_t rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats *stats, char *page)
{ {
struct rtrs_srv_stats_rdma_stats *r = &stats->rdma_stats; int cpu;
struct rtrs_srv_stats_rdma_stats sum;
struct rtrs_srv_stats_rdma_stats *r;
memset(&sum, 0, sizeof(sum));
for_each_possible_cpu(cpu) {
r = per_cpu_ptr(stats->rdma_stats, cpu);
sum.dir[READ].cnt += r->dir[READ].cnt;
sum.dir[READ].size_total += r->dir[READ].size_total;
sum.dir[WRITE].cnt += r->dir[WRITE].cnt;
sum.dir[WRITE].size_total += r->dir[WRITE].size_total;
}
return sysfs_emit(page, "%lld %lld %lld %lldn %u\n", return sysfs_emit(page, "%llu %llu %llu %llu\n",
(s64)atomic64_read(&r->dir[READ].cnt), sum.dir[READ].cnt, sum.dir[READ].size_total,
(s64)atomic64_read(&r->dir[READ].size_total), sum.dir[WRITE].cnt, sum.dir[WRITE].size_total);
(s64)atomic64_read(&r->dir[WRITE].cnt),
(s64)atomic64_read(&r->dir[WRITE].size_total), 0);
} }
...@@ -220,6 +220,8 @@ static void rtrs_srv_path_stats_release(struct kobject *kobj) ...@@ -220,6 +220,8 @@ static void rtrs_srv_path_stats_release(struct kobject *kobj)
stats = container_of(kobj, struct rtrs_srv_stats, kobj_stats); stats = container_of(kobj, struct rtrs_srv_stats, kobj_stats);
free_percpu(stats->rdma_stats);
kfree(stats); kfree(stats);
} }
......
...@@ -1513,6 +1513,7 @@ static void free_path(struct rtrs_srv_path *srv_path) ...@@ -1513,6 +1513,7 @@ static void free_path(struct rtrs_srv_path *srv_path)
kobject_del(&srv_path->kobj); kobject_del(&srv_path->kobj);
kobject_put(&srv_path->kobj); kobject_put(&srv_path->kobj);
} else { } else {
free_percpu(srv_path->stats->rdma_stats);
kfree(srv_path->stats); kfree(srv_path->stats);
kfree(srv_path); kfree(srv_path);
} }
...@@ -1755,13 +1756,17 @@ static struct rtrs_srv_path *__alloc_path(struct rtrs_srv_sess *srv, ...@@ -1755,13 +1756,17 @@ static struct rtrs_srv_path *__alloc_path(struct rtrs_srv_sess *srv,
if (!srv_path->stats) if (!srv_path->stats)
goto err_free_sess; goto err_free_sess;
srv_path->stats->rdma_stats = alloc_percpu(struct rtrs_srv_stats_rdma_stats);
if (!srv_path->stats->rdma_stats)
goto err_free_stats;
srv_path->stats->srv_path = srv_path; srv_path->stats->srv_path = srv_path;
srv_path->dma_addr = kcalloc(srv->queue_depth, srv_path->dma_addr = kcalloc(srv->queue_depth,
sizeof(*srv_path->dma_addr), sizeof(*srv_path->dma_addr),
GFP_KERNEL); GFP_KERNEL);
if (!srv_path->dma_addr) if (!srv_path->dma_addr)
goto err_free_stats; goto err_free_percpu;
srv_path->s.con = kcalloc(con_num, sizeof(*srv_path->s.con), srv_path->s.con = kcalloc(con_num, sizeof(*srv_path->s.con),
GFP_KERNEL); GFP_KERNEL);
...@@ -1813,6 +1818,8 @@ static struct rtrs_srv_path *__alloc_path(struct rtrs_srv_sess *srv, ...@@ -1813,6 +1818,8 @@ static struct rtrs_srv_path *__alloc_path(struct rtrs_srv_sess *srv,
kfree(srv_path->s.con); kfree(srv_path->s.con);
err_free_dma_addr: err_free_dma_addr:
kfree(srv_path->dma_addr); kfree(srv_path->dma_addr);
err_free_percpu:
free_percpu(srv_path->stats->rdma_stats);
err_free_stats: err_free_stats:
kfree(srv_path->stats); kfree(srv_path->stats);
err_free_sess: err_free_sess:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/refcount.h> #include <linux/refcount.h>
#include <linux/percpu.h>
#include "rtrs-pri.h" #include "rtrs-pri.h"
/* /*
...@@ -29,15 +30,15 @@ enum rtrs_srv_state { ...@@ -29,15 +30,15 @@ enum rtrs_srv_state {
*/ */
struct rtrs_srv_stats_rdma_stats { struct rtrs_srv_stats_rdma_stats {
struct { struct {
atomic64_t cnt; u64 cnt;
atomic64_t size_total; u64 size_total;
} dir[2]; } dir[2];
}; };
struct rtrs_srv_stats { struct rtrs_srv_stats {
struct kobject kobj_stats; struct kobject kobj_stats;
struct rtrs_srv_stats_rdma_stats rdma_stats; struct rtrs_srv_stats_rdma_stats __percpu *rdma_stats;
struct rtrs_srv_path *srv_path; struct rtrs_srv_path *srv_path;
}; };
struct rtrs_srv_con { struct rtrs_srv_con {
...@@ -130,8 +131,8 @@ void close_path(struct rtrs_srv_path *srv_path); ...@@ -130,8 +131,8 @@ void close_path(struct rtrs_srv_path *srv_path);
static inline void rtrs_srv_update_rdma_stats(struct rtrs_srv_stats *s, static inline void rtrs_srv_update_rdma_stats(struct rtrs_srv_stats *s,
size_t size, int d) size_t size, int d)
{ {
atomic64_inc(&s->rdma_stats.dir[d].cnt); this_cpu_inc(s->rdma_stats->dir[d].cnt);
atomic64_add(size, &s->rdma_stats.dir[d].size_total); this_cpu_add(s->rdma_stats->dir[d].size_total, size);
} }
/* functions which are implemented in rtrs-srv-stats.c */ /* functions which are implemented in rtrs-srv-stats.c */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment