From patchwork Wed Jun 6 15:24:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Pen X-Patchwork-Id: 10450435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9BF5860146 for ; Wed, 6 Jun 2018 15:25:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D2AC2978D for ; Wed, 6 Jun 2018 15:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81FDF297A8; Wed, 6 Jun 2018 15:25:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5D872978D for ; Wed, 6 Jun 2018 15:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932307AbeFFPZs (ORCPT ); Wed, 6 Jun 2018 11:25:48 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51524 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932268AbeFFPZi (ORCPT ); Wed, 6 Jun 2018 11:25:38 -0400 Received: by mail-wm0-f66.google.com with SMTP id r15-v6so12272904wmc.1 for ; Wed, 06 Jun 2018 08:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=za9Vv3eF7JcmsMg4/u2wyrtsFaNq+FVVT6yhsgzr9yw=; b=qnlyhPxkX0ud15lItvPcopEimATVRXEHLvLmvpLD0ytA/KVri9BqThwo9RrH2xZ2HP 549PWDs8u2EQ6WIxQD+QnHgmtHxB7pA7jIXYxxp+v7BYWc1ONvDqbO+TCkSnv20sTaBQ jVy1gR3Y5R3uXS1jjHffZjP+VtVWL6WQkOEKp0KPWRAta7p2YtuNfnp/Aq9gEDFfcYI6 F1wU+zFGqs2gFIIwOh7lbhZq3moMHi47t/QdHGrw4yPqUPQF7S61BMgUNCByu7JynbDE 7xs4k/wS3JgkRW96STOHkPJHoTmfWULUWYTccQWigniq2Zb6RYZP4P+uXmJIghQ4i54b Pdrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=za9Vv3eF7JcmsMg4/u2wyrtsFaNq+FVVT6yhsgzr9yw=; b=TCiWonPK3053Bs+88TCK9odHyI/A3W9OgAvG0v0ta87xtG0Xy9tJ/Rbp8MHdMyfhmU nUDUbq2xJk3CnhLgdCt9SzKl5IfOMJc1eRlXdbd9d+nsVuykda+KEM9HD1DHIA5rNPya SKBCfBtx2lCR7vrBBj/+CSiU1EKgRWpQleEQKjW9ZZSkEFpHjNkLcS6Ms/L6lC8ftea+ vBQAHGz0U145ZtyxMVHA1qRAxfQOoLmW1FKKiKFnh+xX4SLibT8zAfO8qgPc3QIkuyt8 dS5XN3KBjtjQ1LAeC0rXgYiZpAdB2UCe+6x4pJxiH+yzKcwnP/jvUALdQ+SsoLr52ggW j0qg== X-Gm-Message-State: APt69E2CtysLh7c3+mU52I57f1zkdEuoMNU1nrIOBOezmemOOX3WpYEr j2h401vaNcNVpctzWcJbyE0hTGmNWAM= X-Google-Smtp-Source: ADUXVKLnoYe2DoNtx2BPMaCtAUoCcPjz4R9JX5La+fVRbvBc14+TRotS+cJzGrNAq0KuWjHHJ4Ooyg== X-Received: by 2002:a1c:8645:: with SMTP id i66-v6mr2243664wmd.40.1528298736374; Wed, 06 Jun 2018 08:25:36 -0700 (PDT) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id n11-v6sm18645834wro.13.2018.06.06.08.25.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jun 2018 08:25:35 -0700 (PDT) From: Roman Pen To: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Bart Van Assche , Or Gerlitz , Doug Ledford , Danil Kipnis , Jack Wang , Roman Pen Subject: [PATCH v3 07/25] ibtrs: client: statistics functions Date: Wed, 6 Jun 2018 17:24:57 +0200 Message-Id: <20180606152515.25807-8-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180606152515.25807-1-roman.penyaev@profitbricks.com> References: <20180606152515.25807-1-roman.penyaev@profitbricks.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This introduces set of functions used on client side to account statistics of RDMA data sent/received, amount of IOs inflight, latency, cpu migrations, etc. Almost all statistics is collected using percpu variables. Signed-off-by: Roman Pen Signed-off-by: Danil Kipnis Cc: Jack Wang --- drivers/infiniband/ulp/ibtrs/ibtrs-clt-stats.c | 455 +++++++++++++++++++++++++ 1 file changed, 455 insertions(+) create mode 100644 drivers/infiniband/ulp/ibtrs/ibtrs-clt-stats.c diff --git a/drivers/infiniband/ulp/ibtrs/ibtrs-clt-stats.c b/drivers/infiniband/ulp/ibtrs/ibtrs-clt-stats.c new file mode 100644 index 000000000000..af2ed05d2900 --- /dev/null +++ b/drivers/infiniband/ulp/ibtrs/ibtrs-clt-stats.c @@ -0,0 +1,455 @@ +/* + * InfiniBand Transport Layer + * + * Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. + * Authors: Fabian Holler + * Jack Wang + * Kleber Souza + * Danil Kipnis + * Roman Penyaev + * Milind Dumbare + * + * Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. + * Authors: Danil Kipnis + * Roman Penyaev + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#undef pr_fmt +#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include "ibtrs-clt.h" + +static inline int ibtrs_clt_ms_to_id(unsigned long ms) +{ + int id = ms ? ilog2(ms) - MIN_LOG_LAT + 1 : 0; + + return clamp(id, 0, LOG_LAT_SZ - 1); +} + +void ibtrs_clt_update_rdma_lat(struct ibtrs_clt_stats *stats, bool read, + unsigned long ms) +{ + struct ibtrs_clt_stats_pcpu *s; + int id; + + id = ibtrs_clt_ms_to_id(ms); + s = this_cpu_ptr(stats->pcpu_stats); + if (read) { + s->rdma_lat_distr[id].read++; + if (s->rdma_lat_max.read < ms) + s->rdma_lat_max.read = ms; + } else { + s->rdma_lat_distr[id].write++; + if (s->rdma_lat_max.write < ms) + s->rdma_lat_max.write = ms; + } +} + +void ibtrs_clt_decrease_inflight(struct ibtrs_clt_stats *stats) +{ + atomic_dec(&stats->inflight); +} + +void ibtrs_clt_update_wc_stats(struct ibtrs_clt_con *con) +{ + struct ibtrs_clt_sess *sess = to_clt_sess(con->c.sess); + struct ibtrs_clt_stats *stats = &sess->stats; + struct ibtrs_clt_stats_pcpu *s; + int cpu; + + cpu = raw_smp_processor_id(); + s = this_cpu_ptr(stats->pcpu_stats); + s->wc_comp.cnt++; + s->wc_comp.total_cnt++; + if (unlikely(con->cpu != cpu)) { + s->cpu_migr.to++; + + /* Careful here, override s pointer */ + s = per_cpu_ptr(stats->pcpu_stats, con->cpu); + atomic_inc(&s->cpu_migr.from); + } +} + +void ibtrs_clt_inc_failover_cnt(struct ibtrs_clt_stats *stats) +{ + struct ibtrs_clt_stats_pcpu *s; + + s = this_cpu_ptr(stats->pcpu_stats); + s->rdma.failover_cnt++; +} + +static inline u32 ibtrs_clt_stats_get_avg_wc_cnt(struct ibtrs_clt_stats *stats) +{ + u32 cnt = 0; + u64 sum = 0; + int cpu; + + for_each_possible_cpu(cpu) { + struct ibtrs_clt_stats_pcpu *s; + + s = per_cpu_ptr(stats->pcpu_stats, cpu); + sum += s->wc_comp.total_cnt; + cnt += s->wc_comp.cnt; + } + + return cnt ? sum / cnt : 0; +} + +int ibtrs_clt_stats_wc_completion_to_str(struct ibtrs_clt_stats *stats, + char *buf, size_t len) +{ + return scnprintf(buf, len, "%u\n", + ibtrs_clt_stats_get_avg_wc_cnt(stats)); +} + +ssize_t ibtrs_clt_stats_rdma_lat_distr_to_str(struct ibtrs_clt_stats *stats, + char *page, size_t len) +{ + struct ibtrs_clt_stats_rdma_lat res[LOG_LAT_SZ]; + struct ibtrs_clt_stats_rdma_lat max; + struct ibtrs_clt_stats_pcpu *s; + + ssize_t cnt = 0; + int i, cpu; + + max.write = 0; + max.read = 0; + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + + if (max.write < s->rdma_lat_max.write) + max.write = s->rdma_lat_max.write; + if (max.read < s->rdma_lat_max.read) + max.read = s->rdma_lat_max.read; + } + for (i = 0; i < ARRAY_SIZE(res); i++) { + res[i].write = 0; + res[i].read = 0; + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + + res[i].write += s->rdma_lat_distr[i].write; + res[i].read += s->rdma_lat_distr[i].read; + } + } + + for (i = 0; i < ARRAY_SIZE(res) - 1; i++) + cnt += scnprintf(page + cnt, len - cnt, + "< %6d ms: %llu %llu\n", + 1 << (i + MIN_LOG_LAT), res[i].read, + res[i].write); + cnt += scnprintf(page + cnt, len - cnt, ">= %5d ms: %llu %llu\n", + 1 << (i - 1 + MIN_LOG_LAT), res[i].read, + res[i].write); + cnt += scnprintf(page + cnt, len - cnt, " maximum ms: %llu %llu\n", + max.read, max.write); + + return cnt; +} + +int ibtrs_clt_stats_migration_cnt_to_str(struct ibtrs_clt_stats *stats, + char *buf, size_t len) +{ + struct ibtrs_clt_stats_pcpu *s; + + size_t used; + int cpu; + + used = scnprintf(buf, len, " "); + for_each_possible_cpu(cpu) + used += scnprintf(buf + used, len - used, " CPU%u", cpu); + + used += scnprintf(buf + used, len - used, "\nfrom:"); + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + used += scnprintf(buf + used, len - used, " %d", + atomic_read(&s->cpu_migr.from)); + } + + used += scnprintf(buf + used, len - used, "\nto :"); + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + used += scnprintf(buf + used, len - used, " %d", + s->cpu_migr.to); + } + used += scnprintf(buf + used, len - used, "\n"); + + return used; +} + +int ibtrs_clt_stats_reconnects_to_str(struct ibtrs_clt_stats *stats, char *buf, + size_t len) +{ + return scnprintf(buf, len, "%d %d\n", + stats->reconnects.successful_cnt, + stats->reconnects.fail_cnt); +} + +ssize_t ibtrs_clt_stats_rdma_to_str(struct ibtrs_clt_stats *stats, + char *page, size_t len) +{ + struct ibtrs_clt_stats_rdma sum; + struct ibtrs_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; + } + + return scnprintf(page, len, "%llu %llu %llu %llu %u %llu\n", + 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); +} + +int ibtrs_clt_stats_sg_list_distr_to_str(struct ibtrs_clt_stats *stats, + char *buf, size_t len) +{ + struct ibtrs_clt_stats_pcpu *s; + + int i, cpu, cnt; + + cnt = scnprintf(buf, len, "n\\cpu:"); + for_each_possible_cpu(cpu) + cnt += scnprintf(buf + cnt, len - cnt, "%5d", cpu); + + for (i = 0; i < SG_DISTR_SZ; i++) { + if (i <= MAX_LIN_SG) + cnt += scnprintf(buf + cnt, len - cnt, "\n= %3d:", i); + else if (i < SG_DISTR_SZ - 1) + cnt += scnprintf(buf + cnt, len - cnt, + "\n< %3d:", + 1 << (i + MIN_LOG_SG - MAX_LIN_SG)); + else + cnt += scnprintf(buf + cnt, len - cnt, + "\n>=%3d:", + 1 << (i + MIN_LOG_SG - MAX_LIN_SG - 1)); + + for_each_possible_cpu(cpu) { + unsigned int p, p_i, p_f; + u64 total, distr; + + s = per_cpu_ptr(stats->pcpu_stats, cpu); + total = s->sg_list_total; + distr = s->sg_list_distr[i]; + + p = total ? distr * 1000 / total : 0; + p_i = p / 10; + p_f = p % 10; + + if (distr) + cnt += scnprintf(buf + cnt, len - cnt, + " %2u.%01u", p_i, p_f); + else + cnt += scnprintf(buf + cnt, len - cnt, " 0"); + } + } + + cnt += scnprintf(buf + cnt, len - cnt, "\ntotal:"); + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + cnt += scnprintf(buf + cnt, len - cnt, " %llu", + s->sg_list_total); + } + cnt += scnprintf(buf + cnt, len - cnt, "\n"); + + return cnt; +} + +ssize_t ibtrs_clt_reset_all_help(struct ibtrs_clt_stats *s, + char *page, size_t len) +{ + return scnprintf(page, len, "echo 1 to reset all statistics\n"); +} + +int ibtrs_clt_reset_rdma_stats(struct ibtrs_clt_stats *stats, bool enable) +{ + struct ibtrs_clt_stats_pcpu *s; + int cpu; + + if (unlikely(!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 ibtrs_clt_reset_rdma_lat_distr_stats(struct ibtrs_clt_stats *stats, + bool enable) +{ + struct ibtrs_clt_stats_pcpu *s; + int cpu; + + if (enable) { + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + memset(&s->rdma_lat_max, 0, sizeof(s->rdma_lat_max)); + memset(&s->rdma_lat_distr, 0, + sizeof(s->rdma_lat_distr)); + } + } + stats->enable_rdma_lat = enable; + + return 0; +} + +int ibtrs_clt_reset_sg_list_distr_stats(struct ibtrs_clt_stats *stats, + bool enable) +{ + struct ibtrs_clt_stats_pcpu *s; + int cpu; + + if (unlikely(!enable)) + return -EINVAL; + + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + memset(&s->sg_list_total, 0, sizeof(s->sg_list_total)); + memset(&s->sg_list_distr, 0, sizeof(s->sg_list_distr)); + } + + return 0; +} + +int ibtrs_clt_reset_cpu_migr_stats(struct ibtrs_clt_stats *stats, bool enable) +{ + struct ibtrs_clt_stats_pcpu *s; + int cpu; + + if (unlikely(!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 ibtrs_clt_reset_reconnects_stat(struct ibtrs_clt_stats *stats, bool enable) +{ + if (unlikely(!enable)) + return -EINVAL; + + memset(&stats->reconnects, 0, sizeof(stats->reconnects)); + + return 0; +} + +int ibtrs_clt_reset_wc_comp_stats(struct ibtrs_clt_stats *stats, bool enable) +{ + struct ibtrs_clt_stats_pcpu *s; + int cpu; + + if (unlikely(!enable)) + return -EINVAL; + + for_each_possible_cpu(cpu) { + s = per_cpu_ptr(stats->pcpu_stats, cpu); + memset(&s->wc_comp, 0, sizeof(s->wc_comp)); + } + + return 0; +} + +int ibtrs_clt_reset_all_stats(struct ibtrs_clt_stats *s, bool enable) +{ + if (enable) { + ibtrs_clt_reset_rdma_stats(s, enable); + ibtrs_clt_reset_rdma_lat_distr_stats(s, enable); + ibtrs_clt_reset_sg_list_distr_stats(s, enable); + ibtrs_clt_reset_cpu_migr_stats(s, enable); + ibtrs_clt_reset_reconnects_stat(s, enable); + ibtrs_clt_reset_wc_comp_stats(s, enable); + atomic_set(&s->inflight, 0); + return 0; + } + + return -EINVAL; +} + +static inline void ibtrs_clt_record_sg_distr(u64 stat[SG_DISTR_SZ], u64 *total, + unsigned int cnt) +{ + int i; + + i = cnt > MAX_LIN_SG ? ilog2(cnt) + MAX_LIN_SG - MIN_LOG_SG + 1 : cnt; + i = i < SG_DISTR_SZ ? i : SG_DISTR_SZ - 1; + + stat[i]++; + (*total)++; +} + +static inline void ibtrs_clt_update_rdma_stats(struct ibtrs_clt_stats *stats, + size_t size, int d) +{ + struct ibtrs_clt_stats_pcpu *s; + + s = this_cpu_ptr(stats->pcpu_stats); + s->rdma.dir[d].cnt++; + s->rdma.dir[d].size_total += size; +} + +void ibtrs_clt_update_all_stats(struct ibtrs_clt_io_req *req, int dir) +{ + struct ibtrs_clt_con *con = req->con; + struct ibtrs_clt_sess *sess = to_clt_sess(con->c.sess); + struct ibtrs_clt_stats *stats = &sess->stats; + unsigned int len; + + struct ibtrs_clt_stats_pcpu *s; + + s = this_cpu_ptr(stats->pcpu_stats); + ibtrs_clt_record_sg_distr(s->sg_list_distr, &s->sg_list_total, + req->sg_cnt); + len = req->usr_len + req->data_len; + ibtrs_clt_update_rdma_stats(stats, len, dir); + atomic_inc(&stats->inflight); +} + +int ibtrs_clt_init_stats(struct ibtrs_clt_stats *stats) +{ + stats->enable_rdma_lat = false; + stats->pcpu_stats = alloc_percpu(typeof(*stats->pcpu_stats)); + if (unlikely(!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; +} + +void ibtrs_clt_free_stats(struct ibtrs_clt_stats *stats) +{ + free_percpu(stats->pcpu_stats); +}