coroutine-lock: add limited spinning to CoMutex

Running a very small critical section on pthread_mutex_t and CoMutex
shows that pthread_mutex_t is much faster because it doesn't actually
go to sleep.  What happens is that the critical section is shorter
than the latency of entering the kernel and thus FUTEX_WAIT always
fails.  With CoMutex there is no such latency but you still want to
avoid wait and wakeup.  So introduce it artificially.

This only works with one waiters; because CoMutex is fair, it will
always have more waits and wakeups than a pthread_mutex_t.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Message-id: 20170213181244.16297-3-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
3 files changed
tree: 8fd7a9adcdc981c7785d157d852cded18d4e9034
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. chardev/
  6. contrib/
  7. crypto/
  8. default-configs/
  9. disas/
  10. docs/
  11. fpu/
  12. fsdev/
  13. gdb-xml/
  14. hw/
  15. include/
  16. io/
  17. libdecnumber/
  18. linux-headers/
  19. linux-user/
  20. migration/
  21. nbd/
  22. net/
  23. pc-bios/
  24. po/
  25. qapi/
  26. qga/
  27. qobject/
  28. qom/
  29. replay/
  30. roms/
  31. scripts/
  32. slirp/
  33. stubs/
  34. target/
  35. tcg/
  36. tests/
  37. trace/
  38. ui/
  39. util/
  40. .dir-locals.el
  41. .exrc
  42. .gitignore
  43. .gitmodules
  44. .mailmap
  45. .travis.yml
  46. accel.c
  47. arch_init.c
  48. atomic_template.h
  49. balloon.c
  50. block.c
  51. blockdev-nbd.c
  52. blockdev.c
  53. blockjob.c
  54. bootdevice.c
  55. bt-host.c
  56. bt-vhci.c
  57. Changelog
  58. CODING_STYLE
  59. configure
  60. COPYING
  61. COPYING.LIB
  62. cpu-exec-common.c
  63. cpu-exec.c
  64. cpus-common.c
  65. cpus.c
  66. cputlb.c
  67. device-hotplug.c
  68. device_tree.c
  69. disas.c
  70. dma-helpers.c
  71. dump.c
  72. exec.c
  73. gdbstub.c
  74. HACKING
  75. hax-stub.c
  76. hmp-commands-info.hx
  77. hmp-commands.hx
  78. hmp.c
  79. hmp.h
  80. ioport.c
  81. iothread.c
  82. kvm-all.c
  83. kvm-stub.c
  84. LICENSE
  85. MAINTAINERS
  86. Makefile
  87. Makefile.objs
  88. Makefile.target
  89. memory.c
  90. memory_ldst.inc.c
  91. memory_mapping.c
  92. module-common.c
  93. monitor.c
  94. numa.c
  95. os-posix.c
  96. os-win32.c
  97. page_cache.c
  98. qapi-schema.json
  99. qdev-monitor.c
  100. qdict-test-data.txt
  101. qemu-bridge-helper.c
  102. qemu-doc.texi
  103. qemu-ga.texi
  104. qemu-img-cmds.hx
  105. qemu-img.c
  106. qemu-img.texi
  107. qemu-io-cmds.c
  108. qemu-io.c
  109. qemu-nbd.c
  110. qemu-nbd.texi
  111. qemu-option-trace.texi
  112. qemu-options-wrapper.h
  113. qemu-options.h
  114. qemu-options.hx
  115. qemu-seccomp.c
  116. qemu-tech.texi
  117. qemu.nsi
  118. qemu.sasl
  119. qmp.c
  120. qtest.c
  121. README
  122. replication.c
  123. replication.h
  124. rules.mak
  125. softmmu_template.h
  126. spice-qemu-char.c
  127. tcg-runtime.c
  128. tci.c
  129. thunk.c
  130. tpm.c
  131. trace-events
  132. translate-all.c
  133. translate-all.h
  134. translate-common.c
  135. user-exec-stub.c
  136. user-exec.c
  137. VERSION
  138. version.rc
  139. vl.c
  140. xen-common-stub.c
  141. xen-common.c
  142. xen-hvm-stub.c
  143. xen-hvm.c
  144. xen-mapcache.c