Skip to content

Commit

Permalink
allow -j (jobs) param to set zeroconf slots
Browse files Browse the repository at this point in the history
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
Eric Fontaine committed Jul 6, 2016
1 parent 544904c commit 6e8300f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions man/distccd.1
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dparent.c
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/zeroconf-reg.c
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
21 changes: 19 additions & 2 deletions src/zeroconf.c
Expand Up @@ -77,6 +77,7 @@ struct host {
AvahiAddress address;
uint16_t port;
int n_cpus;
int n_jobs;

AvahiServiceResolver *resolver;
};
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/zeroconf.h
Expand Up @@ -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);
Expand Down

0 comments on commit 6e8300f

Please sign in to comment.