Exemple #1
0
uint32_t thread_count_native(struct cpuid_state_t *state)
{
#if defined(TARGET_OS_MACOSX)
	uint32_t count;
	size_t  size = sizeof(count);

	if (sysctlbyname("hw.ncpu", &count, &size, NULL, 0))
		return 1;

	return count;
#elif defined(TARGET_OS_SOLARIS)
	long count;

	if ((count = sysconf(_SC_NPROCESSORS_ONLN)) == -1)
		return 1;

	(void)state;

	return (uint32_t)count;
#else
	static unsigned int i = 0;
	if (i) return i;
	if (thread_bind_native(state, 0) != 0) {
		fprintf(stderr, "ERROR: thread_bind() doesn't appear to be working correctly.\n");
		abort();
	}
	while (thread_bind_native(state, ++i) == 0);
	return i;
#endif
}
Exemple #2
0
static void *apic_nonsensical_worker_thread(void *flagptr)
{
	uint8_t *flag = (uint8_t *)flagptr;
	uint32_t hwthreads = thread_count_native(NULL);
	struct timeval tv;
	while (*flag) {
		thread_bind_native(NULL, rand() % hwthreads);
		gettimeofday(&tv, NULL);
	}
	pthread_exit(NULL);
	return NULL;
}
Exemple #3
0
uint32_t thread_count_native( __unused_variable struct cpuid_state_t *state)
{
#ifdef TARGET_OS_MACOSX
	uint32_t count;
	size_t  size = sizeof(count);

	if (sysctlbyname("hw.ncpu", &count, &size, NULL, 0))
		return 1;

	return count;
#else
	static unsigned int i = 0;
	if (i) return i;
	if (thread_bind_native(state, 0) != 0) {
		fprintf(stderr, "ERROR: thread_bind() doesn't appear to be working correctly.\n");
		abort();
	}
	while (thread_bind_native(state, ++i) == 0);
	return i;
#endif
}
Exemple #4
0
static void *apic_validation_thread(void *ptr)
{
	struct apic_validate_t *meta = (struct apic_validate_t *)ptr;
	thread_bind_native(NULL, meta->index);
	while (!meta->failed && *meta->worker_flag) {
		usleep(5000);
		if (get_apicid(meta->state) != meta->expected) {
			meta->failed = 1;
		}
	}
	pthread_exit(NULL);
	return NULL;
}