Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3815302imm; Tue, 29 May 2018 14:21:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLB+GBWd/IdQAKb4SCwAmHgtBu9Emx+5dbu9sWZq8LEwCejnVMSI/fv0syT7zNpQPWmoPAJ X-Received: by 2002:a65:5cc5:: with SMTP id b5-v6mr55557pgt.85.1527628919643; Tue, 29 May 2018 14:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527628919; cv=none; d=google.com; s=arc-20160816; b=0tKceP1JSZJoHLXdGE5z+SnoaD/HHiWaTFBTc4PpeYXeq+mcc944c0t1tE9+Wy21Ob v6gTsZcq+CtkPCdAz+APnY7gF/lgmO4BbHIx3WP88CGlzmYeKNTlDgxpNorqzrVqMlAB 9enmeWaAm/YC0NrZRgsONqJzMV0iEaFpwXV3VL18qvhqIB+HISuvzOf1+WCpN9rDDEZq ZIAXm6k+xmoDJsiMzYT5O49wpBIkz0qAN5eAnNT4FFodogDgpdZZ5Eyj17HX/iz7wjTX HOeXUyyTBhRwc5EVickflwc4RUUAcgLAToXKMbW2KzVjQwe8+Vm3WFD81emWne5Wn22n 7x6A== 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=ZEQhu3WT2vrLlb25BDJ81qDNzncILk6QIrMc35SIdhE=; b=Y1m+MEM3rer5/3kkiBT5qX/uLvfxEPfHQ3icXKRYUsCuHCmeKbjM3YIxuk3BZfweJP UpfVP0Et51TwIAQkoO7w326qXrgHcVE8P6UoBFK2VJwd4SrSeGlC/V4VUiKogTppuh0h wF912CSAzZRXCXr4NnGOYmWsHTG3LyopHwN/ppQdiwjFodOzMAPUOt3CwqYL9JGr1dFC fJJPK4icpgO42JRusW67Jn2DkYyK/iZIJFAyMwd6maLDhkFU7FW3ssSLm3vybmay0RlT K+fBxFDCSJxPQtdKaJB5n4gPjrq5RLT8VduHeVus09qC9RaB216JFb2PfhjUtlXxcIN8 bkCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=R2GbRWyY; 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 j8-v6si32350983plk.0.2018.05.29.14.21.46; Tue, 29 May 2018 14:21:59 -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=R2GbRWyY; 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 S967663AbeE2VUi (ORCPT + 99 others); Tue, 29 May 2018 17:20:38 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:43794 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967099AbeE2VRc (ORCPT ); Tue, 29 May 2018 17:17:32 -0400 Received: by mail-qk0-f193.google.com with SMTP id h19-v6so12714755qkj.10 for ; Tue, 29 May 2018 14:17:32 -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=ZEQhu3WT2vrLlb25BDJ81qDNzncILk6QIrMc35SIdhE=; b=R2GbRWyYGljhw+xZUkDdu2tAceCVGfM3u403a6pJoT2Hxo+wEJXn9afo9tERKc8RGU KjD40vAZNS0BmxGN6AYvA6U0puU76/m8dMIutyoV422lJIdGAAfRBQsKxpndmPaCXl42 tEGbY+Sy+jH3yrgLu8rTLEVXzAcoUgNML9y2Shwr1KItgi+3DBYgMC3HDshNmjk+FOPP fUFdT1L6ALa4CrlWbUHfzMm1y0T0WG2vvJnS5AVbnArxaTy7mjJJ8EB74cl8AZHJv/fK XvJMW8R3fNCG+LHDsqu9Rl3ktZZMsBzfc7D7+OlmwNPVxGy2M7UvOX9pcUbQsTOpS2MU r+jg== 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=ZEQhu3WT2vrLlb25BDJ81qDNzncILk6QIrMc35SIdhE=; b=ECIMdD7GjLyYI2MYVm7VGVfl0vGQHxi2h6CvsUiK8wE9dY/Y37JirIV+Ck4pjzdizH eCkTzeXsQDjb+IFHMpoLHBcFpFjLt8VhOWaEfi0XvZ+4xtAHby9qayLm+VRX3PMCvJDO VXwfwnWQFLisK7JAA7f1/WOleX4oaW+53ick/OzMgbCzYcYNBWmvdrbUgVo2IW1jFUFp OaM37cmKLRlc73GWQRMgFiGsaYYi5gtkXk68sLm9CXkd8iSHhDorJcnMkHO15ef2a5+S q22gx1UclDHA83DxjYRUoaGuwcYlc7HZPF4t54y3zLOzRH6ORrN3eP+q4q+38BsYo3YL yFpg== X-Gm-Message-State: APt69E0hy9rGI4W8J+DoIMb+Wp3IZSWNmOmMTrL4r+/NfGJwlqcIpIU2 o+TWrXcPhBw903chrF1XtD4+2Q== X-Received: by 2002:a37:2545:: with SMTP id x66-v6mr85417qkg.190.1527628652161; Tue, 29 May 2018 14:17:32 -0700 (PDT) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id u192-v6sm23559749qka.55.2018.05.29.14.17.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 14:17:31 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, kernel-team@fb.com, linux-block@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.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, 29 May 2018 17:17:14 -0400 Message-Id: <20180529211724.4531-4-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180529211724.4531-1-josef@toxicpanda.com> References: <20180529211724.4531-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. Signed-off-by: Josef Bacik --- block/blk-cgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++--- include/linux/blk-cgroup.h | 3 +++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index eb85cb87c40f..9e767e4a852d 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -954,13 +954,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 +990,40 @@ 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; + } + + 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); + if (total) { + count = snprintf(buf, size, "\n"); + if (count >= size) + continue; + total += count; + seq_commit(sf, total); + } } rcu_read_unlock(); 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