From: Omar Sandoval <osandov@osandov.com>
To: Shaohua Li <shli@kernel.org>
Cc: linux-block@vger.kernel.org, vgoyal@redhat.com, tj@kernel.org,
axboe@kernel.dk, Kernel-team@fb.com, Shaohua Li <shli@fb.com>,
Omar Sandoval <osandov@fb.com>
Subject: Re: [PATCH V2 1/3] blk-stat: delete useless code
Date: Tue, 10 Oct 2017 10:57:14 -0700 [thread overview]
Message-ID: <20171010175714.GA30738@vader.DHCP.thefacebook.com> (raw)
In-Reply-To: <74821887899a7d05c6429e03f0dc49a079c446b9.1507337347.git.shli@fb.com>
On Fri, Oct 06, 2017 at 05:55:59PM -0700, Shaohua Li wrote:
> From: Shaohua Li <shli@fb.com>
>
> Fix two issues:
> - the per-cpu stat flush is unnecessary, nobody uses per-cpu stat except
> sum it to global stat. We can do the calculation there. The flush just
> wastes cpu time.
One thing that the stat flushing avoids is overflowing the batch
counter, but with the current windows we're using, that seems really
unlikely, so I think this is okay.
Since they diverged, I would kind of like to separate the types for the
per-cpu buffer and the final stats, but this is fine for now.
> - some fields are signed int/s64. I don't see the point.
I like this part.
Reviewed-by: Omar Sandoval <osandov@fb.com>
> Cc: Omar Sandoval <osandov@fb.com>
> Signed-off-by: Shaohua Li <shli@fb.com>
> ---
> block/blk-stat.c | 45 +++++++--------------------------------------
> include/linux/blk_types.h | 5 ++---
> 2 files changed, 9 insertions(+), 41 deletions(-)
>
> diff --git a/block/blk-stat.c b/block/blk-stat.c
> index c52356d..3a2f3c9 100644
> --- a/block/blk-stat.c
> +++ b/block/blk-stat.c
> @@ -11,8 +11,6 @@
> #include "blk-mq.h"
> #include "blk.h"
>
> -#define BLK_RQ_STAT_BATCH 64
> -
> struct blk_queue_stats {
> struct list_head callbacks;
> spinlock_t lock;
> @@ -23,45 +21,21 @@ static void blk_stat_init(struct blk_rq_stat *stat)
> {
> stat->min = -1ULL;
> stat->max = stat->nr_samples = stat->mean = 0;
> - stat->batch = stat->nr_batch = 0;
> -}
> -
> -static void blk_stat_flush_batch(struct blk_rq_stat *stat)
> -{
> - const s32 nr_batch = READ_ONCE(stat->nr_batch);
> - const s32 nr_samples = READ_ONCE(stat->nr_samples);
> -
> - if (!nr_batch)
> - return;
> - if (!nr_samples)
> - stat->mean = div64_s64(stat->batch, nr_batch);
> - else {
> - stat->mean = div64_s64((stat->mean * nr_samples) +
> - stat->batch,
> - nr_batch + nr_samples);
> - }
> -
> - stat->nr_samples += nr_batch;
> - stat->nr_batch = stat->batch = 0;
> + stat->batch = 0;
> }
>
> +/* src is a per-cpu stat, mean isn't initialized */
> static void blk_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
> {
> - blk_stat_flush_batch(src);
> -
> if (!src->nr_samples)
> return;
>
> dst->min = min(dst->min, src->min);
> dst->max = max(dst->max, src->max);
>
> - if (!dst->nr_samples)
> - dst->mean = src->mean;
> - else {
> - dst->mean = div64_s64((src->mean * src->nr_samples) +
> - (dst->mean * dst->nr_samples),
> - dst->nr_samples + src->nr_samples);
> - }
> + dst->mean = div_u64(src->batch + dst->mean * dst->nr_samples,
> + dst->nr_samples + src->nr_samples);
> +
> dst->nr_samples += src->nr_samples;
> }
>
> @@ -69,13 +43,8 @@ static void __blk_stat_add(struct blk_rq_stat *stat, u64 value)
> {
> stat->min = min(stat->min, value);
> stat->max = max(stat->max, value);
> -
> - if (stat->batch + value < stat->batch ||
> - stat->nr_batch + 1 == BLK_RQ_STAT_BATCH)
> - blk_stat_flush_batch(stat);
> -
> stat->batch += value;
> - stat->nr_batch++;
> + stat->nr_samples++;
> }
>
> void blk_stat_add(struct request *rq)
> @@ -84,7 +53,7 @@ void blk_stat_add(struct request *rq)
> struct blk_stat_callback *cb;
> struct blk_rq_stat *stat;
> int bucket;
> - s64 now, value;
> + u64 now, value;
>
> now = __blk_stat_time(ktime_to_ns(ktime_get()));
> if (now < blk_stat_time(&rq->issue_stat))
> diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> index a2d2aa7..3385c89 100644
> --- a/include/linux/blk_types.h
> +++ b/include/linux/blk_types.h
> @@ -329,11 +329,10 @@ static inline bool blk_qc_t_is_internal(blk_qc_t cookie)
> }
>
> struct blk_rq_stat {
> - s64 mean;
> + u64 mean;
> u64 min;
> u64 max;
> - s32 nr_samples;
> - s32 nr_batch;
> + u32 nr_samples;
> u64 batch;
> };
>
> --
> 2.9.5
>
next prev parent reply other threads:[~2017-10-10 17:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-07 0:55 [PATCH V2 0/3] block: export latency info for cgroups Shaohua Li
2017-10-07 0:55 ` [PATCH V2 1/3] blk-stat: delete useless code Shaohua Li
2017-10-10 17:57 ` Omar Sandoval [this message]
2017-10-10 18:02 ` Jens Axboe
2017-10-07 0:56 ` [PATCH V2 2/3] block: set request_list for request Shaohua Li
2017-10-10 19:47 ` Jens Axboe
2017-10-07 0:56 ` [PATCH V2 3/3] blockcg: export latency info for each cgroup Shaohua Li
2017-10-10 17:35 ` weiping zhang
2017-10-10 18:23 ` Shaohua Li
2017-10-11 14:41 ` weiping zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171010175714.GA30738@vader.DHCP.thefacebook.com \
--to=osandov@osandov.com \
--cc=Kernel-team@fb.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=osandov@fb.com \
--cc=shli@fb.com \
--cc=shli@kernel.org \
--cc=tj@kernel.org \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox