dm-stats.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef DM_STATS_H
  3. #define DM_STATS_H
  4. #include <linux/types.h>
  5. #include <linux/mutex.h>
  6. #include <linux/list.h>
  7. int dm_statistics_init(void);
  8. void dm_statistics_exit(void);
  9. struct dm_stats {
  10. struct mutex mutex;
  11. struct list_head list; /* list of struct dm_stat */
  12. struct dm_stats_last_position __percpu *last;
  13. bool precise_timestamps;
  14. };
  15. struct dm_stats_aux {
  16. bool merged;
  17. unsigned long long duration_ns;
  18. };
  19. int dm_stats_init(struct dm_stats *st);
  20. void dm_stats_cleanup(struct dm_stats *st);
  21. struct mapped_device;
  22. int dm_stats_message(struct mapped_device *md, unsigned int argc, char **argv,
  23. char *result, unsigned int maxlen);
  24. void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
  25. sector_t bi_sector, unsigned int bi_sectors, bool end,
  26. unsigned long start_time,
  27. struct dm_stats_aux *aux);
  28. static inline bool dm_stats_used(struct dm_stats *st)
  29. {
  30. return !list_empty(&st->list);
  31. }
  32. static inline void dm_stats_record_start(struct dm_stats *stats, struct dm_stats_aux *aux)
  33. {
  34. if (unlikely(stats->precise_timestamps))
  35. aux->duration_ns = ktime_to_ns(ktime_get());
  36. }
  37. #endif