bench_runner.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef BENCH_RUNNER_H
  2. #define BENCH_RUNNER_H
  3. // override LFS_TRACE
  4. void bench_trace(const char *fmt, ...);
  5. #define LFS_TRACE_(fmt, ...) \
  6. bench_trace("%s:%d:trace: " fmt "%s\n", \
  7. __FILE__, \
  8. __LINE__, \
  9. __VA_ARGS__)
  10. #define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
  11. #define LFS_EMUBD_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
  12. // provide BENCH_START/BENCH_STOP macros
  13. void bench_start(void);
  14. void bench_stop(void);
  15. #define BENCH_START() bench_start()
  16. #define BENCH_STOP() bench_stop()
  17. // note these are indirectly included in any generated files
  18. #include "bd/lfs_emubd.h"
  19. #include <stdio.h>
  20. // give source a chance to define feature macros
  21. #undef _FEATURES_H
  22. #undef _STDIO_H
  23. // generated bench configurations
  24. struct lfs_config;
  25. enum bench_flags {
  26. BENCH_REENTRANT = 0x1,
  27. };
  28. typedef uint8_t bench_flags_t;
  29. typedef struct bench_define {
  30. intmax_t (*cb)(void *data);
  31. void *data;
  32. } bench_define_t;
  33. struct bench_case {
  34. const char *name;
  35. const char *path;
  36. bench_flags_t flags;
  37. size_t permutations;
  38. const bench_define_t *defines;
  39. bool (*filter)(void);
  40. void (*run)(struct lfs_config *cfg);
  41. };
  42. struct bench_suite {
  43. const char *name;
  44. const char *path;
  45. bench_flags_t flags;
  46. const char *const *define_names;
  47. size_t define_count;
  48. const struct bench_case *cases;
  49. size_t case_count;
  50. };
  51. // access generated bench defines
  52. intmax_t bench_define(size_t define);
  53. #define BENCH_DEFINE(i) bench_define(i)
  54. // a few preconfigured defines that control how benches run
  55. #define READ_SIZE_i 0
  56. #define PROG_SIZE_i 1
  57. #define BLOCK_SIZE_i 2
  58. #define BLOCK_COUNT_i 3
  59. #define CACHE_SIZE_i 4
  60. #define LOOKAHEAD_SIZE_i 5
  61. #define BLOCK_CYCLES_i 6
  62. #define ERASE_VALUE_i 7
  63. #define ERASE_CYCLES_i 8
  64. #define BADBLOCK_BEHAVIOR_i 9
  65. #define POWERLOSS_BEHAVIOR_i 10
  66. #define READ_SIZE bench_define(READ_SIZE_i)
  67. #define PROG_SIZE bench_define(PROG_SIZE_i)
  68. #define BLOCK_SIZE bench_define(BLOCK_SIZE_i)
  69. #define BLOCK_COUNT bench_define(BLOCK_COUNT_i)
  70. #define CACHE_SIZE bench_define(CACHE_SIZE_i)
  71. #define LOOKAHEAD_SIZE bench_define(LOOKAHEAD_SIZE_i)
  72. #define BLOCK_CYCLES bench_define(BLOCK_CYCLES_i)
  73. #define ERASE_VALUE bench_define(ERASE_VALUE_i)
  74. #define ERASE_CYCLES bench_define(ERASE_CYCLES_i)
  75. #define BADBLOCK_BEHAVIOR bench_define(BADBLOCK_BEHAVIOR_i)
  76. #define POWERLOSS_BEHAVIOR bench_define(POWERLOSS_BEHAVIOR_i)
  77. #define BENCH_IMPLICIT_DEFINES \
  78. BENCH_DEF(READ_SIZE, PROG_SIZE) \
  79. BENCH_DEF(PROG_SIZE, BLOCK_SIZE) \
  80. BENCH_DEF(BLOCK_SIZE, 0) \
  81. BENCH_DEF(BLOCK_COUNT, (1024*1024)/BLOCK_SIZE) \
  82. BENCH_DEF(CACHE_SIZE, lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \
  83. BENCH_DEF(LOOKAHEAD_SIZE, 16) \
  84. BENCH_DEF(BLOCK_CYCLES, -1) \
  85. BENCH_DEF(ERASE_VALUE, 0xff) \
  86. BENCH_DEF(ERASE_CYCLES, 0) \
  87. BENCH_DEF(BADBLOCK_BEHAVIOR, LFS_EMUBD_BADBLOCK_PROGERROR) \
  88. BENCH_DEF(POWERLOSS_BEHAVIOR, LFS_EMUBD_POWERLOSS_NOOP)
  89. #define BENCH_GEOMETRY_DEFINE_COUNT 4
  90. #define BENCH_IMPLICIT_DEFINE_COUNT 11
  91. #endif