Skip to content
Tcl Source Code Artifact [dd451a40ad]
Login

Artifact [dd451a40ad]

Artifact dd451a40ad0e406a7c5bad0a0b7a4d36f6b3188e:

Ticket change [dd451a40ad] - New ticket [2904418fffffffff|2904418fff] <i>One millisecond of busyloop in [after]</i>. by ferrieux on 2009-11-26 10:01:46.
D 2009-11-26T10:01:46
J assignee kennykb
J cmimetype text/plain
J comment A\ssynchronous\s[after]\smay\swaste\sup\sto\sa\sfull\smillisecond\sof\sCPU\sbusylooping\son\sgettimeofday().\nStrace\s-tt\s-T\soutput\sfrom\san\sinteractive\stclsh\swhere\sI\styped\s"after\s10":\n\n10:43:11.589638\sread(0,\s"after\s10\\n",\s4096)\s=\s9\s<3.160754>\n10:43:14.750481\sgettimeofday({1259228594,\s750498},\sNULL)\s=\s0\s<0.000006>\n10:43:14.750519\sgettimeofday({1259228594,\s750535},\sNULL)\s=\s0\s<0.000006>\n10:43:14.750555\sgettimeofday({1259228594,\s750571},\sNULL)\s=\s0\s<0.000005>\n10:43:14.750593\sselect(0,\sNULL,\sNULL,\sNULL,\s{0,\s9000})\s=\s0\s(Timeout)\s<0.009340>\n10:43:14.759973\sgettimeofday({1259228594,\s759991},\sNULL)\s=\s0\s<0.000007>\n10:43:14.760021\sgettimeofday({1259228594,\s760035},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760055\sgettimeofday({1259228594,\s760069},\sNULL)\s=\s0\s<0.000006>\n10:43:14.760094\sgettimeofday({1259228594,\s760106},\sNULL)\s=\s0\s<0.000004>\n10:43:14.760132\sgettimeofday({1259228594,\s760144},\sNULL)\s=\s0\s<0.000006>\n10:43:14.760162\sgettimeofday({1259228594,\s760177},\sNULL)\s=\s0\s<0.000007>\n10:43:14.760197\sgettimeofday({1259228594,\s760209},\sNULL)\s=\s0\s<0.000006>\n10:43:14.760234\sgettimeofday({1259228594,\s760248},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760268\sgettimeofday({1259228594,\s760281},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760299\sgettimeofday({1259228594,\s760311},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760331\sgettimeofday({1259228594,\s760344},\sNULL)\s=\s0\s<0.000006>\n10:43:14.760362\sgettimeofday({1259228594,\s760375},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760397\sgettimeofday({1259228594,\s760413},\sNULL)\s=\s0\s<0.000007>\n10:43:14.760432\sgettimeofday({1259228594,\s760444},\sNULL)\s=\s0\s<0.000006>\n10:43:14.760462\sgettimeofday({1259228594,\s760474},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760492\sgettimeofday({1259228594,\s760505},\sNULL)\s=\s0\s<0.000005>\n10:43:14.760534\swrite(1,\s"%\s",\s2)\s\s\s\s\s\s\s=\s2\s<0.000009>\n10:43:14.760575\sread(0,\s\n\nClearly\swhat\shappens\sis\sa\srounding\sproblem:\sthe\sselect()\sdoes\san\sefficient\swait\son\sthe\sinteger\spart,\sin\smilliseconds,\sof\sthe\scomputed\sETA,\sthen\sthe\sloop\sin\sAfterDelay\schecks\sagain,\sand\sfinds\sa\ssubmillisecond\sremaining\stime,\sso\sno\smore\sselect()s,\sand\sbusily\scalls\sgettimeofday\suntil\sthe\starget\sis\sreached.\n\n(As\sa\sside\snote,\sthe\sfact\sthat\sthe\sselect()\srounds\sto\smilliseconds\swhile\sits\sargument\sis\sin\smicroseconds\sseems\sstrange.\sBut\sthis\sis\sa\sred\sherring,\ssince\sthe\sOS's\sresolution\sisn't\sthat\sfine\sanyway).\n\nI\sthink\sthat\s[after]\sshould\shave\sa\sdeclared\spolicy\sof\seither\s"undershooting"\s(floor\sof\svalue)\sor\s"overshooting"\s(ceiling\sof\svalue)\sto\scompute\sthe\sselect()\smillisecond\stimeout,\sand\sjust\scall\sit\sonce\sand\sreturn,\swithout\sbusylooping\sto\sfine-tune\sthe\sresult.\sThe\srationale\sis\sthat\sanybody\swanting\sa\snon-drifting\sclock\scan\ssimply\suse\s[clock\sclicks]\sor\s[clock\smilliseconds]\sand\srecompute\shis\s[after]\sargument.\sAtomic\saccuracy\sof\s[after]\sis\sa\spipe\sdream\sin\ssoft-realtime\sOSes\sin\sany\scase.\n\nFWIW,\sI\sput\sthis\sa\shigh\sprio\seven\sthough\sit\sis\san\sold\sbug,\sbecause,\sit\scompletely\scripples\sthe\sperformance\sof\sa\sscript\sof\smine\swhich\sotherwise\shappily\sswallows\smegabits\sper\sseconds\sof\sMPEG\sTS\sstream\sand\sachieves\sabsolutely\sno\sdrift.\sYes,\sin\sTcl\s:)\n
J foundin None
J is_private 0
J priority 8
J resolution None
J status Open
J submitter ferrieux
J subsystem 03.\sTimer\sEvents
J title One\smillisecond\sof\sbusyloop\sin\s[after]
J type Bug
K 2904418fffffffffffffffffffffffffffffffff
U ferrieux
Z f8b953813e33727455d7e70cda7dc3dd