Created
July 22, 2016 13:19
-
-
Save Rondom/c00bb175c0fcd16b5ba6cf123fd7030a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#include <lkl.h> | |
#include <lkl_host.h> | |
#include <time.h> | |
void *do_stuff(void *foo) { | |
// struct lkl_timespec time = {0, 5000000L}; | |
// lkl_sys_nanosleep(&time, NULL); | |
lkl_sys_getpid(); | |
lkl_stop_syscall_thread(); | |
return NULL; | |
} | |
int run_threads(int nr_threads) { | |
fprintf(stderr, "Running %d threads...\n", nr_threads); | |
pthread_t threads[nr_threads]; | |
for (int i = 0; i <= nr_threads; i++) { | |
if (pthread_create(&threads[i], NULL, do_stuff, NULL)) { | |
fprintf(stderr, "pthread_create: :-(\n"); | |
return 1; | |
} | |
} | |
for (int i = 0; i <= nr_threads; i++) { | |
if (pthread_join(threads[i], NULL)) { | |
fprintf(stderr, "pthread_join: :(\n"); | |
return 1; | |
} | |
} | |
return 0; | |
} | |
int main(int argc, char **argv) { | |
if (argc != 4) { | |
printf("Usage: %s MEM_MB ITERATIONS THREADS", argv[0]); | |
return 3; | |
} | |
int mem = atoi(argv[1]); | |
int iterations = atoi(argv[2]); | |
int threads = atoi(argv[3]); | |
fprintf(stderr, "Starting kernel...\n"); | |
lkl_start_kernel(&lkl_host_ops, mem * 1024 * 1024, ""); | |
lkl_register_dbg_handler(); | |
for (int j = 0; j < iterations; j++) { | |
printf("Iteration %d/%d\n", j + 1, iterations); | |
if (run_threads(threads)) { | |
return 1; | |
} | |
// this is to allow the host to "recover" and not deny us pthread_create | |
struct timespec time = {0, 50000000L}; | |
nanosleep(&time, NULL); | |
} | |
fprintf(stderr, "Shutting down kernel...\n"); | |
lkl_sys_halt(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment