blktrace_api.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPIBLKTRACE_H
  3. #define _UAPIBLKTRACE_H
  4. #include <linux/types.h>
  5. /*
  6. * Trace categories
  7. */
  8. enum blktrace_cat {
  9. BLK_TC_READ = 1 << 0, /* reads */
  10. BLK_TC_WRITE = 1 << 1, /* writes */
  11. BLK_TC_FLUSH = 1 << 2, /* flush */
  12. BLK_TC_SYNC = 1 << 3, /* sync IO */
  13. BLK_TC_SYNCIO = BLK_TC_SYNC,
  14. BLK_TC_QUEUE = 1 << 4, /* queueing/merging */
  15. BLK_TC_REQUEUE = 1 << 5, /* requeueing */
  16. BLK_TC_ISSUE = 1 << 6, /* issue */
  17. BLK_TC_COMPLETE = 1 << 7, /* completions */
  18. BLK_TC_FS = 1 << 8, /* fs requests */
  19. BLK_TC_PC = 1 << 9, /* pc requests */
  20. BLK_TC_NOTIFY = 1 << 10, /* special message */
  21. BLK_TC_AHEAD = 1 << 11, /* readahead */
  22. BLK_TC_META = 1 << 12, /* metadata */
  23. BLK_TC_DISCARD = 1 << 13, /* discard requests */
  24. BLK_TC_DRV_DATA = 1 << 14, /* binary per-driver data */
  25. BLK_TC_FUA = 1 << 15, /* fua requests */
  26. BLK_TC_END = 1 << 15, /* we've run out of bits! */
  27. };
  28. #define BLK_TC_SHIFT (16)
  29. #define BLK_TC_ACT(act) ((act) << BLK_TC_SHIFT)
  30. /*
  31. * Basic trace actions
  32. */
  33. enum blktrace_act {
  34. __BLK_TA_QUEUE = 1, /* queued */
  35. __BLK_TA_BACKMERGE, /* back merged to existing rq */
  36. __BLK_TA_FRONTMERGE, /* front merge to existing rq */
  37. __BLK_TA_GETRQ, /* allocated new request */
  38. __BLK_TA_SLEEPRQ, /* sleeping on rq allocation */
  39. __BLK_TA_REQUEUE, /* request requeued */
  40. __BLK_TA_ISSUE, /* sent to driver */
  41. __BLK_TA_COMPLETE, /* completed by driver */
  42. __BLK_TA_PLUG, /* queue was plugged */
  43. __BLK_TA_UNPLUG_IO, /* queue was unplugged by io */
  44. __BLK_TA_UNPLUG_TIMER, /* queue was unplugged by timer */
  45. __BLK_TA_INSERT, /* insert request */
  46. __BLK_TA_SPLIT, /* bio was split */
  47. __BLK_TA_BOUNCE, /* bio was bounced */
  48. __BLK_TA_REMAP, /* bio was remapped */
  49. __BLK_TA_ABORT, /* request aborted */
  50. __BLK_TA_DRV_DATA, /* driver-specific binary data */
  51. __BLK_TA_CGROUP = 1 << 8, /* from a cgroup*/
  52. };
  53. /*
  54. * Notify events.
  55. */
  56. enum blktrace_notify {
  57. __BLK_TN_PROCESS = 0, /* establish pid/name mapping */
  58. __BLK_TN_TIMESTAMP, /* include system clock */
  59. __BLK_TN_MESSAGE, /* Character string message */
  60. __BLK_TN_CGROUP = __BLK_TA_CGROUP, /* from a cgroup */
  61. };
  62. /*
  63. * Trace actions in full. Additionally, read or write is masked
  64. */
  65. #define BLK_TA_QUEUE (__BLK_TA_QUEUE | BLK_TC_ACT(BLK_TC_QUEUE))
  66. #define BLK_TA_BACKMERGE (__BLK_TA_BACKMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
  67. #define BLK_TA_FRONTMERGE (__BLK_TA_FRONTMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
  68. #define BLK_TA_GETRQ (__BLK_TA_GETRQ | BLK_TC_ACT(BLK_TC_QUEUE))
  69. #define BLK_TA_SLEEPRQ (__BLK_TA_SLEEPRQ | BLK_TC_ACT(BLK_TC_QUEUE))
  70. #define BLK_TA_REQUEUE (__BLK_TA_REQUEUE | BLK_TC_ACT(BLK_TC_REQUEUE))
  71. #define BLK_TA_ISSUE (__BLK_TA_ISSUE | BLK_TC_ACT(BLK_TC_ISSUE))
  72. #define BLK_TA_COMPLETE (__BLK_TA_COMPLETE| BLK_TC_ACT(BLK_TC_COMPLETE))
  73. #define BLK_TA_PLUG (__BLK_TA_PLUG | BLK_TC_ACT(BLK_TC_QUEUE))
  74. #define BLK_TA_UNPLUG_IO (__BLK_TA_UNPLUG_IO | BLK_TC_ACT(BLK_TC_QUEUE))
  75. #define BLK_TA_UNPLUG_TIMER (__BLK_TA_UNPLUG_TIMER | BLK_TC_ACT(BLK_TC_QUEUE))
  76. #define BLK_TA_INSERT (__BLK_TA_INSERT | BLK_TC_ACT(BLK_TC_QUEUE))
  77. #define BLK_TA_SPLIT (__BLK_TA_SPLIT)
  78. #define BLK_TA_BOUNCE (__BLK_TA_BOUNCE)
  79. #define BLK_TA_REMAP (__BLK_TA_REMAP | BLK_TC_ACT(BLK_TC_QUEUE))
  80. #define BLK_TA_ABORT (__BLK_TA_ABORT | BLK_TC_ACT(BLK_TC_QUEUE))
  81. #define BLK_TA_DRV_DATA (__BLK_TA_DRV_DATA | BLK_TC_ACT(BLK_TC_DRV_DATA))
  82. #define BLK_TN_PROCESS (__BLK_TN_PROCESS | BLK_TC_ACT(BLK_TC_NOTIFY))
  83. #define BLK_TN_TIMESTAMP (__BLK_TN_TIMESTAMP | BLK_TC_ACT(BLK_TC_NOTIFY))
  84. #define BLK_TN_MESSAGE (__BLK_TN_MESSAGE | BLK_TC_ACT(BLK_TC_NOTIFY))
  85. #define BLK_IO_TRACE_MAGIC 0x65617400
  86. #define BLK_IO_TRACE_VERSION 0x07
  87. /*
  88. * The trace itself
  89. */
  90. struct blk_io_trace {
  91. __u32 magic; /* MAGIC << 8 | version */
  92. __u32 sequence; /* event number */
  93. __u64 time; /* in nanoseconds */
  94. __u64 sector; /* disk offset */
  95. __u32 bytes; /* transfer length */
  96. __u32 action; /* what happened */
  97. __u32 pid; /* who did it */
  98. __u32 device; /* device number */
  99. __u32 cpu; /* on what cpu did it happen */
  100. __u16 error; /* completion error */
  101. __u16 pdu_len; /* length of data after this trace */
  102. /* cgroup id will be stored here if exists */
  103. };
  104. /*
  105. * The remap event
  106. */
  107. struct blk_io_trace_remap {
  108. __be32 device_from;
  109. __be32 device_to;
  110. __be64 sector_from;
  111. };
  112. enum {
  113. Blktrace_setup = 1,
  114. Blktrace_running,
  115. Blktrace_stopped,
  116. };
  117. #define BLKTRACE_BDEV_SIZE 32
  118. /*
  119. * User setup structure passed with BLKTRACESETUP
  120. */
  121. struct blk_user_trace_setup {
  122. char name[BLKTRACE_BDEV_SIZE]; /* output */
  123. __u16 act_mask; /* input */
  124. __u32 buf_size; /* input */
  125. __u32 buf_nr; /* input */
  126. __u64 start_lba;
  127. __u64 end_lba;
  128. __u32 pid;
  129. };
  130. #endif /* _UAPIBLKTRACE_H */