* [PATCH 2/3] lto: support --jobserver-style=fifo for recent GNU make [not found] <95d2ec7222d50c8ca1e6535cb8c272d47abbb08d.1660046383.git.mliska@suse.cz> @ 2022-08-09 12:00 ` Martin Liška 2022-08-10 11:11 ` Martin Liška [not found] ` <7ad7af4bb978bffdbc220c754002c667df1b0209.1660046383.git.mliska@suse.cz> 1 sibling, 1 reply; 5+ messages in thread From: Martin Liška @ 2022-08-09 12:00 UTC (permalink / raw) To: gcc-patches Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/ChangeLog: * jobserver.h (jobserver_info::jobserver_info): Parse FIFO format of --jobserver-auth. --- gcc/jobserver.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/jobserver.h b/gcc/jobserver.h index 85453dd3c79..856e326ddfc 100644 --- a/gcc/jobserver.h +++ b/gcc/jobserver.h @@ -39,14 +39,22 @@ struct jobserver_info int rfd = -1; /* File descriptor for writing used for jobserver communication. */ int wfd = -1; + /* Named pipe path. */ + string pipe_path = ""; /* Return true if jobserver is active. */ bool is_active = false; }; jobserver_info::jobserver_info () { + /* Traditionally, GNU make uses opened pipes for jobserver-auth, + e.g. --jobserver-auth=3,4. + Starting with GNU make 4.4, one can use --jobserver-style=fifo + and then named pipe is used: --jobserver-auth=fifo:/tmp/hcsparta. */ + /* Detect jobserver and drop it if it's not working. */ string js_needle = "--jobserver-auth="; + string fifo_prefix = "fifo:"; const char *envval = getenv ("MAKEFLAGS"); if (envval != NULL) @@ -55,8 +63,15 @@ jobserver_info::jobserver_info () size_t n = makeflags.rfind (js_needle); if (n != string::npos) { - if (sscanf (makeflags.c_str () + n + js_needle.size (), - "%d,%d", &rfd, &wfd) == 2 + string ending = makeflags.substr (n + js_needle.size ()); + if (ending.find (fifo_prefix) == 0) + { + ending = ending.substr (fifo_prefix.size ()); + pipe_path = ending.substr (0, ending.find (' ')); + is_active = true; + } + else if (sscanf (makeflags.c_str () + n + js_needle.size (), + "%d,%d", &rfd, &wfd) == 2 && rfd > 0 && wfd > 0 && is_valid_fd (rfd) -- 2.37.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] lto: support --jobserver-style=fifo for recent GNU make 2022-08-09 12:00 ` [PATCH 2/3] lto: support --jobserver-style=fifo for recent GNU make Martin Liška @ 2022-08-10 11:11 ` Martin Liška 0 siblings, 0 replies; 5+ messages in thread From: Martin Liška @ 2022-08-10 11:11 UTC (permalink / raw) To: gcc-patches [-- Attachment #1: Type: text/plain, Size: 294 bytes --] On 8/9/22 14:00, Martin Liška wrote: > |Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin| Sending v2 where I renamed the file. I'm going to install it as the original fifo support patch was already approved by Richi. Cheers, Martin [-- Attachment #2: 0002-lto-support-jobserver-style-fifo-for-recent-GNU-make.patch --] [-- Type: text/x-patch, Size: 2324 bytes --] From 4a678594435e2133166fad7cdc7ed144205455ff Mon Sep 17 00:00:00 2001 From: Martin Liska <mliska@suse.cz> Date: Tue, 9 Aug 2022 13:59:36 +0200 Subject: [PATCH 2/3] lto: support --jobserver-style=fifo for recent GNU make gcc/ChangeLog: * opts-jobserver.h: Add one member. * opts-common.cc (jobserver_info::jobserver_info): Parse FIFO format of --jobserver-auth. --- gcc/opts-common.cc | 17 +++++++++++++++-- gcc/opts-jobserver.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index 4d4f424df13..c2993f9140a 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -2010,8 +2010,14 @@ void prepend_xassembler_to_collect_as_options (const char *collect_as_options, jobserver_info::jobserver_info () { + /* Traditionally, GNU make uses opened pipes for jobserver-auth, + e.g. --jobserver-auth=3,4. + Starting with GNU make 4.4, one can use --jobserver-style=fifo + and then named pipe is used: --jobserver-auth=fifo:/tmp/hcsparta. */ + /* Detect jobserver and drop it if it's not working. */ string js_needle = "--jobserver-auth="; + string fifo_prefix = "fifo:"; const char *envval = getenv ("MAKEFLAGS"); if (envval != NULL) @@ -2020,8 +2026,15 @@ jobserver_info::jobserver_info () size_t n = makeflags.rfind (js_needle); if (n != string::npos) { - if (sscanf (makeflags.c_str () + n + js_needle.size (), - "%d,%d", &rfd, &wfd) == 2 + string ending = makeflags.substr (n + js_needle.size ()); + if (ending.find (fifo_prefix) == 0) + { + ending = ending.substr (fifo_prefix.size ()); + pipe_path = ending.substr (0, ending.find (' ')); + is_active = true; + } + else if (sscanf (makeflags.c_str () + n + js_needle.size (), + "%d,%d", &rfd, &wfd) == 2 && rfd > 0 && wfd > 0 && is_valid_fd (rfd) diff --git a/gcc/opts-jobserver.h b/gcc/opts-jobserver.h index 68ce188b84a..98ea2579962 100644 --- a/gcc/opts-jobserver.h +++ b/gcc/opts-jobserver.h @@ -37,6 +37,8 @@ struct jobserver_info int rfd = -1; /* File descriptor for writing used for jobserver communication. */ int wfd = -1; + /* Named pipe path. */ + string pipe_path = ""; /* Return true if jobserver is active. */ bool is_active = false; }; -- 2.37.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <7ad7af4bb978bffdbc220c754002c667df1b0209.1660046383.git.mliska@suse.cz>]
* [PATCH 3/3] lto: respect jobserver in parallel WPA streaming [not found] ` <7ad7af4bb978bffdbc220c754002c667df1b0209.1660046383.git.mliska@suse.cz> @ 2022-08-09 12:00 ` Martin Liška 2022-08-10 10:52 ` Richard Biener 0 siblings, 1 reply; 5+ messages in thread From: Martin Liška @ 2022-08-09 12:00 UTC (permalink / raw) To: gcc-patches Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR lto/106328 gcc/ChangeLog: * jobserver.h (struct jobserver_info): Add pipefd. (jobserver_info::connect): New. (jobserver_info::disconnect): Likewise. (jobserver_info::get_token): Likewise. (jobserver_info::return_token): Likewise. gcc/lto/ChangeLog: * lto.cc (wait_for_child): Decrement nruns once a process finishes. (stream_out_partitions): Use job server if active. (do_whole_program_analysis): Likewise. --- gcc/jobserver.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ gcc/lto/lto.cc | 55 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 96 insertions(+), 13 deletions(-) diff --git a/gcc/jobserver.h b/gcc/jobserver.h index 856e326ddfc..2a7dc9f4113 100644 --- a/gcc/jobserver.h +++ b/gcc/jobserver.h @@ -31,6 +31,18 @@ struct jobserver_info /* Default constructor. */ jobserver_info (); + /* Connect to the server. */ + void connect (); + + /* Disconnect from the server. */ + void disconnect (); + + /* Get token from the server. */ + bool get_token (); + + /* Return token to the server. */ + void return_token (); + /* Error message if there is a problem. */ string error_msg = ""; /* Skipped MAKEFLAGS where --jobserver-auth is skipped. */ @@ -41,6 +53,8 @@ struct jobserver_info int wfd = -1; /* Named pipe path. */ string pipe_path = ""; + /* Pipe file descriptor. */ + int pipefd = -1; /* Return true if jobserver is active. */ bool is_active = false; }; @@ -97,4 +111,44 @@ jobserver_info::jobserver_info () error_msg = "jobserver is not available: " + error_msg; } +void +jobserver_info::connect () +{ + if (!pipe_path.empty ()) + pipefd = open (pipe_path.c_str (), O_RDWR); +} + +void +jobserver_info::disconnect () +{ + if (!pipe_path.empty ()) + { + gcc_assert (close (pipefd) == 0); + pipefd = -1; + } +} + +bool +jobserver_info::get_token () +{ + int fd = pipe_path.empty () ? rfd : pipefd; + char c; + unsigned n = read (fd, &c, 1); + if (n != 1) + { + gcc_assert (errno == EAGAIN); + return false; + } + else + return true; +} + +void +jobserver_info::return_token () +{ + int fd = pipe_path.empty () ? wfd : pipefd; + char c = 'G'; + gcc_assert (write (fd, &c, 1) == 1); +} + #endif /* GCC_JOBSERVER_H */ diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc index 31b0c1862f7..56266195ead 100644 --- a/gcc/lto/lto.cc +++ b/gcc/lto/lto.cc @@ -54,11 +54,17 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "builtins.h" #include "lto-common.h" - +#include "jobserver.h" /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */ static int lto_parallelism; +/* Number of active WPA streaming processes. */ +static int nruns = 0; + +/* GNU make's jobserver info. */ +static jobserver_info *jinfo = NULL; + /* Return true when NODE has a clone that is analyzed (i.e. we need to load its body even if the node itself is not needed). */ @@ -205,6 +211,12 @@ wait_for_child () "streaming subprocess was killed by signal"); } while (!WIFEXITED (status) && !WIFSIGNALED (status)); + + --nruns; + + /* Return token to the jobserver if active. */ + if (jinfo != NULL && jinfo->is_active) + jinfo->return_token (); } #endif @@ -228,25 +240,35 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, bool ARG_UNUSED (last)) { #ifdef HAVE_WORKING_FORK - static int nruns; - if (lto_parallelism <= 1) { stream_out_partitions_1 (temp_filename, blen, min, max); return; } - /* Do not run more than LTO_PARALLELISM streamings - FIXME: we ignore limits on jobserver. */ if (lto_parallelism > 0 && nruns >= lto_parallelism) - { - wait_for_child (); - nruns --; - } + wait_for_child (); + /* If this is not the last parallel partition, execute new streaming process. */ if (!last) { + if (jinfo != NULL && jinfo->is_active) + while (true) + { + if (jinfo->get_token ()) + break; + if (nruns > 0) + wait_for_child (); + else + { + /* There are no free tokens, lets do the job outselves. */ + stream_out_partitions_1 (temp_filename, blen, min, max); + asm_nodes_output = true; + return; + } + } + pid_t cpid = fork (); if (!cpid) @@ -264,10 +286,12 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, /* Last partition; stream it and wait for all children to die. */ else { - int i; stream_out_partitions_1 (temp_filename, blen, min, max); - for (i = 0; i < nruns; i++) + while (nruns > 0) wait_for_child (); + + if (jinfo != NULL && jinfo->is_active) + jinfo->disconnect (); } asm_nodes_output = true; #else @@ -460,9 +484,14 @@ do_whole_program_analysis (void) lto_parallelism = 1; - /* TODO: jobserver communication is not supported, yet. */ if (!strcmp (flag_wpa, "jobserver")) - lto_parallelism = param_max_lto_streaming_parallelism; + { + jinfo = new jobserver_info (); + if (jinfo->is_active) + jinfo->connect (); + + lto_parallelism = param_max_lto_streaming_parallelism; + } else { lto_parallelism = atoi (flag_wpa); -- 2.37.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] lto: respect jobserver in parallel WPA streaming 2022-08-09 12:00 ` [PATCH 3/3] lto: respect jobserver in parallel WPA streaming Martin Liška @ 2022-08-10 10:52 ` Richard Biener 2022-08-10 11:10 ` Martin Liška 0 siblings, 1 reply; 5+ messages in thread From: Richard Biener @ 2022-08-10 10:52 UTC (permalink / raw) To: Martin Liška; +Cc: GCC Patches On Tue, Aug 9, 2022 at 2:02 PM Martin Liška <mliska@suse.cz> wrote: > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed? > Thanks, > Martin > > PR lto/106328 > > gcc/ChangeLog: > > * jobserver.h (struct jobserver_info): Add pipefd. > (jobserver_info::connect): New. > (jobserver_info::disconnect): Likewise. > (jobserver_info::get_token): Likewise. > (jobserver_info::return_token): Likewise. > > gcc/lto/ChangeLog: > > * lto.cc (wait_for_child): Decrement nruns once a process > finishes. > (stream_out_partitions): Use job server if active. > (do_whole_program_analysis): Likewise. > --- > gcc/jobserver.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ > gcc/lto/lto.cc | 55 +++++++++++++++++++++++++++++++++++++------------ > 2 files changed, 96 insertions(+), 13 deletions(-) > > diff --git a/gcc/jobserver.h b/gcc/jobserver.h > index 856e326ddfc..2a7dc9f4113 100644 > --- a/gcc/jobserver.h > +++ b/gcc/jobserver.h > @@ -31,6 +31,18 @@ struct jobserver_info > /* Default constructor. */ > jobserver_info (); > > + /* Connect to the server. */ > + void connect (); > + > + /* Disconnect from the server. */ > + void disconnect (); > + > + /* Get token from the server. */ > + bool get_token (); > + > + /* Return token to the server. */ > + void return_token (); > + > /* Error message if there is a problem. */ > string error_msg = ""; > /* Skipped MAKEFLAGS where --jobserver-auth is skipped. */ > @@ -41,6 +53,8 @@ struct jobserver_info > int wfd = -1; > /* Named pipe path. */ > string pipe_path = ""; > + /* Pipe file descriptor. */ > + int pipefd = -1; > /* Return true if jobserver is active. */ > bool is_active = false; > }; > @@ -97,4 +111,44 @@ jobserver_info::jobserver_info () > error_msg = "jobserver is not available: " + error_msg; > } > > +void > +jobserver_info::connect () > +{ > + if (!pipe_path.empty ()) > + pipefd = open (pipe_path.c_str (), O_RDWR); > +} > + > +void > +jobserver_info::disconnect () If it's not a template and the methods not inline won't we get multiple definition errors when this include file is included in multiple places from an executable? opts-common.cc might be a good place to stuff it, and opts.h to declare (if it were not for std::string, so possibly jobserver.h is good enough, or opts-jobserver.h?) > +{ > + if (!pipe_path.empty ()) > + { > + gcc_assert (close (pipefd) == 0); > + pipefd = -1; > + } > +} > + > +bool > +jobserver_info::get_token () > +{ > + int fd = pipe_path.empty () ? rfd : pipefd; > + char c; > + unsigned n = read (fd, &c, 1); > + if (n != 1) > + { > + gcc_assert (errno == EAGAIN); > + return false; > + } > + else > + return true; > +} > + > +void > +jobserver_info::return_token () > +{ > + int fd = pipe_path.empty () ? wfd : pipefd; > + char c = 'G'; > + gcc_assert (write (fd, &c, 1) == 1); > +} > + > #endif /* GCC_JOBSERVER_H */ > diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc > index 31b0c1862f7..56266195ead 100644 > --- a/gcc/lto/lto.cc > +++ b/gcc/lto/lto.cc > @@ -54,11 +54,17 @@ along with GCC; see the file COPYING3. If not see > #include "attribs.h" > #include "builtins.h" > #include "lto-common.h" > - > +#include "jobserver.h" > > /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */ > static int lto_parallelism; > > +/* Number of active WPA streaming processes. */ > +static int nruns = 0; > + > +/* GNU make's jobserver info. */ > +static jobserver_info *jinfo = NULL; > + > /* Return true when NODE has a clone that is analyzed (i.e. we need > to load its body even if the node itself is not needed). */ > > @@ -205,6 +211,12 @@ wait_for_child () > "streaming subprocess was killed by signal"); > } > while (!WIFEXITED (status) && !WIFSIGNALED (status)); > + > + --nruns; > + > + /* Return token to the jobserver if active. */ > + if (jinfo != NULL && jinfo->is_active) > + jinfo->return_token (); > } > #endif > > @@ -228,25 +240,35 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, > bool ARG_UNUSED (last)) > { > #ifdef HAVE_WORKING_FORK > - static int nruns; > - > if (lto_parallelism <= 1) > { > stream_out_partitions_1 (temp_filename, blen, min, max); > return; > } > > - /* Do not run more than LTO_PARALLELISM streamings > - FIXME: we ignore limits on jobserver. */ > if (lto_parallelism > 0 && nruns >= lto_parallelism) > - { > - wait_for_child (); > - nruns --; > - } > + wait_for_child (); > + > /* If this is not the last parallel partition, execute new > streaming process. */ > if (!last) > { > + if (jinfo != NULL && jinfo->is_active) > + while (true) > + { > + if (jinfo->get_token ()) > + break; > + if (nruns > 0) > + wait_for_child (); > + else > + { > + /* There are no free tokens, lets do the job outselves. */ > + stream_out_partitions_1 (temp_filename, blen, min, max); > + asm_nodes_output = true; > + return; > + } > + } > + > pid_t cpid = fork (); > > if (!cpid) > @@ -264,10 +286,12 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, > /* Last partition; stream it and wait for all children to die. */ > else > { > - int i; > stream_out_partitions_1 (temp_filename, blen, min, max); > - for (i = 0; i < nruns; i++) > + while (nruns > 0) > wait_for_child (); > + > + if (jinfo != NULL && jinfo->is_active) > + jinfo->disconnect (); > } > asm_nodes_output = true; > #else > @@ -460,9 +484,14 @@ do_whole_program_analysis (void) > > lto_parallelism = 1; > > - /* TODO: jobserver communication is not supported, yet. */ > if (!strcmp (flag_wpa, "jobserver")) > - lto_parallelism = param_max_lto_streaming_parallelism; > + { > + jinfo = new jobserver_info (); > + if (jinfo->is_active) > + jinfo->connect (); > + > + lto_parallelism = param_max_lto_streaming_parallelism; > + } > else > { > lto_parallelism = atoi (flag_wpa); > -- > 2.37.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] lto: respect jobserver in parallel WPA streaming 2022-08-10 10:52 ` Richard Biener @ 2022-08-10 11:10 ` Martin Liška 0 siblings, 0 replies; 5+ messages in thread From: Martin Liška @ 2022-08-10 11:10 UTC (permalink / raw) To: Richard Biener; +Cc: GCC Patches [-- Attachment #1: Type: text/plain, Size: 419 bytes --] On 8/10/22 12:52, Richard Biener wrote: > If it's not a template and the methods not inline won't we get multiple > definition errors when this include file is included in multiple places > from an executable? opts-common.cc might be a good place to > stuff it, and opts.h to declare (if it were not for std::string, so possibly > jobserver.h is good enough, or opts-jobserver.h?) Works for me, updated in v2. Martin [-- Attachment #2: 0003-lto-respect-jobserver-in-parallel-WPA-streaming.patch --] [-- Type: text/x-patch, Size: 6066 bytes --] From ff2073e1f549df40a5e859e2cde9a403307c1960 Mon Sep 17 00:00:00 2001 From: Martin Liska <mliska@suse.cz> Date: Tue, 9 Aug 2022 13:59:39 +0200 Subject: [PATCH 3/3] lto: respect jobserver in parallel WPA streaming PR lto/106328 gcc/ChangeLog: * opts-jobserver.h (struct jobserver_info): Add pipefd. (jobserver_info::connect): New. (jobserver_info::disconnect): Likewise. (jobserver_info::get_token): Likewise. (jobserver_info::return_token): Likewise. * opts-common.cc: Implement the new functions. gcc/lto/ChangeLog: * lto.cc (wait_for_child): Decrement nruns once a process finishes. (stream_out_partitions): Use job server if active. (do_whole_program_analysis): Likewise. --- gcc/lto/lto.cc | 58 +++++++++++++++++++++++++++++++++----------- gcc/opts-common.cc | 42 ++++++++++++++++++++++++++++++++ gcc/opts-jobserver.h | 14 +++++++++++ 3 files changed, 100 insertions(+), 14 deletions(-) diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc index 31b0c1862f7..c82307f4f7e 100644 --- a/gcc/lto/lto.cc +++ b/gcc/lto/lto.cc @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ +#define INCLUDE_STRING #include "config.h" #include "system.h" #include "coretypes.h" @@ -54,11 +55,17 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "builtins.h" #include "lto-common.h" +#include "opts-jobserver.h" - -/* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */ +/* Number of parallel tasks to run. */ static int lto_parallelism; +/* Number of active WPA streaming processes. */ +static int nruns = 0; + +/* GNU make's jobserver info. */ +static jobserver_info *jinfo = NULL; + /* Return true when NODE has a clone that is analyzed (i.e. we need to load its body even if the node itself is not needed). */ @@ -205,6 +212,12 @@ wait_for_child () "streaming subprocess was killed by signal"); } while (!WIFEXITED (status) && !WIFSIGNALED (status)); + + --nruns; + + /* Return token to the jobserver if active. */ + if (jinfo != NULL && jinfo->is_active) + jinfo->return_token (); } #endif @@ -228,25 +241,35 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, bool ARG_UNUSED (last)) { #ifdef HAVE_WORKING_FORK - static int nruns; - if (lto_parallelism <= 1) { stream_out_partitions_1 (temp_filename, blen, min, max); return; } - /* Do not run more than LTO_PARALLELISM streamings - FIXME: we ignore limits on jobserver. */ if (lto_parallelism > 0 && nruns >= lto_parallelism) - { - wait_for_child (); - nruns --; - } + wait_for_child (); + /* If this is not the last parallel partition, execute new streaming process. */ if (!last) { + if (jinfo != NULL && jinfo->is_active) + while (true) + { + if (jinfo->get_token ()) + break; + if (nruns > 0) + wait_for_child (); + else + { + /* There are no free tokens, lets do the job outselves. */ + stream_out_partitions_1 (temp_filename, blen, min, max); + asm_nodes_output = true; + return; + } + } + pid_t cpid = fork (); if (!cpid) @@ -264,10 +287,12 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, /* Last partition; stream it and wait for all children to die. */ else { - int i; stream_out_partitions_1 (temp_filename, blen, min, max); - for (i = 0; i < nruns; i++) + while (nruns > 0) wait_for_child (); + + if (jinfo != NULL && jinfo->is_active) + jinfo->disconnect (); } asm_nodes_output = true; #else @@ -460,9 +485,14 @@ do_whole_program_analysis (void) lto_parallelism = 1; - /* TODO: jobserver communication is not supported, yet. */ if (!strcmp (flag_wpa, "jobserver")) - lto_parallelism = param_max_lto_streaming_parallelism; + { + jinfo = new jobserver_info (); + if (jinfo->is_active) + jinfo->connect (); + + lto_parallelism = param_max_lto_streaming_parallelism; + } else { lto_parallelism = atoi (flag_wpa); diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index c2993f9140a..6c9355f6372 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -2059,3 +2059,45 @@ jobserver_info::jobserver_info () if (!error_msg.empty ()) error_msg = "jobserver is not available: " + error_msg; } + +void +jobserver_info::connect () +{ + if (!pipe_path.empty ()) + pipefd = open (pipe_path.c_str (), O_RDWR); +} + +void +jobserver_info::disconnect () +{ + if (!pipe_path.empty ()) + { + gcc_assert (close (pipefd) == 0); + pipefd = -1; + } +} + +bool +jobserver_info::get_token () +{ + int fd = pipe_path.empty () ? rfd : pipefd; + char c; + unsigned n = read (fd, &c, 1); + if (n != 1) + { + gcc_assert (errno == EAGAIN); + return false; + } + else + return true; +} + +void +jobserver_info::return_token () +{ + int fd = pipe_path.empty () ? wfd : pipefd; + char c = 'G'; + gcc_assert (write (fd, &c, 1) == 1); +} + + diff --git a/gcc/opts-jobserver.h b/gcc/opts-jobserver.h index 98ea2579962..76c1d9b2882 100644 --- a/gcc/opts-jobserver.h +++ b/gcc/opts-jobserver.h @@ -29,6 +29,18 @@ struct jobserver_info /* Default constructor. */ jobserver_info (); + /* Connect to the server. */ + void connect (); + + /* Disconnect from the server. */ + void disconnect (); + + /* Get token from the server. */ + bool get_token (); + + /* Return token to the server. */ + void return_token (); + /* Error message if there is a problem. */ string error_msg = ""; /* Skipped MAKEFLAGS where --jobserver-auth is skipped. */ @@ -39,6 +51,8 @@ struct jobserver_info int wfd = -1; /* Named pipe path. */ string pipe_path = ""; + /* Pipe file descriptor. */ + int pipefd = -1; /* Return true if jobserver is active. */ bool is_active = false; }; -- 2.37.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-10 11:11 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <95d2ec7222d50c8ca1e6535cb8c272d47abbb08d.1660046383.git.mliska@suse.cz> 2022-08-09 12:00 ` [PATCH 2/3] lto: support --jobserver-style=fifo for recent GNU make Martin Liška 2022-08-10 11:11 ` Martin Liška [not found] ` <7ad7af4bb978bffdbc220c754002c667df1b0209.1660046383.git.mliska@suse.cz> 2022-08-09 12:00 ` [PATCH 3/3] lto: respect jobserver in parallel WPA streaming Martin Liška 2022-08-10 10:52 ` Richard Biener 2022-08-10 11:10 ` Martin Liška
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).