/* * Invoked once on module load. * * This routine should return 0 on success, and -1 otherwise. */ int codegen_init(hsignature_t *sig) { const char *url; hcfg_t *cfg; url = session_getcfg(CFGKEY_TARGET_URL); if (!url || url[0] == '\0') { session_error("Destination URL for" " generated code objects not specified"); return -1; } url = session_getcfg(CFGKEY_SERVER_URL); if (!url || url[0] == '\0') { session_error("Codegen server URL not specified"); return -1; } sockfd = url_connect(url); if (sockfd == -1) { session_error("Invalid codegen server URL"); return -1; } /* In the future, we should rewrite the code generator system to * avoid using hmesg_t types. Until then, generate a fake * HMESG_SESSION message to maintain compatibility. */ mesg = HMESG_INITIALIZER; hsignature_copy(&mesg.data.session.sig, sig); cfg = hcfg_alloc(); hcfg_set(cfg, CFGKEY_SERVER_URL, session_getcfg(CFGKEY_SERVER_URL)); hcfg_set(cfg, CFGKEY_TARGET_URL, session_getcfg(CFGKEY_TARGET_URL)); hcfg_set(cfg, CFGKEY_REPLY_URL, session_getcfg(CFGKEY_REPLY_URL)); hcfg_set(cfg, CFGKEY_SLAVE_LIST, session_getcfg(CFGKEY_SLAVE_LIST)); hcfg_set(cfg, CFGKEY_SLAVE_PATH, session_getcfg(CFGKEY_SLAVE_PATH)); mesg.data.session.cfg = cfg; mesg.type = HMESG_SESSION; mesg.status = HMESG_STATUS_REQ; if (mesg_send(sockfd, &mesg) < 1) return -1; if (mesg_recv(sockfd, &mesg) < 1) return -1; if (callback_generate(sockfd, codegen_callback) != 0) { session_error("Could not register callback for codegen plugin"); return -1; } return 0; }
int constraint_init(hsignature_t *sig) { /* Make a copy of the signature. */ hsignature_copy(&local_sig, sig); /* Initialize layer variables. */ if (strategy_cfg(sig) != 0) return -1; if (build_vars_text(sig) != 0) return -1; if (build_bounds_text(sig) != 0) return -1; if (build_user_text() != 0) return -1; /* Calculate the range for each tuning variable, given the constraints. */ if (update_bounds(sig) != 0) return -1; return 0; }
int harmony_join(hdesc_t *hdesc, const char *host, int port, const char *name) { int i, perf_len; int apply_argv = (hdesc->state < HARMONY_STATE_CONNECTED); char *cfgval; /* Verify that we have *at least* one variable bound, and that * this descriptor isn't already associated with a tuning * session. */ if (hdesc->ptr_len == 0) { hdesc->errstr = "No variables bound to Harmony session"; errno = EINVAL; return -1; } if (hdesc->state >= HARMONY_STATE_READY) { hdesc->errstr = "Descriptor already joined with an existing session"; errno = EINVAL; return -1; } if (hdesc->state == HARMONY_STATE_INIT) { hdesc->socket = tcp_connect(host, port); if (hdesc->socket < 0) { hdesc->errstr = "Error establishing TCP connection with server"; return -1; } if (hdesc->id == NULL) hdesc->id = default_id(hdesc->socket); hdesc->state = HARMONY_STATE_CONNECTED; hdesc->sess.sig.name = stralloc(name); if (!hdesc->sess.sig.name) { hdesc->errstr = "Error allocating memory for signature name"; return -1; } } /* Prepare a Harmony message. */ hmesg_scrub(&hdesc->mesg); hdesc->mesg.data.join = HSIGNATURE_INITIALIZER; if (hsignature_copy(&hdesc->mesg.data.join, &hdesc->sess.sig) < 0) { hdesc->errstr = "Internal error copying signature data"; return -1; } /* send the client registration message */ if (send_request(hdesc, HMESG_JOIN) != 0) return -1; if (hdesc->mesg.status != HMESG_STATUS_OK) { hdesc->errstr = "Invalid message received"; errno = EINVAL; return -1; } hsignature_fini(&hdesc->sess.sig); if (hsignature_copy(&hdesc->sess.sig, &hdesc->mesg.data.join) < 0) { hdesc->errstr = "Error copying received signature structure"; return -1; } /* Apply argv configuration directives now, if necessary. */ if (apply_argv) { for (i = 0; i < hdesc->cmd_len; ++i) { char *key, *val, *cpy; cpy = stralloc(hdesc->cmd[i]); if (hcfg_parse(cpy, &key, &val)) { /* This should never fail, but just in case. */ hdesc->errstr = "Error parsing argv config directive."; return -1; } if (hcfg_set(hdesc->sess.cfg, key, val)) { hdesc->errstr = "Error applying argv config directive."; return -1; } free(cpy); } } cfgval = harmony_getcfg(hdesc, CFGKEY_PERF_COUNT); if (cfgval) { perf_len = atoi(cfgval); if (perf_len < 1) { hdesc->errstr = "Invalid value for " CFGKEY_PERF_COUNT; return -1; } free(cfgval); } else { perf_len = DEFAULT_PERF_COUNT; } hdesc->perf = hperf_alloc(perf_len); if (!hdesc->perf) { hdesc->errstr = "Error allocating performance array."; return -1; } hdesc->state = HARMONY_STATE_READY; return 0; }