]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Improve the method of checking queue empty
authorFeng, Bob C <bob.c.feng@intel.com>
Mon, 3 Aug 2020 02:03:38 +0000 (10:03 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 7 Aug 2020 01:44:36 +0000 (01:44 +0000)
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2807

The Queue.empty() method is not reliable in the multiple
process runtime environment. This patch uses a new method
to check if all modules are processed and workers need
to be stopped. That is to add a None item at the bottom
of the queue. Worker check if it gets that None item to
know if all the module is processed.

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Lucy Yan <lucyyan@google.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGenWorker.py
BaseTools/Source/Python/build/build.py

index 563d91b421cef4df35372b851c0e9291f7c35f6c..017f67639935328c3945cf6aada22374f66ed7c3 100755 (executable)
@@ -24,6 +24,7 @@ import traceback
 import sys\r
 from AutoGen.DataPipe import MemoryDataPipe\r
 import logging\r
+import time\r
 \r
 def clearQ(q):\r
     try:\r
@@ -111,7 +112,11 @@ class AutoGenManager(threading.Thread):
                     break\r
                 if badnews == "Done":\r
                     fin_num += 1\r
+                elif badnews == "QueueEmpty":\r
+                    EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), badnews))\r
+                    self.TerminateWorkers()\r
                 else:\r
+                    EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), badnews))\r
                     self.Status = False\r
                     self.TerminateWorkers()\r
                 if fin_num == len(self.autogen_workers):\r
@@ -227,12 +232,21 @@ class AutoGenWorkerInProcess(mp.Process):
             PlatformMetaFile = self.GetPlatformMetaFile(self.data_pipe.Get("P_Info").get("ActivePlatform"),\r
                                              self.data_pipe.Get("P_Info").get("WorkspaceDir"))\r
             while True:\r
-                if self.module_queue.empty():\r
-                    break\r
                 if self.error_event.is_set():\r
                     break\r
                 module_count += 1\r
-                module_file,module_root,module_path,module_basename,module_originalpath,module_arch,IsLib = self.module_queue.get_nowait()\r
+                try:\r
+                    module_file,module_root,module_path,module_basename,module_originalpath,module_arch,IsLib = self.module_queue.get_nowait()\r
+                except Empty:\r
+                    EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), "Fake Empty."))\r
+                    time.sleep(0.01)\r
+                    continue\r
+                if module_file is None:\r
+                    EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), "Worker get the last item in the queue."))\r
+                    self.feedback_q.put("QueueEmpty")\r
+                    time.sleep(0.01)\r
+                    continue\r
+\r
                 modulefullpath = os.path.join(module_root,module_file)\r
                 taskname = " : ".join((modulefullpath,module_arch))\r
                 module_metafile = PathClass(module_file,module_root)\r
@@ -280,11 +294,11 @@ class AutoGenWorkerInProcess(mp.Process):
                     else:\r
                         self.cache_q.put((Ma.MetaFile.Path, Ma.Arch, "MakeCache", False))\r
 \r
-        except Empty:\r
-            pass\r
-        except:\r
+        except Exception as e:\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), str(e)))\r
             self.feedback_q.put(taskname)\r
         finally:\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), "Done"))\r
             self.feedback_q.put("Done")\r
             self.cache_q.put("CacheDone")\r
 \r
index 1ab1e60a6499f4876da081726db171f4bde51464..59ceacfed027ccb73438d447754ea22f91e5f1b0 100755 (executable)
@@ -1217,7 +1217,7 @@ class Build():
             mqueue = mp.Queue()\r
             for m in AutoGenObject.GetAllModuleInfo:\r
                 mqueue.put(m)\r
-\r
+            mqueue.put((None,None,None,None,None,None,None))\r
             AutoGenObject.DataPipe.DataContainer = {"CommandTarget": self.Target}\r
             AutoGenObject.DataPipe.DataContainer = {"Workspace_timestamp": AutoGenObject.Workspace._SrcTimeStamp}\r
             AutoGenObject.CreateLibModuelDirs()\r
@@ -2174,6 +2174,7 @@ class Build():
             data_pipe_file = os.path.join(Pa.BuildDir, "GlobalVar_%s_%s.bin" % (str(Pa.Guid),Pa.Arch))\r
             Pa.DataPipe.dump(data_pipe_file)\r
 \r
+            mqueue.put((None,None,None,None,None,None,None))\r
             autogen_rt, errorcode = self.StartAutoGen(mqueue, Pa.DataPipe, self.SkipAutoGen, PcdMaList, cqueue)\r
 \r
             if not autogen_rt:\r