Blame src/thread/bench.c

nsz 4d3523
#define _XOPEN_SOURCE 700
nsz 4d3523
#include <stdio.h>
nsz 4d3523
#include <stdlib.h>
nsz 4d3523
#include <string.h>
nsz 4d3523
#include <pthread.h>
nsz 4d3523
#include <unistd.h>
nsz 4d3523
#include "test.h"
nsz 4d3523
nsz 4d3523
void *emptyfunc(void *dummy) {
nsz 4d3523
	return 0;
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
void bench_pthread_createjoin_serial1(int N) {
nsz 4d3523
	int i;
nsz 4d3523
	pthread_t td;
nsz 4d3523
	void *dummy;
nsz 4d3523
nsz 4d3523
	for (i=0; i
nsz 4d3523
		pthread_create(&td, 0, emptyfunc, 0);
nsz 4d3523
		pthread_join(td, &dummy);
nsz 4d3523
	}
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
void bench_pthread_createjoin_serial2(int N) {
nsz 4d3523
	int i, j;
nsz 4d3523
	pthread_t td[50];
nsz 4d3523
	void *dummy;
nsz 4d3523
nsz 4d3523
	for (j=0; j
nsz 4d3523
		for (i=0; i
nsz 4d3523
			pthread_create(td+i, 0, emptyfunc, 0);
nsz 4d3523
		for (i=0; i
nsz 4d3523
			pthread_join(td[i], &dummy);
nsz 4d3523
	}
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
void bench_pthread_create_serial1(int N) {
nsz 4d3523
	int i,j;
nsz 4d3523
	pthread_attr_t attr;
nsz 4d3523
	pthread_t td[50];
nsz 4d3523
	void *dummy;
nsz 4d3523
nsz 4d3523
	pthread_attr_init(&attr);
nsz 4d3523
	pthread_attr_setstacksize(&attr, 16384);
nsz 4d3523
	for (j=0; j
nsz 4d3523
		for (i=0; i
nsz 4d3523
			pthread_create(td+i, &attr, emptyfunc, 0);
nsz 4d3523
		stop_timer();
nsz 4d3523
		for (i=0; i
nsz 4d3523
			pthread_join(td[i], &dummy);
nsz 4d3523
		start_timer();
nsz 4d3523
	}
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
static int lockN;
nsz 4d3523
void *lockunlock(void *mut)
nsz 4d3523
{
nsz 4d3523
	int i;
nsz 4d3523
	for (i=0; i
nsz 4d3523
		pthread_mutex_lock(mut);
nsz 4d3523
		pthread_mutex_unlock(mut);
nsz 4d3523
	}
nsz 4d3523
	return 0;
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
void bench_pthread_uselesslock(int N) {
nsz 4d3523
	pthread_t td;
nsz 4d3523
	pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
nsz 4d3523
	void *dummy;
nsz 4d3523
nsz 4d3523
	lockN = N;
nsz 4d3523
	pthread_create(&td, 0, lockunlock, &mut;;
nsz 4d3523
	pthread_join(td, &dummy);
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
void bench_pthread_createjoin_min1(int N) {
nsz 4d3523
	size_t i;
nsz 4d3523
	pthread_t td;
nsz 4d3523
	pthread_attr_t a;
nsz 4d3523
	void *dummy;
nsz 4d3523
nsz 4d3523
	pthread_attr_init(&a);
nsz 4d3523
	pthread_attr_setstacksize(&a, sysconf(_SC_PAGESIZE));
nsz 4d3523
	pthread_attr_setguardsize(&a, 0);
nsz 4d3523
	for (i=0; i
nsz 4d3523
		pthread_create(&td, &a, emptyfunc, 0);
nsz 4d3523
		pthread_join(td, &dummy);
nsz 4d3523
	}
nsz 4d3523
}
nsz 4d3523
nsz 4d3523
void bench_pthread_createjoin_min2(int N) {
nsz 4d3523
	int i, j;
nsz 4d3523
	pthread_t td[50];
nsz 4d3523
	pthread_attr_t a;
nsz 4d3523
	void *dummy;
nsz 4d3523
nsz 4d3523
	pthread_attr_init(&a);
nsz 4d3523
	pthread_attr_setstacksize(&a, sysconf(_SC_PAGESIZE));
nsz 4d3523
	pthread_attr_setguardsize(&a, 0);
nsz 4d3523
	for (j=0; j
nsz 4d3523
		for (i=0; i
nsz 4d3523
			pthread_create(td+i, &a, emptyfunc, 0);
nsz 4d3523
		for (i=0; i
nsz 4d3523
			pthread_join(td[i], &dummy);
nsz 4d3523
	}
nsz 4d3523
}