void testbar() { long i; double meantime, sd; int indices[nthreads]; phaser_t ph; phaser_create(&ph, SIGNAL_WAIT, degree); start_finish(); printf("\n"); printf("--------------------------------------------------------\n"); printf("Computing PHASER BARRIER time\n"); for(i = 1; i < nthreads; ++i) { indices[i] = i; async(&barrier_test, (void *) (indices+i), NULL, NULL, PHASER_TRANSMIT_ALL); } indices[0] = 0; barrier_test((void *) indices); end_finish(); phaser_drop(ph); stats (&meantime, &sd); printf("BARRIER time = %f microseconds +/- %f\n", meantime, CONF95*sd); printf("BARRIER overhead = %f microseconds +/- %f\n", meantime-reftime, CONF95*(sd+refsd)); }
int main (int argc, char ** argv) { printf("Hello\n"); hclib_init(&argc, argv); phaser_t ph; phaser_create(&ph, SIGNAL_WAIT, 2); phaser_mode_t mode = SIGNAL_WAIT; phased_t phased; phased.count = 1; phased.phasers = &ph; phased.phasers_mode = &mode; async(&barrier_test, NULL, NULL, &phased, 0); // Participate in the barrier barrier_test(NULL); // current worker enters in helper mode // and will pick up one of the tasks hclib_finalize(); return 0; }
int main (int argc, char ** argv) { hclib_init(); // TODO should get number of workers here int nthreads = 3; int degree = nthreads; int i; phaser_t ph; phaser_create(&ph, SIGNAL_WAIT, degree); for(i = 1; i < nthreads; ++i) { printf("Create async %d\n", i); async(&barrier_test, NULL, NULL, NULL, PHASER_TRANSMIT_ALL); } // Participate in the barrier barrier_test(NULL); // current worker enters in helper mode // and will pick up one of the tasks hclib_finalize(); return 0; }
if ((global_mem->g_verbose) && (barrier_errs != 0)) printf("\nThread %" PRIu32 " (id=%d core=%d) had %" PRIu32 " barrier_errs in %" PRIu32 " iterations\n", thread_num, per_thread_mem->thread_id, per_thread_mem->thread_core, barrier_errs, iterations); return barrier_errs; } static void *no_barrier_functional_test(void *arg UNUSED) { per_thread_mem_t *per_thread_mem; uint32_t barrier_errs; per_thread_mem = thread_init(); barrier_errs = barrier_test(per_thread_mem, 1); /* * Note that the following CU_ASSERT MAY appear incorrect, but for the * no_barrier test it should see barrier_errs or else there is something * wrong with the test methodology or the ODP thread implementation. * So this test PASSES only if it sees barrier_errs or a single * worker was used. */ CU_ASSERT(barrier_errs != 0 || global_mem->g_num_threads == 1); thread_finalize(per_thread_mem); return NULL; } static void *barrier_functional_test(void *arg UNUSED)
static int user_main(int argc, char *argv[]) { int i; /* Sample the memory usage now */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmbefore = mallinfo(); g_mmprevious = g_mmbefore; #else (void)mallinfo(&g_mmbefore); memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); #endif #endif printf("\nuser_main: Begin argument test\n"); printf("user_main: Started with argc=%d\n", argc); /* Verify passed arguments */ if (argc != NARGS + 1) { printf("user_main: Error expected argc=%d got argc=%d\n", NARGS+1, argc); } for (i = 0; i <= NARGS; i++) { printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]); } for (i = 1; i <= NARGS; i++) { if (strcmp(argv[i], g_argv[i-1]) != 0) { printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n", i, g_argv[i-1], argv[i]); } } check_test_memory_usage(); /* Check environment variables */ #ifndef CONFIG_DISABLE_ENVIRON show_environment(true, true, true); unsetenv(g_var1_name); show_environment(false, true, true); check_test_memory_usage(); clearenv(); show_environment(false, false, false); check_test_memory_usage(); #endif /* Top of test loop */ #if CONFIG_EXAMPLES_OSTEST_LOOPS > 1 for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++) #elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0 for (;;) #endif { #if CONFIG_NFILE_DESCRIPTORS > 0 /* Checkout /dev/null */ printf("\nuser_main: /dev/null test\n"); dev_null(); check_test_memory_usage(); #endif #ifdef CONFIG_ARCH_FPU /* Check that the FPU is properly supported during context switching */ printf("\nuser_main: FPU test\n"); fpu_test(); check_test_memory_usage(); #endif #ifdef CONFIG_SCHED_WAITPID /* Check waitpid() and friends */ printf("\nuser_main: waitpid test\n"); waitpid_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and pthread mutex */ printf("\nuser_main: mutex test\n"); mutex_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES) /* Verify recursive mutexes */ printf("\nuser_main: recursive mutex test\n"); recursive_mutex_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread cancellation */ printf("\nuser_main: cancel test\n"); cancel_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and semaphores */ printf("\nuser_main: semaphore test\n"); sem_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and condition variables */ printf("\nuser_main: condition variable test\n"); #ifdef CONFIG_PRIORITY_INHERITANCE printf("\n Skipping, Test logic incompatible with priority inheritance\n"); #else cond_test(); check_test_memory_usage(); #endif #endif #if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK) /* Verify pthreads and condition variable timed waits */ printf("\nuser_main: timed wait test\n"); timedwait_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and message queues */ printf("\nuser_main: message queue test\n"); mqueue_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK) /* Verify pthreads and message queues */ printf("\nuser_main: timed message queue test\n"); timedmqueue_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_SIGNALS /* Verify signal handlers */ printf("\nuser_main: signal handler test\n"); sighand_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS) /* Verify posix timers */ printf("\nuser_main: POSIX timer test\n"); timer_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0 /* Verify round robin scheduling */ printf("\nuser_main: round-robin scheduler test\n"); rr_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread barriers */ printf("\nuser_main: barrier test\n"); barrier_test(); check_test_memory_usage(); #endif #if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify priority inheritance */ printf("\nuser_main: priority inheritance test\n"); priority_inheritance(); check_test_memory_usage(); #endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ #ifdef CONFIG_ARCH_HAVE_VFORK printf("\nuser_main: vfork() test\n"); vfork_test(); #endif /* Compare memory usage at time ostest_main started until * user_main exits. These should not be identical, but should * be similar enough that we can detect any serious OS memory * leaks. */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmafter = mallinfo(); #else (void)mallinfo(&g_mmafter); #endif printf("\nFinal memory usage:\n"); show_memory_usage(&g_mmbefore, &g_mmafter); #endif } printf("user_main: Exitting\n"); return 0; }
static int user_main(int argc, char *argv[]) #endif { int i; /* Sample the memory usage now */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmbefore = mallinfo(); g_mmprevious = g_mmbefore; #else (void)mallinfo(&g_mmbefore); memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); #endif #endif printf("\nuser_main: Begin argument test\n"); printf("user_main: Started with argc=%d\n", argc); /* Verify passed arguments */ if (argc != NARGS + 1) { printf("user_main: Error expected argc=%d got argc=%d\n", NARGS+1, argc); } for (i = 0; i <= NARGS; i++) { printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]); } for (i = 1; i <= NARGS; i++) { if (strcmp(argv[i], g_argv[i-1]) != 0) { printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n", i, g_argv[i-1], argv[i]); } } check_test_memory_usage(); /* If retention of child status is enable, then suppress it for this task. * This task may produce many, many children (especially if * CONFIG_EXAMPLES_OSTEST_LOOPS) and it does not harvest their exit status. * As a result, the test may fail inappropriately unless retention of * child exit status is disabled. * * So basically, this tests that child status can be disabled, but cannot * verify that status is retained correctly. */ #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) { struct sigaction sa; int ret; sa.sa_handler = SIG_IGN; sa.sa_flags = SA_NOCLDWAIT; ret = sigaction(SIGCHLD, &sa, NULL); if (ret < 0) { printf("user_main: ERROR: sigaction failed: %d\n", errno); } } #endif /* Check environment variables */ #ifndef CONFIG_DISABLE_ENVIRON show_environment(true, true, true); unsetenv(g_var1_name); show_environment(false, true, true); check_test_memory_usage(); clearenv(); show_environment(false, false, false); check_test_memory_usage(); #endif /* Top of test loop */ #if CONFIG_EXAMPLES_OSTEST_LOOPS > 1 for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++) #elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0 for (;;) #endif { #if CONFIG_NFILE_DESCRIPTORS > 0 /* Checkout /dev/null */ printf("\nuser_main: /dev/null test\n"); dev_null(); check_test_memory_usage(); #endif #ifdef CONFIG_ARCH_FPU /* Check that the FPU is properly supported during context switching */ printf("\nuser_main: FPU test\n"); fpu_test(); check_test_memory_usage(); #endif /* Checkout task_restart() */ printf("\nuser_main: task_restart test\n"); restart_test(); check_test_memory_usage(); #ifdef CONFIG_SCHED_WAITPID /* Check waitpid() and friends */ printf("\nuser_main: waitpid test\n"); waitpid_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and pthread mutex */ printf("\nuser_main: mutex test\n"); mutex_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES) /* Verify recursive mutexes */ printf("\nuser_main: recursive mutex test\n"); recursive_mutex_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread cancellation */ printf("\nuser_main: cancel test\n"); cancel_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and semaphores */ printf("\nuser_main: semaphore test\n"); sem_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and condition variables */ printf("\nuser_main: condition variable test\n"); #ifdef CONFIG_PRIORITY_INHERITANCE printf("\n Skipping, Test logic incompatible with priority inheritance\n"); #else cond_test(); check_test_memory_usage(); #endif #endif #if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and condition variable timed waits */ printf("\nuser_main: timed wait test\n"); timedwait_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and message queues */ printf("\nuser_main: message queue test\n"); mqueue_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and message queues */ printf("\nuser_main: timed message queue test\n"); timedmqueue_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_SIGNALS /* Verify signal handlers */ printf("\nuser_main: signal handler test\n"); sighand_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS) /* Verify posix timers */ printf("\nuser_main: POSIX timer test\n"); timer_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0 /* Verify round robin scheduling */ printf("\nuser_main: round-robin scheduler test\n"); rr_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread barriers */ printf("\nuser_main: barrier test\n"); barrier_test(); check_test_memory_usage(); #endif #if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify priority inheritance */ printf("\nuser_main: priority inheritance test\n"); priority_inheritance(); check_test_memory_usage(); #endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ #if defined(CONFIG_ARCH_HAVE_VFORK) && defined(CONFIG_SCHED_WAITPID) && \ !defined(CONFIG_DISABLE_SIGNALS) printf("\nuser_main: vfork() test\n"); vfork_test(); #endif /* Compare memory usage at time ostest_main started until * user_main exits. These should not be identical, but should * be similar enough that we can detect any serious OS memory * leaks. */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmafter = mallinfo(); #else (void)mallinfo(&g_mmafter); #endif printf("\nFinal memory usage:\n"); show_memory_usage(&g_mmbefore, &g_mmafter); #endif } printf("user_main: Exitting\n"); return 0; }