UPSTREAM: udelay: Lower the sleep vs delay threshold

By default, we busy-loop (a.k.a., "delay") for most delay values, and
only allow sleeping for large delays. But busy-looping is expensive, as
it wastes CPU cycles.

In a simple program that runs a bunch of samples of [1] over 1000
samples, I find that for 0.1 s (100000 us):

 64x2 AMD CPU (CONFIG_HZ=250 / CONFIG_NO_HZ_FULL=y):
   min diff: 60 us
   max diff: 831 us
   mean diff: 135 us

 4+2 Mediatek MT8183 CPU (CONFIG_HZ=1000 / CONFIG_NO_HZ_IDLE=y /
                          sysctl kernel.timer_highres=1):
   min diff: 70 us
   max diff: 1556 us
   mean diff: 146 us

 4+2 Mediatek MT8183 CPU (CONFIG_HZ=1000 / CONFIG_NO_HZ_IDLE=y /
                          sysctl kernel.timer_highres=0):
   min diff: 94 us
   max diff: 7222 us
   mean diff: 1201 us

i.e., maximum 1.5% error, typically ~0.1% error with high resolution
timers. Max 7% error, typical 1% error with low resolution timers. The
error is always in the positive direction (i.e., sleep longer than the
requested delay, not shorter than the request).

This seems reasonable.

[1] Stripped / pseudocode:

  clock_gettime(CLOCK_MONOTONIC, before);
  nanosleep({ .tv_nsec = usecs * 1000 }, NULL);
  clock_gettime(CLOCK_MONOTONIC, after);
  diff = abs((after - before) / 1000 - usecs));

(cherry picked from commit 54b053e6b23715fbefa59b71d2cc5211508f2d79)

Original-Change-Id: Ifd4821c66c5564f7c975c08769a6742f645e9be0
Original-Signed-off-by: Brian Norris <briannorris@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/80808
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
GitOrigin-RevId: 54b053e6b23715fbefa59b71d2cc5211508f2d79
Change-Id: I0661f48cbe0e7a798b5ca4dfa639c8a44afba770
Signed-off-by: chromeos-ci-prod <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/5372143
Commit-Queue: Hsuan Ting Chen <roccochen@chromium.org>
Reviewed-by: Hsuan Ting Chen <roccochen@chromium.org>
1 file changed
tree: a05a39759dd2b1d6bc6f111316eff68897987a10
  1. .github/
  2. bindings/
  3. doc/
  4. Documentation/
  5. include/
  6. Makefile.d/
  7. meson_cross/
  8. platform/
  9. scripts/
  10. subprojects/
  11. tests/
  12. util/
  13. .gitattributes
  14. .gitignore
  15. 82802ab.c
  16. action_descriptor.c
  17. action_descriptor.h
  18. amd_imc.c
  19. asm106x.c
  20. at45db.c
  21. atahpt.c
  22. atapromise.c
  23. atavia.c
  24. big_lock.c
  25. big_lock.h
  26. bitbang_spi.c
  27. board_enable.c
  28. buspirate_spi.c
  29. cbtable.c
  30. ch341a_spi.c
  31. ch347_spi.c
  32. chipset_enable.c
  33. cli_classic.c
  34. cli_common.c
  35. cli_getopt.c
  36. cli_output.c
  37. COPYING
  38. cros_ec.c
  39. cros_ec_commands.h
  40. custom_baud.c
  41. custom_baud_darwin.c
  42. custom_baud_linux.c
  43. dediprog.c
  44. developerbox_spi.c
  45. digilent_spi.c
  46. DIR_METADATA
  47. dirtyjtag_spi.c
  48. dmi.c
  49. Doxyfile
  50. drkaiser.c
  51. dummyflasher.c
  52. edi.c
  53. en29lv640b.c
  54. erasure_layout.c
  55. file_lock.c
  56. flashchips.c
  57. flashchips_crosbl.c
  58. flashrom.c
  59. fmap.c
  60. ft2232_spi.c
  61. gfxnvidia.c
  62. helpers.c
  63. helpers_fileio.c
  64. hwaccess_physmap.c
  65. hwaccess_x86_io.c
  66. hwaccess_x86_msr.c
  67. i2c_helper_linux.c
  68. ich_descriptors.c
  69. ichspi.c
  70. internal.c
  71. internal_par.c
  72. ipc_lock.h
  73. it8212.c
  74. it87spi.c
  75. jedec.c
  76. jlink_spi.c
  77. known_boards.c
  78. layout.c
  79. libflashrom.c
  80. libflashrom.map
  81. linux_mtd.c
  82. linux_spi.c
  83. MAINTAINERS
  84. Makefile
  85. Makefile.include
  86. mcp6x_spi.c
  87. mediatek_i2c_spi.c
  88. meson.build
  89. meson_options.txt
  90. mstarddc_spi.c
  91. ni845x_spi.c
  92. nic3com.c
  93. nicintel.c
  94. nicintel_eeprom.c
  95. nicintel_spi.c
  96. nicnatsemi.c
  97. nicrealtek.c
  98. ogp_spi.c
  99. opaque.c
  100. OWNERS
  101. parade_lspcon.c
  102. parallel.c
  103. pcidev.c
  104. pickit2_spi.c
  105. pony_spi.c
  106. power.c
  107. power.h
  108. PRESUBMIT.cfg
  109. print.c
  110. print_wiki.c
  111. printlock.c
  112. processor_enable.c
  113. programmer.c
  114. programmer_table.c
  115. raiden_debug_spi.c
  116. rayer_spi.c
  117. README.chromiumos
  118. README.rst
  119. realtek_mst_i2c_spi.c
  120. s25f.c
  121. satamv.c
  122. satasii.c
  123. sb600spi.c
  124. serial.c
  125. serprog.c
  126. sfdp.c
  127. spi.c
  128. spi25.c
  129. spi25_statusreg.c
  130. spi95.c
  131. sst28sf040.c
  132. sst49lfxxxc.c
  133. sst_fwhub.c
  134. stlinkv3_spi.c
  135. stm50.c
  136. superio.c
  137. test_build.sh
  138. udelay.c
  139. unblocked_terms.txt
  140. usb_device.c
  141. usbblaster_spi.c
  142. usbdev.c
  143. VERSION
  144. w29ee011.c
  145. w39.c
  146. wbsio_spi.c
  147. writeprotect.c
  148. writeprotect_ranges.c