Ejemplo n.º 1
0
void
prot() {
	if (++caught == n) {
		caught = 0;
		n = benchmp_interval(benchmp_getstate());
	}
}
static void interval(int x)
{
    if (++caught == n) {
	caught = 0;
	n = benchmp_interval(benchmp_getstate());
    }

    setitimer(ITIMER_REAL, &value, NULL);
}
Ejemplo n.º 3
0
void 
benchmp_child(benchmp_f initialize, 
		benchmp_f benchmark,
		benchmp_f cleanup,
		int childid,
		int response, 
		int start_signal, 
		int result_signal, 
		int exit_signal,
		int enough,
	        iter_t iterations,
		int parallel, 
	        int repetitions,
		void* cookie
		)
{
	iter_t		iterations_batch = (parallel > 1) ? get_n() : 1;

	_benchmp_child_state.state = warmup;
	_benchmp_child_state.initialize = initialize;
	_benchmp_child_state.benchmark = benchmark;
	_benchmp_child_state.cleanup = cleanup;
	_benchmp_child_state.childid = childid;
	_benchmp_child_state.response = response;
	_benchmp_child_state.start_signal = start_signal;
	_benchmp_child_state.result_signal = result_signal;
	_benchmp_child_state.exit_signal = exit_signal;
	_benchmp_child_state.enough = enough;
	_benchmp_child_state.iterations = iterations;
	_benchmp_child_state.iterations_batch = iterations_batch;
	_benchmp_child_state.parallel = parallel;
	_benchmp_child_state.repetitions = repetitions;
	_benchmp_child_state.cookie = cookie;
	_benchmp_child_state.need_warmup = 1;
	_benchmp_child_state.i = 0;
	_benchmp_child_state.r_size = sizeof_result(repetitions);
	_benchmp_child_state.r = (result_t*)malloc(_benchmp_child_state.r_size);

	if (!_benchmp_child_state.r) return;
	insertinit(_benchmp_child_state.r);
	set_results(_benchmp_child_state.r);

	if (benchmp_sigchld_handler != SIG_DFL) {
		signal(SIGCHLD, benchmp_sigchld_handler);
	} else {
		signal(SIGCHLD, benchmp_child_sigchld);
	}

	if (initialize)
		(*initialize)(0, cookie);
	
	if (benchmp_sigterm_handler != SIG_DFL) {
		signal(SIGTERM, benchmp_sigterm_handler);
	} else {
		signal(SIGTERM, benchmp_child_sigterm);
	}
	if (benchmp_sigterm_received)
		benchmp_child_sigterm(SIGTERM);

	/* start experiments, collecting results */
	insertinit(_benchmp_child_state.r);

	while (1) {
		(*benchmark)(benchmp_interval(&_benchmp_child_state), cookie);
	}
}