void *test_percpu_list_thread(void *arg)
{
	int i;
	struct percpu_list *list = (struct percpu_list *)arg;

	if (rseq_register_current_thread()) {
		fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
			errno, strerror(errno));
		abort();
	}

	for (i = 0; i < 100000; i++) {
		struct percpu_list_node *node;

		node = this_cpu_list_pop(list, NULL);
		sched_yield();  /* encourage shuffling */
		if (node)
			this_cpu_list_push(list, node, NULL);
	}

	if (rseq_unregister_current_thread()) {
		fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n",
			errno, strerror(errno));
		abort();
	}

	return NULL;
}
int main(int argc, char **argv)
{
	if (rseq_register_current_thread()) {
		fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
			errno, strerror(errno));
		goto error;
	}
	printf("spinlock\n");
	test_percpu_spinlock();
	printf("percpu_list\n");
	test_percpu_list();
	if (rseq_unregister_current_thread()) {
		fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n",
			errno, strerror(errno));
		goto error;
	}
	return 0;

error:
	return -1;
}
void *test_percpu_spinlock_thread(void *arg)
{
	struct spinlock_test_data *data = arg;
	int i, cpu;

	if (rseq_register_current_thread()) {
		fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
			errno, strerror(errno));
		abort();
	}
	for (i = 0; i < data->reps; i++) {
		cpu = rseq_this_cpu_lock(&data->lock);
		data->c[cpu].count++;
		rseq_percpu_unlock(&data->lock, cpu);
	}
	if (rseq_unregister_current_thread()) {
		fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n",
			errno, strerror(errno));
		abort();
	}

	return NULL;
}
Example #4
0
int main(int argc, char **argv)
{
	void *handle1, *handle2;
	int i, ret;

	if (rseq_register_current_thread())
		abort();
	for (i = 0; i < 10000; i++) {
		handle1 = dlopen("./libtest-linked-lib.so",
				RTLD_NOW | RTLD_GLOBAL);
		assert(handle1);
		linked_lib_fn = dlsym(handle1, "linked_lib_fn");
		assert(linked_lib_fn);

		linked_lib_fn();

		/*
		 * Need to clear rseq_cs before lib unload.
	 	 */
		rseq_prepare_unload();

		ret = dlclose(handle1);
		assert(!ret);

		handle2 = dlopen("./libtest-linked-lib2.so",
				RTLD_NOW | RTLD_GLOBAL);
		assert(handle2);
		ret = dlclose(handle2);
		assert(!ret);

		poll(NULL, 0, 1);	/* Sleep 1ms */
	}
	if (rseq_unregister_current_thread())
		abort();

	return 0;
}
Example #5
0
int main(int argc, char **argv)
{
	int cpu, ret;

	if (rseq_register_current_thread())
		abort();
	cpu = rseq_cpu_start();
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
	ret = rseq_addv(&v, 1, cpu);
	if (ret)
		goto end;
end:
	if (rseq_unregister_current_thread())
		abort();
	printf("total %" PRIdPTR "\n", v);
	return 0;
}