/* * The medium thread tries to acquire a mutex, releases it once acquired and then * receives from highest priority thread in scenario 1. It increments 2 counters * on success, one for each operation. * It acquires a mutex at initialisation time and waits for any thread before * releasing the mutex in scenario 2. It increments 2 counters on success, * one for each operation. */ void mixed_pi_medium(int argc, char **argv) { L4_ThreadId_t any_thread, tid; L4_MsgTag_t tag; int counter = 10000; while (!libs_ready) ; while (L4_IsNilThread(medium1_prio_thread)) ; tid = medium1_prio_thread; //printf("Middle thread %lx/%lx starts PI test\n", me, pi_main.raw); while (1) { // Initialisation if (scenario2) { //printf("Middle thread %lx/%lx acquires mutex for resource\n", me, pi_main.raw); okl4_libmutex_count_lock(resource_mutex); cnt_m1++; } //printf("(Initialisation) Medium thread %lx/%lx blocks open receiving\n", me, pi_main.raw); L4_Wait(&any_thread); //printf("(Initialisation) Medium thread %lx/%lx received from 0x%lx\n", me, pi_main.raw, any_thread.raw); L4_LoadMR(0, 0); L4_Send(tid); L4_Yield(); /*** Start test ***/ while (stop_spinning) ; wait_a_bit(counter); if (scenario1) { okl4_libmutex_count_lock(resource_mutex); cnt_m1++; wait_a_bit(counter); } else if (scenario2) { //printf("Middle thread %lx/%lx blocks open receiving\n", me, pi_main.raw); tag = L4_Wait(&any_thread); if (L4_IpcSucceeded(tag) && (any_thread.raw == low_prio_thread.raw)) cnt_m2++; wait_a_bit(counter); } okl4_libmutex_count_unlock(resource_mutex); if (!flag1 && (counter < LIMIT)) { counter *= 2; } if (scenario1) { cnt_m2++; tag = L4_Receive(high_prio_thread); if (L4_IpcFailed(tag)) cnt_m2--; } L4_Yield(); tid = pi_main; } }
int main(void) { #if 0 static char restxt[20] = "Welcome to lkOS/lxL4"; //char *data = (char *) malloc(20); //static char data[20]; L4m_Setbrk(USR_STACK_BEG + PGSIZE); char *data = (char *) USR_STACK_BEG; char *res = (char *) USR_STACK_BEG + 20; memcpy(res, restxt, 20); #else static char restxt[20] = "Welcome to lkOS/lxL4"; #endif again:; char *data = (char *) malloc(20); char *res = (char *) malloc(20); memcpy(res, restxt, 20); //printstr("w waiting...\n"); L4_Wait(5, data); //printstr("w got data="); //printnstr(data, sizeof(data)); //printstr("\n"); //printstr("w replying...\n"); L4_ReplyWait(5, res, data); free(data); free(res); goto again; }
static void pager (void) { L4_ThreadId_t tid; L4_MsgTag_t tag; L4_Msg_t msg; L4_Send(master_tid); for (;;) { tag = L4_Wait(&tid); for (;;) { L4_Word_t faddr, fip; L4_MsgStore(tag, &msg); if (L4_UntypedWords (tag) != 2 || !L4_IpcSucceeded (tag)) { printf ("Malformed pagefault IPC from %p (tag=%p)\n", (void *) tid.raw, (void *) tag.raw); L4_KDB_Enter ("malformed pf"); break; } faddr = L4_MsgWord(&msg, 0); fip = L4_MsgWord (&msg, 1); L4_MsgClear(&msg); { L4_MapItem_t map; L4_SpaceId_t space; L4_Word_t seg, offset, cache, rwx, size; int r; seg = get_seg(KBENCH_SPACE, faddr, &offset, &cache, &rwx); assert(seg != ~0UL); size = L4_GetMinPageBits(); faddr &= ~((1ul << size)-1); offset &= ~((1ul << size)-1); space.raw = __L4_TCR_SenderSpace(); L4_MapItem_Map(&map, seg, offset, faddr, size, cache, rwx); r = L4_ProcessMapItem(space, map); assert(r == 1); } L4_MsgLoad(&msg); // tag = L4_ReplyWait (tid, &tid); tag = L4_MsgTag(); L4_Set_SendBlock(&tag); L4_Set_ReceiveBlock(&tag); tag = L4_Ipc(tid, L4_anythread, tag, &tid); } } }
static void ipc_test(struct bench_test *test, int args[]) { L4_ThreadId_t tid; /* Send "begin" message to notify pager to startup both threads */ L4_MsgTag_t tag = L4_Niltag; L4_Set_Label(&tag, START_LABEL); L4_Set_MsgTag(tag); L4_Send(pager_tid); L4_Wait(&tid); }
/* * Intermediate thread 1 has priority in between highest and medium thread. * Intermediate thread 2 has priority in between medium and lowest thread. * They set their flag each time they run during the PI test. */ void mixed_pi_intermediate(int argc, char **argv) { int num = 0; L4_ThreadId_t any_thread; L4_MsgTag_t tag = L4_Niltag; while (!libs_ready) ; if (argc) { num = atoi(argv[0]); } else { printf("(%s Intermediate Thread) Error: Argument(s) missing!\n", test_name); L4_Set_Label(&tag, 0xdead); L4_Set_MsgTag(tag); L4_Call(pi_main); } // Initialisation if (num == 1) { L4_Wait(&any_thread); L4_LoadMR(0, 0); L4_Send(pi_main); } else if (num == 2) { L4_Wait(&any_thread); while (L4_IsNilThread(medium2_prio_thread)) ; L4_LoadMR(0, 0); L4_Send(medium2_prio_thread); } L4_Yield(); // Thread is now ready to set the flag the next time it is run. while(1) { if (num == 1) { flag1 = 1; } else if (num == 2) { flag3 = 1; } L4_LoadMR(0, 0); L4_Send(high_prio_thread); } }
int main(void) { L4m_fault_info_t u; L4m_fault_result_t r; L4_Wait(2, &u.data); while (1) { ad_t buff = alloc_page(); load_data((char *) buff); r.sv_buff = buff; L4_ReplyWait(2, &r.data, &u.data); } }
void fault_server(void) { L4m_fault_info_t u; L4m_fault_result_t r; L4_Wait(2, &u.data); while (1) { ad_t offset = u.pf_offset & PGMASK; ad_t buff = FDMEM0_ADDR + offset; r.sv_buff = buff; L4_ReplyWait(2, &r.data, &u.data); } }
static void w_thread(void) { static char data[20], res[20] = "Welcome to my lwL4!"; for (;;) L4_Yield(); again: //printstr("w waiting...\n"); L4_Wait(5, data); //printstr("w got data="); //printnstr(data, sizeof(data)); //printstr("\n"); //printstr("w replying...\n"); L4_ReplyWait(5, res, data); goto again; }
struct pbuf * rpc_call(struct pbuf *pbuf, int port) { L4_ThreadId_t from; opaque_auth_t auth; reply_stat r; /* Send the thing */ rpc_send(pbuf, port, signal, NULL, L4_Myself().raw); /* We wait for a reply */ L4_Wait(&from); pbuf_adv_arg(call_pbuf, 0, 8); /* check if it was an accepted reply */ getfrombuf(call_pbuf, (char*) &r, sizeof(r)); if(r != MSG_ACCEPTED) { debug( "Message NOT accepted (%d)\n", r ); /* extract error code */ getfrombuf(call_pbuf, (char*) &r, sizeof(r)); debug( "Error code %d\n", r ); if(r == 1) { /* get the auth problem */ getfrombuf(call_pbuf, (char*) &r, sizeof(r)); debug( "auth_stat %d\n", r ); } return 0; } /* and the auth data!*/ getfrombuf(call_pbuf, (char*) &auth, sizeof(auth)); debug("Got auth data. size is %d\n", auth.size); /* check its accept stat */ getfrombuf(call_pbuf, (char*) &r, sizeof(r)); if( r == SUCCESS ) return call_pbuf; else { debug( "reply stat was %d\n", r ); return NULL; } }
static void measure_effective_prio(L4_Word_t expect_prio) { L4_Word_t label, prio; L4_ThreadId_t any_thread; L4_MsgTag_t tag; prio = 9; do { prio--; L4_Set_Priority(measure_thread, prio); tag = L4_Wait(&any_thread); label = L4_Label(tag); } while ((label != 0x1) && (prio > 1)); _fail_unless(prio == expect_prio, __FILE__, __LINE__, "Wrong effective priority: %lu", prio); }
static void synch_pong (void *arg) { L4_ThreadId_t caller; L4_MsgTag_t tag; VERBOSE_HIGH("Pong running\n"); while(pingpong_cleanup == 0) { tag = L4_Wait(&caller); pingpong_counter++; L4_LoadMR (0, 0); L4_Send(caller); } L4_Call(L4_Myself()); }
static void ping_thread_rpc_server(void) { int i; L4_ThreadId_t cap; /* Wait for pong thread to come up */ L4_Wait(&cap); for (i = 0; i < num_iterations; i++) { pingpong_ipc_rpc_server(cap, num_mrs, &cap); } /* Tell master that we're finished */ L4_Set_MsgTag(L4_Niltag); L4_Send(master_tid); L4_WaitForever(); /* NOTREACHED */ }
static void synch_ping (void *arg) { L4_ThreadId_t partner; L4_MsgTag_t tag; VERBOSE_HIGH("Ping running\n"); /* XXX partner always thread 0 (created before us) */ partner = get_thread_id(0); while(pingpong_cleanup == 0) { L4_LoadMR (0, 0); L4_Send(partner); tag = L4_Wait(&partner); } L4_Call(L4_Myself()); }
int okl4_message_wait(void *recv_buff, okl4_word_t recv_buff_size, okl4_word_t *recv_bytes, okl4_kcap_t *reply_cap) { L4_MsgTag_t tag; L4_ThreadId_t from; okl4_word_t bytes_received; /* Ensure buffer is word-aligned. */ assert((okl4_word_t)recv_buff % sizeof(okl4_word_t) == 0); /* Perform the wait. */ L4_Set_NotifyMask(0); tag = L4_Wait(&from); if (!L4_IpcSucceeded(tag)) { return _okl4_message_errno(tag, L4_ErrorCode()); } /* Determine the number of words received, which is in the label. */ bytes_received = L4_Label(tag); /* Ensure that the number of bytes the message claims to contain is roughly * the same as the number of words we received. */ assert(ROUND_UP(bytes_received, sizeof(okl4_word_t)) == L4_UntypedWords(tag) * sizeof(okl4_word_t)); /* Copy to the buffer. */ _okl4_message_copy_mrs_to_buff(recv_buff, min(recv_buff_size, bytes_received)); /* Give parameters back to the caller. */ if (recv_bytes != NULL) { *recv_bytes = bytes_received; } if (reply_cap != NULL) { *reply_cap = from; } return OKL4_OK; }
/** * DESCRIPTION: If the semaphore is 'empty', the calling thread is blocked. * If the semaphore is 'full', it is taken and control is returned * to the caller. If the time indicated in 'timeout' is reached, * the thread will unblock and return an error indication. If the * timeout is set to 'IX_OSAL_WAIT_NONE', the thread will never block; * if it is set to 'IX_OSAL_WAIT_FOREVER', the thread will block until * the semaphore is available. * * */ static IX_STATUS ixOsalSemaphoreWaitInternal(struct semaphore *sem, bool wait) { IX_STATUS ixStatus = IX_SUCCESS; // Get the lock, decrement the count, add to queue, get out with count ixOsalFastMutexLock(&sem->fInterlockP); // Will need to block eventually int mycount = sem->fCount--; if (mycount <= 0) { if (!wait) { sem->fCount++; ixStatus = IX_FAIL; } else { // we are going to wait so add to queue struct tid_list entry, **add; // Find end of tid_list XXX why not use a STAIL list? for (add = &(sem->fQueue); *add; add = &((*add)->fNext)) ; entry.fTid = L4_Myself(); entry.fNext = NULL; *add = &entry; } } ixOsalFastMutexUnlock(&sem->fInterlockP); if (mycount <= 0 && ixStatus != IX_FAIL) { // We are going to wait, but anything can wake us up // This is a bad assumption we could wake on anything FIXME L4_ThreadId_t partner; L4_Wait(&partner); } return ixStatus; }
/* poke/peek thread. obeys POKE, PEEK, and QUIT. */ static void poke_peek_fn(void *param_ptr) { #if 0 diag("%s: started as %lu:%lu. pager is %#lx", __func__, L4_ThreadNo(L4_MyGlobalId()), L4_Version(L4_MyGlobalId()), L4_Pager()); #endif for(;;) { L4_ThreadId_t from; L4_MsgTag_t tag = L4_Wait(&from); for(;;) { if(L4_IpcFailed(tag)) break; if(tag.X.label == QUIT_LABEL) { // diag("%s: quitting", __func__); return; } else if(tag.X.label == PEEK_LABEL) { L4_Word_t addr; L4_StoreMR(1, &addr); L4_LoadMR(0, (L4_MsgTag_t){ .X.u = 1 }.raw); L4_LoadMR(1, *(uint8_t *)addr); } else if(tag.X.label == POKE_LABEL) {
static void synch_recv (void *arg) { L4_ThreadId_t caller; L4_MsgTag_t tag; int i; int j=1000; while(pingpong_cleanup == 0) { tag = L4_Wait(&caller); pingpong_counter++; for (i=0; i < j; i++) ; j+=1000; if ((pingpong_counter % 50) == 0) { printf(" %d: %d\n", pingpong_counter, j); } } L4_Call(L4_Myself()); }
int main(int argc, char **argv) { int i, tmp, eg_num, nb_philosophers, nb_dinners, server_on; L4_ThreadId_t *philo_tids; L4_ThreadId_t tid, any_thread; L4_MsgTag_t tag = L4_Niltag; /*** Initialisation ***/ dp_main = thread_l4tid(env_thread(iguana_getenv("MAIN"))); eg_num = nb_philosophers = nb_dinners = server_on = 0; if (argc == 3) { eg_num = atoi(argv[0]); nb_philosophers = atoi(argv[1]); server_on = atoi(argv[2]); } else { printf("(%s 0x%lx) Error: Argument(s) missing!\n", test_name, dp_main.raw); return 1; } if (!server_on) printf("Start %s test #%d(0x%lx): %d philosophers\n", test_name, eg_num, dp_main.raw, nb_philosophers); chopstick = malloc((nb_philosophers + 1) * sizeof(okl4_libmutex_t)); philo_tids = malloc(nb_philosophers * sizeof(L4_ThreadId_t)); for (i = 0; i < nb_philosophers; i++) { chopstick[i] = malloc (sizeof(struct okl4_libmutex)); okl4_libmutex_init(chopstick[i]); } chopstick[nb_philosophers] = NULL; // Tell other threads that it is safe to use libraries and mutexes libs_ready = 1; // Retrieve philosophers thread Ids and give them a go for (i = 0; i < nb_philosophers; i++) { L4_Wait(&tid); philo_tids[i] = tid; } /*** Start test ***/ meal_served = 1; tmp = nb_philosophers; while (tmp) { tag = L4_Wait(&any_thread); for (i = 0; i < nb_philosophers; i++) { if (any_thread.raw == philo_tids[i].raw) { thread_delete(any_thread); tmp--; if (L4_Label(tag) == 0xfed) { // Philosopher finished eating nb_dinners++; } break; } } } /*** Test finished ***/ free(philo_tids); for (i = 0; i < nb_philosophers; i++) { okl4_libmutex_free(chopstick[i]); free(chopstick[i]); } //free(*chopstick); // If RTOS server is on, report results to it. if (server_on) { rtos_init(); dining_philosophers_results(eg_num, nb_philosophers, nb_dinners); rtos_cleanup(); } else printf("%s test #%d(0x%lx) finished\n", test_name, eg_num, dp_main.raw); return 0; }
static void pager (void) { L4_ThreadId_t tid; L4_MsgTag_t tag; L4_Msg_t msg; int count = 0; for (;;) { tag = L4_Wait(&tid); for (;;) { L4_Word_t faddr, fip; L4_MsgStore(tag, &msg); if (L4_Label(tag) == START_LABEL) { // Startup notification, start ping and pong thread void (*start_addr)(void); void (*pong_start_addr)(void); L4_Word_t *pong_stack_addr = pong_stack; if (pagertimer) { start_addr = ping_thread_pager; } else if (pagertimer_simulated) { start_addr = ping_thread_simulated; } else if (fass_buffer) { start_addr = ping_thread_buffer; } else if (fault_test) { count = 0; start_addr = NULL; } else if (intra_close) { start_addr = ping_thread_close; } else if (intra_open) { start_addr = ping_thread_open; } else if (intra_rpc) { start_addr = ping_thread_rpc_server; } else if (intra_ovh) { start_addr = ping_thread_ovh; } else if (intra_async) { start_addr = ping_thread_async; } else if (intra_async_ovh) { start_addr = ping_thread_async_ovh; } else { start_addr = ping_thread; } if (start_addr != NULL) { /*printf("ping_start_addr: %lx ping_stack_addr: %lx\n", START_ADDR (start_addr), (L4_Word_t) ping_stack);*/ send_startup_ipc (ping_tid, START_ADDR(start_addr), (L4_Word_t) ping_stack + sizeof (ping_stack) - 32); L4_ThreadSwitch(ping_tid); } if (fass_buffer) { pong_start_addr = pong_thread_buffer; pong_stack_addr = pong_stack_fass; } else if (fass) { pong_start_addr = pong_thread_fass; pong_stack_addr = pong_stack_fass; } else if (fault_test) { pong_stack_addr = pong_stack_fass; pong_start_addr = pong_thread_faulter; } else if (intra_close) { pong_start_addr = pong_thread_close; } else if (intra_open) { pong_start_addr = pong_thread_open; } else if (intra_rpc) { pong_start_addr = pong_thread_close; } else if (intra_ovh) { pong_start_addr = pong_thread_ovh; } else if (intra_async) { pong_start_addr = pong_thread_async; } else if (intra_async_ovh) { pong_start_addr = pong_thread_async_ovh; } else { pong_start_addr = pong_thread; } if (!pagertimer) { /*printf("pong_start_addr: %lx pong_stack_addr: %lx\n", START_ADDR (pong_start_addr), (L4_Word_t) pong_stack_addr);*/ L4_Set_Priority(ping_tid, 100); L4_Set_Priority(pong_tid, 99); send_startup_ipc (pong_tid, START_ADDR (pong_start_addr), (L4_Word_t) pong_stack_addr + sizeof (ping_stack) - 32); } break; } if (L4_UntypedWords (tag) != 2 || !L4_IpcSucceeded (tag)) { printf ("pingpong: malformed pagefault IPC from %p (tag=%p)\n", (void *) tid.raw, (void *) tag.raw); L4_KDB_Enter ("malformed pf"); break; } faddr = L4_MsgWord(&msg, 0); fip = L4_MsgWord (&msg, 1); L4_MsgClear(&msg); if (fault_test && (faddr == (uintptr_t) fault_area)) { if (count < num_iterations) { count++; } else { /* Tell master that we're finished */ L4_Set_MsgTag (L4_Niltag); L4_Send (master_tid); break; } } else { L4_MapItem_t map; L4_SpaceId_t space; L4_Word_t seg, offset, cache, rwx, size; int r; seg = get_seg(KBENCH_SPACE, faddr, &offset, &cache, &rwx); //if can not find mapping, must be page fault test, //just map any valid address, since fault address is dummy. if (seg == ~0UL) seg = get_seg(KBENCH_SPACE, (L4_Word_t) fault_area, &offset, &cache, &rwx); if (tid.raw == ping_th.raw) space = ping_space; else if (tid.raw == pong_th.raw) { if (pong_space.raw != L4_nilspace.raw) space = pong_space; else //pong_space is not created, only ping_space is used. space = ping_space; } else space = KBENCH_SPACE; size = L4_GetMinPageBits(); faddr &= ~((1ul << size)-1); offset &= ~((1ul << size)-1); L4_MapItem_Map(&map, seg, offset, faddr, size, cache, rwx); r = L4_ProcessMapItem(space, map); assert(r == 1); } L4_MsgLoad(&msg); tag = L4_ReplyWait (tid, &tid); } } }
int main(void) { int i = 0; int res = 1; L4_SpaceId_t space; okl4_allocator_attr_t attr; L4_Word_t end, result; L4_CapId_t sender; L4_MsgTag_t tag; L4_Msg_t msg; struct okl4_bitmap_allocator *spaceid_pool = okl4_env_get("MAIN_SPACE_ID_POOL"); HEAP_EXHAUSTION_CLIST = L4_ClistId(*(OKL4_ENV_GET_MAIN_CLISTID("MAIN_CLIST_ID"))); while(res == 1) { result = okl4_kspaceid_allocany(spaceid_pool, &space); if (result != OKL4_OK) { printf("Failed to allocate space id\n"); } res = create_address_space(space, L4_Fpage(0xb10000, 0x1000)); if (res != 1) { printf("SpaceControl failed, space id=%lu, Error code: %lu\n", space.space_no, L4_ErrorCode()); break; } /* 2gb mapping of 512k pages*/ res = map_series(space, 0x80000, 4096, 0, 0); i++; } printf("Created %d address spaces\n", i); if (i == 0) { okl4_kspaceid_free(spaceid_pool, space); res = 0; goto ipc_ktest; } /* clean up */ okl4_kspaceid_getattribute(spaceid_pool, &attr); end = attr.base + attr.size; for (i = attr.base; i < end; i++) { L4_SpaceId_t id = L4_SpaceId(i); if (okl4_kspaceid_isallocated(spaceid_pool, id)) { L4_SpaceControl(id, L4_SpaceCtrl_delete, HEAP_EXHAUSTION_CLIST, L4_Nilpage, 0, NULL); okl4_kspaceid_free(spaceid_pool, id); } } res = 1; ipc_ktest: tag = L4_Wait(&sender); L4_MsgClear(&msg); L4_MsgAppendWord(&msg, (L4_Word_t)res); L4_MsgLoad(&msg); L4_Reply(sender); assert(L4_IpcSucceeded(tag)); L4_WaitForever(); }
int main(int argc, char **argv) { struct okl4_libmutex rm; L4_ThreadId_t tid; int i, max_iteration, eg_num, server_on; L4_Word_t me; L4_MsgTag_t tag = L4_Niltag; /*** Initialisation ***/ pi_main = thread_l4tid(env_thread(iguana_getenv("MAIN"))); me = pi_main.raw; eg_num = max_iteration = server_on = 0; if (argc == 3) { eg_num = atoi(argv[0]); max_iteration = atoi(argv[1]); server_on = atoi(argv[2]); } else { printf("(%s 0x%lx) Error: Argument(s) missing!\n", test_name, me); return 1; } resource_mutex = &rm; okl4_libmutex_init(resource_mutex); high_prio_thread = medium1_prio_thread = medium2_prio_thread = medium3_prio_thread = low_prio_thread = L4_nilthread; high_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_HIGH"))); medium3_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_INTERMEDIATE_2"))); medium2_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_MEDIUM"))); medium1_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_INTERMEDIATE_1"))); low_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_LOW"))); // Tell other threads that it is safe to use libraries libs_ready = 1; if (!server_on) printf("Start %s test #%d(0x%lx)\n", test_name, eg_num, me); /*** Start test ***/ scenario1 = 1; for (i = 0; i < 2 * max_iteration; i++) { // Wait for threads to be ready tag = L4_Wait(&tid); // If one thread had a problem while initialisation, then stop the test and notify // server that the test is dead. if (L4_Label(tag) == 0xdead) { rtos_init(); test_died(test_name, eg_num); rtos_cleanup(); return 1; } // Tell high prio thread to start the next iteration. L4_LoadMR(0, 0); tag = L4_Send(high_prio_thread); stop_spinning = 0; // Wait for the iteration to finish. L4_Receive(high_prio_thread); stop_spinning = 1; // If end of iterations for scenario1, then report results to RTOS server if server is on. if (i == (max_iteration - 1)) { if (server_on) { rtos_init(); mixed_priority_inversion_results(eg_num, 1, max_iteration, cnt_h, cnt_m1, cnt_m2, cnt_l, cnt_i1, cnt_i2); } else print_metrics(max_iteration); // Start scenario2 cnt_h = cnt_m1 = cnt_m2 = cnt_l = cnt_i1 = cnt_i2 = 0; scenario1 = 0; scenario2 = 1; } } /*** Test finished ***/ thread_delete(medium1_prio_thread); thread_delete(medium3_prio_thread); thread_delete(high_prio_thread); thread_delete(medium2_prio_thread); thread_delete(low_prio_thread); /* Clean up allocated mutexes. */ okl4_libmutex_free(resource_mutex); // If RTOS server is on, report results to it. if (server_on) { mixed_priority_inversion_results(eg_num, 2, max_iteration, cnt_h, cnt_m1, cnt_m2, cnt_l, cnt_i1, cnt_i2); rtos_cleanup(); } else { print_metrics(max_iteration); printf("%s test #%d(0x%lx) finished\n", test_name, eg_num, me); } return 0; }
/* * Get current value, request timeout for different threads, check all notified * correctly. */ static void test02(void) { uint32_t cur_value; L4_Word_t result, i; thread_ref_t thread1, thread2, thread3; L4_ThreadId_t tid1, tid2, tid3, any_thread; L4_Word_t notifybits1 = 0x1; L4_Word_t notifybits2 = 0x2; L4_Word_t notifybits3 = 0x3; L4_MsgTag_t tag; L4_Word_t label; printf("%s: ", __func__); thread1 = thread_create_simple(waiting_notify_thread, NULL, 99); thread2 = thread_create_simple(waiting_notify_thread, NULL, 99); thread3 = thread_create_simple(waiting_notify_thread, NULL, 99); tid1 = thread_l4tid(thread1); tid2 = thread_l4tid(thread2); tid3 = thread_l4tid(thread3); tag = L4_Make_MsgTag(notifybits1, 0); L4_Set_MsgTag(tag); tag = L4_Call(tid1); tag = L4_Make_MsgTag(notifybits2, 0); L4_Set_MsgTag(tag); tag = L4_Call(tid2); tag = L4_Make_MsgTag(notifybits3, 0); L4_Set_MsgTag(tag); tag = L4_Call(tid3); result = counter_current_value(&cur_value); if (result == 0) { FAILED(); return; } result = counter_request(cur_value + 10, tid1, notifybits1); if (result == 0) { FAILED(); return; } result = counter_request(cur_value + 12, tid2, notifybits2); if (result == 0) { FAILED(); return; } result = counter_request(cur_value + 14, tid3, notifybits3); if (result == 0) { FAILED(); return; } for (i = 0; i < 3; i++) { tag = L4_Wait(&any_thread); label = L4_Label(tag); if (((i == 0) && (label != 0x1)) || ((i == 1) && (label != 0x2)) || ((i == 2) && (label != 0x3))) { thread_delete(tid1); thread_delete(tid2); thread_delete(tid3); FAILED(); return; } } thread_delete(tid1); thread_delete(tid2); thread_delete(tid3); PASSED(); }