help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Evenly distributing job slots


From: Siyang He
Subject: Evenly distributing job slots
Date: Tue, 6 Jun 2023 00:00:12 -0400

Say I'm a developer for foo, and users can run several instances of foo in
parallel using a Makefile.

To minimize bottlenecking, I would like to distribute job slots evenly. For
instance, when calling "make -j12" on four instances of foo, each instance
should launch three threads.

Ideally I would like to calculate the thread-count-per-instance from
entirely within foo. I managed to get the thread count, but I am having
trouble counting the number of instances currently running. As far as I
know, this number is not passed by Make.

So far I have been resorting to counting the bytes in the jobserver pipe,
and subtracting this count from the total thread count. I am calling
ioctl() for this. Users are expected to have Linux and gnulib, so I don't
have to worry about ioctl()'s portability.

My problems are twofold: 1) somehow foo reads more bytes from the pipe than
the number of available tokens, and 2) different instances often read
different numbers of bytes from the pipe.

I have attached a minimal working example of foo (that does nothing but
print how many bytes are in the jobserver pipe) and Makefile. I'm having
Make run four foo instances in parallel, so on -j12 each foo should read
eight bytes from the pipe. On my machine, I almost always see the first
three instances reading 10 bytes, and the last one reading 11.

But my bigger point is whether I am missing some better approach. Maybe
Make does pass the instance count somehow?

Attachment: foo.c
Description: Text Data

Attachment: Makefile
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]