stats.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2023 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #ifndef __XFS_SCRUB_STATS_H__
  7. #define __XFS_SCRUB_STATS_H__
  8. struct xchk_stats_run {
  9. u64 scrub_ns;
  10. u64 repair_ns;
  11. unsigned int retries;
  12. bool repair_attempted;
  13. bool repair_succeeded;
  14. };
  15. #ifdef CONFIG_XFS_ONLINE_SCRUB_STATS
  16. struct xchk_stats;
  17. int __init xchk_global_stats_setup(struct dentry *parent);
  18. void xchk_global_stats_teardown(void);
  19. int xchk_mount_stats_alloc(struct xfs_mount *mp);
  20. void xchk_mount_stats_free(struct xfs_mount *mp);
  21. void xchk_stats_register(struct xchk_stats *cs, struct dentry *parent);
  22. void xchk_stats_unregister(struct xchk_stats *cs);
  23. void xchk_stats_merge(struct xfs_mount *mp, const struct xfs_scrub_metadata *sm,
  24. const struct xchk_stats_run *run);
  25. static inline u64 xchk_stats_now(void) { return ktime_get_ns(); }
  26. static inline u64 xchk_stats_elapsed_ns(u64 since)
  27. {
  28. u64 now = xchk_stats_now();
  29. /*
  30. * If the system doesn't have a high enough resolution clock, charge at
  31. * least one nanosecond so that our stats don't report instantaneous
  32. * runtimes.
  33. */
  34. if (now == since)
  35. return 1;
  36. return now - since;
  37. }
  38. #else
  39. # define xchk_global_stats_setup(parent) (0)
  40. # define xchk_global_stats_teardown() ((void)0)
  41. # define xchk_mount_stats_alloc(mp) (0)
  42. # define xchk_mount_stats_free(mp) ((void)0)
  43. # define xchk_stats_register(cs, parent) ((void)0)
  44. # define xchk_stats_unregister(cs) ((void)0)
  45. # define xchk_stats_now() (0)
  46. # define xchk_stats_elapsed_ns(x) (0 * (x))
  47. # define xchk_stats_merge(mp, sm, run) ((void)0)
  48. #endif /* CONFIG_XFS_ONLINE_SCRUB_STATS */
  49. #endif /* __XFS_SCRUB_STATS_H__ */