aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuliano Belinassi <giuliano.belinassi@usp.br>2020-07-29 11:03:45 -0300
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-07-29 11:03:45 -0300
commit503e39b8fbe7ea13d5d65cb3a6f32ea308b09d65 (patch)
treec8b6aa0f765e7350ab763c54522227144223d065
parent47981062961083e03a08123169ed9d55ef59f633 (diff)
downloadgcc-503e39b8fbe7ea13d5d65cb3a6f32ea308b09d65.zip
gcc-503e39b8fbe7ea13d5d65cb3a6f32ea308b09d65.tar.gz
gcc-503e39b8fbe7ea13d5d65cb3a6f32ea308b09d65.tar.bz2
Automatic detect jobserver
This commit adds a way to automatic detect if a GNU Make jobserver is up and running by checking if provided file descriptors are FIFOs. gcc/ChangeLog 2020-07-29 Giuliano Belinassi <giuliano.belinassi@usp.br> * cgraphunit.c (maybe_compile_in_parallel): Implement automatic jobserver detection flag. * jobserver.cc (jobserver_initialize): Check if Make fds are FIFOs.
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/cgraphunit.c19
-rw-r--r--gcc/jobserver.cc31
3 files changed, 31 insertions, 26 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ed48394..79e5c1c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2020-07-29 Giuliano Belinassi <giuliano.belinassi@usp.br>
+
+ * cgraphunit.c (maybe_compile_in_parallel): Implement automatic
+ jobserver detection flag.
+ * jobserver.cc (jobserver_initialize): Check if Make fds are FIFOs.
+ (jobserver_finalize): Set nonblock_mode back to false.
+
2020-07-27 Giuliano Belinassi <giuliano.belinassi@usp.br>
* Makefile.in: Mark jobserver.cc to be compiled.
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index a029455..c9f413c 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2774,22 +2774,35 @@ static bool maybe_compile_in_parallel (void)
bool promote_statics = param_promote_statics;
bool balance = param_balance_partitions;
bool jobserver = false;
+ bool job_auto = false;
int num_jobs = -1;
if (!flag_parallel_jobs || !split_outputs)
return false;
- if (!strcmp (flag_parallel_jobs, "jobserver"))
+ if (!strcmp (flag_parallel_jobs, "auto"))
+ {
+ jobserver = jobserver_initialize ();
+ job_auto = true;
+ }
+ else if (!strcmp (flag_parallel_jobs, "jobserver"))
jobserver = jobserver_initialize ();
else if (is_number (flag_parallel_jobs))
num_jobs = atoi (flag_parallel_jobs);
else
gcc_unreachable ();
+ if (job_auto && !jobserver)
+ {
+ num_jobs = sysconf (_SC_NPROCESSORS_CONF);
+ if (num_jobs > 2)
+ num_jobs = 2;
+ }
+
if (num_jobs < 0 && !jobserver)
{
- error (UNKNOWN_LOCATION,
- "'-fparallel-jobs=jobserver', but no GNU Jobserver found");
+ inform (UNKNOWN_LOCATION,
+ "-fparallel-jobs=jobserver, but no GNU Jobserver found");
return false;
}
diff --git a/gcc/jobserver.cc b/gcc/jobserver.cc
index 4c879cc..9c6bcb6 100644
--- a/gcc/jobserver.cc
+++ b/gcc/jobserver.cc
@@ -72,6 +72,13 @@ bool jobserver_initialize ()
if (!success)
return false;
+ struct stat statbuf;
+ if (fstat (rfd, &statbuf) < 0
+ || (statbuf.st_mode & S_IFMT) != S_IFIFO
+ || fstat (wfd, &statbuf) < 0
+ || (statbuf.st_mode & S_IFMT) != S_IFIFO)
+ return false;
+
int flags = fcntl (rfd, F_GETFL);
if (flags < 0)
return false;
@@ -81,29 +88,6 @@ bool jobserver_initialize ()
nonblock_mode = true;
return (jobserver_initialized = true);
-
-#if 0
- /* Test if we can read from the rfd. */
- jobserver_token_t token;
- ssize_t r = read (rfd, &token, sizeof (jobserver_token_t));
-
- gcc_assert (r == sizeof (jobserver_token_t) || r == 0 || r == -1);
-
- if (r < 0)
- {
- /* Check errno. We may have no problem at all. */
- if (errno != EAGAIN)
- return false;
- }
-
- /* Reading 0 bytes indicate that fd was closed by parent process. */
- if (r == 0)
- return false;
-
- /* Check if we got a important token that we have to return. */
- if (token != JOBSERVER_NULL_TOKEN)
- jobserver_return_token (token);
-#endif
}
/* Finalize the jobserver, so this interface could be used again later. */
@@ -116,6 +100,7 @@ bool jobserver_finalize ()
close (wfd);
rfd = wfd = -1;
+ nonblock_node = false;
jobserver_initialized = false;
return true;