)]}'
{
  "commit": "5e7f5a178bba45c5aca3448fddecabd4e28f1f6b",
  "tree": "761019b04370c87f7fba955dea631e3008f010f6",
  "parents": [
    "e1b004c3ef9c59db5f013528628b51c8653155ec"
  ],
  "author": {
    "name": "Patrick Pannuto",
    "email": "ppannuto@codeaurora.org",
    "time": "Mon Aug 02 15:01:04 2010 -0700"
  },
  "committer": {
    "name": "Thomas Gleixner",
    "email": "tglx@linutronix.de",
    "time": "Wed Aug 04 11:00:45 2010 +0200"
  },
  "message": "timer: Added usleep_range timer\n\nusleep_range is a finer precision implementations of msleep\nand is designed to be a drop-in replacement for udelay where\na precise sleep / busy-wait is unnecessary.\n\nSince an easy interface to hrtimers could lead to an undesired\nproliferation of interrupts, we provide only a \"range\" API,\nforcing the caller to think about an acceptable tolerance on\nboth ends and hopefully avoiding introducing another interrupt.\n\nINTRO\n\nAs discussed here ( http://lkml.org/lkml/2007/8/3/250 ), msleep(1) is not\nprecise enough for many drivers (yes, sleep precision is an unfair notion,\nbut consistently sleeping for ~an order of magnitude greater than requested\nis worth fixing). This patch adds a usleep API so that udelay does not have\nto be used. Obviously not every udelay can be replaced (those in atomic\ncontexts or being used for simple bitbanging come to mind), but there are\nmany, many examples of\n\nmydriver_write(...)\n/* Wait for hardware to latch */\nudelay(100)\n\nin various drivers where a busy-wait loop is neither beneficial nor\nnecessary, but msleep simply does not provide enough precision and people\nare using a busy-wait loop instead.\n\nCONCERNS FROM THE RFC\n\nWhy is udelay a problem / necessary? Most callers of udelay are in device/\ndriver initialization code, which is serial...\n\n\tAs I see it, there is only benefit to sleeping over a delay; the\n\tnotion of \"refactoring\" areas that use udelay was presented, but\n\tI see usleep as the refactoring. Consider i2c, if the bus is busy,\n\tyou need to wait a bit (say 100us) before trying again, your\n\tcurrent options are:\n\n\t\t* udelay(100)\n\t\t* msleep(1) \u003c-- As noted above, actually as high as ~20ms\n\t\t\t\ton some platforms, so not really an option\n\t\t* Manually set up an hrtimer to try again in 100us (which\n\t\t  is what usleep does anyway...)\n\n\tPeople choose the udelay route because it is EASY; we need to\n\tprovide a better easy route.\n\n\tDevice / driver / boot code is *currently* serial, but every few\n\tmonths someone makes noise about parallelizing boot, and IMHO, a\n\tlittle forward-thinking now is one less thing to worry about\n\tif/when that ever happens\n\nudelay\u0027s could be preempted\n\n\tSure, but if udelay plans on looping 1000 times, and it gets\n\tpreempted on loop 200, whenever it\u0027s scheduled again, it is\n\tgoing to do the next 800 loops.\n\nIs the interruptible case needed?\n\n\tProbably not, but I see usleep as a very logical parallel to msleep,\n\tso it made sense to include the \"full\" API. Processors are getting\n\tfaster (albeit not as quickly as they are becoming more parallel),\n\tso if someone wanted to be interruptible for a few usecs, why not\n\tlet them? If this is a contentious point, I\u0027m happy to remove it.\n\nOTHER THOUGHTS\n\nI believe there is also value in exposing the usleep_range option; it gives\nthe scheduler a lot more flexibility and allows the programmer to express\nhis intent much more clearly; it\u0027s something I would hope future driver\nwriters will take advantage of.\n\nTo get the results in the NUMBERS section below, I literally s/udelay/usleep\nthe kernel tree; I had to go in and undo the changes to the USB drivers, but\neverything else booted successfully; I find that extremely telling in and\nof itself -- many people are using a delay API where a sleep will suit them\njust fine.\n\nSOME ATTEMPTS AT NUMBERS\n\nIt turns out that calculating quantifiable benefit on this is challenging,\nso instead I will simply present the current state of things, and I hope\nthis to be sufficient:\n\nHow many udelay calls are there in 2.6.35-rc5?\n\n\tudealy(ARG) \u003e\u003d\t| COUNT\n\t1000\t\t| 319\n\t500\t\t| 414\n\t100\t\t| 1146\n\t20\t\t| 1832\n\nI am working on Android, so that is my focus for this. The following table\nis a modified usleep that simply printk\u0027s the amount of time requested to\nsleep; these tests were run on a kernel with udelay \u003e\u003d 20 --\u003e usleep\n\n\"boot\" is power-on to lock screen\n\"power collapse\" is when the power button is pushed and the device suspends\n\"resume\" is when the power button is pushed and the lock screen is displayed\n         (no touchscreen events or anything, just turning on the display)\n\"use device\" is from the unlock swipe to clicking around a bit; there is no\n\tsd card in this phone, so fail loading music, video, camera\n\n\tACTION\t\t| TOTAL NUMBER OF USLEEP CALLS\t| NET TIME (us)\n\tboot\t\t| 22\t\t\t\t| 1250\n\tpower-collapse\t| 9\t\t\t\t| 1200\n\tresume\t\t| 5\t\t\t\t| 500\n\tuse device\t| 59\t\t\t\t| 7700\n\nThe most interesting category to me is the \"use device\" field; 7700us of\nbusy-wait time that could be put towards better responsiveness, or at the\nleast less power usage.\n\nSigned-off-by: Patrick Pannuto \u003cppannuto@codeaurora.org\u003e\nCc: apw@canonical.com\nCc: corbet@lwn.net\nCc: arjan@linux.intel.com\nCc: Randy Dunlap \u003crdunlap@xenotime.net\u003e\nCc: Andrew Morton \u003cakpm@linux-foundation.org\u003e\nSigned-off-by: Thomas Gleixner \u003ctglx@linutronix.de\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "fd832c6d419efc377a698eecd146032d5f68a8d1",
      "old_mode": 33188,
      "old_path": "include/linux/delay.h",
      "new_id": "a6ecb34cf547da29ad16edf8b109de2511d10cd5",
      "new_mode": 33188,
      "new_path": "include/linux/delay.h"
    },
    {
      "type": "modify",
      "old_id": "ce98685cd1cb449adc31b12c694ac7bd755e1abc",
      "old_mode": 33188,
      "old_path": "kernel/timer.c",
      "new_id": "723a62e86dcb19dabce404aafbf42782bfc8e5e1",
      "new_mode": 33188,
      "new_path": "kernel/timer.c"
    }
  ]
}
