2020-05-11 15:51:13 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
/*
|
|
|
|
|
* RDMA Transport Layer
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
|
|
|
|
|
* Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
|
|
|
|
|
* Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
#undef pr_fmt
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
|
|
|
|
|
|
|
|
|
|
#include "rtrs-clt.h"
|
|
|
|
|
|
|
|
|
|
void rtrs_clt_update_wc_stats(struct rtrs_clt_con *con)
|
|
|
|
|
{
|
2022-01-05 19:07:06 +01:00
|
|
|
struct rtrs_clt_path *clt_path = to_clt_path(con->c.path);
|
|
|
|
|
struct rtrs_clt_stats *stats = clt_path->stats;
|
2020-05-11 15:51:13 +02:00
|
|
|
struct rtrs_clt_stats_pcpu *s;
|
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
|
|
cpu = raw_smp_processor_id();
|
RDMA/rtrs: Call {get,put}_cpu_ptr to silence a debug kernel warning
With preemption enabled (CONFIG_DEBUG_PREEMPT=y), the following appeared
when rnbd client tries to map remote block device.
BUG: using smp_processor_id() in preemptible [00000000] code: bash/1733
caller is debug_smp_processor_id+0x17/0x20
CPU: 0 PID: 1733 Comm: bash Not tainted 5.16.0-rc1 #5
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.14.0-0-g155821a-rebuilt.opensuse.org 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x5d/0x78
dump_stack+0x10/0x12
check_preemption_disabled+0xe4/0xf0
debug_smp_processor_id+0x17/0x20
rtrs_clt_update_all_stats+0x3b/0x70 [rtrs_client]
rtrs_clt_read_req+0xc3/0x380 [rtrs_client]
? rtrs_clt_init_req+0xe3/0x120 [rtrs_client]
rtrs_clt_request+0x1a7/0x320 [rtrs_client]
? 0xffffffffc0ab1000
send_usr_msg+0xbf/0x160 [rnbd_client]
? rnbd_clt_put_sess+0x60/0x60 [rnbd_client]
? send_usr_msg+0x160/0x160 [rnbd_client]
? sg_alloc_table+0x27/0xb0
? sg_zero_buffer+0xd0/0xd0
send_msg_sess_info+0xe9/0x180 [rnbd_client]
? rnbd_clt_put_sess+0x60/0x60 [rnbd_client]
? blk_mq_alloc_tag_set+0x2ef/0x370
rnbd_clt_map_device+0xba8/0xcd0 [rnbd_client]
? send_msg_open+0x200/0x200 [rnbd_client]
rnbd_clt_map_device_store+0x3e5/0x620 [rnbd_client
To supress the calltrace, let's call get_cpu_ptr/put_cpu_ptr pair in
rtrs_clt_update_rdma_stats to disable preemption when accessing per-cpu
variable.
While at it, let's make the similar change in rtrs_clt_update_wc_stats.
And for rtrs_clt_inc_failover_cnt, though it was only called inside rcu
section, but it still can be preempted in case CONFIG_PREEMPT_RCU is
enabled, so change it to {get,put}_cpu_ptr pair either.
Link: https://lore.kernel.org/r/20211128133501.38710-1-guoqing.jiang@linux.dev
Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2021-11-28 21:35:01 +08:00
|
|
|
s = get_cpu_ptr(stats->pcpu_stats);
|
2021-08-06 13:21:10 +02:00
|
|
|
if (con->cpu != cpu) {
|
2020-05-11 15:51:13 +02:00
|
|
|
s->cpu_migr.to++;
|
|
|
|
|
|
|
|
|
|
/* Careful here, override s pointer */
|
|
|
|
|
s = per_cpu_ptr(stats->pcpu_stats, con->cpu);
|
|
|
|
|
atomic_inc(&s->cpu_migr.from);
|
|
|
|
|
}
|
RDMA/rtrs: Call {get,put}_cpu_ptr to silence a debug kernel warning
With preemption enabled (CONFIG_DEBUG_PREEMPT=y), the following appeared
when rnbd client tries to map remote block device.
BUG: using smp_processor_id() in preemptible [00000000] code: bash/1733
caller is debug_smp_processor_id+0x17/0x20
CPU: 0 PID: 1733 Comm: bash Not tainted 5.16.0-rc1 #5
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.14.0-0-g155821a-rebuilt.opensuse.org 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x5d/0x78
dump_stack+0x10/0x12
check_preemption_disabled+0xe4/0xf0
debug_smp_processor_id+0x17/0x20
rtrs_clt_update_all_stats+0x3b/0x70 [rtrs_client]
rtrs_clt_read_req+0xc3/0x380 [rtrs_client]
? rtrs_clt_init_req+0xe3/0x120 [rtrs_client]
rtrs_clt_request+0x1a7/0x320 [rtrs_client]
? 0xffffffffc0ab1000
send_usr_msg+0xbf/0x160 [rnbd_client]
? rnbd_clt_put_sess+0x60/0x60 [rnbd_client]
? send_usr_msg+0x160/0x160 [rnbd_client]
? sg_alloc_table+0x27/0xb0
? sg_zero_buffer+0xd0/0xd0
send_msg_sess_info+0xe9/0x180 [rnbd_client]
? rnbd_clt_put_sess+0x60/0x60 [rnbd_client]
? blk_mq_alloc_tag_set+0x2ef/0x370
rnbd_clt_map_device+0xba8/0xcd0 [rnbd_client]
? send_msg_open+0x200/0x200 [rnbd_client]
rnbd_clt_map_device_store+0x3e5/0x620 [rnbd_client
To supress the calltrace, let's call get_cpu_ptr/put_cpu_ptr pair in
rtrs_clt_update_rdma_stats to disable preemption when accessing per-cpu
variable.
While at it, let's make the similar change in rtrs_clt_update_wc_stats.
And for rtrs_clt_inc_failover_cnt, though it was only called inside rcu
section, but it still can be preempted in case CONFIG_PREEMPT_RCU is
enabled, so change it to {get,put}_cpu_ptr pair either.
Link: https://lore.kernel.org/r/20211128133501.38710-1-guoqing.jiang@linux.dev
Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2021-11-28 21:35:01 +08:00
|
|
|
put_cpu_ptr(stats->pcpu_stats);
|
2020-05-11 15:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rtrs_clt_inc_failover_cnt(struct rtrs_clt_stats *stats)
|
|
|
|
|
{
|
2022-07-12 12:31:10 +02:00
|
|
|
this_cpu_inc(stats->pcpu_stats->rdma.failover_cnt);
|
2020-05-11 15:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 14:53:33 +02:00
|
|
|
int rtrs_clt_stats_migration_from_cnt_to_str(struct rtrs_clt_stats *stats, char *buf)
|
2020-05-11 15:51:13 +02:00
|
|
|
{
|
|
|
|
|
struct rtrs_clt_stats_pcpu *s;
|
|
|
|
|
|
|
|
|
|
size_t used;
|
|
|
|
|
int cpu;
|
|
|
|
|
|
2021-09-22 14:53:33 +02:00
|
|
|
used = 0;
|
2020-05-11 15:51:13 +02:00
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
|
s = per_cpu_ptr(stats->pcpu_stats, cpu);
|
2021-09-22 14:53:33 +02:00
|
|
|
used += sysfs_emit_at(buf, used, "%d ",
|
2020-05-11 15:51:13 +02:00
|
|
|
atomic_read(&s->cpu_migr.from));
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 14:53:33 +02:00
|
|
|
used += sysfs_emit_at(buf, used, "\n");
|
|
|
|
|
|
|
|
|
|
return used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rtrs_clt_stats_migration_to_cnt_to_str(struct rtrs_clt_stats *stats, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct rtrs_clt_stats_pcpu *s;
|
|
|
|
|
|
|
|
|
|
size_t used;
|
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
|
|
used = 0;
|
2020-05-11 15:51:13 +02:00
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
|
s = per_cpu_ptr(stats->pcpu_stats, cpu);
|
2021-09-22 14:53:33 +02:00
|
|
|
used += sysfs_emit_at(buf, used, "%d ", s->cpu_migr.to);
|
2020-05-11 15:51:13 +02:00
|
|
|
}
|
2021-09-22 14:53:33 +02:00
|
|
|
|
2021-09-22 14:53:27 +02:00
|
|
|
used += sysfs_emit_at(buf, used, "\n");
|
2020-05-11 15:51:13 +02:00
|
|
|
|
|
|
|
|
return used;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 14:53:28 +02:00
|
|
|
int rtrs_clt_stats_reconnects_to_str(struct rtrs_clt_stats *stats, char *buf)
|
2020-05-11 15:51:13 +02:00
|
|
|
{
|
2021-09-22 14:53:27 +02:00
|
|
|
return sysfs_emit(buf, "%d %d\n", stats->reconnects.successful_cnt,
|
|
|
|
|
stats->reconnects.fail_cnt);
|
2020-05-11 15:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 14:53:28 +02:00
|
|
|
ssize_t rtrs_clt_stats_rdma_to_str(struct rtrs_clt_stats *stats, char *page)
|
2020-05-11 15:51:13 +02:00
|
|
|
{
|
|
|
|
|
struct rtrs_clt_stats_rdma sum;
|
|
|
|
|
struct rtrs_clt_stats_rdma *r;
|
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
|
|
memset(&sum, 0, sizeof(sum));
|
|
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
|
r = &per_cpu_ptr(stats->pcpu_stats, cpu)->rdma;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
sum.failover_cnt += r->failover_cnt;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 14:53:27 +02:00
|
|
|
return sysfs_emit(page, "%llu %llu %llu %llu %u %llu\n",
|
2020-05-11 15:51:13 +02:00
|
|
|
sum.dir[READ].cnt, sum.dir[READ].size_total,
|
|
|
|
|
sum.dir[WRITE].cnt, sum.dir[WRITE].size_total,
|
|
|
|
|
atomic_read(&stats->inflight), sum.failover_cnt);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 14:53:28 +02:00
|
|
|
ssize_t rtrs_clt_reset_all_help(struct rtrs_clt_stats *s, char *page)
|
2020-05-11 15:51:13 +02:00
|
|
|
{
|
2021-09-22 14:53:27 +02:00
|
|
|
return sysfs_emit(page, "echo 1 to reset all statistics\n");
|
2020-05-11 15:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rtrs_clt_reset_rdma_stats(struct rtrs_clt_stats *stats, bool enable)
|
|
|
|
|
{
|
|
|
|
|
struct rtrs_clt_stats_pcpu *s;
|
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
|
s = per_cpu_ptr(stats->pcpu_stats, cpu);
|
|
|
|
|
memset(&s->rdma, 0, sizeof(s->rdma));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rtrs_clt_reset_cpu_migr_stats(struct rtrs_clt_stats *stats, bool enable)
|
|
|
|
|
{
|
|
|
|
|
struct rtrs_clt_stats_pcpu *s;
|
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
|
s = per_cpu_ptr(stats->pcpu_stats, cpu);
|
|
|
|
|
memset(&s->cpu_migr, 0, sizeof(s->cpu_migr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rtrs_clt_reset_reconnects_stat(struct rtrs_clt_stats *stats, bool enable)
|
|
|
|
|
{
|
|
|
|
|
if (!enable)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
memset(&stats->reconnects, 0, sizeof(stats->reconnects));
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rtrs_clt_reset_all_stats(struct rtrs_clt_stats *s, bool enable)
|
|
|
|
|
{
|
|
|
|
|
if (enable) {
|
|
|
|
|
rtrs_clt_reset_rdma_stats(s, enable);
|
|
|
|
|
rtrs_clt_reset_cpu_migr_stats(s, enable);
|
|
|
|
|
rtrs_clt_reset_reconnects_stat(s, enable);
|
|
|
|
|
atomic_set(&s->inflight, 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void rtrs_clt_update_rdma_stats(struct rtrs_clt_stats *stats,
|
|
|
|
|
size_t size, int d)
|
|
|
|
|
{
|
2022-07-12 12:31:10 +02:00
|
|
|
this_cpu_inc(stats->pcpu_stats->rdma.dir[d].cnt);
|
|
|
|
|
this_cpu_add(stats->pcpu_stats->rdma.dir[d].size_total, size);
|
2020-05-11 15:51:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rtrs_clt_update_all_stats(struct rtrs_clt_io_req *req, int dir)
|
|
|
|
|
{
|
|
|
|
|
struct rtrs_clt_con *con = req->con;
|
2022-01-05 19:07:06 +01:00
|
|
|
struct rtrs_clt_path *clt_path = to_clt_path(con->c.path);
|
|
|
|
|
struct rtrs_clt_stats *stats = clt_path->stats;
|
2020-05-11 15:51:13 +02:00
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
|
|
len = req->usr_len + req->data_len;
|
|
|
|
|
rtrs_clt_update_rdma_stats(stats, len, dir);
|
2021-08-06 13:21:11 +02:00
|
|
|
if (req->mp_policy == MP_POLICY_MIN_INFLIGHT)
|
2020-05-11 15:51:13 +02:00
|
|
|
atomic_inc(&stats->inflight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rtrs_clt_init_stats(struct rtrs_clt_stats *stats)
|
|
|
|
|
{
|
|
|
|
|
stats->pcpu_stats = alloc_percpu(typeof(*stats->pcpu_stats));
|
|
|
|
|
if (!stats->pcpu_stats)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* successful_cnt will be set to 0 after session
|
|
|
|
|
* is established for the first time
|
|
|
|
|
*/
|
|
|
|
|
stats->reconnects.successful_cnt = -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|