simpletrace: Thread-safe tracing

Trace events outside the global mutex cannot be used with the simple
trace backend since it is not thread-safe.  There is no check to prevent
them being enabled so people sometimes learn this the hard way.

This patch restructures the simple trace backend with a ring buffer
suitable for multiple concurrent writers.  A writeout thread empties the
trace buffer when threshold fill levels are reached.  Should the
writeout thread be unable to keep up with trace generation, records will
simply be dropped.

Each time events are dropped a special record is written to the trace
file indicating how many events were dropped.  The event ID is
0xfffffffffffffffe and its signature is dropped(uint32_t count).

Signed-off-by: Stefan Hajnoczi <[email protected]>
5 files changed
tree: 9b60b859d24881e2d032828c3788b2171f3ceaa6
  1. audio/
  2. block/
  3. bsd-user/
  4. darwin-user/
  5. default-configs/
  6. docs/
  7. fpu/
  8. fsdev/
  9. gdb-xml/
  10. hw/
  11. linux-user/
  12. net/
  13. pc-bios/
  14. QMP/
  15. roms/
  16. scripts/
  17. slirp/
  18. sysconfigs/
  19. target-alpha/
  20. target-arm/
  21. target-cris/
  22. target-i386/
  23. target-lm32/
  24. target-m68k/
  25. target-microblaze/
  26. target-mips/
  27. target-ppc/
  28. target-s390x/
  29. target-sh4/
  30. target-sparc/
  31. tcg/
  32. tests/
  33. ui/
  34. .gitignore
  35. .gitmodules
  36. a.out.h
  37. acl.c
  38. acl.h
  39. aes.c
  40. aes.h
  41. aio.c
  42. alpha-dis.c
  43. alpha.ld
  44. arch_init.c
  45. arch_init.h
  46. arm-dis.c
  47. arm-semi.c
  48. arm.ld
  49. async.c
  50. balloon.c
  51. balloon.h
  52. bitmap.c
  53. bitmap.h
  54. bitops.c
  55. bitops.h
  56. block-migration.c
  57. block-migration.h
  58. block.c
  59. block.h
  60. block_int.h
  61. blockdev.c
  62. blockdev.h
  63. bswap.h
  64. bt-host.c
  65. bt-host.h
  66. bt-vhci.c
  67. buffered_file.c
  68. buffered_file.h
  69. cache-utils.c
  70. cache-utils.h
  71. Changelog
  72. check-qdict.c
  73. check-qfloat.c
  74. check-qint.c
  75. check-qjson.c
  76. check-qlist.c
  77. check-qstring.c
  78. cmd.c
  79. cmd.h
  80. CODING_STYLE
  81. compatfd.c
  82. compatfd.h
  83. config.h
  84. configure
  85. console.c
  86. console.h
  87. COPYING
  88. COPYING.LIB
  89. cpu-all.h
  90. cpu-common.h
  91. cpu-defs.h
  92. cpu-exec.c
  93. cpus.c
  94. cpus.h
  95. cris-dis.c
  96. cursor.c
  97. cursor_hidden.xpm
  98. cursor_left_ptr.xpm
  99. cutils.c
  100. def-helper.h
  101. device_tree.c
  102. device_tree.h
  103. dis-asm.h
  104. disas.c
  105. disas.h
  106. dma-helpers.c
  107. dma.h
  108. dyngen-exec.h
  109. elf.h
  110. envlist.c
  111. envlist.h
  112. exec-all.h
  113. exec.c
  114. gdbstub.c
  115. gdbstub.h
  116. gen-icount.h
  117. HACKING
  118. hmp-commands.hx
  119. host-utils.c
  120. host-utils.h
  121. hpet.h
  122. hppa-dis.c
  123. hppa.ld
  124. i386-dis.c
  125. i386.ld
  126. ia64-dis.c
  127. ia64.ld
  128. input.c
  129. ioport-user.c
  130. ioport.c
  131. ioport.h
  132. iorange.h
  133. iov.c
  134. iov.h
  135. json-lexer.c
  136. json-lexer.h
  137. json-parser.c
  138. json-parser.h
  139. json-streamer.c
  140. json-streamer.h
  141. kvm-all.c
  142. kvm-stub.c
  143. kvm.h
  144. libfdt_env.h
  145. LICENSE
  146. linux-aio.c
  147. m68k-dis.c
  148. m68k-semi.c
  149. m68k.ld
  150. MAINTAINERS
  151. Makefile
  152. Makefile.dis
  153. Makefile.hw
  154. Makefile.objs
  155. Makefile.target
  156. Makefile.user
  157. microblaze-dis.c
  158. migration-exec.c
  159. migration-fd.c
  160. migration-tcp.c
  161. migration-unix.c
  162. migration.c
  163. migration.h
  164. mips-dis.c
  165. mips.ld
  166. module.c
  167. module.h
  168. monitor.c
  169. monitor.h
  170. nbd.c
  171. nbd.h
  172. net-checksum.c
  173. net.c
  174. net.h
  175. notify.c
  176. notify.h
  177. os-posix.c
  178. os-win32.c
  179. osdep.c
  180. osdep.h
  181. oslib-posix.c
  182. oslib-win32.c
  183. path.c
  184. pci-ids.txt
  185. pflib.c
  186. pflib.h
  187. poison.h
  188. posix-aio-compat.c
  189. ppc-dis.c
  190. ppc.ld
  191. ppc64.ld
  192. qbool.c
  193. qbool.h
  194. qdict-test-data.txt
  195. qdict.c
  196. qdict.h
  197. qemu-aio.h
  198. qemu-barrier.h
  199. qemu-char.c
  200. qemu-char.h
  201. qemu-common.h
  202. qemu-config.c
  203. qemu-config.h
  204. qemu-doc.texi
  205. qemu-error.c
  206. qemu-error.h
  207. qemu-img-cmds.hx
  208. qemu-img.c
  209. qemu-img.texi
  210. qemu-io.c
  211. qemu-lock.h
  212. qemu-log.h
  213. qemu-malloc.c
  214. qemu-nbd.c
  215. qemu-nbd.texi
  216. qemu-objects.h
  217. qemu-option.c
  218. qemu-option.h
  219. qemu-options.h
  220. qemu-options.hx
  221. qemu-os-posix.h
  222. qemu-os-win32.h
  223. qemu-queue.h
  224. qemu-sockets.c
  225. qemu-tech.texi
  226. qemu-thread.c
  227. qemu-thread.h
  228. qemu-timer-common.c
  229. qemu-timer.c
  230. qemu-timer.h
  231. qemu-tool.c
  232. qemu-x509.h
  233. qemu.sasl
  234. qemu_socket.h
  235. qerror.c
  236. qerror.h
  237. qfloat.c
  238. qfloat.h
  239. qint.c
  240. qint.h
  241. qjson.c
  242. qjson.h
  243. qlist.c
  244. qlist.h
  245. qmp-commands.hx
  246. qobject.h
  247. qstring.c
  248. qstring.h
  249. range.h
  250. readline.c
  251. readline.h
  252. README
  253. rules.mak
  254. rwhandler.c
  255. rwhandler.h
  256. s390-dis.c
  257. s390.ld
  258. savevm.c
  259. sh4-dis.c
  260. simpletrace.c
  261. simpletrace.h
  262. softmmu-semi.h
  263. softmmu_defs.h
  264. softmmu_exec.h
  265. softmmu_header.h
  266. softmmu_template.h
  267. sparc-dis.c
  268. sparc.ld
  269. sparc64.ld
  270. spice-qemu-char.c
  271. sysemu.h
  272. targphys.h
  273. tcg-runtime.c
  274. thunk.c
  275. thunk.h
  276. TODO
  277. trace-events
  278. translate-all.c
  279. uboot_image.h
  280. usb-bsd.c
  281. usb-linux.c
  282. usb-stub.c
  283. VERSION
  284. version.rc
  285. vgafont.h
  286. vl.c
  287. x86_64.ld