0001
0002 #ifndef DM_STATS_H
0003 #define DM_STATS_H
0004
0005 #include <linux/types.h>
0006 #include <linux/mutex.h>
0007 #include <linux/list.h>
0008
0009 int dm_statistics_init(void);
0010 void dm_statistics_exit(void);
0011
0012 struct dm_stats {
0013 struct mutex mutex;
0014 struct list_head list;
0015 struct dm_stats_last_position __percpu *last;
0016 bool precise_timestamps;
0017 };
0018
0019 struct dm_stats_aux {
0020 bool merged;
0021 unsigned long long duration_ns;
0022 };
0023
0024 void dm_stats_init(struct dm_stats *st);
0025 void dm_stats_cleanup(struct dm_stats *st);
0026
0027 struct mapped_device;
0028
0029 int dm_stats_message(struct mapped_device *md, unsigned argc, char **argv,
0030 char *result, unsigned maxlen);
0031
0032 void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
0033 sector_t bi_sector, unsigned bi_sectors, bool end,
0034 unsigned long start_time,
0035 struct dm_stats_aux *aux);
0036
0037 static inline bool dm_stats_used(struct dm_stats *st)
0038 {
0039 return !list_empty(&st->list);
0040 }
0041
0042 static inline void dm_stats_record_start(struct dm_stats *stats, struct dm_stats_aux *aux)
0043 {
0044 if (unlikely(stats->precise_timestamps))
0045 aux->duration_ns = ktime_to_ns(ktime_get());
0046 }
0047
0048 #endif