diff mbox

[U-Boot,7/7] tools/genboardscfg.py: improve performance

Message ID 1408535269-24066-8-git-send-email-yamada.m@jp.panasonic.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Masahiro Yamada Aug. 20, 2014, 11:47 a.m. UTC
I guess some developers are already getting sick of this tool
because it takes a few minites to generate the boards.cfg
on reasonable computers.

This commit makes it about 4 times faster.
You might not be satisfied at all, but better than now.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

On my computer (Core i7 2700K + 16GB memory),

60 sec --> 14 sec

This commit does not solve the root cause at all.
We still need to find a better way to replace this patch.


 tools/genboardscfg.py | 43 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)

Comments

Simon Glass Aug. 20, 2014, 7:15 p.m. UTC | #1
On 20 August 2014 05:47, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> I guess some developers are already getting sick of this tool
> because it takes a few minites to generate the boards.cfg
> on reasonable computers.
>
> This commit makes it about 4 times faster.
> You might not be satisfied at all, but better than now.
>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

Acked-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/tools/genboardscfg.py b/tools/genboardscfg.py
index 899db69..bfa338c 100755
--- a/tools/genboardscfg.py
+++ b/tools/genboardscfg.py
@@ -30,7 +30,7 @@  CONFIG_DIR = 'configs'
 REFORMAT_CMD = [os.path.join('tools', 'reformat.py'),
                 '-i', '-d', '-', '-s', '8']
 SHOW_GNU_MAKE = 'scripts/show-gnu-make'
-SLEEP_TIME=0.03
+SLEEP_TIME=0.003
 
 COMMENT_BLOCK = '''#
 # List of boards
@@ -315,13 +315,22 @@  class Slot:
         Arguments:
           output: File object which the result is written to
           maintainers_database: An instance of class MaintainersDatabase
+          devnull: file object of 'dev/null'
+          make_cmd: the command name of Make
         """
-        self.occupied = False
         self.build_dir = tempfile.mkdtemp()
         self.devnull = devnull
-        self.make_cmd = make_cmd
+        self.ps = subprocess.Popen([make_cmd, 'O=' + self.build_dir,
+                                    'allnoconfig'], stdout=devnull)
+        self.occupied = True
         self.parser = DotConfigParser(self.build_dir, output,
                                       maintainers_database)
+        self.tmp_defconfig = os.path.join(CONFIG_DIR, '.tmp_defconfig')
+        os.makedirs(os.path.join(self.build_dir, CONFIG_DIR))
+        self.env = os.environ.copy()
+        self.env['srctree'] = os.getcwd()
+        self.env['UBOOTVERSION'] = 'dummy'
+        self.env['KCONFIG_OBJDIR'] = ''
 
     def __del__(self):
         """Delete the working directory"""
@@ -344,13 +353,33 @@  class Slot:
         """
         if self.occupied:
             return False
-        o = 'O=' + self.build_dir
-        self.ps = subprocess.Popen([self.make_cmd, o, defconfig],
-                                   stdout=self.devnull)
+
+        f = open(os.path.join(self.build_dir, self.tmp_defconfig), 'w')
+        for line in open(os.path.join(CONFIG_DIR, defconfig)):
+            colon = line.find(':CONFIG_')
+            if colon == -1:
+                f.write(line)
+            else:
+                f.write(line[colon + 1:])
+        f.close()
+
+        self.ps = subprocess.Popen([os.path.join('scripts', 'kconfig', 'conf'),
+                                    '--defconfig=' + self.tmp_defconfig,
+                                    'Kconfig'],
+                                   stdout=self.devnull,
+                                   cwd=self.build_dir,
+                                   env=self.env)
+
         self.defconfig = defconfig
         self.occupied = True
         return True
 
+    def wait(self):
+        """Wait until the current subprocess finishes."""
+        while self.occupied and self.ps.poll() == None:
+            time.sleep(SLEEP_TIME)
+        self.occupied = False
+
     def poll(self):
         """Check if the subprocess is running and invoke the .config
         parser if the subprocess is terminated.
@@ -388,6 +417,8 @@  class Slots:
         for i in range(jobs):
             self.slots.append(Slot(output, maintainers_database,
                                    devnull, make_cmd))
+        for slot in self.slots:
+            slot.wait()
 
     def add(self, defconfig):
         """Add a new subprocess if a vacant slot is available.