Added time_wait_ms function to stdlib

This commit is contained in:
Sparchatus 2022-03-23 15:55:20 +00:00
parent 6e1f536635
commit f2f7c37442
6 changed files with 31 additions and 12 deletions

View File

@ -82,7 +82,6 @@ struct paging_state {
struct capref free_l2_vnode;
struct capref free_l3_vnode;
// TODO rueegges: implement more precisely?
struct pt_vaddr_reg_t vaddr_head;
};

View File

@ -152,6 +152,7 @@ time_t mktime(struct tm *);
size_t strftime(char * __restrict, size_t, const char * __restrict,
const struct tm * __restrict);
time_t time(time_t *);
void time_wait_ms(unsigned long);
#if __POSIX_VISIBLE >= 200112
struct sigevent;
int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict);

View File

@ -317,7 +317,6 @@ errval_t paging_init_state(struct paging_state *st, lvaddr_t start_vaddr,
assert(ca != NULL);
// initialize slab allocators
// TODO rueegges: is this how we should initialize the slab allocators?
slab_init(&st->pt_slabs, PT_META_MAX_SIZE, NULL);
slab_init(&st->pt_children_slabs, BASE_PAGE_SIZE, NULL);

View File

@ -1,6 +1,7 @@
#include <test_helper.h>
#include <test_spawn.h>
#include <spawn/spawn.h>
#include <time.h>
#define PROCESS_COUNT 5
@ -14,7 +15,8 @@ void do_test_spawn(void) {
CHECK_ERR(spawn_load_by_name("hello", &(si[i]), &(pid[i])));
}
for(volatile int j = 0; j < 300000000; ++j);
// wait for 10 seconds before continuing
time_wait_ms(10000);
for(uint i = 0; i < PROCESS_COUNT; ++i) {
debug_printf("TEST_SPAWN: Killing %u\n", i);

View File

@ -50,3 +50,24 @@ time(time_t *t)
*t = retval;
return (retval);
}
/**
* \brief Wait for ms milliseconds before returning.
*
* \param ms Duration to wait
*
* Very ugly and approximate but useful
*
*/
void
time_wait_ms(unsigned long ms) {
struct timespec tt;
clock_gettime(CLOCK_REALTIME, &tt);
long start = tt.tv_sec * 1000 + tt.tv_nsec / 1000 / 1000;
long now;
do {
clock_gettime(CLOCK_REALTIME, &tt);
now = tt.tv_sec * 1000 + tt.tv_nsec / 1000 / 1000;
} while(start + ms > now);
}

View File

@ -16,7 +16,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <aos/aos.h>
@ -24,12 +24,7 @@
int main(int argc, char *argv[])
{
struct timespec tt;
if (clock_gettime(CLOCK_REALTIME, &tt) < 0) return 1;
double time = tt.tv_sec + tt.tv_nsec / 1000000000.0;
printf("Hello, world! I am %lfs\n", time);
printf("Hello, world!\n");
printf("argv:\n");
for(int i = 0; i < argc; ++i) {
@ -38,10 +33,12 @@ int main(int argc, char *argv[])
// if we receive the catch command, RUN!
if (argc > 1 && !strncmp(argv[1], HELLO_CATCH_COMMAND, sizeof(HELLO_CATCH_COMMAND))) {
int iter = 0;
while(1) {
printf("Catch %lf if you can!\n", time);
printf("Catch me if you can! %d\n", iter);
// wait for 1 second
for(volatile int j = 0; j < 50000000; ++j);
time_wait_ms(1000);
++iter;
}
}