ããã¯ããªãŒã¢ã«ãŽãªãºã ã«èå³ãæã€ããã«ãªããšãããã«è³ªåãèŠãã¿å§ããŸãããã³ãŒãã®ãé åºã埩å ãããããã®ã¡ã¢ãªããªã¢ã®å¿ èŠæ§ã¯ã©ãããæ¥ãã®ã§ããããã
ãã¡ããã ç¹å®ã®ã¢ãŒããã¯ãã£ã«é¢ããããã¥ã¢ã«ã®æ°åããŒãžãèªãã åŸãçããèŠã€ãããŸãã ãããããã®çãã¯ãã®ç¹å®ã®ã¢ãŒããã¯ãã£ã«é©ããŠããŸãã å ±éç¹ã¯ãããŸããïŒ æçµçã«ã¯ãã³ãŒãã移æ€å¯èœã«ããå¿ èŠããããŸãã ãŸããC ++ 11ã¡ã¢ãªã¢ãã«ã¯ç¹å®ã®ããã»ããµåãã«èª¿æŽãããŠããŸããã
æãåãå ¥ããããäžè¬çãªçãã¯ã ããŒã«ããã±ããŒæ°ã®2010幎ã®èšäºã Memory BarriersïŒa Hardware View of Software Hackersãã§åºãããŸããã 圌ã®èšäºã®äŸ¡å€ã¯äžè¬çã§ãã圌ã¯ãããã€ãã®åçŽåãããæœè±¡çãªã¢ãŒããã¯ãã£ãæ§ç¯ãããã®äŸã«åºã¥ããŠãã¡ã¢ãªããªã¢ãšã¯äœãããªãå°å ¥ãããã®ããåæããŸããã
äžè¬çã«ãããŒã«ã»ããã±ããŒã¯æå人ã§ãã 圌ã¯Linuxã«ãŒãã«ã§ç©æ¥µçã«äœ¿çšãããŠããRCUãã¯ãããžãŒã®éçºè ã§ãããç©æ¥µçãªããã¢ãŒã¿ãŒã§ãããã¡ã¢ãªãå®å šã«è§£æŸããå¥ã®ã¢ãããŒããšããŠææ°ããŒãžã§ã³ã®libcdsã§ãå®è£ ãããŠããŸãïŒäžè¬çã«ãRCUã«ã€ããŠã¯å¥ã«è©±ãããïŒã 圌ã¯ãŸããC ++ 11ã¡ã¢ãªã¢ãã«ã®äœæ¥ã«ãåå ããŸããã
èšäºã倧ããã®ã§ãååã ãã®ç¿»èš³ãããŸãã ç§ã¯ããã€ãã®ã³ã¡ã³ããè¿œå ããããšãèš±å¯ããŸãã[ãã®ãããªããã¹ãã§åŒ·èª¿è¡šç€ºãããŠããŸã] ã
ã¡ã¢ãªããªã¢ïŒãœãããŠã§ã¢ããã«ãŒã®ããŒããŠã§ã¢ãã¥ãŒ
CPUèšèšè ãã¡ã¢ãªããªã¢ãå°å ¥ããããã«ãã£ãŠéçºè ã«è±ã眮ããã®ã¯ãªãã§ããïŒ ç°¡åãªçãã¯æ¬¡ã®ãšããã§ããã¡ã¢ãªã¢ã¯ã»ã¹ã®é åºãå€æŽãããšããã©ãŒãã³ã¹ãåäžããŸãããŸããããªããã£ãã®æ£ç¢ºæ§ãã¡ã¢ãªã¢ã¯ã»ã¹ã®é åºã«äŸåããåæããªããã£ã[ããã³ãã¡ããããã¯ããªãŒã¢ã«ãŽãªãºã ]ãªã©ããã¯ãªãŒã³ã¢ãããããã«ã¯ãã¡ã¢ãªããªã¢ãå¿ èŠã§ãã
詳现ãªåçãåŸãã«ã¯ãCPUãã£ãã·ã¥ãã©ã®ããã«æ©èœãããããããŠãããããã«æ¹åããããã«äœãå¿ èŠããããç解ããå¿ èŠããããŸãã ãããã£ãŠãããã«ïŒ
- ãã£ãã·ã¥ã®æ§é ãèæ ®ããŠãã ããã
- ãã£ãã·ã¥ã³ããŒã¬ã³ã¹ãããã³ã«ãç°ãªãããã»ããµã®åã¡ã¢ãªã»ã«ã®å¯èŠæ§ãã©ã®ããã«ä¿èšŒãããã説æããŸãã
- ãã£ãã·ã¥ãæ倧ã®ããã©ãŒãã³ã¹ãéæããããã«ãã¹ãã¢ãããã¡ãšç¡å¹åãã¥ãŒãã©ã®ããã«åœ¹ç«ã€ããæ€èšããŠãã ããã
ã¡ã¢ãªããªã¢ã¯ãé«ãããã©ãŒãã³ã¹ãšã¹ã±ãŒã©ããªãã£ãå®çŸããããã«å¿ èŠãªæªã§ããããšãããããŸãã ãã®æªã®æ ¹æºã¯ãCPUãã¡ã¢ãªãããã»ããµãšã¡ã¢ãªãšã®ã€ã³ã¿ãŒãã§ãŒã¹ãããæ¡éãã«éããšããäºå®ã§ãã
ãã£ãã·ã¥æ§é
ææ°ã®CPUã¯ãã¡ã¢ãªãµãã·ã¹ãã ãããã¯ããã«é«éã§ãã 2006幎ã®ãµã³ãã«ããã»ããµã¯ããç§ããã10åœä»€ãå®è¡ã§ããŸããããã¡ã€ã³ã¡ã¢ãªããããŒã¿ãæœåºããã«ã¯æ°åããç§ããããŸããã ãã®é床ã®äžåè¡¡ïŒ2æ¡ä»¥äžïŒïŒã¯ãææ°ã®ããã»ããµã§ãã«ãã¡ã¬ãã€ããã£ãã·ã¥ã«ã€ãªãã£ãŠããŸãã ãã£ãã·ã¥ã¯ããã»ããµã«å±ããååãšããŠããã£ãã·ã¥ãžã®ã¢ã¯ã»ã¹æéã¯æ°ã¯ããã¯ãµã€ã¯ã«ã§ãã
ã泚æ
å®éãäžè¬çãªæ¹æ³ã¯ããã€ãã®ã¬ãã«ã®ãã£ãã·ã¥ãæã€ããšã§ãã ããªã¥ãŒã å
ã®æå°ãã£ãã·ã¥ã¯ããã»ããµã«æãè¿ãã1ã¯ããã¯ãµã€ã¯ã«ã§äœ¿çšå¯èœã§ãã 2次ãã£ãã·ã¥ã®ã¢ã¯ã»ã¹æéã¯çŽ10ã¯ããã¯ãµã€ã¯ã«ã§ãã ã»ãšãã©ã®çç£çãªããã»ããµã«ã¯ã3ã€ãŸãã¯4ã€ã®ãã£ãã·ã¥ã¬ãã«ããããŸã
CPUã¯ããã£ãã·ã¥ã©ã€ã³ãšåŒã°ãããã£ãã·ã¥ãããã¯ãšããŒã¿ã亀æããŸãã ãã£ãã·ã¥ã©ã€ã³ã®ãµã€ãºã¯ãéåžž2ã®çŽ¯ä¹ã§ã16ã256ãã€ãïŒCPUã«äŸåïŒã§ãã ããã»ããµãæåã«ã¡ã¢ãªã»ã«ã«ã¢ã¯ã»ã¹ãããšããã»ã«ã¯ãã£ãã·ã¥ã«ãããŸããããã®ç¶æ³ã¯ã ãã¹ ïŒãã£ãã·ã¥ãã¹ãããæ£ç¢ºã«ã¯ãã¹ã¿ãŒãã¢ããããŸãã¯ããŠã©ãŒã ã¢ããããã£ãã·ã¥ãã¹ïŒãšåŒã°ããŸãã ãã¹ãšã¯ãããŒã¿ãã¡ã¢ãªããååŸããããŸã§ãCPUãæ°çŸãµã€ã¯ã«åŸ æ©ããïŒåæ¢ããïŒããšãæå³ããŸãã æåŸã«ãããŒã¿ããã£ãã·ã¥ã«ããŒãããããã®ã¢ãã¬ã¹ãžã®åŸç¶ã®ã¢ã¯ã»ã¹ã§ãã£ãã·ã¥å ã®ããŒã¿ãæ€åºããããããCPUã¯ãã«ã¹ããŒãã§å®è¡ãããŸãã
ãã°ãããããšããã£ãã·ã¥ããã£ã±ãã«ãªãããã¹ãçºçãããšããã£ãã·ã¥ããããŒã¿ãçµãåºãããæ°ããèŠæ±ãããããŒã¿ã«å ŽæãäžããããŸãã ãã®ãããªãã¹ã¯ããã£ãã·ãã£ãã¹ãšåŒã°ããŸãã ããã«ããã£ãã·ã¥ã¯ã ãã±ãããµã€ãºãåºå®ãããããã·ã¥ããŒãã«ïŒãŸãã¯CPUéçºè ãåŒã³åºãã»ãã ïŒãšããŠããŒããŠã§ã¢ã§ç·šæãããŠããããããã£ãã·ã¥ããã£ã±ãã§ãªãå Žåã§ãçºçããå¯èœæ§ããããŸãã
å³ã®å³ã¯ã256ãã€ãã®ãã£ãã·ã¥ã©ã€ã³ãæã€2é£æ³ïŒ2ãŠã§ã€ïŒãã£ãã·ã¥ã瀺ããŠããŸãã è¡ã¯ç©ºã®å ŽåããããŸããããã¯ãããŒãã«å ã®ç©ºã®ã»ã«ã«å¯Ÿå¿ããŸãã å·ŠåŽã®æ°åã¯ãã»ã«ã«å«ããããšãã§ããã¢ãã¬ã¹ã§ãã è¡ã¯256ãã€ãã§æŽåããŠãããããã¢ãã¬ã¹ã®äžäœ8ãããã¯ãŒãã§ãããããã·ã¥é¢æ°ã¯æ¬¡ã®4ããããããã·ã¥ããŒãã«ã®ã€ã³ããã¯ã¹ãšããŠéžæããŸãã ããã°ã©ã ã³ãŒããã¢ãã¬ã¹0x43210E00-0x43210EFFã«ãããããã°ã©ã èªäœãã¢ãã¬ã¹0x12345000-0x12345EFFã®ããŒã¿ã«ã¢ã¯ã»ã¹ãããšããŸãã 次ã«ãã¢ãã¬ã¹0x12345F00ã«ç§»åãããŸãã ãã®ã¢ãã¬ã¹ã¯0xFè¡ã§ããã·ã¥ããããã®è¡ã®äž¡æ¹ã®ã»ã«ã¯ç©ºã§ããããã256ãã€ãã®ããŒã¿ãã©ã¡ããäžæ¹ã«å ¥ããããšãã§ããŸãã ããã°ã©ã ã0x1233000ã§ã¢ã¯ã»ã¹ãããã®ããã·ã¥ã0x0ã§ããå Žåã察å¿ãã256ãã€ãã®ããŒã¿ã0x0è¡ã®ã»ã«1ïŒãŠã§ã€1ïŒã«é 眮ã§ããŸãã ããã°ã©ã ãã¢ãã¬ã¹0x1233E00ïŒããã·ã¥= 0xEïŒã«ã¢ã¯ã»ã¹ããå Žåãæ°ãã256ãã€ãã®ããŒã¿çšã«ã¹ããŒã¹ã解æŸããããã«ãããããã®è¡ïŒãŠã§ã€ïŒããã£ãã·ã¥ããããã·ã¥ããå¿ èŠããããŸãã åŸã§ãã®ããã·ã¥ãããããŒã¿ã«ã¢ã¯ã»ã¹ããå¿ èŠãããå Žåããã¹ãçºçããŸãã ãã®ãããªå€±æã¯ãçµåæ§ãã¹ãšåŒã°ããŸãã
ããã¯ãã¹ãŠããŒã¿ã®èªã¿åãã«é¢ãããã®ã§ãæžã蟌ã¿ãè¡ããšã©ããªããŸããïŒ ãã¹ãŠã®CPUã¯ããŒã¿ã«åŸã£ãŠäžè²«ããŠããå¿ èŠããããããæžã蟌ã¿ã®åã«ãä»ã®CPUã®ãã£ãã·ã¥ããããŒã¿ãåé€ïŒç¡å¹åïŒããå¿ èŠããããŸãã ç¡å¹åãå®äºãããšãããã»ããµã¯å®å šã«ããŒã¿ãèšé²ã§ããŸãã ããŒã¿ãCPUãã£ãã·ã¥ã«ãããèªã¿åãå°çšã®å Žåãããã¯æžã蟌ã¿ãã¹ãšåŒã°ããŸãã CPUãä»ã®ããã»ããµã®ãã£ãã·ã¥ã«ãããã®ãããªããŒã¿ãç¡å¹ã«ããåŸã«ã®ã¿ãCPUã¯ãã®ããŒã¿ãåæžã蟌ã¿ïŒããã³èªã¿åãïŒã§ããŸãã ããã«ãããCPUãããŒã¿ãžã®ã¢ã¯ã»ã¹ãè©Šã¿ãŠãããšãã«ãå¥ã®CPUãæžã蟌ã¿ã®ããã«ããããç¡å¹ã«ãããšãããŒã¿ãéä¿¡ã«äœ¿çšããããšãã«ãã®ãããªç¶æ³ãçºçããããã éä¿¡ãã¹ãšåŒã°ãããã¹ãåãåããŸãããã¥ãŒããã¯ã¹ãŸãã¯ã¹ãã³ããã¯[ãã¥ãŒããã¯ã¹èªäœãæããä¿è·ããããŒã¿ã§ã¯ãããŸããã mutexã¯äœããã®ãã©ã°ã§ã] ã
ã芧ã®ãšããããã¹ãŠã®CPUã®ããŒã¿ã®äžè²«æ§ã管çããã«ã¯ãå€å€§ãªåªåãå¿ èŠã§ãã ããããèªã¿åã/ç¡å¹å/æžã蟌ã¿ããã¹ãŠè¡ããããšãããŒã¿ã倱ãããããïŒããã«æªãããšã«ïŒCPUããšã«ãã£ãã·ã¥å ã®ããŒã¿ãç°ãªãããšã¯å®¹æã«æ³åã§ããŸãã ãããã®åé¡ã¯ãããŒã¿äžè²«æ§ãããã³ã«ã«ãã£ãŠå¯ŸåŠãããŠããŸãã
ãã£ãã·ã¥äžè²«æ§ãããã³ã«
ãã®ãããã³ã«ã¯ãã£ãã·ã¥ã©ã€ã³ã®ç¶æ ãå¶åŸ¡ããæŽåæ§ã確ä¿ããŠããŒã¿æ倱ãé²ããŸãã ãã®ãããªãããã³ã«ã¯éåžžã«è€éã§ãæ°åã®ç¶æ ããããŸãããããã§ã¯4ã€ã®ç¶æ ãæã€MESIãããã³ã«ãæ€èšããã ãã§ååã§ãã
MESIã®ç¶æ
MESIã¯4ã€ã®å¯èœãªãã£ãã·ã¥ã©ã€ã³ç¶æ ã§ãïŒModified-Exclusive-Shared-Invalidã ãã®ãããã³ã«ããµããŒãããã«ã¯ãããŒã¿èªäœã«å ããŠãåè¡ã«ãã®ç¶æ ãæ ŒçŽãã2ãããã®ã¿ã°ãå¿ èŠã§ãã
å€æŽãããã¹ããŒã¿ã¹ã¯ããã£ãã·ã¥ã©ã€ã³ã®ããŒã¿ããã£ãã·ã¥ã®ããã»ããµææè ã«ãã£ãŠæžã蟌ãŸããã°ããã§ãããå€æŽãä»ã®CPUã®ãã£ãã·ã¥ã«ãŸã çŸããŠããªãããšãä¿èšŒããŸãã 1ã€ã®CPUãããŒã¿ãææããŠãããšèšããŸãã ãã®ãããªè¡ã®ããŒã¿ã¯æãæ°ããã®ã§ããã£ãã·ã¥ã®è¡ã¯ã¡ã¢ãªïŒãŸãã¯æ¬¡ã®ã¬ãã«ã®ãã£ãã·ã¥ïŒã«æžã蟌ãæºåãã§ããŠãããè¡ãä»ã®ããŒã¿ã§åããåã«ã¬ã³ãŒããäœæããå¿ èŠããããŸãã
Exclusiveç¶æ ã¯ããã£ãã·ã¥ãææããããã»ããµã«ãã£ãŠããŒã¿ããŸã å€æŽãããŠããªãããšãé€ããŠãModifiedãšéåžžã«äŒŒãŠããŸãã ããã¯ããã®è¡ãã¡ã¢ãªãšäžèŽããææ°ã®ããŒã¿ãå«ãããšãæå³ããŸãã CPUææè ã¯ãä»ã®CPUã«éç¥ããããšãªãããã€ã§ããã®ãã£ãã·ã¥ã©ã€ã³ã«æžã蟌ãããšãã§ããŸãããŸããã¡ã¢ãªã«æžãæ»ãããšãªã匷å¶çã«ãã£ãã·ã¥ã©ã€ã³ã«æžã蟌ãããšãã§ããŸãã
å ±æã¹ããŒã¿ã¹ã¯ãã©ã€ã³ãä»ã®CPUã®å°ãªããšã1ã€ã®ä»ã®ãã£ãã·ã¥ã«è€è£œãããŠããããšã瀺ããŸãã ãã®ãããªè¡ã®CPUææè ã¯ãä»ã®CPUãšã®äºåã®èª¿æŽãªãã«ããã«æžã蟌ãããšã¯ã§ããŸããã æä»çç¶æ ã«é¢ããŠã¯ãã©ã€ã³ã¯ã¡ã¢ãªã«åãããããä»ã®CPUã«éç¥ããããã¡ã¢ãªã«æžãæ»ãããããã«åŒ·å¶çã«åºåã§ããŸãã
ç¡å¹ç¶æ ã®ãã£ãã·ã¥ã©ã€ã³ã¯ç©ºã§ããã€ãŸããããŒã¿ãå«ãŸããŠããŸããïŒãŸãã¯ã¬ããŒãžãå«ãŸããŠããŸãïŒã æ°ããããŒã¿ããã£ãã·ã¥ã«ããŒãããå¿ èŠãããå Žåãå¯èœãªéãç¡å¹ãªè¡ã«é 眮ãããŸãã
ãã¹ãŠã®CPUã¯ã·ã¹ãã ã®ãã£ãã·ã¥å šäœã®äžè²«æ§ãç¶æããå¿ èŠãããããããããã³ã«ã¯ãã¹ãŠã®ããã»ããµãŒã®ãã£ãã·ã¥ã©ã€ã³ã®ã¹ããŒã¿ã¹ã®å€åã調æŽããã¡ãã»ãŒãžãèšè¿°ããŸãã
MESIãããã³ã«ã¡ãã»ãŒãž
ããç¶æ ããå¥ã®ç¶æ ãžã®é·ç§»ã®å€ãã¯ãCPUéã®çžäºäœçšãå¿ èŠãšããŸãã ãã¹ãŠã®CPUãåäžã®å ±æãã¹ã«æ¥ç¶ãããŠããå Žåã次ã®ã¡ãã»ãŒãžã§ååã§ãã
- èªã¿åã ïŒãã®ã¡ãã»ãŒãžã«ã¯ãèªã¿åãäžã®ãã£ãã·ã¥ã©ã€ã³ã®ç©çã¢ãã¬ã¹ãå«ãŸããŸãã
- èªã¿åãå¿ç ïŒåã®èªã¿åãã¡ãã»ãŒãžã§èŠæ±ãããããŒã¿ãå«ãŸããŸãã èªã¿åãå¿çã¯ãã¡ã¢ãªãµãã·ã¹ãã ãŸãã¯å¥ã®ãã£ãã·ã¥ããéä¿¡ãããå ŽåããããŸãã ããšãã°ãããŒã¿ãæ¢ã«ãå€æŽæžã¿ãç¶æ ã®ãã£ãã·ã¥ã«ããå Žåããã®ãããªãã£ãã·ã¥ã¯èªã¿åãã«å¿çããå¯èœæ§ããããŸã
- ç¡å¹å ïŒ ç¡å¹ã«ãããã£ãã·ã¥ã©ã€ã³ã®ç©çã¢ãã¬ã¹ãå«ãŸããŸãã ä»ã®ãã¹ãŠã®ãã£ãã·ã¥ã¯ããŒã¿ãåé€ãããã®ã¡ãã»ãŒãžã«è¿ä¿¡ããå¿ èŠããããŸãã
- Invalidate Acknowledge ïŒ Invalidateãåä¿¡ããCPUã¯ãå¿ èŠãªããŒã¿ãåé€ãã Invalidate Acknowledgeã§ç¢ºèªããå¿ èŠããããŸã
- ç¡å¹åã®èªã¿åã ïŒãã®ã¡ãã»ãŒãžã«ã¯ãèªã¿åãäžã®ãã£ãã·ã¥ã©ã€ã³ã®ç©çã¢ãã¬ã¹ãå«ãŸããŸãã åæã«ããã®ããŒã¿ãåé€ããããä»ã®ãã£ãã·ã¥ã«æ瀺ããŸãã ããã¯ãåºæ¬çã«èªã¿åãã¡ãã»ãŒãžãšç¡å¹åã¡ãã»ãŒãžã®çµã¿åããã§ãã ãã®ã¡ãã»ãŒãžã«ã¯ã Read Responseå¿çãšè€æ°ã®Invalidate Acknowledgeãå¿ èŠã§ã
- ã©ã€ããã㯠ïŒã¡ã¢ãªã«æžã蟌ãããã®ã¢ãã¬ã¹ãšå®éã®ããŒã¿ãå«ãŸããŸãã ãã£ãã·ã¥ãå€æŽç¶æ ã®å¯Ÿå¿ããè¡ããã©ãã·ã¥ã§ããããã«ããŸãã
ã芧ã®ãšããããã«ãããã»ããµãã·ã³ã¯ã¡ãã»ãŒãžã³ã°ã·ã¹ãã ã§ãããæ¬è³ªçã«ã¯ããã»ããµã«ããŒã®äžã«ããã³ã³ãã¥ãŒã¿ã§ãã
質çå¿ç
2ã€ã®ããã»ããµãåããã£ãã·ã¥ã©ã€ã³ãåæã«ç¡å¹ã«ãããšã©ããªããŸããïŒ
ãããã®1ã€ïŒãåè ãïŒãæåã«å ±æãã¹ã«ã¢ã¯ã»ã¹ããŸãã ä»ã®CPUã¯ããã®ãã£ãã·ã¥ã©ã€ã³ã®ã³ããŒãç¡å¹ã«ãããç¡å¹å確èªãã§å¿çããå¿ èŠããããŸãã ãã¡ããããè² ãããCPUã¯å³åº§ã«èªã¿åãç¡å¹åãã©ã³ã¶ã¯ã·ã§ã³ãéå§ã§ãããããåã¡ã¯çåœã«ãªãå¯èœæ§ããããŸãã
倧èŠæš¡ãªãã«ãããã»ããµã·ã¹ãã ã§ãç¡å¹åããšããã¡ãã»ãŒãžã衚瀺ãããå Žåããã¹ãŠã®CPUã¯ãç¡å¹å確èªãã§å¿çããå¿ èŠããããŸãã ãã®ãããªçãã®ççºçãªæµãã¯ãã·ã¹ãã ã®å®å šãªã·ã£ããããŠã³ã«ã€ãªãããŸããïŒ
ã¯ãã倧èŠæš¡ãªã·ã¹ãã ããã®ããã«æ§ç¯ãããŠããã°å¯èœã§ãã ããããããšãã°NUMAã®ãããªã·ã¹ãã ã¯ãéåžžããã®ãããªå Žåãé²ãããã ãã«ã ãã£ã¬ã¯ããªããŒã¹ã® [NUMAã®ãã£ã¬ã¯ããª-ããŒããããŒã]ãã£ãã·ã¥äžè²«æ§ãµããŒããããã³ã«ã䜿çšããŸãã
ãããã®1ã€ïŒãåè ãïŒãæåã«å ±æãã¹ã«ã¢ã¯ã»ã¹ããŸãã ä»ã®CPUã¯ããã®ãã£ãã·ã¥ã©ã€ã³ã®ã³ããŒãç¡å¹ã«ãããç¡å¹å確èªãã§å¿çããå¿ èŠããããŸãã ãã¡ããããè² ãããCPUã¯å³åº§ã«èªã¿åãç¡å¹åãã©ã³ã¶ã¯ã·ã§ã³ãéå§ã§ãããããåã¡ã¯çåœã«ãªãå¯èœæ§ããããŸãã
倧èŠæš¡ãªãã«ãããã»ããµã·ã¹ãã ã§ãç¡å¹åããšããã¡ãã»ãŒãžã衚瀺ãããå Žåããã¹ãŠã®CPUã¯ãç¡å¹å確èªãã§å¿çããå¿ èŠããããŸãã ãã®ãããªçãã®ççºçãªæµãã¯ãã·ã¹ãã ã®å®å šãªã·ã£ããããŠã³ã«ã€ãªãããŸããïŒ
ã¯ãã倧èŠæš¡ãªã·ã¹ãã ããã®ããã«æ§ç¯ãããŠããã°å¯èœã§ãã ããããããšãã°NUMAã®ãããªã·ã¹ãã ã¯ãéåžžããã®ãããªå Žåãé²ãããã ãã«ã ãã£ã¬ã¯ããªããŒã¹ã® [NUMAã®ãã£ã¬ã¯ããª-ããŒããããŒã]ãã£ãã·ã¥äžè²«æ§ãµããŒããããã³ã«ã䜿çšããŸãã
MESIç¶æ å³
å³åŽã®å³ã®é·ç§»ã«ã¯ã次ã®æå³ããããŸãã
- é·ç§»aïŒM-> EïŒ ïŒãã£ãã·ã¥ã©ã€ã³ã¯ã¡ã¢ãªã«æžãæ»ãããŸãããCPUã¯ãã£ãã·ã¥ã«æ®ããå€æŽããæš©å©ãæã£ãŠããŸãã ãã®ç§»è¡ã«ã¯ããã©ã€ãããã¯ãã¡ãã»ãŒãžãå¿ èŠã§ãã
- 移è¡bïŒE-> MïŒ ïŒCPUã¯ãã£ãã·ã¥ã©ã€ã³ã«æžã蟌ã¿ãŸãããã£ãã·ã¥ã©ã€ã³ã«ã¯æä»çã¢ã¯ã»ã¹ããããŸãã ãã®ç§»è¡ã«ã¯ã¡ãã»ãŒãžã¯å¿ èŠãããŸããã
- é·ç§»cïŒM-> IïŒ ïŒCPUã¯ããå€æŽãç¶æ ã®ãèªã¿åãç¡å¹åããã£ãã·ã¥ã©ã€ã³ã¡ãã»ãŒãžãåä¿¡ããŸãã CPUã¯ãã®ããŒã«ã«ã³ããŒãåé€ãããèªã¿åãå¿çãããã³ãç¡å¹å確èªãã¡ãã»ãŒãžã§å¿çããå¿ èŠããããŸãã ãããã£ãŠãCPUã¯ããŒã¿ãéä¿¡ããèªå® ã«ããŒã¿ã®ã³ããŒããªãããšã瀺ããŸã
- 移è¡dïŒI-> MïŒ ïŒCPUã¯ããã£ãã·ã¥ã«ãªãããŒã¿ã«å¯ŸããŠèªã¿åã-å€æŽ-æžã蟌ã¿ïŒRMWïŒæäœãå®è¡ããŸãã ãèªã¿åãç¡å¹åãä¿¡å·ãéä¿¡ãããèªã¿åãå¿çãã§ããŒã¿ãåä¿¡ããŸãã CPUã¯ããã¹ãŠã®ã確èªå¿çã®ç¡å¹åãå¿çãåä¿¡ããå Žåã«ã®ã¿ç§»è¡ãå®äºããŸãã
- é·ç§»eïŒS-> MïŒ ïŒCPUã¯ãèªã¿åãå°çšã§ãã£ãããŒã¿ã«å¯ŸããŠèªã¿åã-å€æŽ-æžã蟌ã¿ïŒRMWïŒæäœãå®è¡ããŸãã ãç¡å¹åãä¿¡å·ãéå§ãããç¡å¹å確èªãå¿çã®å®å šãªã»ãããåä¿¡ãããŸã§åŸ æ©ããå¿ èŠããããŸãã
- é·ç§»fïŒM-> SïŒ ïŒä»ã®ããã»ããµãŒãããŒã¿ãèªã¿åã£ãŠããããã®ããŒã¿ã¯CPUã®ãã£ãã·ã¥ã«ãããŸãã ãã®çµæãããŒã¿ã¯èªã¿åãå°çšã«ãªããã¡ã¢ãªãžã®æžã蟌ã¿ã«ã€ãªããå¯èœæ§ããããŸãã ãã®é·ç§»ã¯ãèªã¿åãä¿¡å·ã«ãã£ãŠããªã¬ãŒãããŸãã CPUã¯ãèŠæ±ãããããŒã¿ãå«ããèªã¿åãå¿çãã¡ãã»ãŒãžã§å¿çããŸãã
- é·ç§»gïŒE-> SïŒ ïŒä»ã®ããã»ããµãããŒã¿ãèªã¿èŸŒãã§ããããã®ããŒã¿ã¯CPUã®ãã£ãã·ã¥ã«ãããŸãã ããŒã¿ã¯å ±æããããããèªã¿åãå°çšã«ãªããŸãã é·ç§»ã¯ããèªã¿åããä¿¡å·ãåä¿¡ããããšã«ããéå§ãããŸãã CPUã¯ãèŠæ±ãããããŒã¿ãå«ããèªã¿åãå¿çãã¡ãã»ãŒãžã§å¿çããŸãã
- é·ç§»hïŒS-> EïŒ ïŒCPUã¯ããã£ãã·ã¥ã©ã€ã³ã«ããŒã¿ãæžã蟌ãå¿ èŠããããšå€æãããç¡å¹åãã¡ãã»ãŒãžãéä¿¡ããŸãã CPUããç¡å¹å確èªå¿çãã®å®å šãªã»ãããåä¿¡ãããŸã§ã移è¡ã¯å®äºããŸããã ä»ã®CPUã¯ããã©ã€ãããã¯ãã¡ãã»ãŒãžã䜿çšããŠãã£ãã·ã¥ãããã£ãã·ã¥ã©ã€ã³ãã¹ããŒããããããã®ããŒã¿ããã£ãã·ã¥ããã®ã¯CPUã ãã«ãªããŸãã
- é·ç§»iïŒE-> IïŒ ïŒå¥ã®CPUãCPUãææããããŒã¿ã«å¯ŸããŠRMWæäœãå®è¡ããããã»ããµããã£ãã·ã¥ã©ã€ã³ãç¡å¹ã«ããããã«ããŸãã é·ç§»ã¯ãread invalidateããšããã¡ãã»ãŒãžã§å§ãŸããCPUã¯ãread responseãããã³ãinvalidate acknowledgeããšããã¡ãã»ãŒãžã§å¿çããŸãã
- é·ç§»jïŒI-> EïŒ ïŒCPUã¯ããŒã¿ãæ°ãããã£ãã·ã¥ã©ã€ã³ã«ä¿åãããèªã¿åãç¡å¹åãã¡ãã»ãŒãžãéä¿¡ããŸãã CPUã¯ããèªã¿åãå¿çããšãç¡å¹å確èªå¿çãã®å®å šãªã»ãããåä¿¡ãããŸã§ã移è¡ãå®äºã§ããŸããã èšé²ãå®äºãããšããã«ããã£ãã·ã¥ã©ã€ã³ã¯é·ç§»ïŒbïŒã«ãããå€æŽãç¶æ ã«ãªããŸã
- é·ç§»kïŒI-> SïŒ ïŒCPUã¯ããŒã¿ãæ°ãããã£ãã·ã¥ã©ã€ã³ã«ããŒãããŸãã CPUã¯ãèªã¿åããã¡ãã»ãŒãžãéä¿¡ãããèªã¿åãå¿çããåä¿¡ããããšã§é·ç§»ãå®äºããŸã
- é·ç§»lïŒS-> IïŒ ïŒå¥ã®CPUãããŒã¿ããã£ãã·ã¥ã©ã€ã³ã«æ ŒçŽããŸãããã£ãã·ã¥ã©ã€ã³ã¯èªã¿åãå°çšã¹ããŒã¿ã¹ã§ããããã¯ã3çªç®ã®CPUïŒãŸãã¯ãããšãã°ç§ãã¡ã®ãã®ïŒãããŒã¿ãå ±æããããã§ãã 移è¡ã¯ãç¡å¹åããåãå ¥ããããšããå§ãŸããCPUã¯ãç¡å¹å確èªãã§å¿çããŸã
質çå¿ç
éã¯ãè€æ°ã®é
延ãå¿
èŠãšãããã®ãããªéãé·ç§»ãã©ã®ããã«åŠçããŸããïŒ
éåžžãè¿œå ã®ç¶æ ãå°å ¥ããŸãã ãã ãããã®ãããªç¶æ ã¯ãã£ãã·ã¥ã©ã€ã³ã«ä¿åããå¿ èŠã¯ãããŸãããã€ãŸãããã£ãã·ã¥ã©ã€ã³ç¶æ ã§ã¯ãããŸããã åæç¹ã§ãé·ç§»ç¶æ ã«ã§ããã®ã¯å°æ°ã®ãã£ãã·ã¥ã©ã€ã³ã®ã¿ã§ãã ããã§èª¬æããç°¡ç¥åãããMESIãããå®éã®ãã£ãã·ã¥ã³ããŒã¬ã³ã·ãµããŒããããã³ã«ãã¯ããã«è€éã«ããã®ã¯ãæéçã«åæ£ããéãé·ç§»ã®ååšã§ãã
éåžžãè¿œå ã®ç¶æ ãå°å ¥ããŸãã ãã ãããã®ãããªç¶æ ã¯ãã£ãã·ã¥ã©ã€ã³ã«ä¿åããå¿ èŠã¯ãããŸãããã€ãŸãããã£ãã·ã¥ã©ã€ã³ç¶æ ã§ã¯ãããŸããã åæç¹ã§ãé·ç§»ç¶æ ã«ã§ããã®ã¯å°æ°ã®ãã£ãã·ã¥ã©ã€ã³ã®ã¿ã§ãã ããã§èª¬æããç°¡ç¥åãããMESIãããå®éã®ãã£ãã·ã¥ã³ããŒã¬ã³ã·ãµããŒããããã³ã«ãã¯ããã«è€éã«ããã®ã¯ãæéçã«åæ£ããéãé·ç§»ã®ååšã§ãã
MESIãããã³ã«ã®äŸ
MESIããã£ãã·ã¥ã©ã€ã³ã«é¢ããŠã©ã®ããã«æ©èœãããããã¡ã¢ãªããã£ãã·ã¥ã«çŽæ¥ãããã³ã°ãã4ããã»ããµã·ã¹ãã ã®äŸã䜿çšããŠèŠãŠã¿ãŸãããã ããŒã¿ã¯ã¡ã¢ãªã®ã¢ãã¬ã¹0ã«ãããŸãã次ã®è¡šã«ãããŒã¿ã®å€æŽã瀺ããŸãã æåã®åã¯æäœã®ã·ãªã¢ã«çªå·ã2çªç®ã¯æäœãå®è¡ããããã»ããµãŒã®çªå·ã3çªç®ã¯æäœã次ã®4åã¯åCPUã®ãã£ãã·ã¥ã©ã€ã³ã®ã¹ããŒã¿ã¹ïŒã¡ã¢ãªã¢ãã¬ã¹/ç¶æ ã®åœ¢åŒïŒãæåŸã®2åã¯ã¡ã¢ãªã«æ£ããããŒã¿ãå«ãŸããŠããïŒVïŒãŸãã¯ãªãïŒIïŒã
ãŸããCPUã®ãã£ãã·ã¥ã©ã€ã³ããç¡å¹ãç¶æ ã«ãããã¡ã¢ãªã«æ£ããããŒã¿ãå«ãŸããŠããŸãã CPU 0ãã¢ãã¬ã¹0ã®ããŒã¿ãèªã¿åããšãCPU 0ã®ãã£ãã·ã¥ã©ã€ã³ã¯ãå ±æãç¶æ ã«ãªããã¡ã¢ãªãšäžèŽããŸãã CPU 3ã¯ã¢ãã¬ã¹0ã®ããŒã¿ãèªã¿åãããããã£ãã·ã¥ã©ã€ã³ã¯äž¡æ¹ã®CPUã®ãã£ãã·ã¥ã§ãå ±æãç¶æ ã«ãªããŸãããããã§ãã¡ã¢ãªãšæŽåããŠããŸãã 次ã«ãCPU 0ã¯ã¢ãã¬ã¹8ã®ããŒã¿ãããŒãããŸããããã«ããããã£ãã·ã¥ã©ã€ã³ãæ··ã¿åããæ°ããããŒã¿ãè¿œå ãããŸãïŒã¢ãã¬ã¹8ã§èªã¿åãããŸãïŒã 次ã«ãCPU 2ã¯ã¢ãã¬ââã¹0ã®ããŒã¿ãèªã¿åããŸãããããŒã¿ãæžã蟌ãå¿ èŠãããããšãèªèãïŒRMWæäœïŒããèªã¿åãç¡å¹åãä¿¡å·ã䜿çšããŠããŒã¿ã®æä»ã³ããŒãããããšã確èªããŸãã ãread invalidateãä¿¡å·ã¯ãCPU 3ã®ãã£ãã·ã¥ã©ã€ã³ãç¡å¹ã«ããŸãïŒãã ãããã®ããŒã¿ã¯ã¡ã¢ãªãšäžè²«æ§ããããŸãïŒã 次ã«ãCPU 2ã¯æžã蟌ã¿ãè¡ããŸãããããã¯RMWæäœã®äžéšã§ããããã£ãã·ã¥ã©ã€ã³ããå€æŽæžã¿ãç¶æ ã«ããŸãã ã¡ã¢ãªå ã®ããŒã¿ã¯å»æ¢ãããŸããã CPU 1ã¯ã¢ãããã¯ã€ã³ã¯ãªã¡ã³ããå®è¡ããèªã¿åãç¡å¹åä¿¡å·ã䜿çšããŠããŒã¿ãåä¿¡ããŸãã CPU 2ãã£ãã·ã¥ããããŒã¿ãåä¿¡ããCPU 2èªäœã§ã¯ããŒã¿ãç¡å¹ã«ãªããŸãã ãã®çµæãCPU 1ã®ãã£ãã·ã¥ã©ã€ã³ã®ããŒã¿ã¯ãå€æŽãç¶æ ã«ããããŸã ã¡ã¢ãªãšæŽåããŠããŸããã æåŸã«ãCPU 1ã¯ã¢ãã¬ã¹8ã®ããŒã¿ãèªã¿åãããã£ãã·ã¥ã©ã€ã³ãã¡ã¢ãªã«ãã©ãã·ã¥ããŸãïŒãã©ã€ãããã¯ãã¡ãã»ãŒãžã䜿çšïŒã
ã質åãšåçã
ãµã³ãã«ãåæ¢ãããšãããã£ãã·ã¥ã«ã¯ããã€ãã®ããŒã¿ãå«ãŸããŠããŸãã ãŸãããã¹ãŠã®CPUã®ãã£ãã·ã¥ã©ã€ã³ããç¡å¹åãç¶æ
ã«ããããã®äžé£ã®æäœã¯ã©ãã§ããããã
CPUãç¹å¥ãªãã£ãã·ã¥ãªã»ããåœä»€ïŒããã£ãã·ã¥ããã©ãã·ã¥ãïŒããµããŒãããªãéãããã®ãããªã·ãŒã±ã³ã¹ã¯ååšããŸããã ã»ãšãã©ã®ããã»ããµã«ã¯ãã®åœä»€ããããŸãã
CPUãç¹å¥ãªãã£ãã·ã¥ãªã»ããåœä»€ïŒããã£ãã·ã¥ããã©ãã·ã¥ãïŒããµããŒãããªãéãããã®ãããªã·ãŒã±ã³ã¹ã¯ååšããŸããã ã»ãšãã©ã®ããã»ããµã«ã¯ãã®åœä»€ããããŸãã
äžèŠãªé²é³ããŠã³ã¿ã€ã
åã«ç¢ºèªãããã£ãã·ã¥æ§é ã¯ããã®ããŒã¿ãææããCPUã«å¯ŸããŠåªããèªã¿åã/æžã蟌ã¿ããã©ãŒãã³ã¹ãæäŸããŸãããç¹å®ã®ãã£ãã·ã¥ã©ã€ã³ãžã®æåã®æžã蟌ã¿ã®ããã©ãŒãã³ã¹ã¯éåžžã«äœããªããŸãã ããã確èªããã«ã¯ãå³ã®å³ãæ€èšããŠãã ããã
ãã®å³ã¯ãCPU 1ã®ãã£ãã·ã¥ã«ãããã£ãã·ã¥ã©ã€ã³ã®ããã»ããµ0ã«ããæžã蟌ã¿é 延ã瀺ããŠããŸããCPU0ã¯ããã£ãã·ã¥ã©ã€ã³ãæžã蟌ã¿å¯èœã«ãªããŸã§ããªãé·ãæéåŸ æ©ããå¿ èŠããããŸãããã£ãã·ã¥1ããCPU 0ã«ç§»è¡ããŸãããã£ãã·ã¥ã©ã€ã³ã1ã€ã®CPUããå¥ã®CPUã«è»¢éããŸããéåžžãã¬ãžã¹ã¿ãæäœããåœä»€ã®æéãããæ¡éãã«é·ããªããŸãã
ãã ããCPU 0ã®å Žåãããã»ã©é·ãåŸ ã€å¿ èŠã¯ãããŸãããCPU1ããéä¿¡ãããããŒã¿ã«é¢ä¿ãªããCPU 0ã¯ãããã確å®ã«äžæžãããŸãã
ãããã¡ãä¿åãã
äžèŠãªããŠã³ã¿ã€ã ã«å¯ŸåŠãã1ã€ã®æ¹æ³ã¯ãå³ã®å³ã«ç€ºãããã«ãåCPUãšãã®ãã£ãã·ã¥ã®éã«ã¹ãã¢ãããã¡ãŒãè¿œå ããããšã§ãã ãã®ãããªãããã¡ãŒã䜿çšãããšãCPU 0ã¯åçŽã«æžã蟌ã¿æäœãã¹ãã¢ãããã¡ãŒã«æžã蟌ã¿ãäœæ¥ãç¶è¡ã§ããŸãã å¿ èŠãªã¡ãã»ãŒãžã³ã°ã®åŸããã£ãã·ã¥ã©ã€ã³ãæçµçã«CPU 1ããCPU 0ã«ç§»åãããšãããŒã¿ã¯ã¹ãã¢ãããã¡ãŒããããã»ããµ0ã®ãã£ãã·ã¥ã©ã€ã³ã«ç§»åã§ããŸãã
ãã ãããã®ãããªãœãªã¥ãŒã·ã§ã³ã¯è¿œå ã®åé¡ã«ã€ãªãããŸããããã«ã€ããŠã¯ã次ã®2ã€ã®ã»ã¯ã·ã§ã³ã§æ€èšããŸãã
ã¹ãã¢è»¢é
èªå·±æŽåæ§ãšåŒã°ããæåã®åé¡ã確èªããã«ã¯ã次ã®ã³ãŒããæ€èšããŠãã ããã
1 a = 1; 2 b = a + 1; 3 assert( b == 2 );
å€æ°ãaããšãbãã®åæå€ã¯0ã§ããå€æ°ãaãã¯ããã»ããµ1ã®ãã£ãã·ã¥ã«ãããå€æ°ãbãã¯ããã»ããµ0ã®ãã£ãã·ã¥ã«ãããŸãã
ã©ããã£ãããã
assert
æ©èœããã®ã§ããããïŒ ãã ãã瀺ãããŠããã¢ãŒããã¯ãã£ã®ããã»ããµã誰ããå®è£ ããå Žåã圌ã¯é©ããã§ãããã ãã®ãããªã·ã¹ãã ã§ã¯ã次ã®äžé£ã®ã€ãã³ããçºçããå¯èœæ§ããããŸãã
- 1. CPU 0ã¯
a = 1
å®è¡ãéå§ããŸã - 2. CPU 0ã¯ããã£ãã·ã¥ã«ãaãããããã©ããã確èªããããã§ãªããã®ã確èªããŸãã
- 3.ãããã£ãŠãCPU 0ã¯ããaãã§ãã£ãã·ã¥ã©ã€ã³ã®æä»çæš©å©ãååŸããããã«ããèªã¿åãç¡å¹åãä¿¡å·ãéä¿¡ããŸãã
- 4. CPU 0ãã¹ãã¢ãããã¡ã«ãaããæžã蟌ã
- ã CPU 1ã¯ãèªã¿åãç¡å¹åãã¡ãã»ãŒãžãåä¿¡ãããaããããã£ãã·ã¥ã©ã€ã³ãéä¿¡ãããã®ãã£ãã·ã¥ã©ã€ã³ãåé€ïŒç¡å¹åïŒããããšã§å¿çããŸãã
- 6. CPU 0ã¯
b = a + 1
å®è¡ãéå§ããŸã - 7. CPU 0ã¯CPU 1ããå¿çãåä¿¡ããŸããããã«ã¯ãå€ããŒãã® ãaãå€ãå«ãŸããŠããããã®è¡ããã£ãã·ã¥ã«å ¥ããŸã
- 8. CPU 0ã¯ãã£ãã·ã¥ãããaããããŒãããŸã- å€ãŒããããŒããããŸã
- 9. CPU 0ã¯ãã¹ãã¢ãããã¡ã«ä¿åããããã£ãã·ã¥ã«æžã蟌ãèŠæ±ãå®è¡ããå€ãaã= 1ããã£ãã·ã¥ã©ã€ã³ã«æžã蟌ã¿ãŸã
- 10. CPU 0ã¯1ããŒãã«å ç®ãã以åã«ãaããšããŠèªã¿åããçµæããã£ãã·ã¥ã©ã€ã³ãbãã«ä¿åããŸãïŒããã¯æãåºãããã«ãCPU 0ãææããŠããŸãïŒ
- 11. CPU 0ã¯
assert(b == 2)
å®è¡assert(b == 2)
ããšã©ãŒãã¹ããŒããŸã-assert
ããªã¬ãŒãããŸã
åé¡ã¯ããaãã®ã³ããŒã2ã€ããããšã§ãã1ã€ã¯ãã£ãã·ã¥ã«ããã1ã€ã¯ã¹ãã¢ãããã¡ãŒã«ãããŸãã
ãã®äŸã¯éåžžã«éèŠãªä¿èšŒã«éåããŸã ã åCPUã¯åžžã«ããã°ã©ã ã§æå®ãããé åº ïŒããããããã°ã©ã é åº ïŒã§æäœãå®è¡ããå¿ èŠããããŸã ã ããã°ã©ãã«ãšã£ãŠããã®ä¿èšŒã¯çŽæçãªèŠä»¶ã§ãããããããŒããŠã§ã¢ãšã³ãžãã¢ã¯ã¹ãã¢è»¢éãå®è£ ããå¿ èŠããããŸãããåCPUã¯ããã£ãã·ã¥ããã ãã§ãªããã¹ãã¢ãããã¡ãããããŒã¿ãèªã¿åããŸãã ã€ãŸããåæžã蟌ã¿æäœã¯ããã£ãã·ã¥ã«ã¢ã¯ã»ã¹ããããšãªããã¹ãã¢ãããã¡ãŒãä»ããŠæ¬¡ã®èªã¿åãæäœã«çŽæ¥è»¢éã§ããŸãã
ã¹ãã¢è»¢éã§ã¯ãäžèšã®äŸã®ã¹ããã8ã¯ãã¹ãã¢ãããã¡ããå€æ°ãaãã®æ£ããå€1ãèªã¿åãå¿ èŠããããŸãã ãã®çµæããbãã®å€ã¯2ã«ãªããŸããããã¯å¿ èŠãªãã®ã§ãã
æžã蟌ã¿ãããã¡ãšã¡ã¢ãªããªã¢
ã°ããŒãã«ã¡ã¢ãªã®é åºã®éåãšããå¥ã®åé¡ã確èªããã«ã¯ãå€æ°ãaããšãbãã®åæå€ã0ã§ãã次ã®äŸãèããŠãã ããã
1 void foo() 2 { 3 a = 1; 4 b = 1; 5 } 6 7 void bar() 8 { 9 while ( b == 0 ) continue; 10 assert( a == 1 ); 11 }
CPU 0ã
foo()
ãCPU 1ã
bar()
å®è¡ã
bar()
ã ãaããå«ãã¡ã¢ãªãCPU 1ã®ãã£ãã·ã¥ã®ã¿ã«ãããCPU 0ããbããå«ãã¡ã¢ãªãææããŠãããšããŸãã ãã®åŸã次ã®äžé£ã®ã¢ã¯ã·ã§ã³ãå¯èœã§ãã
- 1. CPU 0ã¯
a=1
å®è¡a=1
ãŸãã ãaãã®ãã£ãã·ã¥ã©ã€ã³ã¯CPU 0ã®ãã£ãã·ã¥ã«ãªããããCPU 0ã¯æ°ããå€ãaããæžã蟌ã¿ãããã¡ã«é 眮ãããèªã¿åãç¡å¹åãä¿¡å·ãçºä¿¡ããŸãã - 2. CPU 1ã¯
while (b==0) continue
ã§å®è¡while (b==0) continue
ãŸããããbãã¯ãã£ãã·ã¥ã«ãªãããããreadãã¡ãã»ãŒãžãéä¿¡ããŸã - 3. CPU 0ã¯
b = 1
å®è¡ããŸãã 圌ã¯ãã§ã«ãã£ãã·ã¥ã«ãbããææããŠããŸããã€ãŸãã察å¿ãããã£ãã·ã¥ã©ã€ã³ã¯ãæä»çããŸãã¯ãå€æŽãç¶æ ã«ããããã誰ã«ãèšããã«æ°ãããbãå€ããã£ãã·ã¥ã«ä¿åãããã¹ãŠã®æš©å©ããããŸãã - 4. CPU 0ã¯ã¡ãã»ãŒãžãreadããåä¿¡ããå¿çã§ææ°ã®å€ãbããå«ããã£ãã·ã¥ã©ã€ã³ãéä¿¡ããåæã«ãã®ã©ã€ã³ããã£ãã·ã¥å ã®ãå ±æãç¶æ ã«è»¢éããŸãã
- 5. CPU 1ã¯ããbãã®ãã£ãã·ã¥ã©ã€ã³ãåä¿¡ãããã£ãã·ã¥ã«å ¥ããŸã
- 6. CPU 1ã¯ã
b == 1
ã§ããããšããããã®ã§ãwhile (b == 0) continue
å®äºãã次ã®åœä»€ã«é²ãããšãã§ããŸãã - 7. CPU 1ã¯
assert(a == 1)
å®è¡assert(a == 1)
ãŸãã CPU 1ã¯å€ãå€ãaãã§åäœãããããæ¡ä»¶ã¯æºããããªã - 8. CPU 1ã¯ãread invalidateããšããã¡ãã»ãŒãžãåä¿¡ãããaãCPU 0ã®ãã£ãã·ã¥ã©ã€ã³ãéä¿¡ãããšåæã«ããã£ãã·ã¥å ã®ãã®ã©ã€ã³ãç¡å¹ã«ããŸãã é ããã
- 9. CPU 0ã¯ããaãã®ãã£ãã·ã¥ã©ã€ã³ãåä¿¡ãããããã¡ãŒããæžã蟌ã¿ãŸãïŒã¹ãã¢ãããã¡ãŒããã£ãã·ã¥ã«ãã©ãã·ã¥ããŸãïŒã
質çå¿ç
ã¹ããã1ã®CPU 0ããç¡å¹åãã ãã§ãªããç¡å¹åã®èªã¿åãããšããã¡ãã»ãŒãžãéä¿¡ããã®ã¯ãªãã§ããïŒ
ãã£ãã·ã¥ã©ã€ã³ã«ã¯å€æ°ãaãã®å€ã ããå«ãŸããŠããããã§ã¯ãªãããã§ãã ãã£ãã·ã¥ã©ã€ã³ãµã€ãºã¯éåžžã«å€§ããã§ãã
ãã£ãã·ã¥ã©ã€ã³ã«ã¯å€æ°ãaãã®å€ã ããå«ãŸããŠããããã§ã¯ãªãããã§ãã ãã£ãã·ã¥ã©ã€ã³ãµã€ãºã¯éåžžã«å€§ããã§ãã
ããã»ããµã¯ããã°ã©ã å ã®å€æ°ã®é¢ä¿ã«ã€ããŠäœãç¥ããªããããããŒããŠã§ã¢ãšã³ãžãã¢ã¯ãã®å Žåã«æ¯æŽã§ããŸããã ãã®ããããšã³ãžãã¢ã¯ãããã°ã©ããŒãããã°ã©ã ã§åæ§ã®ããŒã¿é¢ä¿ãè¡šçŸã§ããã¡ã¢ãªããªã¢åœä»€ãå°å ¥ããŸããã ããã°ã©ã ã®æçã¯æ¬¡ã®ããã«å€æŽããå¿ èŠããããŸãã
1 void foo() 2 { 3 a = 1; 4 smp_mb(); 5 b =1; 6 } 7 8 void bar() 9 { 10 while ( b == 0 ) continue; 11 assert( a == 1 ); 12 }
ã¡ã¢ãªããªã¢
smp_mb()
[ããã¯Linuxã«ãŒãã«ã®å®éã®æ©èœ]ã¯ã次ã®ãã£ãã·ã¥ãšã³ããªãäœæããåã«ã¹ãã¢ãããã¡ããªã»ããããããã«ããã»ããµã«æ瀺ããŸãã CPUã¯ãã¹ãã¢ãããã¡ã空ã«ãªãã®ãåŸ ã€ã®ããããããã¹ãã¢ãããã¡å ã®ãã¹ãŠã®ãšã³ããªãå®äºãããŸã§ã¹ãã¢ãããã¡ãåŸç¶ã®ãšã³ããªã«äœ¿çšã§ããŸã[ãããã£ãŠãFIFOã®äžéšãã¹ãã¢ãããã¡ã«é 眮ãããŸã] ã
ããã°ã©ã ããªã¢ã·ãŒã±ã³ã¹
- 1. CPU 0ã¯
a=1
å®è¡a=1
ãŸãã ãaãã®ãã£ãã·ã¥ã©ã€ã³ã¯CPU 0ã®ãã£ãã·ã¥ã«ãªããããCPU 0ã¯æ°ããå€ãaããæžã蟌ã¿ãããã¡ã«é 眮ãããèªã¿åãç¡å¹åãä¿¡å·ãçºä¿¡ããŸãã - 2. CPU 1ã¯
while (b==0) continue
ã§å®è¡while (b==0) continue
ãŸããããbãã¯ãã£ãã·ã¥ã«ãªãããããreadãã¡ãã»ãŒãžãéä¿¡ããŸã - 3. CPU 0ã¯
smp_mb()
ãå®è¡ããã¹ãã¢ãããã¡ãŒå ã®ãã¹ãŠã®ã¢ã€ãã ïŒa = 1
ãå«ãsmp_mb()
ãããŒã¯ïŒããŒã¯ïŒããŸãã - 4. CPU 0ã¯
b = 1
å®è¡ããŸãã 圌ã¯ãã§ã«ãbããææããŠããŸãïŒã€ãŸãã察å¿ãããã£ãã·ã¥ã©ã€ã³ã¯ãå€æŽæžã¿ããŸãã¯ãæä»çãç¶æ ã§ãïŒããæžã蟌ã¿ãããã¡ã«ã¯ããŒã¯ãããèŠçŽ ããããŸãã ãããã£ãŠãæ°ããå€ãbãããã£ãã·ã¥ã«æžã蟌ã代ããã«ãæžã蟌ã¿ãããã¡ã«ãbããé 眮ããŸããã ããŒã¯ãããŠããªãèŠçŽ ãšã㊠- 5. CPU 0ã¯ãèªã¿åããã¡ãã»ãŒãžãåä¿¡ããåæå€ãbãïŒ= 0ïŒã®ãã£ãã·ã¥ã©ã€ã³ãããã»ããµ1ã«æž¡ããŸãããŸãããã£ãã·ã¥ã©ã€ã³ã®ç¶æ ããå ±æãã«å€æŽããŸãã
- 6. CPU 1ã¯ãbãã®ãã£ãã·ã¥ã©ã€ã³ãåä¿¡ãããã£ãã·ã¥ã«å ¥ããŸã
- 7. CPU 1ã¯
while (b == 0) continue
å®äºããå¯èœæ§ããããŸãããb=0
ã§ããããšãããããããã«ãŒããç¶è¡ããå¿ èŠããããŸãã æ°ããå€ãbãã¯ãCPU 0ã®æžã蟌ã¿ãããã¡ã«ãŸã é ãããŠããŸã - 8. CPU 1ã¯ãread invalidateããšããã¡ãã»ãŒãžãåä¿¡ãããã£ãã·ã¥ã©ã€ã³ããaãããããã»ããµ0ã«æž¡ãããã®ãã£ãã·ã¥ã©ã€ã³ãç¡å¹ã«ããŸãã
- 9. CPU 0ã¯ããaãã®ãã£ãã·ã¥ã©ã€ã³ãåä¿¡ãã以åã«ãããã¡ãªã³ã°ãããã¬ã³ãŒããå®è¡ãããã®ãã£ãã·ã¥ã©ã€ã³ããaããããå€æŽãç¶æ ã«å€æŽããŸãã
- 10.ãšã³ããªãaãã
smp_mb()
åŒã³åºãã§ããŒã¯ãããå¯äžã®èŠçŽ ã§ãããããCPU 0ã¯ãbããæžã蟌ãããšãã§ããŸããããbãã®ãã£ãã·ã¥ã©ã€ã³ã¯ãå ±æãç¶æ ã§ãã - 11.ãããã£ãŠãCPU 0ã¯ãç¡å¹åãã¡ãã»ãŒãžãããã»ããµ1ã«éä¿¡ããŸã
- 12. CPU 1ã¯ãç¡å¹åãä¿¡å·ãåä¿¡ãããã£ãã·ã¥ã«ãbããå«ããã£ãã·ã¥ã©ã€ã³ãç¡å¹åããããã»ããµ0ã«ã確èªå¿çãä¿¡å·ãéä¿¡ããŸãã
- 13. CPU 1ã¯
while (b == 0) continue
å®è¡ãããŸããããbãã®ãã£ãã·ã¥ã©ã€ã³ã¯ãã£ãã·ã¥ã«ãªãããããreadãã¡ãã»ãŒãžãããã»ããµ0ã«éä¿¡ããŸã - 14. CPU 0ã¯ã確èªå¿çãã¡ãã»ãŒãžãåä¿¡ãããã£ãã·ã¥ã©ã€ã³ããbããããæä»çãç¶æ ã«ãããbãããã£ãã·ã¥ã«ä¿åããŸãã
- 15. CPU 0ã¯ãèªã¿åããä¿¡å·ãåä¿¡ãããã£ãã·ã¥ã©ã€ã³ããbãããããã»ããµ1ã«æž¡ããŸããéäžã§ããbãããã®ãã£ãã·ã¥ã©ã€ã³ã¯ãå ±æãç¶æ ã«ãªããŸãã
- 16. CPU 1ã¯ããbãã®ãã£ãã·ã¥ã©ã€ã³ãåä¿¡ãããã£ãã·ã¥ã«æžã蟌ã¿ãŸã
- 17. CPU 1ã¯
while (b == 0) continue
ããã³ç¶ç¶while (b == 0) continue
å®äºããããšãã§ããŸãã - 18. CPU 1ã¯
assert(a == 1)
å®è¡assert(a == 1)
ãŸããããaãã®ãã£ãã·ã¥ã©ã€ã³ã¯ãã£ãã·ã¥ã«ãããŸããã CPU 0ããå€ãaããåãåããšããã«ãå®è¡ãç¶ç¶ã§ããŸãã å€ãaãã¯ææ°ã®ãã®ã§ãããassert
ã¯æ©èœããŸãã
ã芧ã®ãšãããçŽæçã«ã·ã³ãã«ãªããšã§ããã·ãªã³ã³ã®å€ãã®è€éãªã¹ãããã«ã€ãªãããŸãã
èšé²ã·ãŒã±ã³ã¹ã§ã®äžèŠãªããŠã³ã¿ã€ã
æ®å¿µãªãããåæžã蟌ã¿ãããã¡ã¯æ¯èŒçå°ããããå¿ èŠããããŸãã ããã¯ãCPUã倧éã®ã¬ã³ãŒããå®è¡ãããšãã¹ãã¢ãããã¡ãå®å šã«ãã£ã±ãã«ãªãããšãæå³ããŸãïŒããšãã°ãåã¬ã³ãŒãããã¹ã«ã€ãªããå ŽåïŒã ãã®å ŽåãCPUã¯ãã¹ãŠã®ç¡å¹åãå®äºãããŸã§åŸ æ©ããå¿ èŠããããããCPUã¯ãããã¡ãŒããã£ãã·ã¥ã«ãã©ãã·ã¥ããŠå®è¡ãç¶ç¶ã§ããŸãã ãããã®ã¬ã³ãŒãããã£ãã·ã¥ãã¹ã«ã€ãªãããã©ããã«é¢ä¿ãªããåŸç¶ã®ãã¹ãŠã®æžã蟌ã¿åœä»€ãç¡å¹åã®å®äºãåŸ æ©ããå¿ èŠãããå Žåãã¡ã¢ãªããªã¢ã®çŽåŸã«åãç¶æ³ãçºçããå¯èœæ§ããããŸãã
ãã®ç¶æ³ã¯ãã確èªå¿çã®ç¡å¹åãã¡ãã»ãŒãžã®åŠçãé«éã«ãªãã°è§£æ±ºã§ããŸãã ãããå®çŸãã1ã€ã®æ¹æ³ã¯ãåCPUã«å¯ŸããŠãç¡å¹åãã¡ãã»ãŒãžãã¥ãŒãŸãã¯ç¡å¹åãã¥ãŒãå ¥åããããšã§ãã
ãã¥ãŒãç¡å¹ã«ãã
確èªå¿çã¡ãã»ãŒãžã®ç¡å¹åãéåžžã«é ãçç±ã®1ã€ã¯ã察å¿ãããã£ãã·ã¥ã©ã€ã³ãå®éã«ç¡å¹ã§ããããšãCPUã確èªããå¿ èŠãããããã§ãã ãã®ãããªç¡å¹åã¯ããã£ãã·ã¥ãããžãŒã®å Žåãããšãã°ããã»ããµããã£ãã·ã¥å ã®ãã¹ãŠã®ããŒã¿ãéäžçã«èªã¿æžãããå Žåãéåžžã«é·ããªãå¯èœæ§ããããŸãã ããã«ãçæéã§ç¡å¹åã¡ãã»ãŒãžã®ã¹ããªãŒã å šäœãååšããCPUããããã«å¯ŸåŠã§ããªãå Žåããããæ®ãã®CPUã®ããŠã³ã¿ã€ã ã«ã€ãªãããŸãã
ãã ããCPUã¯ç¢ºèªãéä¿¡ããåã«ãã£ãã·ã¥ã©ã€ã³ãç¡å¹ã«ããå¿ èŠã¯ãããŸããã ãã¡ãããããã»ããµããã®ãã£ãã·ã¥ã©ã€ã³ã«é¢ããä»ã®ã¡ãã»ãŒãžãéä¿¡ããåã«ãã®ã¡ãã»ãŒãžãåŠçãããããšãå®å šã«ç解ããŠãç¡å¹åã¡ãã»ãŒãžããã¥ãŒã«å ¥ããããšãã§ããŸãã
ãã¥ãŒã®ç¡å¹åãšé害ã®ç¢ºèª
å³åŽã®å³ã¯ãç¡å¹åãã¥ãŒãæã€ã·ã¹ãã ã瀺ããŠããŸãã ç¡å¹åãã¥ãŒãåããããã»ããµã¯ããã£ãã·ã¥ã©ã€ã³ãç¡å¹ã«ãªãã®ãåŸ ã€ä»£ããã«ããã¥ãŒã«è¡šç€ºããããšããã«ç¡å¹åã¡ãã»ãŒãžã確èªã§ããŸãã ãã¡ãããCPUã¯ç¡å¹åã¡ãã»ãŒãžãéä¿¡ããæºåããããšãããã®ãã¥ãŒãšäžèŽããŠããå¿ èŠããããŸãããã¥ãŒã«ãã®ãã£ãã·ã¥ã©ã€ã³ã®ç¡å¹åã¬ã³ãŒããæ¢ã«å«ãŸããŠããå Žåãããã»ããµã¯ç¡å¹åã¡ãã»ãŒãžãããã«éä¿¡ã§ããŸããã 代ããã«ããã¥ãŒããã®å¯Ÿå¿ãããšã³ããªãåŠçããããŸã§åŸ æ©ããå¿ èŠããããŸãã
ç¡å¹åãã¥ãŒã«èŠçŽ ãé 眮ããããšã¯ãæ¬è³ªçã«ããã®ãã£ãã·ã¥ã©ã€ã³ã«é¢é£ããMESIãããã³ã«ä¿¡å·ãéä¿¡ããåã«ãã®ç¡å¹åã¡ãã»ãŒãžãåŠçããããšãããã»ããµããçŽæããããšã§ãã
ãã ããç¡å¹åä¿¡å·ã®ãããã¡ãªã³ã°ã¯ãã¡ã¢ãªæäœã®é åºãæ··ä¹±ãããè¿œå ã®æ©äŒã«ã€ãªãããŸããããã«ã€ããŠã¯ä»¥äžã§èª¬æããŸãã
ãã¥ãŒãšã¡ã¢ãªããªã¢ãç¡å¹ã«ãã
ããã»ããµãç¡å¹åãªã¯ãšã¹ãããã¥ãŒã«å ¥ããããã«å¿çãããšããŸãã ãã®ã¢ãããŒãã«ããããã£ãã·ã¥ã®ç¡å¹åé 延ã¯æå°éã«æããããŸãããã¡ã¢ãªããªã¢ãç Žãããšãã§ããŸããããã«ã€ããŠã¯ã次ã®äŸã§èª¬æããŸãã
å€æ°ãaããšãbãã¯æåã¯ãŒãã§ããaãã¯ãå ±æãç¶æ ïŒã€ãŸããèªã¿åãå°çšïŒã®äž¡æ¹ã®ããã»ããµã®ãã£ãã·ã¥ã«ããããbãã¯CPU 0ã«ææãããŠããŸãïŒã€ãŸãããã£ãã·ã¥ã©ã€ã³ã¯ç¶æ ã§ãïŒ ãæä»çããŸãã¯ãä¿®æ£ãã CPU 0ã
foo()
ãCPU 1ã
bar()
ã
bar()
ã
1 void foo() 2 { 3 a = 1; 4 smp_mb(); 5 b = 1; 6 } 7 8 void bar() 9 { 10 while (b == 0) continue; 11 assert(a == 1); 12 }
æäœã®é åºã¯æ¬¡ã®ãšããã§ãã
- 1. CPU 0ã¯
a=1
å®è¡a=1
ãŸãã 察å¿ãããã£ãã·ã¥ã©ã€ã³ã¯CPU 0ã®ãã£ãã·ã¥ã§ã¯èªã¿åãå°çšã§ãããããããã»ããµã¯æ°ããå€ãaããã¹ãã¢ãããã¡ã«å ¥ããã¡ãã»ãŒãžãinvalidateããéä¿¡ããŠãCPU 1ããã£ãã·ã¥ã©ã€ã³ããaãã§ãã©ãã·ã¥ããŸãã - 2. CPU 1ã¯
while(b == 0) continue
å®è¡ãããŸããããbãã¯ãã£ãã·ã¥ã«ãããŸããã ãããã£ãŠããèªã¿åããã¡ãã»ãŒãžãéä¿¡ããŸã - 3. CPU 1ã¯CPU 0ãããç¡å¹åããåä¿¡ããç¡å¹åãã¥ãŒã«æ ŒçŽããŠãããã«å¿çããŸã
- 4. CPU 0ã¯CPU 1ããå¿çãåä¿¡ããŸãããããã£ãŠã
smp_mb()
ïŒè¡4ïŒãèªç±ã«å®è¡ããæ°ããå€ãaããæžã蟌ã¿ãããã¡ãŒãããã£ãã·ã¥ã«å ¥ããŸãã - 5. CPU 0ã¯
b=1
å®è¡ããŸãã ãbãã®ãã£ãã·ã¥ã©ã€ã³ãæ¢ã«ææããŠãããããæ°ãããbãå€ããã£ãã·ã¥ã«ä¿åããã ãã§ãã - 6. CPU 0ã¯ãèªã¿åããä¿¡å·ãåä¿¡ããæ°ããå€ãbãã®ãã£ãã·ã¥ã©ã€ã³ãããã»ããµ1ã«éä¿¡ãããšåæã«ããã®ã©ã€ã³ããå ±æããšããŠããŒã¯ããŸãã
- 7. CPU 1ã¯ãbãã®ãã£ãã·ã¥ã©ã€ã³ãåä¿¡ãããã£ãã·ã¥ã«å ¥ããŸã
- 8.ããã§ãCPU 1ã¯
while(b == 0) continue
ãwhile(b == 0) continue
å®äºwhile(b == 0) continue
ãããã°ã©ã ã®æ¬¡ã®è¡ã«ç§»åã§ããŸãã - 9. CPU 1ã¯
assert(a == 1)
å®è¡assert(a == 1)
ãŸãã å€ãå€ãaãããã£ãã·ã¥ã«ãããããassert
çºçããŠäŸå€ãã¹ããŒããŸã - äŸå€ã«ãããããããCPU 1ã¯ãã¥ãŒã«é 眮ããããç¡å¹åãã¡ãã»ãŒãžãå®è¡ããé 延ããŠãã£ãã·ã¥ã©ã€ã³ãaããç¡å¹åããŸã
質çå¿ç
æé 1ã§éä¿¡ããããç¡å¹åã®èªã¿åããã§ã¯ãªããç¡å¹åã®èªã¿åãããéä¿¡ãããã®ã¯ãªãã§ããïŒ ããã»ããµã¯ãåããã£ãã·ã¥ã©ã€ã³ã«ããä»ã®å€ãæ¬åœã«å¿
èŠãšããŸããïŒ
CPU 0ã«ã¯ããããã®å€ããã¹ãŠãããŸãããããã®å€ã¯ããaããšãšãã«å ±æèªã¿åãå°çšãã£ãã·ã¥ã©ã€ã³ã«ããããã§ãã ãããã£ãŠãCPU 0ãå¿ èŠãšããã®ã¯ããã®ãã£ãã·ã¥ã©ã€ã³ã®ã³ããŒãç Žæ£ããå¿ èŠãããããšãä»ã®ããã»ããµã«éç¥ããããšã ãã§ãã ããã«ã¯ãç¡å¹åããšããã¡ãã»ãŒãžã§ååã§ãã
CPU 0ã«ã¯ããããã®å€ããã¹ãŠãããŸãããããã®å€ã¯ããaããšãšãã«å ±æèªã¿åãå°çšãã£ãã·ã¥ã©ã€ã³ã«ããããã§ãã ãããã£ãŠãCPU 0ãå¿ èŠãšããã®ã¯ããã®ãã£ãã·ã¥ã©ã€ã³ã®ã³ããŒãç Žæ£ããå¿ èŠãããããšãä»ã®ããã»ããµã«éç¥ããããšã ãã§ãã ããã«ã¯ãç¡å¹åããšããã¡ãã»ãŒãžã§ååã§ãã
ãããã£ãŠãé害ã«å¯Ÿããåå¿çãæ¹åããããšã¯ãã¡ã¢ãªããªã¢ãç¡èŠããããšã«ã€ãªããå Žåã«ã¯ã»ãšãã©åœ¹ã«ç«ã¡ãŸããã ãããã£ãŠãã¡ã¢ãªããªã¢ã¯ç¡å¹åãã¥ãŒãšå¯Ÿè©±ããå¿ èŠããããŸããããã»ããµãã¡ã¢ãªããªã¢ãå®è¡ãããšããç¡å¹åãã¥ãŒãå®å šã«åŠçããããŸã§ãããã»ããµã¯ç¡å¹åãã¥ãŒå ã®ãã¹ãŠã®èŠçŽ ãããŒã¯ãã以éã®ãã¹ãŠã®èªã¿åããé ãããå¿ èŠããããŸãã
èªã¿åããšæžã蟌ã¿ã®éå£
åã®ç« ã§ã¯ãã¡ã¢ãªããªã¢ã䜿çšããŠã¹ãã¢ãããã¡å ã®ã¢ã€ãã ãããŒã¯ãããã¥ãŒãç¡å¹ã«ããŸããã ãã ããæåŸã®äŸã§ã¯ã
foo()
ç¡å¹åãã¥ãŒ
foo()
ããåãããçç±ã¯ãããŸããïŒèªã¿åãããªãããïŒããŸãã
bar()
æžã蟌ã¿ãããã¡ãŒ
bar()
ããåãããçç±ããããŸããïŒã¬ã³ãŒãããªãããïŒã
å€ãã®ã¢ãŒããã¯ãã£ã¯ãèªã¿åãå°çšãŸãã¯æžã蟌ã¿å°çšã®æŽçãå¯èœã«ããããã匱ãïŒãããŠçµæãšããŠãããéãïŒã¡ã¢ãªããªã¢ãæäŸããŸãã 倧ãŸãã«èšããšãèªã¿åãã¡ã¢ãªããªã¢ã¯ç¡å¹åãã¥ãŒãšã®ã¿çžäºäœçšãïŒèŠçŽ ãããŒã¯ãã€ãŸããã¥ãŒã«äœããã®é åºãä»ããŸãïŒãæžã蟌ã¿ã¡ã¢ãªããªã¢ã¯ã¹ãã¢ãããã¡ãšã®ã¿çžäºäœçšããŸãïŒèŠçŽ ãããŒã¯ããé åºã埩å ããŸãïŒãããã¡å ïŒã å®å šãªéå£ãäž¡æ¹ãšçžäºäœçšããŸãã
ãããã®ããŒãããªã¢ã®å¹æã¯æ¬¡ã®ãšããã§ããèªã¿åãããªã¢ã®é åºã¯ãããªã¢ãå®è¡ããããã»ããµã®ã¿ãèªã¿åããŸãã ããªã¢ã®åã®ãã¹ãŠã®èªã¿åããå®å šã«å®äºããããªã¢ã®åŸã«èªã¿åããå®è¡ããå§ããŸãã åæ§ã«ãæžã蟌ã¿ããªã¢ã¯ãããã»ããµã®ã¹ãã¢ïŒã¹ãã¢ïŒã®ã¿ã泚æããŸããããªã¢ãå®äºããåã®ãã¹ãŠã®ã¬ã³ãŒããå®äºãããã®åŸãã¹ãã¢ïŒã¹ãã¢ïŒãããªã¢ã®åŸã«å®è¡ãéå§ããŸãã å®å šãªããªã¢ã¯èªã¿åããšæžã蟌ã¿ãæŽçããŸããããã®ããªã¢ãå®è¡ããããã»ããµã«å¯ŸããŠã®ã¿ã§ãã
foo
ãš
bar
ãèªã¿åã/æžã蟌ã¿ããªã¢ã䜿çšããããã«äŸãæŽæ°ãããšã次ã®ããã«ãªããŸãïŒ
1 void foo() 2 { 3 a = 1; 4 smp_wmb(); // 5 b = 1; 6 } 7 8 void bar() 9 { 10 while (b == 0) continue; 11 smp_rmb(); // 11 assert(a == 1); 12 }
ããã€ãã®ã¢ãŒããã¯ãã£ã«ã¯ããã«å€æ§ãªéå£ããããŸããã説æãã3ã€ã®ãªãã·ã§ã³ãç解ããã ãã§ãçè«ã«ã¡ã¢ãªã®éå£ãå°å ¥ã§ããŸãã
翻蚳è ã®ããšãã
ããã§ç¿»èš³ã¯çµäºã§ãã ãªãªãžãã«ã¯ãè¿ä»£å»ºç¯ãæäŸããéå£ãç°¡æœã«ã¬ãã¥ãŒããŸãã èå³ã®ãã人ããªãªãžãã«ã«éããŸã-ããªã¥ãŒã ã«é¢ããŠã¯ãã»ãŒåãæ°ãæ®ã£ãŠããŸãã
èŠçŽããŠã¿ãŸãããã
ãããã£ãŠããã£ãã·ã¥/ã¡ã¢ãªãšçžäºäœçšããããã»ããµã®2ã€ã®æäœ-èªã¿åãïŒããŒãïŒãšæžã蟌ã¿ïŒã¹ãã¢ïŒããããŸãã 2ã€ã®æäœã«ããã4ã€ã®ç°ãªãã¡ã¢ãªããªã¢ãæäŸãããŸãã
op1; // store load barrier ; // memory fence op2; // store load
- ããŒã/ããŒã -以åã®ããŒãåœä»€ãåŸç¶ã®ããŒãåœä»€ã§ç·šæããŸãã ãããŸã§èŠãŠããããã«ããã®ããªã¢ã¯ç¡å¹åãã¥ãŒã«ãé çªã«é 眮ãããŸãããã®ãã¥ãŒãå®å šã«åŠçãããããã¥ãŒãå°æ¥åŠçããé åºãæå®ããã©ãã«ããã®ãã¥ãŒã«å ¥ããŸãã æ¯èŒç軜ãããªã¢
- ã¹ãã¢/ã¹ã㢠-以åã®ã¹ãã¢ã®æ瀺ãåŸç¶ã®ã¹ãã¢ã®æ瀺ãšãšãã«æŽçããŸãã ããã¯ã¹ãã¢ãããã¡ã«åœ±é¿ããŸãïŒèç©ããããããã¡ãå®å šã«åŠçããŸãïŒããªãé«äŸ¡ã§ã-æžã蟌ã¿æäœã¯çŸä»£ã®ããã»ããµã«ãšã£ãŠåžžã«å°é£ã§ãïŒããŸãã¯ãããããã¹ãã¢ãããã¡ã®çŸåšã®å 容ãäœããã®æ¹æ³ã§ããŒã¯ããŸãåŠçããŸãã ãã®å Žåãæ¯èŒç軜ãããªã¢
- ããŒã/ã¹ã㢠-åŸç¶ã®ã¹ãã¢ã§ä»¥åã®ããŒãæ瀺ãæŽçããŸãã 圌ã¯äœã«åœ±é¿ãäžããããšãã§ããŸããïŒ ããã¯ææ©çãªé²é³ãé²ããšæããŸãã ãŸããããªã軜ãéå£ã®ããã§ãã
- ã¹ãã¢/ããŒã -åŸç¶ã®ããŒãã§ä»¥åã®ã¹ãã¢æ瀺ãç·šæããŸãã ã¹ãã¢åœä»€ã¯ã¹ãã¢ãããã¡ã«å ¥ããŸãã ã€ãŸãããã®ããªã¢ã¯ã¹ãã¢ãããã¡ãåçåããå¿ èŠããããŸã-ã©ãã«ãããã«çœ®ãã ãã§ããïŒ ããããããã§ååã§ã¯ãªãããã§ãã çµå±ã®ãšããããŸã ææ©çãªèªæžãããããã®éå£ã¯ãããå¶éããå¿ èŠããããŸãã ç§ãçŸä»£ã®ã¢ãŒããã¯ãã£ã«ã€ããŠç¥ã£ãŠããããšããããã®éå£ã¯ã¹ãã¢ãããã¡ã®å®å šãªåŠçã«ã€ãªãããšçµè«ä»ããããšãã§ããŸããããã¯ããªãé£ããã¢ã¯ã·ã§ã³ã§ãã çµè«ïŒããã¯ãã¹ãŠã®æãéãéå£ã§ã
ããã§ãšãããããŸããç§ãã¡ã¯Sparcã¢ãŒããã¯ãã£ã®ã¡ã¢ãªéå£ãåãé€ããŸããïŒ
Sparcã¢ãŒããã¯ãã£ïŒæãç·©åãããRMOã¢ãŒã-ç·©åãããã¡ã¢ãªã®é åºä»ãïŒã«ã¯ããã©ã¡ãŒã¿ãåžžã«å®æ°ïŒãããåäœã®ORãšçµã¿åãããããšãã§ããããããã©ã°ã®ã»ããïŒãæž¡ããã
åœä»€ããããŸãã ãããã®ãã©ã°ã®ããŒã¢ããã¯ã¯
ã
ã
ã
ïŒä»ã®ç¹å®ã®ãã©ã°ã¯èæ ®ããŸãããã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã³ã°ã«ã¯é©çšãããŸããïŒã
åœä»€ã¯ãããªã¢ã§ãã察å¿ãããªãã¬ãŒã·ã§ã³éã®ã³ãŒãå ã«é 眮ããå¿ èŠããããŸãã
ããšãã°ãSparcã®å®å šãªã¡ã¢ãªããªã¢ã¯ãã¢ã»ã³ãã©ã§ã¯æ¬¡ã®ããã«ãªããŸãã
ååãšããŠã1ã€ã®
ãé€ãããã¹ãŠã®ãã©ã°ãšãã®çµã¿åããã¯ããªã軜ãéå£ãè¡šããŸãã ãŸããããã¯Sparcã¢ãŒããã¯ãã£ã®æ©èœã§ã¯ãªããå®éã«ã¯ãã¹ãŠã®çŸä»£ã®åŒ±é åºããã»ããµã®ããããã£ã§ãã
Sparcã¢ãŒããã¯ãã£ïŒæãç·©åãããRMOã¢ãŒã-ç·©åãããã¡ã¢ãªã®é åºä»ãïŒã«ã¯ããã©ã¡ãŒã¿ãåžžã«å®æ°ïŒãããåäœã®ORãšçµã¿åãããããšãã§ããããããã©ã°ã®ã»ããïŒãæž¡ããã
membar
åœä»€ããããŸãã ãããã®ãã©ã°ã®ããŒã¢ããã¯ã¯
#LoadLoad
ã
#LoadStore
ã
#StoreStore
ã
#StoreLoad
ïŒä»ã®ç¹å®ã®ãã©ã°ã¯èæ ®ããŸãããã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã³ã°ã«ã¯é©çšãããŸããïŒã
membar
åœä»€ã¯ãããªã¢ã§ãã察å¿ãããªãã¬ãŒã·ã§ã³éã®ã³ãŒãå ã«é 眮ããå¿ èŠããããŸãã
-
Load1; membar #LoadLoad; Load2
-
Load; membar #LoadStore; Store
-
Store; membar #StoreLoad; Load
-
Store1; membar #StoreStore; Store2
ããšãã°ãSparcã®å®å šãªã¡ã¢ãªããªã¢ã¯ãã¢ã»ã³ãã©ã§ã¯æ¬¡ã®ããã«ãªããŸãã
membar #LoadLoad|#LoadStore|#StoreStore|#StoreLoad
ååãšããŠã1ã€ã®
#StoreLoad
ãé€ãããã¹ãŠã®ãã©ã°ãšãã®çµã¿åããã¯ããªã軜ãéå£ãè¡šããŸãã ãŸããããã¯Sparcã¢ãŒããã¯ãã£ã®æ©èœã§ã¯ãªããå®éã«ã¯ãã¹ãŠã®çŸä»£ã®åŒ±é åºããã»ããµã®ããããã£ã§ãã
次ãž
ããã§ãç§ãã¡ã¯èšæ¶ã®å£ãã©ãããæ¥ãã®ããèŠãŸããã 圌ããå¿ èŠãªæªã§ããããšãåŠã³ãŸããã ç§ãã¡ã¯ãã³ãŒãå ã§äœããã®æ¹æ³ã§ããããé 眮ããããšããŸããã
ããªãšã³ããã£ãã¹ã±ãžã¥ãŒã©ãšã¡ã¢ãªããªã¢
ã¡ã¢ãªããªã¢ã¯ãã»ãšãã©ãã¹ãŠã®ææ°ã¢ãŒããã¯ãã£ã®ç¬ç«ããã¢ã»ã³ãã©ãŒåœä»€ã§ããããšã«æ³šæãã䟡å€ããããŸãïŒãããããIntel Itaniumã ããç¬ç«ããã¢ãŒããã¯ãã£ãšããŠéç«ã£ãŠããŸã-ããªã¢ã¯ãããŒã/ã¹ãã¢/ RMWåœä»€ã®äžéšã«ãªããŸãïŒã ããã¯ããªãŒã¢ã«ãŽãªãºã ã§ã¯ãããªã¢ãæ£ããé
眮ããããšãéèŠã§ãã ããããææ°ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ãå§åçã«ããªãšã³ããã£ããªããã»ã¹/ã¹ã¬ããå¶åŸ¡ã¢ãã«ãå®è£
ããŠããŸãã ã€ãŸããã¹ããªãŒã ã«ã¯äžå®éã®æéãå²ãåœãŠããããã®åŸãå¥ã®ã¹ããªãŒã ã«çœ®ãæããããŸãã æŒãåºãïŒã³ã³ããã¹ãã¹ã€ããã³ã°ïŒã¯ãã¡ã¢ãªããªã¢ã®åœä»€ã®çŽåã«çºçããå¯èœæ§ããããŸãã , â , ?
. - , , . lock-free , , , - .
. - , , . lock-free , , , - .
ã¡ã¢ãªããªã¢ã®é 眮ã«å¯Ÿããèæ ®ãããã¢ãããŒãããèªã¿åã/æžã蟌ã¿ã¢ãããŒããšåŒã³ãŸãã C ++ 11æšæºã®éçºäžã«ãã¡ã¢ãªãžã®ã¢ã¯ã»ã¹ãæŽçããåé¡ã«å¯Ÿããèªã¿åã/æžã蟌ã¿ã®ã¢ãããŒããã¢ãŒããã¯ãã£ã«ããŸãã«ãé¢é£ããŠãããšèªèãããååŸ/解æŸã®ã»ãã³ãã£ã¯ã¹ãéçºãããæšæºã®åºç€ã圢æããŸããããã®èšäºã§è€æ°åè¿°ã¹ãããŠããããã«ãã¡ã¢ãªããªã¢ã¯ãããªã¢ãå®è¡ããããã»ããµã®ã¿ã«çŽæ¥åœ±é¿ããéæ¥çã«ïŒMESIãããã³ã«ãä»ããŠïŒä»ã®ããã»ããµã«ã®ã¿åœ±é¿ããŸããååŸ/ãªãªãŒã¹ã¢ãã«ã®åäœã¯ç°ãªããŸã- ç°ãªã䞊åã¹ã¬ããïŒã€ãŸããããã»ããµ/ã³ã¢ïŒãã©ã®ããã«çžäºäœçšããããä»®å®ããŸãããå®éã«ãããéæããæ¹æ³ã¯äœããããŸãããå®éããã®ã¢ãã«ã®å®è£ ã¯ãç¹å®ã®ã¡ã¢ãªããªã¢ã®äœ¿çšã§ãã
次ã®Essentialsèšäºã§C ++ 11ã¡ã¢ãªã¢ãã«ã«ã€ããŠèª¬æããŸãã
ããã¯ããªãŒã®ããŒã¿æ§é
éå§ãã
åºæ¬ïŒ
äžïŒ
å€ããïŒ
åºæ¬ïŒ
- ååæ§ããã³ååããªããã£ã
- èšæ¶ã®å£ã¯ã©ãããæ¥ãã®ã§ããïŒ
- ã¡ã¢ãªã¢ãã«
äžïŒ
- ã¡ã¢ãªç®¡çã¹ããŒã
- RCU
- ã¹ã¿ãã¯ã®é²å
- å¥ã®è«æ
- ãã¥ãŒåæ
- 䞊è¡ãããïŒãŠã©ãŒã ã¢ãã
- 䞊è¡ãããïŒåããã·ã¥ãåæ§ç¯ãªã
- 䞊è¡ãããïŒãªã¹ããã¹ããã
- äžèŽãããïŒæš
- ã€ãã¬ãŒã¿ïŒãã«ãã¬ãã«é å
- å埩å¯èœãªãªã¹ã
å€ããïŒ