Don't pollute struct mapped_device with dm_stats_precise_timestamps; move it into struct dm_stats. This patch also removes dm_stats->last_sector and dm_stats->last_rw which are unused. Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx> --- drivers/md/dm-core.h | 2 -- drivers/md/dm-stats.c | 28 ++++++++++++++++++++++++---- drivers/md/dm-stats.h | 9 +++++++-- drivers/md/dm.c | 5 +---- 4 files changed, 32 insertions(+), 12 deletions(-) Index: linux-dm/drivers/md/dm-core.h =================================================================== --- linux-dm.orig/drivers/md/dm-core.h 2022-02-16 17:49:02.000000000 +0100 +++ linux-dm/drivers/md/dm-core.h 2022-02-16 18:06:28.000000000 +0100 @@ -113,8 +113,6 @@ struct mapped_device { struct blk_mq_tag_set *tag_set; bool init_tio_pdu:1; - bool dm_stats_precise_timestamps:1; - struct srcu_struct io_barrier; #ifdef CONFIG_BLK_DEV_ZONED Index: linux-dm/drivers/md/dm-stats.c =================================================================== --- linux-dm.orig/drivers/md/dm-stats.c 2022-02-16 17:49:02.000000000 +0100 +++ linux-dm/drivers/md/dm-stats.c 2022-02-16 18:41:57.000000000 +0100 @@ -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,21 @@ 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 +392,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 +437,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); /* @@ -1006,11 +1028,9 @@ static int message_stats_create(struct m a = dm_shift_arg(&as); if (!a) goto ret_einval; - if (!strcasecmp(a, "precise_timestamps")) { + if (!strcasecmp(a, "precise_timestamps")) stat_flags |= STAT_PRECISE_TIMESTAMPS; - md->dm_stats_precise_timestamps = true; - // FIXME: disable md->dm_stats_precise_timestamps when no longer needed - } else if (!strncasecmp(a, "histogram:", 10)) { + else if (!strncasecmp(a, "histogram:", 10)) { if (n_histogram_entries) goto ret_einval; if ((r = parse_histogram(a + 10, &n_histogram_entries, &histogram_boundaries))) Index: linux-dm/drivers/md/dm-stats.h =================================================================== --- linux-dm.orig/drivers/md/dm-stats.h 2022-02-16 17:49:02.000000000 +0100 +++ linux-dm/drivers/md/dm-stats.h 2022-02-16 18:41:19.000000000 +0100 @@ -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 Index: linux-dm/drivers/md/dm.c =================================================================== --- linux-dm.orig/drivers/md/dm.c 2022-02-16 17:49:02.000000000 +0100 +++ linux-dm/drivers/md/dm.c 2022-02-16 18:34:29.000000000 +0100 @@ -567,9 +567,7 @@ static struct dm_io *alloc_io(struct map io->start_io_acct = false; io->was_accounted = 0; - if (unlikely(md->dm_stats_precise_timestamps && - dm_stats_used(&md->stats))) - io->stats_aux.duration_ns = ktime_to_ns(ktime_get()); + dm_stats_record_start(&md->stats, &io->stats_aux); return io; } @@ -1695,7 +1693,6 @@ static struct mapped_device *alloc_dev(i md->numa_node_id = numa_node_id; md->init_tio_pdu = false; - md->dm_stats_precise_timestamps = false; md->type = DM_TYPE_NONE; mutex_init(&md->suspend_lock); mutex_init(&md->type_lock); -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel