void ohoi_mc_event(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_mc_t *mc, void *cb_data) { struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; int rv; if ((ipmi_mc_get_channel(mc) == 0) && (ipmi_mc_get_address(mc) == 32) && ipmi_handler->d_type == IPMI_DOMAIN_TYPE_ATCA) { ipmi_handler->virt_mcid = ipmi_mc_convert_to_id(mc); } g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock); switch (op) { case IPMI_ADDED: /* if we get an MC but inactive, register a call to add it once it goes active */ rv = ipmi_mc_add_active_handler(mc, mc_active, handler); rv = ipmi_mc_set_sdrs_first_read_handler(mc, mc_processed, handler); if(!ipmi_mc_is_active(mc)) { trace_ipmi_mc("ADDED but inactive...we ignore", mc); break; } else { mc_add(mc, handler); break; } case IPMI_DELETED: trace_ipmi_mc("DELETED, but nothing done", mc); break; case IPMI_CHANGED: if(!ipmi_mc_is_active(mc)) { trace_ipmi("CHANGED and is inactive: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); } else { mc_add(mc, handler); } break; } g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); }
void ohoi_mc_event(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_mc_t *mc, void *cb_data) { struct oh_handler_state *handler = cb_data; switch (op) { case IPMI_ADDED: if(!ipmi_mc_is_active(mc)) { dbg("MC added but inactive...we ignore (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); break; } else { mc_add(mc, handler); dbg("MC added and is active: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); break; } case IPMI_DELETED: dbg("MC deleted: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); break; case IPMI_CHANGED: if(!ipmi_mc_is_active(mc)) { dbg("MC changed and is inactive: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); /* we need to remove it from RPT */ } else { mc_add(mc, handler); dbg("MC changed and is active: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); } break; } }
static void mc_active(ipmi_mc_t *mc, int active, void *cb_data) { struct oh_handler_state *handler = cb_data; // struct ohoi_handler *ipmi_handler = handler->data; if (active) { mc_add(mc, handler); } else { mc_remove(mc, handler); } }
int main(int argc, char *argv[]) { struct memcache *mc = NULL; int i, ret; u_int32_t hash_pre, hash_post; void *v; mc = mc_new(); if (mc == NULL) err(EX_OSERR, "Unable to allocate a new memcache object"); mc_server_add4(mc, "localhost:11211"); warnx("mc_add"); mc_err_filter_del(MCM_ERR_LVL_INFO); mc_err_filter_del(MCM_ERR_LVL_NOTICE); ret = mc_add(mc, key, strlen(key), val, strlen(val), 0, 0); printf("add %d\n", ret); ret = mc_set(mc, key, strlen(key), val, strlen(val), 0, 0); hash_pre = mc_hash_key(val, strlen(val)); printf("set %d\n", ret); for (i = 0; i < 10000; i++) { v = mc_aget(mc, key, strlen(key)); if (v != NULL) { hash_post = mc_hash_key(v, strlen(v)); if (hash_post != hash_pre) { printf("Hash pre (%u) != post (%u)\n", hash_pre, hash_post); } free(v); } else { printf("Return value null on iteration %d\n", i); } } mc_free(mc); return EX_OK; }
static void mc_active(ipmi_mc_t *mc, int active, void *cb_data) { struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; int rv; if (active) { dbg("MC added and active...(%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); mc_add(mc, handler); ipmi_handler->mc_count++; /* register MC level SDRs read */ rv = ipmi_mc_set_sdrs_first_read_handler(mc, mc_SDRs_read_done, &ipmi_handler->mc_count); if (rv) dbg("mc level SDRs read handler failed"); } }
int main(int argc, char *argv[]) { struct memcache *mc = NULL; u_int32_t num_tests = 0, valsize = 0; u_int32_t i; struct timeval t1, t2; const char *key; char *tests = NULL; char *val; u_int32_t keylen; double addtime, deltime; const char fmt[] = "%s\t%f\t%f\t%f\n"; struct memcache_req *req; struct memcache_res *res; if (argc > 1) num_tests = strtol(argv[1], NULL, 10); if (num_tests == 0) num_tests = 10; if (argc > 2) valsize = strtol(argv[2], NULL, 10); if (argc > 3) tests = strdup(argv[3]); if (tests == NULL) tests = strdup("adgs"); if (valsize == 0) valsize = 50; val = (char *)malloc(valsize + 1); memset(val, 69, valsize); val[valsize] = '\0'; /* XXX I should add a min/max time value for each request */ printf("Value size:\t%d\n", valsize); printf("Num tests:\t%d\n", num_tests); printf("Test\tOps per second\tTotal Time\tTime per Request\n"); key = "bench_key"; keylen = strlen(key); mc = mc_new(); if (mc == NULL) err(EX_OSERR, "Unable to allocate a new memcache object"); mc_err_filter_del(MCM_ERR_LVL_INFO); mc_err_filter_del(MCM_ERR_LVL_NOTICE); mc_server_add4(mc, "localhost:11211"); /* Establish a connection */ mc_set(mc, key, keylen, val, valsize, 0, 0); /* BEGIN set test, if specified */ if (strchr(tests, (int)'s') != NULL) { if (gettimeofday(&t1, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); for (i = 0; i < num_tests; i++) { mc_set(mc, key, keylen, val, valsize, 0, 0); } if (gettimeofday(&t2, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); /* END set test */ printf(fmt, "set", num_tests / tt(&t1, &t2), tt(&t1, &t2), tt(&t1, &t2) / num_tests); } if (strchr(tests, (int)'g') != NULL) { /* BEGIN get request */ req = mc_req_new(); res = mc_req_add(req, key, keylen); res->size = valsize; res->val = malloc(res->size); mc_res_free_on_delete(res, 1); if (gettimeofday(&t1, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); for (i = 0; i < num_tests; i++) { mc_get(mc, req); } if (gettimeofday(&t2, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); mc_req_free(req); /* END get test */ printf(fmt, "get", num_tests / tt(&t1, &t2), tt(&t1, &t2), tt(&t1, &t2) / num_tests); } if (strchr(tests, 'a') != NULL || strchr(tests, 'd') != NULL) { /* Run the add/delete test */ mc_delete(mc, key, keylen, 0); addtime = deltime = 0.0; for (i = 0; i < num_tests; i++) { /* BEGIN add test */ if (strchr(tests, 'a') != NULL) { if (gettimeofday(&t1, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); mc_add(mc, key, keylen, val, valsize, 0, 0); if (gettimeofday(&t2, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); addtime += tt(&t1, &t2); /* END add test */ } /* BEGIN delete test */ if (strchr(tests, 'd') != NULL) { if (gettimeofday(&t1, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); mc_delete(mc, key, keylen, 0); if (gettimeofday(&t2, NULL) != 0) err(EX_OSERR, "gettimeofday(2)"); deltime += tt(&t1, &t2); /* END delete test */ } } if (strchr(tests, 'a') != NULL) printf(fmt, "add", num_tests / addtime, addtime, addtime / num_tests); if (strchr(tests, 'd') != NULL) printf(fmt, "delete", num_tests / deltime, deltime, deltime / num_tests); } free(tests); free(val); mc_free(mc); return EX_OK; }
void ohoi_mc_event(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_mc_t *mc, void *cb_data) { struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; int rv; switch (op) { case IPMI_ADDED: /* if we get an MC but inactive, register a call to add it once it goes active */ rv = ipmi_mc_add_active_handler(mc, mc_active, handler); if(!ipmi_mc_is_active(mc)) { dbg("MC updated but inactive...we ignore (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); break; } else { /* MC is active */ mc_add(mc, handler); ipmi_handler->mc_count++; dbg("OP:ADD - mc count increment: %d", ipmi_handler->mc_count); /* register MC level SDRs read */ ipmi_mc_set_sdrs_first_read_handler(mc, mc_SDRs_read_done, &ipmi_handler->mc_count); dbg("MC updated and is active: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); break; } case IPMI_DELETED: dbg("MC deleted: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); /* most likely won't get called during discovery so comment out for now */ //ipmi_handler->mc_count--; /* need to add call to remove from RPT */ break; case IPMI_CHANGED: if(!ipmi_mc_is_active(mc)) { dbg("MC changed and is inactive: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); } else { mc_add(mc, handler); dbg("MC changed and is active: (%d %x)\n", ipmi_mc_get_address(mc), ipmi_mc_get_channel(mc)); } break; } }