From patchwork Tue Jun 5 13:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10448297 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 633D96024A for ; Tue, 5 Jun 2018 13:33:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53D7625F3E for ; Tue, 5 Jun 2018 13:33:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4878D27F81; Tue, 5 Jun 2018 13:33:38 +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=ham 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 C0A3D25F3E for ; Tue, 5 Jun 2018 13:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751915AbeFENdf (ORCPT ); Tue, 5 Jun 2018 09:33:35 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:36182 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751957AbeFEN3z (ORCPT ); Tue, 5 Jun 2018 09:29:55 -0400 Received: by mail-qt0-f195.google.com with SMTP id o9-v6so2354075qtp.3 for ; Tue, 05 Jun 2018 06:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kp8LQTKmX3YVv+T71mlHfYgoh8Y4/YET2LM7+5wZcWg=; b=uTpzeTKXNincpajs1dhzrxo+XBqdx6RWkAwxIsDcBRFaAivsc8jWhGSEoq9HObPZSR zyh+91dTf1K3ZhyKlBb9CB+JeldiPrQWPppve90pXg5d9cR4LcvGWLC25R7d8stg5MjU +lnlNr8pZ1kJYnrW40Bw5uXozGdOzVPY/Qgu3s8q0WahSHqfrrvh1tSyNQY+RxzEHwGD 6YDGSWyqNEf9VMfkUXY95PvuYERuSz5wSOr0/UQPUIJtGSHgMZ7qiLr/+aMiYDuCyGpB JYzK6boXKhAgBSgr3lUtJ46kEMdVJ2eOP9OH5GcYMGwNDQfVQYFtTfMHihbV2MTBm9Fl udVg== 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=Kp8LQTKmX3YVv+T71mlHfYgoh8Y4/YET2LM7+5wZcWg=; b=jre9t5VtOdzEO2XeBEAOrgF/C3I4A+KJdeTnUEC8JrMKry8E7UAktFfQUCc2Ce8Hn9 9ywM609CLnnutQAsFYZL1de/8ualz+kcxr4BD4OvodltWXEhjzBjoPXsjQkg37y/P9+H Kw+5FUFJUlmB+vxPWp39OE8ZZnwqzlcAzURla3wiWSYHS9cawXzZBkfEsbSrXUH6dxFT Jh1yAP8jQz6Atbucz8UaS/hW8X4Mg6o8PeCtc/TN/UxUwYiHqV5T619TM7pNKdNAR/GP X71xEz0ImYt84LNhkWyVjoWu8nPqvZ+zcfPNE3i6jZu4q1xGE94WKTRvG1PoASmCOQva 8I+w== X-Gm-Message-State: APt69E0yJa0YaDHgAxGAxNjL53vPbJluczBU2oSMWT3C+VWACxTy78YY c92A2q3oj0i7dybJZZVS07C0Xg== X-Google-Smtp-Source: ADUXVKKNApFYE74XOj946Haq9J01CxIL2etcpf86fnq5N9f/CkPuakypz0bsOIoyq3HH7SkcqJcUNA== X-Received: by 2002:a0c:d6c7:: with SMTP id l7-v6mr4369894qvi.36.1528205394925; Tue, 05 Jun 2018 06:29:54 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id s186-v6sm34257822qkb.53.2018.06.05.06.29.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:29:54 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, kernel-team@fb.com, linux-block@vger.kernel.org, akpm@linux-foundation.org, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, linux-fsdevel@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 03/13] blk-cgroup: allow controllers to output their own stats Date: Tue, 5 Jun 2018 09:29:38 -0400 Message-Id: <20180605132948.1664-4-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605132948.1664-1-josef@toxicpanda.com> References: <20180605132948.1664-1-josef@toxicpanda.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 From: Josef Bacik blk-iolatency has a few stats that it would like to print out, and instead of adding a bunch of crap to the generic code just provide a helper so that controllers can add stuff to the stat line if they want to. Hide it behind a boot option since it changes the output of io.stat from normal, and these stats are only interesting to developers. Signed-off-by: Josef Bacik --- block/blk-cgroup.c | 61 +++++++++++++++++++++++++++++++++++++++++++--- include/linux/blk-cgroup.h | 3 +++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index eb85cb87c40f..b2ac6a7f851f 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -50,6 +50,8 @@ static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS]; static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */ +static bool blkcg_debug_stats = false; + static bool blkcg_policy_enabled(struct request_queue *q, const struct blkcg_policy *pol) { @@ -954,13 +956,28 @@ static int blkcg_print_stat(struct seq_file *sf, void *v) hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) { const char *dname; + char *buf; struct blkg_rwstat rwstat; u64 rbytes, wbytes, rios, wios; + size_t size = seq_get_buf(sf, &buf), count = 0, total = 0; + int i; dname = blkg_dev_name(blkg); if (!dname) continue; + /* + * Hooray string manipulation, count is the size written NOT + * INCLUDING THE \0, so size is now count+1 less than what we + * had before, but we want to start writing the next bit from + * the \0 so we only add count to buf. + */ + count = snprintf(buf, size, "%s ", dname); + if (count >= size) + continue; + buf += count; + size -= count + 1; + spin_lock_irq(blkg->q->queue_lock); rwstat = blkg_rwstat_recursive_sum(blkg, NULL, @@ -975,9 +992,44 @@ static int blkcg_print_stat(struct seq_file *sf, void *v) spin_unlock_irq(blkg->q->queue_lock); - if (rbytes || wbytes || rios || wios) - seq_printf(sf, "%s rbytes=%llu wbytes=%llu rios=%llu wios=%llu\n", - dname, rbytes, wbytes, rios, wios); + if (rbytes || wbytes || rios || wios) { + total += count; + count = snprintf(buf, size, + "rbytes=%llu wbytes=%llu rios=%llu wios=%llu", + rbytes, wbytes, rios, wios); + if (count >= size) + continue; + buf += count; + total += count; + size -= count + 1; + } + + if (!blkcg_debug_stats) + goto next; + + mutex_lock(&blkcg_pol_mutex); + for (i = 0; i < BLKCG_MAX_POLS; i++) { + struct blkcg_policy *pol = blkcg_policy[i]; + + if (!blkg->pd[i] || !pol->pd_stat_fn) + continue; + + count = pol->pd_stat_fn(blkg->pd[i], buf, size); + if (count >= size) + continue; + buf += count; + total += count; + size -= count + 1; + } + mutex_unlock(&blkcg_pol_mutex); +next: + if (total) { + count = snprintf(buf, size, "\n"); + if (count >= size) + continue; + total += count; + seq_commit(sf, total); + } } rcu_read_unlock(); @@ -1547,3 +1599,6 @@ void blkcg_policy_unregister(struct blkcg_policy *pol) mutex_unlock(&blkcg_pol_register_mutex); } EXPORT_SYMBOL_GPL(blkcg_policy_unregister); + +module_param(blkcg_debug_stats, bool, 0444); +MODULE_PARM_DESC(blkcg_debug_stats, "True if you want debug stats, false if not"); diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index 69aa71dc0c04..b41292726c0f 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -148,6 +148,8 @@ typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd); typedef void (blkcg_pol_offline_pd_fn)(struct blkg_policy_data *pd); typedef void (blkcg_pol_free_pd_fn)(struct blkg_policy_data *pd); typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkg_policy_data *pd); +typedef size_t (blkcg_pol_stat_pd_fn)(struct blkg_policy_data *pd, char *buf, + size_t size); struct blkcg_policy { int plid; @@ -167,6 +169,7 @@ struct blkcg_policy { blkcg_pol_offline_pd_fn *pd_offline_fn; blkcg_pol_free_pd_fn *pd_free_fn; blkcg_pol_reset_pd_stats_fn *pd_reset_stats_fn; + blkcg_pol_stat_pd_fn *pd_stat_fn; }; extern struct blkcg blkcg_root;