MPLAB X – force build process to use more than one thread

I use Microchip MPLAB X IDE under Windows 7 to write, compile and debug code for PIC24 processor. During my work on a small  project I have about  50 source C files. It takes some time to rebuild everything from scratch (one minute and a few seconds) on my iCore 7 PC. MPLAB X rebuilds everything from scratch when new file is added to the project.  It is quite annoying for me I have to wait every time for the MPLAB to build my code. It’s a waste. I going to explain how I managed to eliminate this waste.

MPLAB X is based on Netbeans, and uses Cygwins’ Makefile based build system. When build command is executed Cygwin’s make.exe is called. Unfortunately there is now way to set the number of building threads in the MPLAB X configuration menu. My first idea was change the name of make.exe  (located by default at C:\mplab_msys\bin)  to make-bin.exe to and replace it with simple batch file:

make-bin.exe -j 10 %*

where 10 is count of threads build process should spawn. It didn’t work. MPLAB X calls CreateProcess to execute make.exe, the make.exe have to be binary executable in PE format.

I compiled simple wrapper:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 4096

int main(int argc, char *argv[])
{
       unsigned int len = 0;
       char *cmd = malloc(MAX_LEN);
       memset(cmd, 0, MAX_LEN);

       argv++;
       argc--;

       strcat(cmd, "make-bin.exe -j 20");
       while(argc--)
       {
           len += strlen(*argv);
           len++;
           if (len &gt; MAX_LEN)
               exit(EXIT_FAILURE);
           strcat(cmd, " ");
           strcat(cmd, *argv++);
       }

       printf("%s\n", cmd);
       return system(cmd);
}

and replaced make.exe with it.

I use 20 building threads, builing time is reduced to 17 secodns for my project, so it is more or less 4 times shorter.

I played a little with count of building threads:

  • 1 thread – total time: 1m 3s,
  • 2 threads – total time: 35s,
  • 4 threads – total time: 23s,
  • 8 threads – total time: 18s,
  • 20 threads – total time: 17s,
  • 100 threads – total time 18s.
Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s