Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp608320pxb; Tue, 5 Apr 2022 15:50:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3mnuxtozs8Tz40jXWQ4GgPRnUMKUkInNvEiavG2XSlxMkruXnIL0hnOIyvrdW8WNopx93 X-Received: by 2002:a17:90a:4590:b0:1bc:4afa:1778 with SMTP id v16-20020a17090a459000b001bc4afa1778mr6644848pjg.14.1649199003580; Tue, 05 Apr 2022 15:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649199003; cv=none; d=google.com; s=arc-20160816; b=iLLaGI3mjdRzb6dmBI4yvn8WK7/2MvmjHujaoguX7tA6xclD2smQkcrwXenzxCbTSb x0RZ4Jv2nGhlGUdH/WyEWPLIwZZQlQ9Y01H91A7EO5P4Cidh+TjtOQJv4S3UouLHw2GP DJIkIbknHVCi28o/inlh8duc84UDHIvDW5lFDKBIO5KHD8e7TND/UP+1bwA/UhfwXGN0 9IE+I1h9xJ877efPySAkTYqR2tdJBS9Yk5Dhtmsgb89+BphozkGDH6SbrrmAWx6+cPQ6 nez3VFmNCGpbFEZ0C4NAvSMvwv/QOD73Ol9miZzlhPtZ7Ncd0nfVw/6jFxzyNvDzGW3B HMSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lFf2k0UMRCeXfk/Tpf3M/IrO3v3x45Lng+7FBBg44AM=; b=eklWLE65nCEx8QjHUFETd3gieI0E7GyGtcLMLVxC8bTOLmIyW0YQrnTEI5xWDQBG6f k3GU+MeGRo/pMgXAWwjHRz0gxzxEyvMq8A+cKfAqQpxpvJSZNBIYFVDBkPeVuzfqF1gi h8Nd1TqILT96DOf92zRbgYjicSz1rp8T3yMcTpoWlm6zSZRhqCYr2SESJImZk3cI1dVk CjdmueH7tGabAM7yUarpeOOBSQVsikLGIVS66aw3yVb7FlE9HXvDmW3HYGeUyCXEezZT 4a+cHPB1za+RGSYTa3SjCNu5IA5vZTA+Ta/O+KYONC+T3Fvc8vscWZZ+kBtTAvsTe50r NuHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ihZBfF/U"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i75-20020a636d4e000000b0039895942fb1si14667556pgc.228.2022.04.05.15.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:50:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ihZBfF/U"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 09E651DA6B; Tue, 5 Apr 2022 15:32:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387506AbiDEOcT (ORCPT + 99 others); Tue, 5 Apr 2022 10:32:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240045AbiDEJeB (ORCPT ); Tue, 5 Apr 2022 05:34:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B35C0811A1; Tue, 5 Apr 2022 02:23:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E010C615E4; Tue, 5 Apr 2022 09:23:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF16CC385A2; Tue, 5 Apr 2022 09:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150602; bh=F2sXadztW3MARwarwpZlIp38N5A1LAVO17ur1+LgINs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ihZBfF/UwaZROb9R6rcCsdYRgyNCENTJdkpgjasUuKq3rOLqS0fNpoQlXfdaCEntR lhYyAkM5esxT2U1WkrlFpNpmP21dNKlBWbUnofSU/CuYe1s1XaYj4/H60+Eken3Zn6 eOAxePca+qjUrasxsxu1waKLj7HijREORUed6z5Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Mike Snitzer Subject: [PATCH 5.15 112/913] dm stats: fix too short end duration_ns when using precise_timestamps Date: Tue, 5 Apr 2022 09:19:34 +0200 Message-Id: <20220405070343.184612912@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Snitzer commit 0cdb90f0f306384ecbc60dfd6dc48cdbc1f2d0d8 upstream. dm_stats_account_io()'s STAT_PRECISE_TIMESTAMPS support doesn't handle the fact that with commit b879f915bc48 ("dm: properly fix redundant bio-based IO accounting") io->start_time _may_ be in the past (meaning the start_io_acct() was deferred until later). Add a new dm_stats_recalc_precise_timestamps() helper that will set/clear a new 'precise_timestamps' flag in the dm_stats struct based on whether any configured stats enable STAT_PRECISE_TIMESTAMPS. And update DM core's alloc_io() to use dm_stats_record_start() to set stats_aux.duration_ns if stats->precise_timestamps is true. Also, remove unused 'last_sector' and 'last_rw' members from the dm_stats struct. Fixes: b879f915bc48 ("dm: properly fix redundant bio-based IO accounting") Cc: stable@vger.kernel.org Co-developed-by: Mikulas Patocka Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-stats.c | 28 +++++++++++++++++++++++++--- drivers/md/dm-stats.h | 9 +++++++-- drivers/md/dm.c | 2 ++ 3 files changed, 34 insertions(+), 5 deletions(-) --- a/drivers/md/dm-stats.c +++ b/drivers/md/dm-stats.c @@ -195,6 +195,7 @@ void dm_stats_init(struct dm_stats *stat mutex_init(&stats->mutex); INIT_LIST_HEAD(&stats->list); + stats->precise_timestamps = false; stats->last = alloc_percpu(struct dm_stats_last_position); for_each_possible_cpu(cpu) { last = per_cpu_ptr(stats->last, cpu); @@ -231,6 +232,22 @@ void dm_stats_cleanup(struct dm_stats *s mutex_destroy(&stats->mutex); } +static void dm_stats_recalc_precise_timestamps(struct dm_stats *stats) +{ + struct list_head *l; + struct dm_stat *tmp_s; + bool precise_timestamps = false; + + list_for_each(l, &stats->list) { + tmp_s = container_of(l, struct dm_stat, list_entry); + if (tmp_s->stat_flags & STAT_PRECISE_TIMESTAMPS) { + precise_timestamps = true; + break; + } + } + stats->precise_timestamps = precise_timestamps; +} + static int dm_stats_create(struct dm_stats *stats, sector_t start, sector_t end, sector_t step, unsigned stat_flags, unsigned n_histogram_entries, @@ -376,6 +393,9 @@ static int dm_stats_create(struct dm_sta } ret_id = s->id; list_add_tail_rcu(&s->list_entry, l); + + dm_stats_recalc_precise_timestamps(stats); + mutex_unlock(&stats->mutex); resume_callback(md); @@ -418,6 +438,9 @@ static int dm_stats_delete(struct dm_sta } list_del_rcu(&s->list_entry); + + dm_stats_recalc_precise_timestamps(stats); + mutex_unlock(&stats->mutex); /* @@ -654,9 +677,8 @@ void dm_stats_account_io(struct dm_stats got_precise_time = false; list_for_each_entry_rcu(s, &stats->list, list_entry) { if (s->stat_flags & STAT_PRECISE_TIMESTAMPS && !got_precise_time) { - if (!end) - stats_aux->duration_ns = ktime_to_ns(ktime_get()); - else + /* start (!end) duration_ns is set by DM core's alloc_io() */ + if (end) stats_aux->duration_ns = ktime_to_ns(ktime_get()) - stats_aux->duration_ns; got_precise_time = true; } --- a/drivers/md/dm-stats.h +++ b/drivers/md/dm-stats.h @@ -13,8 +13,7 @@ struct dm_stats { struct mutex mutex; struct list_head list; /* list of struct dm_stat */ struct dm_stats_last_position __percpu *last; - sector_t last_sector; - unsigned last_rw; + bool precise_timestamps; }; struct dm_stats_aux { @@ -40,4 +39,10 @@ static inline bool dm_stats_used(struct return !list_empty(&st->list); } +static inline void dm_stats_record_start(struct dm_stats *stats, struct dm_stats_aux *aux) +{ + if (unlikely(stats->precise_timestamps)) + aux->duration_ns = ktime_to_ns(ktime_get()); +} + #endif --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -537,6 +537,8 @@ static struct dm_io *alloc_io(struct map io->start_time = jiffies; + dm_stats_record_start(&md->stats, &io->stats_aux); + return io; }