Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp920233imm; Tue, 5 Jun 2018 06:34:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLYU+uY9I7CIvAzKXd5klP2QdTOKeO3o3XBaWiiyshhe2NM3VSVoR4fHViUnqlQEiPtFd5X X-Received: by 2002:a65:504a:: with SMTP id k10-v6mr4875187pgo.151.1528205692352; Tue, 05 Jun 2018 06:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528205692; cv=none; d=google.com; s=arc-20160816; b=u+/LqEISqGeq8KSHRgtFgbjZ0f/gYQmNrNDEIz8wmdr5qfTQgzuYx+u8QEDixeo5lW LngxmPCn+heNL1+hePXVzLEEKNUU7KIphEZ2NjkYyWgW55E9M6gCFWPGFdo90IuHYUdI R9LQJNssxjFSH1HU1CKhHWDtEVz4XTSR+QwNcRUYzWIRlhsjO1JV2pBVXfU5NKHW2cew P29gHHxwhUGk5+Ngzap/u+NeezdM8+u7/K+2nvHtlT5Xc0RDHahFxv7QJ12qxlc95z5U mzAGvp8ZDgdfwUWFLfTdqQVgnTO0YmFLO6XP7O9yHV3omD+gKbVAQtpZX2cZKplxLe4W w2lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Kp8LQTKmX3YVv+T71mlHfYgoh8Y4/YET2LM7+5wZcWg=; b=cF3WiAEHy7w47i3DlzVSA39kqSnnujFZdnazKBoZdmgGWJ+WJ8Nt16UXU2xtYrUXnr yuFehPcjKI2zJ16bbwqfkaR6WRMDcskuze0o915nhJmRdZixYgzp2CizZjfppGml3Xo0 RWVj8WE4rFjFJVo6BZQA5MnCb718DzuXMS/yJoJPQloNBLcUhO8TxzRs3ZNwKfaKQwPH uWDeTl08hpCpiWgn22V02RtV0EwKFgggXZINgPpHMfUhECjNyMD96RGZTnkXTC8VdeCN 664G0ffaSTa4/AOyquwdluw/I9kX/aHZOkWHzCd2X8iC7GvUiAj+lDELnI0080DcznGt 7KSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=uTpzeTKX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si47604766pld.218.2018.06.05.06.34.38; Tue, 05 Jun 2018 06:34:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=uTpzeTKX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752262AbeFENdg (ORCPT + 99 others); Tue, 5 Jun 2018 09:33:36 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:41894 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751963AbeFEN3z (ORCPT ); Tue, 5 Jun 2018 09:29:55 -0400 Received: by mail-qt0-f193.google.com with SMTP id y20-v6so2344531qto.8 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=Oe7lyZ0nLRLZ9aySOUt1atdPPW2mz07pmZyur8M4El5vuQpBEDC6luB6MYkPUe9KJS 7K7//KlBq2iMoja2J69PT76m6p/oaZ7GJDFbdmZBIhuBUuNCYySqSLQ8JMOkM9vYo/uE vo10cFEgYUqYGvDkSO3TdF133ZYS99M5bKwGYlTg2QmjfzumZ7JUR84na7S2uf/6RWZY We4BQqCJqI3r0iM+M18mXvFeYILMcrCHmdKSQB5XynEl191eZaORtY32hFtBiPARvWhT IBAQqZ/AQXR/SVgrXc4Fevb1nbOoi8LdVLWon61AHmxbHH4pfsC4+seR/FvbGDiBgHjb Ky5g== X-Gm-Message-State: APt69E365G9oLKQ5YqfW+YhzEj0AhoScqByURYkmO1TI2VnZt/qVmFnW LlWSGtIC0jD2z7yl2muvqjnmFiUW 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.14.3