void quantum_test(void) { thread_detach_and_resume(thread_create("quantum tester 0", &quantum_tester, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("quantum tester 1", &quantum_tester, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("quantum tester 2", &quantum_tester, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("quantum tester 3", &quantum_tester, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); }
static void inetsrv_entry(const struct app_descriptor *app, void *args) { /* XXX wait for the stack to initialize */ printf("starting internet servers\n"); thread_detach_and_resume(thread_create("chargen", &chargen_server, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("discard", &discard_server, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("echo", &echo_server, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); }
static int chargen_server(void *arg) { status_t err; tcp_socket_t *listen_socket; err = tcp_open_listen(&listen_socket, 19); if (err < 0) { TRACEF("error opening chargen listen socket\n"); return -1; } for (;;) { tcp_socket_t *accept_socket; err = tcp_accept(listen_socket, &accept_socket); TRACEF("tcp_accept returns returns %d, handle %p\n", err, accept_socket); if (err < 0) { TRACEF("error accepting socket, retrying\n"); continue; } TRACEF("starting chargen worker\n"); thread_detach_and_resume(thread_create("chargen_worker", &chargen_worker, accept_socket, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); } }
int sleep_test(void) { int i; for (i=0; i < 16; i++) thread_detach_and_resume(thread_create("sleeper", &sleep_thread, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); return 0; }
void context_switch_test(void) { event_init(&context_switch_event, false, 0); event_init(&context_switch_done_event, false, 0); thread_detach_and_resume(thread_create("context switch idle", &context_switch_tester, (void *)1, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_sleep(100); event_signal(&context_switch_event, true); event_wait(&context_switch_done_event); thread_sleep(100); event_unsignal(&context_switch_event); event_unsignal(&context_switch_done_event); thread_detach_and_resume(thread_create("context switch 2a", &context_switch_tester, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 2b", &context_switch_tester, (void *)2, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_sleep(100); event_signal(&context_switch_event, true); event_wait(&context_switch_done_event); thread_sleep(100); event_unsignal(&context_switch_event); event_unsignal(&context_switch_done_event); thread_detach_and_resume(thread_create("context switch 4a", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 4b", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 4c", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_detach_and_resume(thread_create("context switch 4d", &context_switch_tester, (void *)4, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); thread_sleep(100); event_signal(&context_switch_event, true); event_wait(&context_switch_done_event); thread_sleep(100); }
void minip_init_dhcp(tx_func_t tx_func, void *tx_arg) { minip_get_macaddr(mac); minip_init(tx_func, tx_arg, IPV4_NONE, IPV4_NONE, IPV4_NONE); int ret = udp_open(IPV4_BCAST, DHCP_CLIENT_PORT, DHCP_SERVER_PORT, &dhcp_udp_handle); printf("dhcp opened udp: %d\n", ret); minip_udp_listen(DHCP_CLIENT_PORT, dhcp_cb, NULL); dhcp_thr = thread_create("dhcp", dhcp_thread, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE); thread_detach_and_resume(dhcp_thr); }
static int semaphore_test(void) { static semaphore_t isem = SEMAPHORE_INITIAL_VALUE(isem, 99); printf("preinitialized sempahore:\n"); hexdump(&isem, sizeof(isem)); sem_init(&sem, sem_start_value); mutex_init(&sem_test_mutex); sem_remaining_its = sem_total_its; while (1) { mutex_acquire(&sem_test_mutex); if (sem_remaining_its) { thread_detach_and_resume(thread_create("semaphore consumer", &semaphore_consumer, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); atomic_add(&sem_threads, 1); } else { mutex_release(&sem_test_mutex); break; } mutex_release(&sem_test_mutex); } thread_detach_and_resume(thread_create("semaphore producer", &semaphore_producer, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE)); while (sem_threads) thread_yield(); if (sem.count == sem_start_value) printf("semaphore tests successfully complete\n"); else printf("semaphore tests failed: %d != %d\n", sem.count, sem_start_value); sem_destroy(&sem); mutex_destroy(&sem_test_mutex); return 0; }
static void preempt_test(void) { /* create 5 threads, let them run. If the system is properly timer preempting, * the threads should interleave each other at a fine enough granularity so * that they complete at roughly the same time. */ printf("testing preemption\n"); preempt_count = 5; for (int i = 0; i < preempt_count; i++) thread_detach_and_resume(thread_create("preempt tester", &preempt_tester, NULL, LOW_PRIORITY, DEFAULT_STACK_SIZE)); while (preempt_count > 0) { thread_sleep(1000); } printf("done with preempt test, above time stamps should be very close\n"); /* do the same as above, but mark the threads as real time, which should * effectively disable timer based preemption for them. They should * complete in order, about a second apart. */ printf("testing real time preemption\n"); preempt_count = 5; for (int i = 0; i < preempt_count; i++) { thread_t *t = thread_create("preempt tester", &preempt_tester, NULL, LOW_PRIORITY, DEFAULT_STACK_SIZE); thread_set_real_time(t); thread_detach_and_resume(t); } while (preempt_count > 0) { thread_sleep(1000); } printf("done with real-time preempt test, above time stamps should be 1 second apart\n"); }
static void preempt_test(void) { printf("testing preemption\n"); preempt_count = 5; int i; for (i = 0; i < preempt_count; i++) thread_detach_and_resume(thread_create("preempt tester", &preempt_tester, NULL, LOW_PRIORITY, DEFAULT_STACK_SIZE)); while (preempt_count > 0) { thread_sleep(1000); } printf("done with preempt test, above time stamps should be very close\n"); }
void dpc_init(void) { event_init(&dpc_event, false, 0); thread_detach_and_resume(thread_create("dpc", &dpc_thread_routine, NULL, DPC_PRIORITY, DEFAULT_STACK_SIZE)); }
status_t virtio_gpu_start(struct virtio_device *dev) { status_t err; LTRACEF("dev %p\n", dev); struct virtio_gpu_dev *gdev = (struct virtio_gpu_dev *)dev->priv; /* get the display info and see if we find a valid pmode */ err = get_display_info(gdev); if (err < 0) { LTRACEF("failed to get display info\n"); return err; } if (gdev->pmode_id < 0) { LTRACEF("we failed to find a pmode, exiting\n"); return ERR_NOT_FOUND; } /* allocate a resource */ err = allocate_2d_resource(gdev, &gdev->display_resource_id, gdev->pmode.r.width, gdev->pmode.r.height); if (err < 0) { LTRACEF("failed to allocate 2d resource\n"); return err; } /* attach a backing store to the resource */ size_t len = gdev->pmode.r.width * gdev->pmode.r.height * 4; gdev->fb = pmm_alloc_kpages(ROUNDUP(len, PAGE_SIZE) / PAGE_SIZE, NULL); if (!gdev->fb) { TRACEF("failed to allocate framebuffer, wanted 0x%zx bytes\n", len); return ERR_NO_MEMORY; } printf("virtio-gpu: framebuffer at %p, 0x%zx bytes\n", gdev->fb, len); err = attach_backing(gdev, gdev->display_resource_id, gdev->fb, len); if (err < 0) { LTRACEF("failed to attach backing store\n"); return err; } /* attach this resource as a scanout */ err = set_scanout(gdev, gdev->pmode_id, gdev->display_resource_id, gdev->pmode.r.width, gdev->pmode.r.height); if (err < 0) { LTRACEF("failed to set scanout\n"); return err; } /* create the flush thread */ thread_t *t; t = thread_create("virtio gpu flusher", &virtio_gpu_flush_thread, (void *)gdev, HIGH_PRIORITY, DEFAULT_STACK_SIZE); thread_detach_and_resume(t); /* kick it once */ event_signal(&gdev->flush_event, true); LTRACE_EXIT; return NO_ERROR; }