Ejemplo n.º 1
0
static void
_benchmark(ssize_t write_size)
{
	ssize_t res;
	int write_count = 0;
	float secs;

	alarm_notice = 0;

	alarm (10);

	qb_util_stopwatch_start(sw);
	do {
		res = qb_rb_chunk_write(rb, buffer, write_size);
		if (res == write_size) {
			write_count++;
		}
	} while (alarm_notice == 0 && (res == write_size || res == -EAGAIN));
	if (res < 0) {
		perror("qb_ipcc_sendv");
	}
	qb_util_stopwatch_stop(sw);
	secs = qb_util_stopwatch_sec_elapsed_get(sw);

	printf ("%5d messages sent ", write_count);
	printf ("%5ld bytes per write ", (long int) write_size);
	printf ("%7.3f Seconds runtime ", secs);
	printf ("%9.3f TP/s ",
		((float)write_count) / secs);
	printf ("%7.3f MB/s.\n",
		((float)write_count) * ((float)write_size) / secs);
}
Ejemplo n.º 2
0
static void bm_finish(struct bm_ctx *ctx, const char *operation, int32_t size)
{
	qb_util_stopwatch_stop(ctx->sw);
	ctx->secs = qb_util_stopwatch_sec_elapsed_get(ctx->sw);

	ctx->mbs =
	    ((((float)ctx->counter) * size) / ctx->secs) / (1024.0 *
							    1024.0);
}
Ejemplo n.º 3
0
static void resource_execute_cb(struct pe_operation *op)
{
	struct resource *resource;
	struct assembly *assembly;

	qb_enter();

	assembly = qb_map_get(assembly_map, op->hostname);
	resource = qb_map_get(assembly->resource_map, op->rname);

	if (assembly->recover.state != RECOVER_STATE_RUNNING) {
		qb_log(LOG_DEBUG, "can't execute resource in offline state");
		resource_action_completed(op, OCF_UNKNOWN_ERROR);
		return;
	}
	qb_log(LOG_TRACE, "%s_%s_%d [%s] on %s target_rc:%d",
	       op->rname, op->method, op->interval, op->rclass, op->hostname,
	       op->target_outcome);

	qb_util_stopwatch_start(op->time_execed);

	op->resource = resource;
	if (strcmp(op->method, "monitor") == 0) {
		if (strstr(op->rname, op->hostname) != NULL) {
			assert(op->resource);
			if (op->interval > 0) {
				recurring_monitor_start(op);
			} else {
				resource_monitor_execute(op);
			}
		} else {
			qb_util_stopwatch_stop(op->time_execed);
			pe_resource_completed(op, OCF_NOT_RUNNING);
			pe_resource_unref(op);
		}
	} else if (strcmp (op->method, "start") == 0) {
		transport_resource_action(assembly, resource, op);
	} else if (strcmp(op->method, "stop") == 0) {
		if (resource->monitor_op) {
			recurring_monitor_stop(resource->monitor_op);
		}
		transport_resource_action(assembly, resource, op);
	} else if (strcmp(op->method, "delete") == 0) {
		op_history_delete(op);
	} else {
		assert(0);
	}

	qb_leave();
}
Ejemplo n.º 4
0
static void recurring_monitor_start(struct pe_operation *op)
{
	struct resource * r = (struct resource *)op->resource;

	if (!qb_loop_timer_is_running(NULL, r->monitor_timer)) {
		pe_resource_ref(op);
		r->monitor_op = op;
		resource_monitor_execute(op);
	} else {
		qb_util_stopwatch_stop(op->time_execed);
		pe_resource_completed(op, OCF_OK);
		pe_resource_unref(op);
	}
}
Ejemplo n.º 5
0
void
resource_action_completed(struct pe_operation *op,
			  enum ocf_exitcode pe_exitcode)
{
	uint64_t el;
	struct assembly *a = qb_map_get(assembly_map, op->hostname);;
	struct resource *r = qb_map_get(a->resource_map, op->rname);

	qb_enter();

	op->times_executed++;
	qb_util_stopwatch_stop(op->time_execed);
	el = qb_util_stopwatch_us_elapsed_get(op->time_execed);

	qb_log(LOG_INFO, "%s_%s_%d [%s] on %s rc:[%d/%d] time:[%"PRIu64"/%ums]",
	       op->rname, op->method, op->interval, op->rclass, op->hostname,
	       pe_exitcode, op->target_outcome,
	       el / QB_TIME_US_IN_MSEC, op->timeout);

	if (strstr(op->rname, op->hostname) != NULL) {
		op_history_save(r, op, pe_exitcode);
	}

	if (op->times_executed <= 1) {
		pe_resource_completed(op, pe_exitcode);
	}

	resource_state_set(r, op, pe_exitcode);

	if (pe_exitcode != op->target_outcome) {
		schedule_processing();
	}
	if (op->interval > 0) {
		if (pe_exitcode != op->target_outcome) {
			/* unreference as not used by the timer anymore.
			 */
			pe_resource_unref(op);
		} else {
			qb_loop_timer_add(NULL, QB_LOOP_LOW,
					  op->interval * QB_TIME_NS_IN_MSEC, op,
					  resource_monitor_execute,
					  &r->monitor_timer);
		}
	} else {
		pe_resource_unref(op);
	}

	qb_leave();
}
Ejemplo n.º 6
0
static void job_add_self(void *data)
{
	int32_t res;
	uint64_t elapsed1;
	qb_loop_t *l = (qb_loop_t *)data;

	job_1_run_count++;
	qb_util_stopwatch_stop(rl_sw);
	elapsed1 = qb_util_stopwatch_us_elapsed_get(rl_sw);
	if (elapsed1 > (RATE_LIMIT_RUNTIME_SEC * QB_TIME_US_IN_SEC)) {
		/* run for 3 seconds */
		qb_loop_stop(l);
		return;
	}
	res = qb_loop_job_add(l, QB_LOOP_MED, data, job_add_self);
	ck_assert_int_eq(res, 0);
}
Ejemplo n.º 7
0
static void instance_state_completion(char *state, char *address, void *data)
{
	struct assembly *assembly = (struct assembly *)data;

	if (strcmp(state, "ACTIVE") == 0) {
		assembly->address = strdup(address);
		qb_util_stopwatch_stop(assembly->sw_instance_create);
		qb_log(LOG_INFO, "Instance '%s' with address '%s' changed to RUNNING in (%lld ms).",
			assembly->name, assembly->address,
			qb_util_stopwatch_us_elapsed_get(assembly->sw_instance_create) / 1000);
		qb_util_stopwatch_start(assembly->sw_instance_connected);
		transport_connect(assembly);
	} else {
		recover_state_set(&assembly->recover, RECOVER_STATE_UNKNOWN);
		qb_loop_timer_add(NULL, QB_LOOP_LOW,
			PENDING_TIMEOUT * QB_TIME_NS_IN_MSEC, assembly,
			my_instance_state_get, NULL);
	}
}
Ejemplo n.º 8
0
static void
_benchmark(qb_ipcc_connection_t *conn, int write_size)
{
	struct iovec iov[2];
	ssize_t res;
	struct qb_ipc_request_header hdr;
	int write_count = 0;
	float secs;

	alarm_notice = 0;
	hdr.size = write_size;
	hdr.id = QB_IPC_MSG_USER_START + 1;

	iov[0].iov_base = &hdr;
	iov[0].iov_len = sizeof(struct qb_ipc_request_header);

	iov[1].iov_base = data;
	iov[1].iov_len = write_size - sizeof(struct qb_ipc_request_header);

	alarm (10);

	qb_util_stopwatch_start(sw);
	do {
		res = qb_ipcc_sendv(conn, iov, 2);
		if (res == write_size) {
			write_count++;
		}
	} while (alarm_notice == 0 && (res == write_size || res == -EAGAIN));
	if (res < 0) {
		perror("qb_ipcc_sendv");
	}
	qb_util_stopwatch_stop(sw);
	secs = qb_util_stopwatch_sec_elapsed_get(sw);

	printf ("%5d messages sent ", write_count);
	printf ("%5d bytes per write ", write_size);
	printf ("%7.3f Seconds runtime ", secs);
	printf ("%9.3f TP/s ",
		((float)write_count) / secs);
	printf ("%7.3f MB/s.\n",
		((float)write_count) * ((float)write_size) / secs);
}
Ejemplo n.º 9
0
static void op_history_delete(struct pe_operation *op)
{
	struct resource *r;
	qb_map_iter_t *iter;
	const char *key;
	struct operation_history *oh;

	qb_enter();

	/*
	 * Delete this resource from any operational histories
	 */
	iter = qb_map_iter_create(op_history_map);
	while ((key = qb_map_iter_next(iter, (void **)&oh)) != NULL) {
		r = (struct resource *)oh->resource;

		if (r == op->resource) {
			/* stop the recurring monitor.
			 */
			if (qb_loop_timer_is_running(NULL, r->monitor_timer) &&
			    r->monitor_op) {
				recurring_monitor_stop(r->monitor_op);
			}

			qb_map_rm(op_history_map, key);
			free(oh->rsc_id);
			free(oh->operation);
			free(oh->op_digest);
			free(oh);
		}
	}
	qb_map_iter_free(iter);

	qb_util_stopwatch_stop(op->time_execed);
	pe_resource_completed(op, OCF_OK);
	pe_resource_unref(op);

	qb_leave();
}
Ejemplo n.º 10
0
static void
node_state_change_event(void* inst,
			enum recover_state from,
			enum recover_state to)
{
	struct assembly *a = (struct assembly *)inst;

	qb_enter();

	qb_log(LOG_INFO, "Node (%s): changing state from %s to %s",
	       a->name, state_name_str[from], state_name_str[to]);
	cape_admin_event_send(application->name, a, NULL,
			      state_str[from][to],
			      "bla");
	if (to == RECOVER_STATE_RUNNING) {
		qb_util_stopwatch_stop(a->sw_instance_connected);
		qb_log(LOG_INFO, "Assembly '%s' connected in (%"PRIu64" ms).",
			a->name,
			qb_util_stopwatch_us_elapsed_get(a->sw_instance_connected) / QB_TIME_US_IN_MSEC);
		node_update_addr_info(a);
	}
	schedule_processing();
	qb_leave();
}
Ejemplo n.º 11
0
static void
test_this_one(const char *name, snprintf_like_func func)
{
	int i;
	qb_util_stopwatch_t *sw = qb_util_stopwatch_create();
	float elapsed = 452.245252343;
	float ops_per_sec = 0.345624523;

	qb_util_stopwatch_start(sw);
	for (i = 0; i < ITERATIONS; i++) {
		func("%d %s %llu %9.3f", i, "hello", 3425ULL, elapsed);
		func("[%10s] %.32x -> %p", "hello", i, func);
		func("Client %s.%.9s wants to fence (%s) '%s' with device '%3.5f'",
		     "bla", "foooooooooooooooooo",
		     name, "target", ops_per_sec);
		func("Node %s now has process list: %.32x (was %.32x)",
		     "18builder", 2, 0);
	}
	qb_util_stopwatch_stop(sw);
	elapsed = qb_util_stopwatch_sec_elapsed_get(sw);
	ops_per_sec = ((float)ITERATIONS) / elapsed;
	printf("%s] Duration: %9.3f OPs/sec: %9.3f\n", name, elapsed, ops_per_sec);
	qb_util_stopwatch_free(sw);
}