Пример #1
0
int main(int argc, char *argv[])
{
    int i;
    int nkids = 1;

    smp_init();

    if (argc > 1) {
        nkids = strtoul(argv[1], NULL, 0);
        if (nkids > NR_THREADS) {
            fprintf(stderr, "nkids = %d too large, max = %d\n",
                    nkids, NR_THREADS);
            usage(argv[0]);
        }
    }
    printf("%d ", nkids);

    goflag = -1;
    for (i = 0; i < nkids; i++)
        create_thread(counter_test, NULL);

    goflag = 1;
    sleep(1);
    goflag = 0;

    wait_all_threads();

    printf("count: %d\n", counter);

    exit(0);
}
int main(int argc, char *argv[])
{
	int i;
	int nkids = 1;

	smp_init();

	if (argc > 1) {
		nkids = strtoul(argv[1], NULL, 0);
		if (nkids > NR_THREADS) {
			fprintf(stderr, "nkids = %d too large, max = %d\n",
				nkids, NR_THREADS);
			usage(argv[0]);
		}
	}
	printf("Parent thread spawning %d threads.\n", nkids);

	for (i = 0; i < nkids; i++)
		create_thread(thread_test, (void *)i);

	wait_all_threads();

	printf("All spawned threads completed.\n", nkids);

	exit(0);
}
Пример #3
0
static void stresstest(int nreaders, int duration)
{
    int i;

    rcu_stress_current = &rcu_stress_array[0];
    rcu_stress_current->pipe_count = 0;
    rcu_stress_current->mbtest = 1;
    for (i = 0; i < nreaders; i++) {
        create_thread(rcu_read_stress_test);
    }
    create_thread(rcu_update_stress_test);
    for (i = 0; i < 5; i++) {
        create_thread(rcu_fake_update_stress_test);
    }
    goflag = GOFLAG_RUN;
    g_usleep(duration * G_USEC_PER_SEC);
    goflag = GOFLAG_STOP;
    wait_all_threads();
    printf("n_reads: %lld  n_updates: %ld  n_mberror: %d\n",
           n_reads, n_updates, n_mberror);
    printf("rcu_stress_count:");
    for (i = 0; i <= RCU_STRESS_PIPE_LEN; i++) {
        printf(" %lld", rcu_stress_count[i]);
    }
    printf("\n");
    exit(0);
}
int main(int argc, char *argv[])
{
	int i;
	struct memblock *p[2 * TARGET_POOL_SIZE] = { 0 };
	long long nc;
	long long nf;
	int nkids = 1;
	int runlength = 1;
	int totbefore;

	smp_init();
	initpools();

	if (argc > 1) {
		nkids = strtoul(argv[1], NULL, 0);
		if (nkids > NR_THREADS) {
			fprintf(stderr, "nkids = %d too large, max = %d\n",
				nkids, NR_THREADS);
			usage(argv[0]);
		}
	}
	if (argc > 2) {
		runlength = strtoul(argv[2], NULL, 0);
		if (runlength > MAX_RUN) {
			fprintf(stderr, "nkids = %d too large, max = %d\n",
				runlength, MAX_RUN);
			usage(argv[0]);
		}
	}
	printf("%d %d ", nkids, runlength);

	init_per_thread(results, 0L);
	init_per_thread(failures, 0L);
	totbefore = memblocks_available();

	goflag = 1;
	for (i = 0; i < nkids; i++)
		create_thread(memblock_test, (void *)(long)runlength);

	sleep(1);
	goflag = 0;

	wait_all_threads();
	nf = nc = 0;
	for (i = 0; i < NR_THREADS; i++) {
		nc += per_thread(results, i);
		nf += per_thread(failures, i);
	}
	printf("a/f: %Ld  fail: %Ld\n", nc, nf);
	if (memblocks_available() != totbefore) {
		printf("memblocks: before: %d after: %d\n",
		       totbefore, memblocks_available());
	}

	exit(0);
}
int main(int argc, char *argv[])
{
	int i;

	smp_init();

	create_thread(collect_timestamps, (void *)0);
	create_thread(collect_timestamps, (void *)1);
	wait_all_threads();
	for (i = 0; i < sizeof(ts) / sizeof(ts[0]); i++) {
		printf("%llx", ts[i]);
		if (i > 0)
			printf(" %lld", ts[i] - ts[i - 1]);
		printf("\n");
	}
	exit(0);
}
Пример #6
0
static void perftestrun(int nthreads, int duration, int nreaders, int nupdaters)
{
    while (atomic_read(&nthreadsrunning) < nthreads) {
        g_usleep(1000);
    }
    goflag = GOFLAG_RUN;
    g_usleep(duration * G_USEC_PER_SEC);
    goflag = GOFLAG_STOP;
    wait_all_threads();
    printf("n_reads: %lld  n_updates: %ld  nreaders: %d  nupdaters: %d duration: %d\n",
           n_reads, n_updates, nreaders, nupdaters, duration);
    printf("ns/read: %g  ns/update: %g\n",
           ((duration * 1000*1000*1000.*(double)nreaders) /
        (double)n_reads),
           ((duration * 1000*1000*1000.*(double)nupdaters) /
        (double)n_updates));
    exit(0);
}
Пример #7
0
int main(int argc, char *argv[])
{
	int nthreads = 0;

	create_thread(test_xchg_lock, (void *)0);
	nthreads++;
	create_thread(test_xchg_lock, (void *)1);
	nthreads++;

	smp_mb();
	while (atomic_read(&nthreadsrunning) < nthreads)
		poll(NULL, 0, 1);
	WRITE_ONCE(goflag, GOFLAG_RUN);
	smp_mb();
	poll(NULL, 0, 10000);
	smp_mb();
	WRITE_ONCE(goflag, GOFLAG_STOP);
	smp_mb();
	wait_all_threads();
	printf("lockacqs = %lu, lockerr = %lu\n", lockacqs, lockerr);
	return 0;
}
Пример #8
0
static void gtest_stress(int nreaders, int duration)
{
    int i;

    rcu_stress_current = &rcu_stress_array[0];
    rcu_stress_current->pipe_count = 0;
    rcu_stress_current->mbtest = 1;
    for (i = 0; i < nreaders; i++) {
        create_thread(rcu_read_stress_test);
    }
    create_thread(rcu_update_stress_test);
    for (i = 0; i < 5; i++) {
        create_thread(rcu_fake_update_stress_test);
    }
    goflag = GOFLAG_RUN;
    g_usleep(duration * G_USEC_PER_SEC);
    goflag = GOFLAG_STOP;
    wait_all_threads();
    g_assert_cmpint(n_mberror, ==, 0);
    for (i = 2; i <= RCU_STRESS_PIPE_LEN; i++) {
        g_assert_cmpint(rcu_stress_count[i], ==, 0);
    }
}
void perftestrun(int nthreads, int nreaders, int nwriters)
{
	int t;
	int duration = 240;
	long long n_reads = 0LL;
	long long n_read_retries = 0LL;
	long long n_read_errs = 0LL;
	long long n_writes = 0LL;

	smp_mb();
	while (atomic_read(&nthreadsrunning) < nthreads)
		poll(NULL, 0, 1);
	goflag = GOFLAG_RUN;
	smp_mb();
	poll(NULL, 0, duration);
	smp_mb();
	goflag = GOFLAG_STOP;
	smp_mb();
	wait_all_threads();
	for_each_thread(t) {
		n_reads += per_thread(n_reads_pt, t);
		n_read_retries += per_thread(n_read_retries_pt, t);
		n_read_errs += per_thread(n_read_errs_pt, t);
		n_writes += per_thread(n_writes_pt, t);
	}
	if (n_read_errs != 0)
		printf("!!! read-side errors detected: %lld\n", n_read_errs);
	printf("n_reads: %lld n_read_retries: %lld n_writes: %lld nreaders: %d  nwriters: %d n_elems: %d duration: %d\n",
	       n_reads, n_read_retries, n_writes, nreaders, nwriters, n_elems, duration);
	printf("ns/read: %g  ns/write: %g\n",
	       ((duration * 1000*1000.*(double)nreaders) /
	        (double)n_reads),
	       ((duration * 1000*1000.*(double)nwriters) /
	        (double)n_writes));
	exit(0);
}
Пример #10
0
int main(int argc, char *argv[])
{
	int done;
	int i;
	int iter;

	smp_init();

	if (argc > 1) {
		nkids = strtoul(argv[1], NULL, 0);
		if (nkids > NR_THREADS) {
			fprintf(stderr, "nkids = %d too large, max = %d\n",
				nkids, NR_THREADS);
			usage(argv[0]);
		}
	}
	printf("Number of threads: %d\n", nkids);

	spin_lock_init(&mutex);
	goflag = GOFLAG_INIT;
	for (i = 0; i < nkids; i++)
		create_thread(init_test, NULL);

	for (iter = 0; iter < 100; iter++) {
		spin_lock(&mutex);
		for_each_thread(i) {
			per_thread(doneflag, i) = 0;
		}
		__get_thread_var(doneflag) = 1;
		atomic_set(&counter, 0);
		atomic_set(&start_count, 0);
		initialized = 0;
		spin_unlock(&mutex);
		spin_lock(&mutex);
		goflag = GOFLAG_START;
		spin_unlock(&mutex);
		poll(NULL, 0, 1);
		done = 0;
		while (!done) {
			done = 1;
			for (i = 0; i < nkids; i++)
				if (!per_thread(doneflag, i)) {
					done = 0;
					break;
				}
			poll(NULL, 0, 1);
		}
		if (atomic_read(&counter) != 1) {
			printf("Double initialization, counter = %d\n",
			       atomic_read(&counter));
			exit(-1);
		} else {
			printf("Iteration %d succeeded\n", iter);
		}
		spin_lock(&mutex);
		atomic_set(&counter, 0);
		spin_unlock(&mutex);
		spin_lock(&mutex);
		goflag = GOFLAG_INIT;
		while (atomic_read(&counter) < nkids)
			poll(NULL, 0, 1);
		spin_unlock(&mutex);
		spin_lock(&mutex);
		atomic_set(&counter, 0);
		spin_unlock(&mutex);
	}

	goflag = GOFLAG_STOP;

	wait_all_threads();

	exit(0);
}