{"id":1551,"date":"2012-03-20T06:16:43","date_gmt":"2012-03-19T21:16:43","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=1551"},"modified":"2012-03-20T06:16:43","modified_gmt":"2012-03-19T21:16:43","slug":"xv6-46-chapter-4-scheduling-code-scheduling","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/1551","title":{"rendered":"[xv6 #46] Chapter 4 &#8211; Scheduling &#8211; Code: Scheduling"},"content":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u306e53\u301c55\u30da\u30fc\u30b8<\/p>\n<h3>\u672c\u6587<\/h3>\n<p>\u524d\u306e\u7bc0\u3067\u306f\u3001swtch\u306e\u30ed\u30fc\u30ec\u30d9\u30eb\u306b\u304a\u3051\u308b\u8a73\u7d30\u306b\u3064\u3044\u3066\u898b\u305f\u3002<br \/>\n\u3067\u306f\u3001swtch\u304c\u4e0e\u3048\u3089\u308c\u305f\u3068\u3057\u3066\u3001\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3078\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304b\u3089\u30d7\u30ed\u30bb\u30b9\u3078\u306e\u5207\u308a\u66ff\u3048\u306b\u5165\u308a\u7d44\u3093\u3060\u6c7a\u307e\u308a\u3054\u3068\u3092\u8abf\u3079\u3066\u307f\u3088\u3046\u3002<br \/>\nCPU\u3092\u624b\u653e\u3057\u305f\u3044\u30d7\u30ed\u30bb\u30b9\u306f\u3001\u30d7\u30ed\u30bb\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u30ed\u30c3\u30af\u3067\u3042\u308bptable.lock\u3092\u7372\u5f97\u3057\u3001\u4fdd\u6301\u3057\u3066\u3044\u308b\u4ed6\u306e\u3069\u3093\u306a\u30ed\u30c3\u30af\u3092\u3082\u89e3\u653e\u3057\u3001\u81ea\u8eab\u306e\u72b6\u614b\uff08proc-&gt;state\uff09\u3092\u66f4\u65b0\u3057\u3001\u305d\u3057\u3066sched\u3092\u547c\u3070\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\nyield\u306f\u3053\u306esleep\u3057exit\u3059\u308b\u3088\u3046\u306a\u6c7a\u307e\u308a\u3054\u3068\u306b\u5f93\u3046\u304c\u3001\u305d\u308c\u306b\u3064\u3044\u3066\u306f\u5f8c\u3067\u8aac\u660e\u3059\u308b\u3002<br \/>\nsched\u306f\u3001\u305d\u308c\u3089\u306e\u72b6\u614b\u30922\u91cd\u306b\u30c1\u30a7\u30c3\u30af\u3001\u3059\u306a\u308f\u3061\u305d\u308c\u3089\u306e\u72b6\u614b\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<br \/>\n\u30ed\u30c3\u30af\u306f\u4fdd\u6301\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306eCPU\u306f\u5272\u308a\u8fbc\u307f\u7121\u52b9\u306a\u72b6\u614b\u3067\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u6700\u7d42\u7684\u306bsched\u306f\u3001\u73fe\u5728\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092proc-&gt;context\u306b\u4fdd\u5b58\u3057\u3001cpu-&gt;scheduler\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u5207\u308a\u66ff\u3048\u308b\u305f\u3081\u306bswtch\u3092\u547c\u3076\u3002<br \/>\nswtch\u306f\u3001\u307e\u308b\u3067\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304cswtch\u3092\u547c\u3093\u3067\u8fd4\u3063\u3066\u304d\u305f\u76f4\u5f8c\u306e\u3088\u3046\u306b\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306e\u30b9\u30bf\u30c3\u30af\u4e0a\u306b\u623b\u308b\u3002\uff08swtch(&amp;cpu-&gt;scheduler, proc-&gt;context);\u306e\u3068\u3053\u308d\uff09<br \/>\n\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306ffor\u30eb\u30fc\u30d7\u3092\u7d9a\u884c\u3057\u3001\u5b9f\u884c\u3059\u3079\u304d\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u3001\u305d\u308c\u306b\u5207\u308a\u66ff\u3048\u3001\u305d\u308c\u304c\u7e70\u308a\u8fd4\u3055\u308c\u308b\u3002<\/p>\n<p>proc.c\u306escheduler, sched, yield\u95a2\u6570<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ Per-CPU process scheduler.\r\n\/\/ Each CPU calls scheduler() after setting itself up.\r\n\/\/ Scheduler never returns.  It loops, doing:\r\n\/\/  - choose a process to run\r\n\/\/  - swtch to start running that process\r\n\/\/  - eventually that process transfers control\r\n\/\/      via swtch back to the scheduler.\r\nvoid\r\nscheduler(void)\r\n{\r\n  struct proc *p;\r\n\r\n  for(;;){\r\n    \/\/ Enable interrupts on this processor.\r\n    sti();\r\n\r\n    \/\/ Loop over process table looking for process to run.\r\n    acquire(&amp;ptable.lock);\r\n    for(p = ptable.proc; p &lt; &amp;ptable.proc&#x5B;NPROC]; p++){\r\n      if(p-&gt;state != RUNNABLE)\r\n        continue;\r\n\r\n      \/\/ Switch to chosen process.  It is the process's job\r\n      \/\/ to release ptable.lock and then reacquire it\r\n      \/\/ before jumping back to us.\r\n      proc = p;\r\n      switchuvm(p);\r\n      p-&gt;state = RUNNING;\r\n      swtch(&amp;cpu-&gt;scheduler, proc-&gt;context);\r\n      switchkvm();\r\n\r\n      \/\/ Process is done running for now.\r\n      \/\/ It should have changed its p-&gt;state before coming back.\r\n      proc = 0;\r\n    }\r\n    release(&amp;ptable.lock);\r\n\r\n  }\r\n}\r\n\r\n\/\/ Enter scheduler.  Must hold only ptable.lock\r\n\/\/ and have changed proc-&gt;state.\r\nvoid\r\nsched(void)\r\n{\r\n  int intena;\r\n\r\n  if(!holding(&amp;ptable.lock))\r\n    panic(&quot;sched ptable.lock&quot;);\r\n  if(cpu-&gt;ncli != 1)\r\n    panic(&quot;sched locks&quot;);\r\n  if(proc-&gt;state == RUNNING)\r\n    panic(&quot;sched running&quot;);\r\n  if(readeflags()&amp;FL_IF)\r\n    panic(&quot;sched interruptible&quot;);\r\n  intena = cpu-&gt;intena;\r\n  swtch(&amp;proc-&gt;context, cpu-&gt;scheduler);\r\n  cpu-&gt;intena = intena;\r\n}\r\n\r\n\/\/ Give up the CPU for one scheduling round.\r\nvoid\r\nyield(void)\r\n{\r\n  acquire(&amp;ptable.lock);  \/\/DOC: yieldlock\r\n  proc-&gt;state = RUNNABLE;\r\n  sched();\r\n  release(&amp;ptable.lock);\r\n}\r\n<\/pre>\n<p>\u6211\u3005\u306f\u3001xv6\u304cptable.lock\u304cswtch\u306e\u547c\u3073\u51fa\u3057\u306b\u307e\u305f\u304c\u3063\u3066\u4fdd\u6301\u3055\u308c\u3066\u3044\u308b\u306e\u3092\u305f\u3063\u305f\u4eca\u898b\u305f\u3002<br \/>\nswtch\u306e\u547c\u3073\u51fa\u3057\u5143\u306f\u3001\u3059\u3067\u306b\u30ed\u30c3\u30af\u3092\u4fdd\u6301\u3057\u3066\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u304c\u3001\u305d\u306e\u30ed\u30c3\u30af\u306e\u7ba1\u7406\u306f\u5207\u308a\u66ff\u3048\u5148\u306e\u30b3\u30fc\u30c9\u306b\u6e21\u3055\u308c\u308b\u3002<br \/>\n\u3053\u306e\u6c7a\u307e\u308a\u3054\u3068\u306f\u3001\u30ed\u30c3\u30af\u306e\u4f8b\u5916\u7684\u306a\u4f7f\u3044\u65b9\u3067\u3042\u308b\u3002<br \/>\n\u4e00\u822c\u7684\u306a\u6c7a\u307e\u308a\u3054\u3068\u306f\u3001\u30ed\u30c3\u30af\u3092\u7372\u5f97\u3057\u305f\u30b9\u30ec\u30c3\u30c9\u306b\u305d\u306e\u30ed\u30c3\u30af\u3092\u89e3\u653e\u3059\u308b\u8cac\u4efb\u3082\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3042\u308a\u3001\u305d\u308c\u306f\u6b63\u3057\u3055\u306e\u305f\u3081\u3068\u3044\u3046\u5358\u7d14\u660e\u5feb\u306a\u7406\u7531\u306b\u3088\u308b\u3002<br \/>\n\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30b9\u30a4\u30c3\u30c1\u306e\u5834\u5408\u3001ptable.lock\u306f\u30d7\u30ed\u30bb\u30b9\u306estate\u3068context\u30d5\u30a3\u30fc\u30eb\u30c9\uff08\u305d\u308c\u3089\u306fswtch\u306e\u5b9f\u884c\u4e2d\u306f\u672c\u7269\u3067\u306f\u306a\u3044\uff09\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u3092\u4fdd\u8b77\u3059\u308b\u306e\u3067\u3001\u305d\u306e\u4e00\u822c\u7684\u306a\u6c7a\u307e\u308a\u3054\u3068\u3092\u7834\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<br \/>\nptable.lock\u304cswtch\u3092\u5b9f\u884c\u3059\u308b\u9593\u4fdd\u6301\u3055\u308c\u3066\u306a\u304b\u3063\u305f\u5834\u5408\u306b\u8d77\u304d\u308b\u554f\u984c\u306e\u4f8b\u3092\u3072\u3068\u3064\u6319\u3052\u308b\u3002<br \/>\nyield\u304c\u305d\u306e\u72b6\u614b\u3092RUNNABLE\u306b\u30bb\u30c3\u30c8\u3057\u305f\u5f8c\u3001\u3057\u304b\u3057swtch\u304c\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u81ea\u8eab\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30bf\u30c3\u30af\u306e\u4f7f\u7528\u3092\u3084\u3081\u308b\u524d\u306b\u3001\u5225\u306eCPU\u306f\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3092\u6c7a\u5b9a\u3059\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u3053\u308c\u306f2\u3064\u306eCPU\u304c\u540c\u3058\u30b9\u30bf\u30c3\u30af\u4e0a\u3067\u5b9f\u884c\u3055\u308c\u308b\u7d50\u679c\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u305d\u308c\u306f\u6b63\u3057\u304f\u306a\u3044\u72b6\u6cc1\u3067\u3042\u308b\u3002<\/p>\n<p>\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u306f\u5e38\u306bsched\u4e2d\u3067\u81ea\u8eab\u306e\u30d7\u30ed\u30bb\u30c3\u30b5\u3092\u624b\u653e\u3057\u3001\u5e38\u306b\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306e\u540c\u3058\u5834\u6240\u306b\u5207\u308a\u66ff\u3048\u3001\u305d\u3057\u3066\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306f\uff08\u307b\u307c\uff09\u5e38\u306bsched\u4e2d\u306e\u30d7\u30ed\u30bb\u30b9\u3078\u5207\u308a\u66ff\u3048\u308b\u3002<br \/>\n\u5f93\u3063\u3066\u3001xv6\u304c\u3069\u306e\u30b9\u30ec\u30c3\u30c9\u306b\u5207\u308a\u66ff\u3048\u308b\u304b\u305d\u306e\u884c\u756a\u53f7\u3092\u5370\u5b57\u3067\u304d\u305f\u3068\u3057\u305f\u3089\u3001\u6b21\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u30d1\u30bf\u30fc\u30f3\u304c\u89b3\u6e2c\u3067\u304d\u308b\u3060\u308d\u3046\u3002<br \/>\nscheduler\u306eswtch\u306e\u884c\u756a\u53f7\u2192sched\u306eswtch\u306e\u884c\u756a\u53f7\u2192\u2026\u7e70\u308a\u8fd4\u3057\u2026<br \/>\n\u3075\u305f\u3064\u306e\u30b9\u30ec\u30c3\u30c9\u9593\u3067\u8d77\u3053\u308b\u3053\u306e\u69d8\u5f0f\u5316\u3055\u308c\u305f\u5207\u308a\u66ff\u3048\u306b\u304a\u3051\u308b\u624b\u7d9a\u304d\u306f\u3001\u3068\u304d\u3069\u304d\u30b3\u30eb\u30fc\u30c1\u30f3\u306e\u4f8b\u3068\u3057\u3066\u8a00\u53ca\u3055\u308c\u308b\u3002<br \/>\n\u3053\u306e\u4f8b\u3067\u306f\u3001sched\u3068scheduler\u306f\u3001\u305d\u308c\u305e\u308c\u304a\u4e92\u3044\u306e\u30b3\u30eb\u30fc\u30c1\u30f3\u3067\u3042\u308b\u3002<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306eswtch\u304c\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u3078\u5207\u308a\u66ff\u3048\u308b\u3068\u304d\u3001sched\u3067\u7d42\u308f\u3089\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u3002<br \/>\n\u3053\u306e\u5834\u5408\u3092\u6211\u3005\u306f\u7b2c1\u7ae0\u3067\u898b\u305f\u3002<br \/>\n\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u304c\u6700\u521d\u306b\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3055\u308c\u308b\u3068\u304d\u3001forkret\u304b\u3089\u958b\u59cb\u3059\u308b\u3002<br \/>\nforkret\u306f\u3001ptable.lock\u3092\u89e3\u653e\u3059\u308b\u3068\u3044\u3046\u3053\u306e\u6c7a\u307e\u308a\u3054\u3068\u3092\u5f15\u304d\u53d7\u3051\u308b\u305f\u3081\u3060\u3051\u306b\u5b58\u5728\u3059\u308b\u3002<br \/>\n\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u306ftrapret\u304b\u3089\u958b\u59cb\u3067\u304d\u305f\u3002<\/p>\n<p>proc.c\u306eforkret\u95a2\u6570<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ A fork child's very first scheduling by scheduler()\r\n\/\/ will swtch here.  &quot;Return&quot; to user space.\r\nvoid\r\nforkret(void)\r\n{\r\n  static int first = 1;\r\n  \/\/ Still holding ptable.lock from scheduler.\r\n  release(&amp;ptable.lock);\r\n\r\n  if (first) {\r\n    \/\/ Some initialization functions must be run in the context\r\n    \/\/ of a regular process (e.g., they call sleep), and thus cannot \r\n    \/\/ be run from main().\r\n    first = 0;\r\n    initlog();\r\n  }\r\n  \r\n  \/\/ Return to &quot;caller&quot;, actually trapret (see allocproc).\r\n}<\/pre>\n<p>scheduler\u306f\u30b7\u30f3\u30d7\u30eb\u306a\u30eb\u30fc\u30d7\u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\n\u5b9f\u884c\u3059\u3079\u304d\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u3001\u6b62\u307e\u308b\u307e\u3067\u5b9f\u884c\u3057\u3001\u305d\u308c\u3092\u7e70\u308a\u8fd4\u3059\u3002<br \/>\nscheduler\u306f\u3001\u81ea\u8eab\u306e\u6d3b\u52d5\u306e\u5927\u90e8\u5206\u306e\u305f\u3081\u306bptable.lock\u3092\u4fdd\u6301\u3057\u3001\u5916\u5074\u306e\u5404\u30eb\u30fc\u30d7\u3067\u4e00\u5ea6\u30ed\u30c3\u30af\u3092\u89e3\u653e\u3059\u308b\u3002\uff08\u305d\u3057\u3066\u5272\u308a\u8fbc\u307f\u3092\u6709\u52b9\u306b\u3059\u308b\uff09<br \/>\n\u3053\u308c\u306f\u3001\u3053\u306eCPU\u304c\u6687\u306a\u3068\u304d\uff08RUNNABLE\u306a\u30d7\u30ed\u30bb\u30b9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\uff09\u3068\u3044\u3046\u7279\u5225\u306a\u5834\u5408\u306b\u91cd\u8981\u3067\u3042\u308b\u3002<br \/>\n\u3082\u3057\u30ed\u30c3\u30af\u3092\u4fdd\u6301\u3057\u305f\u307e\u307e\u6687\u306a\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u30eb\u30fc\u30d7\u3057\u305f\u5834\u5408\u3001\u30d7\u30ed\u30bb\u30b9\u3092\u5b9f\u884c\u4e2d\u306e\u4ed6\u306e\u3069\u306eCPU\u3082\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30b9\u30a4\u30c3\u30c1\u3084\u3001\u30d7\u30ed\u30bb\u30b9\u95a2\u9023\u306e\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u5b9f\u884c\u3067\u304d\u306a\u304f\u306a\u308a\u3001\u7279\u306b\u6687\u306aCPU\u3092\u305d\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u306e\u30eb\u30fc\u30d7\u306e\u5916\u306b\u8131\u51fa\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u30d7\u30ed\u30bb\u30b9\u3092RUNNABLE\u3068\u3057\u3066\u30de\u30fc\u30af\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u306a\u304f\u306a\u308b\u3002<br \/>\n\u30d7\u30ed\u30bb\u30b9\uff08\u4f8b\u3048\u3070\u30b7\u30a7\u30eb\uff09\u306fI\/O\u5f85\u3061\u306b\u306a\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u3001RUNNABLE\u306a\u30d7\u30ed\u30bb\u30b9\u304c\u5168\u304f\u306a\u3044\u72b6\u6cc1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3001\u6687\u306aCPU\u4e0a\u3067\u5b9a\u671f\u7684\u306b\u5272\u308a\u8fbc\u307f\u3092\u6709\u52b9\u306b\u3059\u308b\u7406\u7531\u3067\u3042\u308b\u3002<br \/>\n\u3082\u3057\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u5e38\u306b\u5272\u308a\u8fbc\u307f\u3092\u7121\u52b9\u5316\u3057\u305f\u307e\u307e\u3060\u3068\u3001I\/O\u306f\u6c7a\u3057\u3066\u5230\u7740\u3057\u306a\u3044\u3002<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306f\u3001p-&gt;state == RUNNABLE\u3067\u3042\u308b\u5b9f\u884c\u53ef\u80fd\u306a\u30d7\u30ed\u30bb\u30b9\u3092\u63a2\u3059\u305f\u3081\u306b\u30d7\u30ed\u30bb\u30b9\u30c6\u30fc\u30d6\u30eb\u3092\u30eb\u30fc\u30d7\u3057\u306a\u304c\u3089\u8d70\u67fb\u3059\u308b\u3002<br \/>\n\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u305f\u3089\u3001CPU\u3054\u3068\u306e\u73fe\u5728\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u3059proc\u5909\u6570\u3092\u30bb\u30c3\u30c8\u3057\u3001switchuvm\u95a2\u6570\u3092\u4f7f\u3063\u3066\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u3078\u5207\u308a\u66ff\u3048\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092RUNNING\u3068\u3057\u3066\u30de\u30fc\u30af\u3057\u3001\u305d\u3057\u3066\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u958b\u59cb\u3059\u308b\u305f\u3081\u306bswtch\u3092\u547c\u3076\u3002\uff08proc = p;\u304b\u3089swtch\u306e\u90e8\u5206\uff09<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u306e\u30b3\u30fc\u30c9\u306e\u69cb\u9020\u306b\u3064\u3044\u3066\u8003\u3048\u308b\u3072\u3068\u3064\u306e\u65b9\u6cd5\u306f\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u304c\u305d\u308c\u305e\u308c\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u95a2\u3059\u308b\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u4e00\u5f0f\u3092\u5f37\u5236\u3059\u308b\u305f\u3081\u6e96\u5099\u3057\u3001\u305d\u308c\u3089\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u304c\u6b63\u3057\u304f\u306a\u3044\u9593\u306f\u5e38\u306bptable.lock\u3092\u4fdd\u6301\u3059\u308b\u3068\u3044\u3046\u4e8b\u3067\u3042\u308b\u3002<br \/>\n\u3082\u3057\u30d7\u30ed\u30bb\u30b9\u304cRUNNING\u306a\u3089\u3001\u30bf\u30a4\u30de\u5272\u308a\u8fbc\u307f\u306b\u3088\u3063\u3066\u547c\u3073\u51fa\u3055\u308c\u308byield\u304c\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u3069\u3053\u304b\u3078\u6b63\u3057\u304f\u5207\u308a\u66ff\u3048\u308b\u4e8b\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u304c\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u306e\u3072\u3068\u3064\u3067\u3042\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001CPU\u306e\u30ec\u30b8\u30b9\u30bf\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u30ec\u30b8\u30b9\u30bf\u306e\u5024\uff08\u305d\u308c\u3089\u306f\u5b9f\u306f\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306e\u4e2d\u306b\u7121\u3044\uff09\u3092\u4fdd\u6301\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001%cr3\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001%esp\u306fswtch\u304c\u6b63\u3057\u304f\u30ec\u30b8\u30b9\u30bf\u3092\u30d7\u30c3\u30b7\u30e5\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30bf\u30c3\u30af\u3092\u6307\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001proc\u306fproc\u914d\u5217\u306b\u304a\u3051\u308b\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u3059\u3082\u306e\u3092\u6307\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u3082\u3057\u30d7\u30ed\u30bb\u30b9\u304cRUNNABLE\u306a\u3089\u3001\u6687\u306aCPU\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u305d\u308c\u3092\u5b9f\u884c\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u3053\u308c\u306f\u3001p-&gt;context\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u306e\u5909\u6570\u3092\u4fdd\u6301\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30bf\u30c3\u30af\u4e0a\u3067\u306f\u3069\u306eCPU\u3082\u5b9f\u884c\u4e2d\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u3092\u3069\u306eCPU\u306e%cr3\u3082\u6307\u3057\u3066\u304a\u3089\u305a\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u3069\u306eCPU\u306eproc\u5909\u6570\u3082\u6307\u3057\u3066\u3044\u306a\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u3092\u4fdd\u8b77\u3059\u308b\u3053\u3068\u304c\u3001\u306a\u305cxv6\u304c\u3042\u308b\u30b9\u30ec\u30c3\u30c9\uff08\u3057\u3070\u3057\u3070yield\u4e2d\uff09\u3067ptable.lock\u3092\u7372\u5f97\u3057\u3001\u4ed6\u306e\u30b9\u30ec\u30c3\u30c9\uff08\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306e\u30b9\u30ec\u30c3\u30c9\u3084\u4ed6\u306e\u6b21\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\uff09\u3067\u305d\u306e\u30ed\u30c3\u30af\u3092\u89e3\u653e\u3059\u308b\u306e\u304b\u3001\u3068\u3044\u3046\u3053\u3068\u306e\u7406\u7531\u3067\u3042\u308b\u3002<br \/>\n\u4e00\u5ea6\u3001\u5b9f\u884c\u4e2d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u72b6\u614b\u3092RUNNABLE\u3078\u5909\u66f4\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u304c\u958b\u59cb\u3057\u305f\u3089\u3001\u305d\u306e\u30b3\u30fc\u30c9\u306f\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u306e\u5fa9\u5143\u304c\u5b8c\u4e86\u3059\u308b\u307e\u3067\u30ed\u30c3\u30af\u3092\u4fdd\u6301\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u958b\u653e\u3059\u308b\u30bf\u30a4\u30df\u30f3\u30b0\u3068\u3057\u3066\u65e9\u304f\u6b63\u3057\u3044\u306e\u306f\u3001scheduler\u304c\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u306e\u4f7f\u7528\u3092\u3084\u3081\u3001proc\u3092\u30af\u30ea\u30a2\u3057\u305f\u5f8c\u3067\u3042\u308b\u3002<br \/>\n\u540c\u69d8\u306b\u3001\u4e00\u5ea6\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u5b9f\u884c\u53ef\u80fd\u306a\u30d7\u30ed\u30bb\u30b9\u3092RUNNING\u306b\u5909\u66f4\u3057\u306f\u3058\u3081\u305f\u3089\u3001\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u304c\u78ba\u5b9f\u306b\u5b9f\u884c\u3055\u308c\u308b\u307e\u3067\uff08yield\u4e2d\u306eswtch\u306e\u5f8c\uff09\u30ed\u30c3\u30af\u3092\u958b\u653e\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u3002<\/p>\n<p>ptable.lock\u306f\u3001\u3088\u304f\u4ed6\u306e\u3082\u306e\u3082\u4fdd\u8b77\u3059\u308b\u3002<br \/>\n\u30d7\u30ed\u30bb\u30b9\u30c6\u30fc\u30d6\u30eb\u30b9\u30ed\u30c3\u30c8\u306e\u7a7a\u304d\u3084\u30d7\u30ed\u30bb\u30b9ID\u306e\u5272\u308a\u5f53\u3066\u3001exit\u3068wait\u9593\u306e\u76f8\u4e92\u4f5c\u7528\u3001\u8d77\u5e8a\uff08wakeups\u3002 \u6b21\u306e\u7ae0\u3067\u8aac\u660e\u3059\u308b\uff09\u306e\u5931\u6557\u3092\u907f\u3051\u308b\u305f\u3081\u306e\u4ed5\u639b\u3051\u3001\u591a\u5206\u4ed6\u306e\u3053\u3068\u3082\u3002<br \/>\nptable.lock\u306e\u5225\u306e\u95a2\u6570\u304c\u5206\u5272\u53ef\u80fd\u304b\u3069\u3046\u304b\u306b\u3064\u3044\u3066\u3001\u3088\u304f\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u306f\u78ba\u5b9f\u306b\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u305f\u3081\u306b\u306f\u591a\u5206\u3001\u8003\u3048\u308b\u4fa1\u5024\u304c\u3042\u308b\u3002<\/p>\n<h3>\u611f\u60f3<\/h3>\n<p>\u9577\u3044\u3002<\/p>\n<p>\u30d7\u30ed\u30bb\u30b9\u5207\u308a\u66ff\u3048\u6642\u306e\u30b3\u30fc\u30c9\u30d1\u30b9\u306e\u8a73\u7d30\u3067\u3059\u3002<br \/>\n\u5927\u304d\u304f2\u30d1\u30bf\u30fc\u30f3\u3042\u3063\u3066\u3001\u3072\u3068\u3064\u306f\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3078\u306e\u5207\u308a\u66ff\u3048\u3001\u3082\u3046\u3072\u3068\u3064\u306f\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304b\u3089\u30d7\u30ed\u30bb\u30b9\u3078\u306e\u5207\u308a\u66ff\u3048\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3078\u306e\u5207\u308a\u66ff\u3048\u306e\u5834\u5408\u3001\u983b\u5ea6\u304c\u4e00\u756a\u591a\u3044\u306e\u304c\u30bf\u30a4\u30de\u5272\u308a\u8fbc\u307f\u8d77\u70b9\u306e\u5207\u308a\u66ff\u3048\u3067\u3059\u304b\u306d\u3002<br \/>\n\u305d\u306e\u969b\u306f\u3001\u5272\u308a\u8fbc\u307f\u2192trap\u2192yield\u2192shced\u2192swtch\u2192scheduler\u3068\u3044\u3046\u6d41\u308c\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304b\u3089\u30d7\u30ed\u30bb\u30b9\u3078\u306e\u5207\u308a\u66ff\u3048\u306e\u5834\u5408\u306f\u3001RUNNABLE\u306a\u30d7\u30ed\u30bb\u30b9\u304c\u898b\u3064\u304b\u3063\u305f\u3089swtch\u3067\u5207\u308a\u66ff\u3048\u308b\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u306d\u3002<\/p>\n<p>\u9014\u4e2d\u8272\u3005\u66f8\u3044\u3066\u3042\u308b\u3068\u3053\u308d\u306f\u3001\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u3059\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u3092\u4fdd\u8b77\u3059\u308b\u305f\u3081\u306b\u5207\u308a\u66ff\u3048\u524d\u306b\u4f55\u3092\u884c\u3046\u304b\u306b\u3064\u3044\u3066\u66f8\u304b\u308c\u3066\u308b\u3093\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u3042\u3068\u306f\u3001\u30ed\u30c3\u30af\u3068\u5272\u308a\u8fbc\u307f\u306e\u517c\u306d\u5408\u3044\u3001\u8907\u6570CPU\u6642\u306b\u304a\u3051\u308b\u554f\u984c\u3001\u3092\u901a\u3058\u3066\u306a\u305c\u3053\u306e\u6d41\u308c\u3067\u51e6\u7406\u3059\u308b\u306e\u304b\u306b\u3064\u3044\u3066\u306e\u8aac\u660e\u3067\u3059\u306d\u3002<\/p>\n<p>\u9055\u3046\u30d7\u30ed\u30bb\u30b9\u3067ptable.lock\u306e\u7372\u5f97\u3068\u958b\u653e\u304c\u884c\u308f\u308c\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u5207\u308a\u66ff\u3048\u306b\u3088\u3063\u3066\u9055\u3046\u30d7\u30ed\u30bb\u30b9\u306b\u306a\u308b\u3068\u3044\u3063\u3066\u3082\u3001CPU\u306f\u540c\u3058\u306a\u306e\u3067\u4e00\u5fdc\u554f\u984c\u306a\u304f\u30ed\u30c3\u30af\u306e\u958b\u653e\u304c\u51fa\u6765\u308b\u308f\u3051\u3067\u3059\u304c\u3001\u304b\u306a\u308a\u7279\u6b8a\u306a\u4f8b\u3060\u3068\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u7d30\u304b\u3044\u3068\u3053\u308d\u3067\u306f\u3001\u30b3\u30eb\u30fc\u30c1\u30f3\u3068\u3044\u3046\u8a00\u8449\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\n<a href=\"http:\/\/ja.wikipedia.org\/wiki\/%E3%82%B3%E3%83%AB%E3%83%BC%E3%83%81%E3%83%B3\" target=\"_blank\">\u30b3\u30eb\u30fc\u30c1\u30f3 &#8211; Wikipedia<\/a>\u306b\u8aac\u660e\u304c\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u3001sched\u3067\u51fa\u3066\u304f\u308bcpu-&gt;intena\u3067\u3059\u304c\u3001pushcli\u306e\u524d\u306b\u5272\u308a\u8fbc\u307f\u304c\u6709\u52b9\u3060\u3063\u305f\u304b\u3069\u3046\u304b\u3092\u8868\u3059\u30d5\u30a3\u30fc\u30eb\u30c9\u307f\u305f\u3044\u3067\u3059\u3002<br \/>\ncpu-&gt;intena\u306e\u4fdd\u5b58\u3068\u5fa9\u5143\u304c\u306a\u3044\u3068\u3001\u305d\u308c\u3092\u53c2\u7167\u3057\u305f\u308a\u66f8\u304d\u63db\u3048\u305f\u308a\u3057\u3066\u3044\u308bpushcli\u3068popcli\uff08\u305d\u308c\u305e\u308cacquire\u3068release\u304b\u3089\u547c\u3070\u308c\u308b\u3002\u7279\u306bpopcli\u306e\u65b9\u304c\uff09\u306e\u52d5\u4f5c\u304c\u304a\u304b\u3057\u304f\u306a\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u306e53\u301c55\u30da\u30fc\u30b8<\/p>\n<h3>\u672c\u6587<\/h3>\n<p>\u524d\u306e\u7bc0\u3067\u306f\u3001swtch\u306e\u30ed\u30fc\u30ec\u30d9\u30eb\u306b\u304a\u3051\u308b\u8a73\u7d30\u306b\u3064\u3044\u3066\u898b\u305f\u3002<br \/>\n\u3067\u306f\u3001swtch\u304c\u4e0e\u3048\u3089\u308c\u305f\u3068\u3057\u3066\u3001\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3078\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304b\u3089\u30d7\u30ed\u30bb\u30b9\u3078\u306e\u5207\u308a\u66ff\u3048\u306b\u5165\u308a\u7d44\u3093\u3060\u6c7a\u307e\u308a\u3054\u3068\u3092\u8abf\u3079\u3066\u307f\u3088\u3046\u3002<br \/>\nCPU\u3092\u624b\u653e\u3057\u305f\u3044\u30d7\u30ed\u30bb\u30b9\u306f\u3001\u30d7\u30ed\u30bb\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u30ed\u30c3\u30af\u3067\u3042\u308bptable.lock\u3092\u7372\u5f97\u3057\u3001\u4fdd\u6301\u3057\u3066\u3044\u308b\u4ed6\u306e\u3069\u3093\u306a\u30ed\u30c3\u30af\u3092\u3082\u89e3\u653e\u3057\u3001\u81ea\u8eab\u306e\u72b6\u614b\uff08proc-&gt;state\uff09\u3092\u66f4\u65b0\u3057\u3001\u305d\u3057\u3066sched\u3092\u547c\u3070\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\nyield\u306f\u3053\u306esleep\u3057exit\u3059\u308b\u3088\u3046\u306a\u6c7a\u307e\u308a\u3054\u3068\u306b\u5f93\u3046\u304c\u3001\u305d\u308c\u306b\u3064\u3044\u3066\u306f\u5f8c\u3067\u8aac\u660e\u3059\u308b\u3002<br \/>\nsched\u306f\u3001\u305d\u308c\u3089\u306e\u72b6\u614b\u30922\u91cd\u306b\u30c1\u30a7\u30c3\u30af\u3001\u3059\u306a\u308f\u3061\u305d\u308c\u3089\u306e\u72b6\u614b\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<br \/>\n\u30ed\u30c3\u30af\u306f\u4fdd\u6301\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306eCPU\u306f\u5272\u308a\u8fbc\u307f\u7121\u52b9\u306a\u72b6\u614b\u3067\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u6700\u7d42\u7684\u306bsched\u306f\u3001\u73fe\u5728\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092proc-&gt;context\u306b\u4fdd\u5b58\u3057\u3001cpu-&gt;scheduler\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u5207\u308a\u66ff\u3048\u308b\u305f\u3081\u306bswtch\u3092\u547c\u3076\u3002<br \/>\nswtch\u306f\u3001\u307e\u308b\u3067\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304cswtch\u3092\u547c\u3093\u3067\u8fd4\u3063\u3066\u304d\u305f\u76f4\u5f8c\u306e\u3088\u3046\u306b\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306e\u30b9\u30bf\u30c3\u30af\u4e0a\u306b\u623b\u308b\u3002\uff08swtch(&amp;cpu-&gt;scheduler, proc-&gt;context);\u306e\u3068\u3053\u308d\uff09<br \/>\n\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306ffor\u30eb\u30fc\u30d7\u3092\u7d9a\u884c\u3057\u3001\u5b9f\u884c\u3059\u3079\u304d\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u3001\u305d\u308c\u306b\u5207\u308a\u66ff\u3048\u3001\u305d\u308c\u304c\u7e70\u308a\u8fd4\u3055\u308c\u308b\u3002<\/p>\n<p>proc.c\u306escheduler, sched, yield\u95a2\u6570<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ Per-CPU process scheduler.\r\n\/\/ Each CPU calls scheduler() after setting itself up.\r\n\/\/ Scheduler never returns.  It loops, doing:\r\n\/\/  - choose a process to run\r\n\/\/  - swtch to start running that process\r\n\/\/  - eventually that process transfers control\r\n\/\/      via swtch back to the scheduler.\r\nvoid\r\nscheduler(void)\r\n{\r\n  struct proc *p;\r\n\r\n  for(;;){\r\n    \/\/ Enable interrupts on this processor.\r\n    sti();\r\n\r\n    \/\/ Loop over process table looking for process to run.\r\n    acquire(&amp;ptable.lock);\r\n    for(p = ptable.proc; p &lt; &amp;ptable.proc&#x5B;NPROC]; p++){\r\n      if(p-&gt;state != RUNNABLE)\r\n        continue;\r\n\r\n      \/\/ Switch to chosen process.  It is the process's job\r\n      \/\/ to release ptable.lock and then reacquire it\r\n      \/\/ before jumping back to us.\r\n      proc = p;\r\n      switchuvm(p);\r\n      p-&gt;state = RUNNING;\r\n      swtch(&amp;cpu-&gt;scheduler, proc-&gt;context);\r\n      switchkvm();\r\n\r\n      \/\/ Process is done running for now.\r\n      \/\/ It should have changed its p-&gt;state before coming back.\r\n      proc = 0;\r\n    }\r\n    release(&amp;ptable.lock);\r\n\r\n  }\r\n}\r\n\r\n\/\/ Enter scheduler.  Must hold only ptable.lock\r\n\/\/ and have changed proc-&gt;state.\r\nvoid\r\nsched(void)\r\n{\r\n  int intena;\r\n\r\n  if(!holding(&amp;ptable.lock))\r\n    panic(&quot;sched ptable.lock&quot;);\r\n  if(cpu-&gt;ncli != 1)\r\n    panic(&quot;sched locks&quot;);\r\n  if(proc-&gt;state == RUNNING)\r\n    panic(&quot;sched running&quot;);\r\n  if(readeflags()&amp;FL_IF)\r\n    panic(&quot;sched interruptible&quot;);\r\n  intena = cpu-&gt;intena;\r\n  swtch(&amp;proc-&gt;context, cpu-&gt;scheduler);\r\n  cpu-&gt;intena = intena;\r\n}\r\n\r\n\/\/ Give up the CPU for one scheduling round.\r\nvoid\r\nyield(void)\r\n{\r\n  acquire(&amp;ptable.lock);  \/\/DOC: yieldlock\r\n  proc-&gt;state = RUNNABLE;\r\n  sched();\r\n  release(&amp;ptable.lock);\r\n}\r\n<\/pre>\n<p>\u6211\u3005\u306f\u3001xv6\u304cptable.lock\u304cswtch\u306e\u547c\u3073\u51fa\u3057\u306b\u307e\u305f\u304c\u3063\u3066\u4fdd\u6301\u3055\u308c\u3066\u3044\u308b\u306e\u3092\u305f\u3063\u305f\u4eca\u898b\u305f\u3002<br \/>\nswtch\u306e\u547c\u3073\u51fa\u3057\u5143\u306f\u3001\u3059\u3067\u306b\u30ed\u30c3\u30af\u3092\u4fdd\u6301\u3057\u3066\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u304c\u3001\u305d\u306e\u30ed\u30c3\u30af\u306e\u7ba1\u7406\u306f\u5207\u308a\u66ff\u3048\u5148\u306e\u30b3\u30fc\u30c9\u306b\u6e21\u3055\u308c\u308b\u3002<br \/>\n\u3053\u306e\u6c7a\u307e\u308a\u3054\u3068\u306f\u3001\u30ed\u30c3\u30af\u306e\u4f8b\u5916\u7684\u306a\u4f7f\u3044\u65b9\u3067\u3042\u308b\u3002<br \/>\n\u4e00\u822c\u7684\u306a\u6c7a\u307e\u308a\u3054\u3068\u306f\u3001\u30ed\u30c3\u30af\u3092\u7372\u5f97\u3057\u305f\u30b9\u30ec\u30c3\u30c9\u306b\u305d\u306e\u30ed\u30c3\u30af\u3092\u89e3\u653e\u3059\u308b\u8cac\u4efb\u3082\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3042\u308a\u3001\u305d\u308c\u306f\u6b63\u3057\u3055\u306e\u305f\u3081\u3068\u3044\u3046\u5358\u7d14\u660e\u5feb\u306a\u7406\u7531\u306b\u3088\u308b\u3002<br \/>\n\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30b9\u30a4\u30c3\u30c1\u306e\u5834\u5408\u3001ptable.lock\u306f\u30d7\u30ed\u30bb\u30b9\u306estate\u3068context\u30d5\u30a3\u30fc\u30eb\u30c9\uff08\u305d\u308c\u3089\u306fswtch\u306e\u5b9f\u884c\u4e2d\u306f\u672c\u7269\u3067\u306f\u306a\u3044\uff09\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u3092\u4fdd\u8b77\u3059\u308b\u306e\u3067\u3001\u305d\u306e\u4e00\u822c\u7684\u306a\u6c7a\u307e\u308a\u3054\u3068\u3092\u7834\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<br \/>\nptable.lock\u304cswtch\u3092\u5b9f\u884c\u3059\u308b\u9593\u4fdd\u6301\u3055\u308c\u3066\u306a\u304b\u3063\u305f\u5834\u5408\u306b\u8d77\u304d\u308b\u554f\u984c\u306e\u4f8b\u3092\u3072\u3068\u3064\u6319\u3052\u308b\u3002<br \/>\nyield\u304c\u305d\u306e\u72b6\u614b\u3092RUNNABLE\u306b\u30bb\u30c3\u30c8\u3057\u305f\u5f8c\u3001\u3057\u304b\u3057swtch\u304c\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u81ea\u8eab\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30bf\u30c3\u30af\u306e\u4f7f\u7528\u3092\u3084\u3081\u308b\u524d\u306b\u3001\u5225\u306eCPU\u306f\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3092\u6c7a\u5b9a\u3059\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u3053\u308c\u306f2\u3064\u306eCPU\u304c\u540c\u3058\u30b9\u30bf\u30c3\u30af\u4e0a\u3067\u5b9f\u884c\u3055\u308c\u308b\u7d50\u679c\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u305d\u308c\u306f\u6b63\u3057\u304f\u306a\u3044\u72b6\u6cc1\u3067\u3042\u308b\u3002<\/p>\n<p>\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u306f\u5e38\u306bsched\u4e2d\u3067\u81ea\u8eab\u306e\u30d7\u30ed\u30bb\u30c3\u30b5\u3092\u624b\u653e\u3057\u3001\u5e38\u306b\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306e\u540c\u3058\u5834\u6240\u306b\u5207\u308a\u66ff\u3048\u3001\u305d\u3057\u3066\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306f\uff08\u307b\u307c\uff09\u5e38\u306bsched\u4e2d\u306e\u30d7\u30ed\u30bb\u30b9\u3078\u5207\u308a\u66ff\u3048\u308b\u3002<br \/>\n\u5f93\u3063\u3066\u3001xv6\u304c\u3069\u306e\u30b9\u30ec\u30c3\u30c9\u306b\u5207\u308a\u66ff\u3048\u308b\u304b\u305d\u306e\u884c\u756a\u53f7\u3092\u5370\u5b57\u3067\u304d\u305f\u3068\u3057\u305f\u3089\u3001\u6b21\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u30d1\u30bf\u30fc\u30f3\u304c\u89b3\u6e2c\u3067\u304d\u308b\u3060\u308d\u3046\u3002<br \/>\nscheduler\u306eswtch\u306e\u884c\u756a\u53f7\u2192sched\u306eswtch\u306e\u884c\u756a\u53f7\u2192\u2026\u7e70\u308a\u8fd4\u3057\u2026<br \/>\n\u3075\u305f\u3064\u306e\u30b9\u30ec\u30c3\u30c9\u9593\u3067\u8d77\u3053\u308b\u3053\u306e\u69d8\u5f0f\u5316\u3055\u308c\u305f\u5207\u308a\u66ff\u3048\u306b\u304a\u3051\u308b\u624b\u7d9a\u304d\u306f\u3001\u3068\u304d\u3069\u304d\u30b3\u30eb\u30fc\u30c1\u30f3\u306e\u4f8b\u3068\u3057\u3066\u8a00\u53ca\u3055\u308c\u308b\u3002<br \/>\n\u3053\u306e\u4f8b\u3067\u306f\u3001sched\u3068scheduler\u306f\u3001\u305d\u308c\u305e\u308c\u304a\u4e92\u3044\u306e\u30b3\u30eb\u30fc\u30c1\u30f3\u3067\u3042\u308b\u3002<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306eswtch\u304c\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u3078\u5207\u308a\u66ff\u3048\u308b\u3068\u304d\u3001sched\u3067\u7d42\u308f\u3089\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u3002<br \/>\n\u3053\u306e\u5834\u5408\u3092\u6211\u3005\u306f\u7b2c1\u7ae0\u3067\u898b\u305f\u3002<br \/>\n\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u304c\u6700\u521d\u306b\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3055\u308c\u308b\u3068\u304d\u3001forkret\u304b\u3089\u958b\u59cb\u3059\u308b\u3002<br \/>\nforkret\u306f\u3001ptable.lock\u3092\u89e3\u653e\u3059\u308b\u3068\u3044\u3046\u3053\u306e\u6c7a\u307e\u308a\u3054\u3068\u3092\u5f15\u304d\u53d7\u3051\u308b\u305f\u3081\u3060\u3051\u306b\u5b58\u5728\u3059\u308b\u3002<br \/>\n\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u306ftrapret\u304b\u3089\u958b\u59cb\u3067\u304d\u305f\u3002<\/p>\n<p>proc.c\u306eforkret\u95a2\u6570<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ A fork child's very first scheduling by scheduler()\r\n\/\/ will swtch here.  &quot;Return&quot; to user space.\r\nvoid\r\nforkret(void)\r\n{\r\n  static int first = 1;\r\n  \/\/ Still holding ptable.lock from scheduler.\r\n  release(&amp;ptable.lock);\r\n\r\n  if (first) {\r\n    \/\/ Some initialization functions must be run in the context\r\n    \/\/ of a regular process (e.g., they call sleep), and thus cannot \r\n    \/\/ be run from main().\r\n    first = 0;\r\n    initlog();\r\n  }\r\n  \r\n  \/\/ Return to &quot;caller&quot;, actually trapret (see allocproc).\r\n}<\/pre>\n<p>scheduler\u306f\u30b7\u30f3\u30d7\u30eb\u306a\u30eb\u30fc\u30d7\u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\n\u5b9f\u884c\u3059\u3079\u304d\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u3001\u6b62\u307e\u308b\u307e\u3067\u5b9f\u884c\u3057\u3001\u305d\u308c\u3092\u7e70\u308a\u8fd4\u3059\u3002<br \/>\nscheduler\u306f\u3001\u81ea\u8eab\u306e\u6d3b\u52d5\u306e\u5927\u90e8\u5206\u306e\u305f\u3081\u306bptable.lock\u3092\u4fdd\u6301\u3057\u3001\u5916\u5074\u306e\u5404\u30eb\u30fc\u30d7\u3067\u4e00\u5ea6\u30ed\u30c3\u30af\u3092\u89e3\u653e\u3059\u308b\u3002\uff08\u305d\u3057\u3066\u5272\u308a\u8fbc\u307f\u3092\u6709\u52b9\u306b\u3059\u308b\uff09<br \/>\n\u3053\u308c\u306f\u3001\u3053\u306eCPU\u304c\u6687\u306a\u3068\u304d\uff08RUNNABLE\u306a\u30d7\u30ed\u30bb\u30b9\u304c\u898b\u3064\u304b\u3089\u306a\u3044\uff09\u3068\u3044\u3046\u7279\u5225\u306a\u5834\u5408\u306b\u91cd\u8981\u3067\u3042\u308b\u3002<br \/>\n\u3082\u3057\u30ed\u30c3\u30af\u3092\u4fdd\u6301\u3057\u305f\u307e\u307e\u6687\u306a\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u30eb\u30fc\u30d7\u3057\u305f\u5834\u5408\u3001\u30d7\u30ed\u30bb\u30b9\u3092\u5b9f\u884c\u4e2d\u306e\u4ed6\u306e\u3069\u306eCPU\u3082\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30b9\u30a4\u30c3\u30c1\u3084\u3001\u30d7\u30ed\u30bb\u30b9\u95a2\u9023\u306e\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u5b9f\u884c\u3067\u304d\u306a\u304f\u306a\u308a\u3001\u7279\u306b\u6687\u306aCPU\u3092\u305d\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u306e\u30eb\u30fc\u30d7\u306e\u5916\u306b\u8131\u51fa\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u30d7\u30ed\u30bb\u30b9\u3092RUNNABLE\u3068\u3057\u3066\u30de\u30fc\u30af\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u306a\u304f\u306a\u308b\u3002<br \/>\n\u30d7\u30ed\u30bb\u30b9\uff08\u4f8b\u3048\u3070\u30b7\u30a7\u30eb\uff09\u306fI\/O\u5f85\u3061\u306b\u306a\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u3001RUNNABLE\u306a\u30d7\u30ed\u30bb\u30b9\u304c\u5168\u304f\u306a\u3044\u72b6\u6cc1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3001\u6687\u306aCPU\u4e0a\u3067\u5b9a\u671f\u7684\u306b\u5272\u308a\u8fbc\u307f\u3092\u6709\u52b9\u306b\u3059\u308b\u7406\u7531\u3067\u3042\u308b\u3002<br \/>\n\u3082\u3057\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u5e38\u306b\u5272\u308a\u8fbc\u307f\u3092\u7121\u52b9\u5316\u3057\u305f\u307e\u307e\u3060\u3068\u3001I\/O\u306f\u6c7a\u3057\u3066\u5230\u7740\u3057\u306a\u3044\u3002<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306f\u3001p-&gt;state == RUNNABLE\u3067\u3042\u308b\u5b9f\u884c\u53ef\u80fd\u306a\u30d7\u30ed\u30bb\u30b9\u3092\u63a2\u3059\u305f\u3081\u306b\u30d7\u30ed\u30bb\u30b9\u30c6\u30fc\u30d6\u30eb\u3092\u30eb\u30fc\u30d7\u3057\u306a\u304c\u3089\u8d70\u67fb\u3059\u308b\u3002<br \/>\n\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3064\u3051\u305f\u3089\u3001CPU\u3054\u3068\u306e\u73fe\u5728\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u3059proc\u5909\u6570\u3092\u30bb\u30c3\u30c8\u3057\u3001switchuvm\u95a2\u6570\u3092\u4f7f\u3063\u3066\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u3078\u5207\u308a\u66ff\u3048\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092RUNNING\u3068\u3057\u3066\u30de\u30fc\u30af\u3057\u3001\u305d\u3057\u3066\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u958b\u59cb\u3059\u308b\u305f\u3081\u306bswtch\u3092\u547c\u3076\u3002\uff08proc = p;\u304b\u3089swtch\u306e\u90e8\u5206\uff09<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u306e\u30b3\u30fc\u30c9\u306e\u69cb\u9020\u306b\u3064\u3044\u3066\u8003\u3048\u308b\u3072\u3068\u3064\u306e\u65b9\u6cd5\u306f\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30ea\u30f3\u30b0\u304c\u305d\u308c\u305e\u308c\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u95a2\u3059\u308b\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u4e00\u5f0f\u3092\u5f37\u5236\u3059\u308b\u305f\u3081\u6e96\u5099\u3057\u3001\u305d\u308c\u3089\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u304c\u6b63\u3057\u304f\u306a\u3044\u9593\u306f\u5e38\u306bptable.lock\u3092\u4fdd\u6301\u3059\u308b\u3068\u3044\u3046\u4e8b\u3067\u3042\u308b\u3002<br \/>\n\u3082\u3057\u30d7\u30ed\u30bb\u30b9\u304cRUNNING\u306a\u3089\u3001\u30bf\u30a4\u30de\u5272\u308a\u8fbc\u307f\u306b\u3088\u3063\u3066\u547c\u3073\u51fa\u3055\u308c\u308byield\u304c\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u3069\u3053\u304b\u3078\u6b63\u3057\u304f\u5207\u308a\u66ff\u3048\u308b\u4e8b\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u304c\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u306e\u3072\u3068\u3064\u3067\u3042\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001CPU\u306e\u30ec\u30b8\u30b9\u30bf\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u30ec\u30b8\u30b9\u30bf\u306e\u5024\uff08\u305d\u308c\u3089\u306f\u5b9f\u306f\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306e\u4e2d\u306b\u7121\u3044\uff09\u3092\u4fdd\u6301\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001%cr3\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001%esp\u306fswtch\u304c\u6b63\u3057\u304f\u30ec\u30b8\u30b9\u30bf\u3092\u30d7\u30c3\u30b7\u30e5\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30bf\u30c3\u30af\u3092\u6307\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001proc\u306fproc\u914d\u5217\u306b\u304a\u3051\u308b\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u3059\u3082\u306e\u3092\u6307\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u3082\u3057\u30d7\u30ed\u30bb\u30b9\u304cRUNNABLE\u306a\u3089\u3001\u6687\u306aCPU\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u305d\u308c\u3092\u5b9f\u884c\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u3053\u308c\u306f\u3001p-&gt;context\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u306e\u5909\u6570\u3092\u4fdd\u6301\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30bf\u30c3\u30af\u4e0a\u3067\u306f\u3069\u306eCPU\u3082\u5b9f\u884c\u4e2d\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u3092\u3069\u306eCPU\u306e%cr3\u3082\u6307\u3057\u3066\u304a\u3089\u305a\u3001\u305d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u3069\u306eCPU\u306eproc\u5909\u6570\u3082\u6307\u3057\u3066\u3044\u306a\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u3092\u4fdd\u8b77\u3059\u308b\u3053\u3068\u304c\u3001\u306a\u305cxv6\u304c\u3042\u308b\u30b9\u30ec\u30c3\u30c9\uff08\u3057\u3070\u3057\u3070yield\u4e2d\uff09\u3067ptable.lock\u3092\u7372\u5f97\u3057\u3001\u4ed6\u306e\u30b9\u30ec\u30c3\u30c9\uff08\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u306e\u30b9\u30ec\u30c3\u30c9\u3084\u4ed6\u306e\u6b21\u306e\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\uff09\u3067\u305d\u306e\u30ed\u30c3\u30af\u3092\u89e3\u653e\u3059\u308b\u306e\u304b\u3001\u3068\u3044\u3046\u3053\u3068\u306e\u7406\u7531\u3067\u3042\u308b\u3002<br \/>\n\u4e00\u5ea6\u3001\u5b9f\u884c\u4e2d\u306e\u30d7\u30ed\u30bb\u30b9\u306e\u72b6\u614b\u3092RUNNABLE\u3078\u5909\u66f4\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u304c\u958b\u59cb\u3057\u305f\u3089\u3001\u305d\u306e\u30b3\u30fc\u30c9\u306f\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u306e\u5fa9\u5143\u304c\u5b8c\u4e86\u3059\u308b\u307e\u3067\u30ed\u30c3\u30af\u3092\u4fdd\u6301\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u958b\u653e\u3059\u308b\u30bf\u30a4\u30df\u30f3\u30b0\u3068\u3057\u3066\u65e9\u304f\u6b63\u3057\u3044\u306e\u306f\u3001scheduler\u304c\u30d7\u30ed\u30bb\u30b9\u306e\u30da\u30fc\u30b8\u30c6\u30fc\u30d6\u30eb\u306e\u4f7f\u7528\u3092\u3084\u3081\u3001proc\u3092\u30af\u30ea\u30a2\u3057\u305f\u5f8c\u3067\u3042\u308b\u3002<br \/>\n\u540c\u69d8\u306b\u3001\u4e00\u5ea6\u3001\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304c\u5b9f\u884c\u53ef\u80fd\u306a\u30d7\u30ed\u30bb\u30b9\u3092RUNNING\u306b\u5909\u66f4\u3057\u306f\u3058\u3081\u305f\u3089\u3001\u30ab\u30fc\u30cd\u30eb\u30b9\u30ec\u30c3\u30c9\u304c\u78ba\u5b9f\u306b\u5b9f\u884c\u3055\u308c\u308b\u307e\u3067\uff08yield\u4e2d\u306eswtch\u306e\u5f8c\uff09\u30ed\u30c3\u30af\u3092\u958b\u653e\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u3002<\/p>\n<p>ptable.lock\u306f\u3001\u3088\u304f\u4ed6\u306e\u3082\u306e\u3082\u4fdd\u8b77\u3059\u308b\u3002<br \/>\n\u30d7\u30ed\u30bb\u30b9\u30c6\u30fc\u30d6\u30eb\u30b9\u30ed\u30c3\u30c8\u306e\u7a7a\u304d\u3084\u30d7\u30ed\u30bb\u30b9ID\u306e\u5272\u308a\u5f53\u3066\u3001exit\u3068wait\u9593\u306e\u76f8\u4e92\u4f5c\u7528\u3001\u8d77\u5e8a\uff08wakeups\u3002 \u6b21\u306e\u7ae0\u3067\u8aac\u660e\u3059\u308b\uff09\u306e\u5931\u6557\u3092\u907f\u3051\u308b\u305f\u3081\u306e\u4ed5\u639b\u3051\u3001\u591a\u5206\u4ed6\u306e\u3053\u3068\u3082\u3002<br \/>\nptable.lock\u306e\u5225\u306e\u95a2\u6570\u304c\u5206\u5272\u53ef\u80fd\u304b\u3069\u3046\u304b\u306b\u3064\u3044\u3066\u3001\u3088\u304f\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u306f\u78ba\u5b9f\u306b\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u305f\u3081\u306b\u306f\u591a\u5206\u3001\u8003\u3048\u308b\u4fa1\u5024\u304c\u3042\u308b\u3002<\/p>\n<h3>\u611f\u60f3<\/h3>\n<p>\u9577\u3044\u3002<\/p>\n<p>\u30d7\u30ed\u30bb\u30b9\u5207\u308a\u66ff\u3048\u6642\u306e\u30b3\u30fc\u30c9\u30d1\u30b9\u306e\u8a73\u7d30\u3067\u3059\u3002<br \/>\n\u5927\u304d\u304f2\u30d1\u30bf\u30fc\u30f3\u3042\u3063\u3066\u3001\u3072\u3068\u3064\u306f\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3078\u306e\u5207\u308a\u66ff\u3048\u3001\u3082\u3046\u3072\u3068\u3064\u306f\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304b\u3089\u30d7\u30ed\u30bb\u30b9\u3078\u306e\u5207\u308a\u66ff\u3048\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u3078\u306e\u5207\u308a\u66ff\u3048\u306e\u5834\u5408\u3001\u983b\u5ea6\u304c\u4e00\u756a\u591a\u3044\u306e\u304c\u30bf\u30a4\u30de\u5272\u308a\u8fbc\u307f\u8d77\u70b9\u306e\u5207\u308a\u66ff\u3048\u3067\u3059\u304b\u306d\u3002<br \/>\n\u305d\u306e\u969b\u306f\u3001\u5272\u308a\u8fbc\u307f\u2192trap\u2192yield\u2192shced\u2192swtch\u2192scheduler\u3068\u3044\u3046\u6d41\u308c\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30b1\u30b8\u30e5\u30fc\u30e9\u304b\u3089\u30d7\u30ed\u30bb\u30b9\u3078\u306e\u5207\u308a\u66ff\u3048\u306e\u5834\u5408\u306f\u3001RUNNABLE\u306a\u30d7\u30ed\u30bb\u30b9\u304c\u898b\u3064\u304b\u3063\u305f\u3089swtch\u3067\u5207\u308a\u66ff\u3048\u308b\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u306d\u3002<\/p>\n<p>\u9014\u4e2d\u8272\u3005\u66f8\u3044\u3066\u3042\u308b\u3068\u3053\u308d\u306f\u3001\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u3059\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u30a4\u30f3\u30d0\u30ea\u30a2\u30f3\u30c8\u3092\u4fdd\u8b77\u3059\u308b\u305f\u3081\u306b\u5207\u308a\u66ff\u3048\u524d\u306b\u4f55\u3092\u884c\u3046\u304b\u306b\u3064\u3044\u3066\u66f8\u304b\u308c\u3066\u308b\u3093\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u3042\u3068\u306f\u3001\u30ed\u30c3\u30af\u3068\u5272\u308a\u8fbc\u307f\u306e\u517c\u306d\u5408\u3044\u3001\u8907\u6570CPU\u6642\u306b\u304a\u3051\u308b\u554f\u984c\u3001\u3092\u901a\u3058\u3066\u306a\u305c\u3053\u306e\u6d41\u308c\u3067\u51e6\u7406\u3059\u308b\u306e\u304b\u306b\u3064\u3044\u3066\u306e\u8aac\u660e\u3067\u3059\u306d\u3002<\/p>\n<p>\u9055\u3046\u30d7\u30ed\u30bb\u30b9\u3067ptable.lock\u306e\u7372\u5f97\u3068\u958b\u653e\u304c\u884c\u308f\u308c\u308b\u90e8\u5206\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u5207\u308a\u66ff\u3048\u306b\u3088\u3063\u3066\u9055\u3046\u30d7\u30ed\u30bb\u30b9\u306b\u306a\u308b\u3068\u3044\u3063\u3066\u3082\u3001CPU\u306f\u540c\u3058\u306a\u306e\u3067\u4e00\u5fdc\u554f\u984c\u306a\u304f\u30ed\u30c3\u30af\u306e\u958b\u653e\u304c\u51fa\u6765\u308b\u308f\u3051\u3067\u3059\u304c\u3001\u304b\u306a\u308a\u7279\u6b8a\u306a\u4f8b\u3060\u3068\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u7d30\u304b\u3044\u3068\u3053\u308d\u3067\u306f\u3001\u30b3\u30eb\u30fc\u30c1\u30f3\u3068\u3044\u3046\u8a00\u8449\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\n<a href=\"http:\/\/ja.wikipedia.org\/wiki\/%E3%82%B3%E3%83%AB%E3%83%BC%E3%83%81%E3%83%B3\" target=\"_blank\">\u30b3\u30eb\u30fc\u30c1\u30f3 &#8211; Wikipedia<\/a>\u306b\u8aac\u660e\u304c\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u3001sched\u3067\u51fa\u3066\u304f\u308bcpu-&gt;intena\u3067\u3059\u304c\u3001pushcli\u306e\u524d\u306b\u5272\u308a\u8fbc\u307f\u304c\u6709\u52b9\u3060\u3063\u305f\u304b\u3069\u3046\u304b\u3092\u8868\u3059\u30d5\u30a3\u30fc\u30eb\u30c9\u307f\u305f\u3044\u3067\u3059\u3002<br \/>\ncpu-&gt;intena\u306e\u4fdd\u5b58\u3068\u5fa9\u5143\u304c\u306a\u3044\u3068\u3001\u305d\u308c\u3092\u53c2\u7167\u3057\u305f\u308a\u66f8\u304d\u63db\u3048\u305f\u308a\u3057\u3066\u3044\u308bpushcli\u3068popcli\uff08\u305d\u308c\u305e\u308cacquire\u3068release\u304b\u3089\u547c\u3070\u308c\u308b\u3002\u7279\u306bpopcli\u306e\u65b9\u304c\uff09\u306e\u52d5\u4f5c\u304c\u304a\u304b\u3057\u304f\u306a\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[405],"class_list":["post-1551","post","type-post","status-publish","format-standard","hentry","category-tech","tag-xv6"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=1551"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1551\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=1551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=1551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=1551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}