Permalink
Browse files

allow -j (jobs) parameter with zeroconf

If server is started in zeroconf mode, the previous behavior was that the number of jobs for any server was hardcoded to 4 * number of cpus.

This commit allows distccd to be invoked in zeroconf mode with the -j parameter to specify n_jobs, the maximum number of concurrent jobs for this server.

If no -j is specified, then this host will publish its n_jobs to be 2 * number of cores + 2.  (Note: this is the same behavior as when invoking a non-zerconf server without specifying -j.)
To maintain backward compatibily, if a distccd zeroconf server doesn't publish a value for n_jobs, then it will be assigned a default n_jobs equal to the previous behavior of 4 * number of cores.
  • Loading branch information...
1 parent 544904c commit 47d0e480e9cf9eae02d00cfb92dfa368ee298a9a @ericfont ericfont committed Jul 3, 2016
Showing with 30 additions and 7 deletions.
  1. +2 −0 man/distccd.1
  2. +1 −1 src/dparent.c
  3. +7 −3 src/zeroconf-reg.c
  4. +19 −2 src/zeroconf.c
  5. +1 −1 src/zeroconf.h
View
@@ -215,6 +215,8 @@ DNS Service Discovery (DNS-SD). This allows distcc clients on the local
network to access this distccd server without explicitly listing its host
name or IP address in their distcc host list: the distcc clients can
just use "+zeroconf" in their distcc host lists.
+Can optionally use -j parameter to specify the maximum number of jobs
+that this server can process concurrently.
.B This option is only available if distccd was compiled with
.B Avahi support enabled.
.TP
View
@@ -141,7 +141,7 @@ int dcc_standalone_server(void)
#ifdef HAVE_AVAHI
/* Zeroconf registration */
if (opt_zeroconf) {
- if (!(avahi = dcc_zeroconf_register((uint16_t) arg_port, n_cpus)))
+ if (!(avahi = dcc_zeroconf_register((uint16_t) arg_port, n_cpus, dcc_max_kids)))
return EXIT_CONNECT_FAILED;
}
#endif
View
@@ -52,6 +52,7 @@ struct context {
AvahiEntryGroup *group;
uint16_t port;
int n_cpus;
+ int n_jobs;
};
static void publish_reply(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata);
@@ -73,9 +74,10 @@ static void register_stuff(struct context *ctx) {
}
if (avahi_entry_group_is_empty(ctx->group)) {
- char cpus[32], machine[64] = "cc_machine=", version[64] = "cc_version=", *m, *v;
+ char cpus[32], jobs[32], machine[64] = "cc_machine=", version[64] = "cc_version=", *m, *v;
snprintf(cpus, sizeof(cpus), "cpus=%i", ctx->n_cpus);
+ snprintf(jobs, sizeof(jobs), "jobs=%i", ctx->n_jobs);
v = dcc_get_gcc_version(version+11, sizeof(version)-11);
m = dcc_get_gcc_machine(machine+11, sizeof(machine)-11);
@@ -93,6 +95,7 @@ static void register_stuff(struct context *ctx) {
ctx->port,
"txtvers=1",
cpus,
+ jobs,
"distcc="PACKAGE_VERSION,
"gnuhost="GNU_HOST,
v ? version : NULL,
@@ -222,8 +225,8 @@ static void client_callback(AvahiClient *client, AvahiClientState state, void *u
}
}
-/* register a distcc service in DNS-SD/mDNS with the given port and number of CPUs */
-void* dcc_zeroconf_register(uint16_t port, int n_cpus) {
+/* register a distcc service in DNS-SD/mDNS with the given port, number of CPUs, and maximum concurrent jobs */
+void* dcc_zeroconf_register(uint16_t port, int n_cpus, int n_jobs) {
struct context *ctx = NULL;
char service[256] = "distcc@";
int error;
@@ -235,6 +238,7 @@ void* dcc_zeroconf_register(uint16_t port, int n_cpus) {
ctx->threaded_poll = NULL;
ctx->port = port;
ctx->n_cpus = n_cpus;
+ ctx->n_jobs = n_jobs;
/* Prepare service name */
gethostname(service+7, sizeof(service)-8);
View
@@ -77,6 +77,7 @@ struct host {
AvahiAddress address;
uint16_t port;
int n_cpus;
+ int n_jobs;
AvahiServiceResolver *resolver;
};
@@ -163,9 +164,9 @@ static int write_hosts(struct daemon_data *d) {
/* Not yet fully resolved */
continue;
if (h->address.proto == AVAHI_PROTO_INET6)
- snprintf(t, sizeof(t), "[%s]:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, d->n_slots * h->n_cpus);
+ snprintf(t, sizeof(t), "[%s]:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, h->n_jobs);
else
- snprintf(t, sizeof(t), "%s:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, d->n_slots * h->n_cpus);
+ snprintf(t, sizeof(t), "%s:%u/%i\n", avahi_address_snprint(a, sizeof(a), &h->address), h->port, h->n_jobs);
if (dcc_writex(d->fd, t, strlen(t)) != 0) {
rs_log_crit("write() failed: %s\n", strerror(errno));
@@ -276,6 +277,21 @@ static void resolve_reply(
avahi_free(value);
}
+ /* Look for the number of jobs in TXT RRs, and if not found, then set n_jobs = 4 * n_cpus */
+ for (i = txt; i; i = i->next) {
+ char *key, *value;
+
+ if (avahi_string_list_get_pair(i, &key, &value, NULL) < 0)
+ continue;
+
+ if (!strcmp(key, "jobs"))
+ if ((h->n_jobs = atoi(value)) <= 0)
+ h->n_jobs = 4 * h->n_cpus;
+
+ avahi_free(key);
+ avahi_free(value);
+ }
+
h->address = *a;
h->port = port;
@@ -350,6 +366,7 @@ static void browse_reply(
h->protocol = protocol;
h->next = d->hosts;
h->n_cpus = 1;
+ h->n_jobs = 4;
d->hosts = h;
}
View
@@ -25,7 +25,7 @@
int dcc_zeroconf_add_hosts(struct dcc_hostdef **re_list, int *ret_nhosts, int slots, struct dcc_hostdef **ret_prev);
-void *dcc_zeroconf_register(uint16_t port, int n_cpus);
+void *dcc_zeroconf_register(uint16_t port, int n_cpus, int n_jobs);
int dcc_zeroconf_unregister(void*);
char* dcc_get_gcc_version(char *s, size_t nbytes);

0 comments on commit 47d0e48

Please sign in to comment.