]> rtime.felk.cvut.cz Git - hercules2020/jailhouse-build.git/commitdiff
Fixes to memguard-test
authorMichal Sojka <michal.sojka@cvut.cz>
Thu, 1 Nov 2018 21:27:05 +0000 (22:27 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 1 Nov 2018 21:27:05 +0000 (22:27 +0100)
test/memguard-test.c

index 69d225868fe1d802b4745ae680017cdfaaba3cfb..d983d16e4c0d2469ff867674f2bdd2ce4f214190 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdbool.h>
 #include <pthread.h>
 #include <stdlib.h>
+#include <error.h>
 
 #ifndef SYS_prem_memguard_check
 #define SYS_prem_memguard_check 793
@@ -127,8 +128,8 @@ static void print_test_info(uint64_t timeout_us, uint64_t mem_budget, uint64_t f
                 flags & MGF_MASK_INT ? 'I' : '-'
                );
        struct mg_ret r = mgret(retval);
-       printf("Testing \"%-40s %-25s ⇒ time:%8u%c mem:%8u%c\" in %s:\n",
-              call, code,
+       printf("Testing \"CPU%d: %-40s %-25s ⇒ time:%8u%c mem:%8u%c\" in %s:\n",
+              sched_getcpu(), call, code,
               r.time, r.time_ovf ? '!' : ' ',
               r.mem, r.mem_ovf ? '!' : ' ',
               __FILE__);
@@ -153,19 +154,17 @@ void wvtest_pass(bool cond, const char* file, int line, const char* str)
 
 void *test_thread(void *ptr)
 {
-    cpu_set_t set;
-    int *cpu;
-    cpu = (int *) ptr;
-     
+       cpu_set_t set;
+       int cpu = (intptr_t)ptr;
+
        /* Ensure that memory phase starts and ends on the same CPU */
        CPU_ZERO(&set);
-       CPU_SET(*cpu, &set);
-       if (sched_setaffinity(getpid(), sizeof(set), &set) < 0)
+       CPU_SET(cpu, &set);
+       if (sched_setaffinity(0, sizeof(set), &set) < 0)
                err(1, "sched_setaffinity");
-       printf("Pinned to CPU %d\n", *cpu);
-    
-    pthread_barrier_wait(&barrier);
-    
+
+       pthread_barrier_wait(&barrier);
+
        struct mg_ret r;
        for (uint64_t flags = 0; flags < 4; flags++) {
                compute_kernel(1); /* warm up */
@@ -240,48 +239,44 @@ void *test_thread(void *ptr)
 
                printf("\n");
        }
-    
-    return NULL;
+
+       return NULL;
 }
 
 int main(int argc, char *argv[])
 {
-       int cpu_mask = 0;
-    
-    int cpu_count = 0;
-    pthread_t threads[MAX_CORES];
-    int cores[MAX_CORES];
-    int retvals[MAX_CORES];
-    
-    /* TODO: currently shared memory */
+       int cpu_mask = 1;
+       int cpu_count = 0;
+       pthread_t threads[MAX_CORES];
+
+       /* TODO: currently shared memory */
        for (int i = 0; i < sizeof(memory); i += 64)
                memory[i] = 1;
 
        if (argc > 1)
                cpu_mask = strtol(argv[1], NULL, 16);
 
-    for(int i=0; i<MAX_CORES; i++){
-        if(cpu_mask & (1 << i)){
-            cpu_count++;
-        }
-    }
-
-    int s = pthread_barrier_init(&barrier, NULL, cpu_count);
-    if (s != 0)
-        err(1, "pthread_barrier_init");
-
-    for(int i=0; i<MAX_CORES; i++){
-        if(cpu_mask & (1 << i)){
-            cores[i] = i;
-            retvals[i] = pthread_create(&threads[i], NULL, test_thread, (void*) &cores[i]);
-        }
-    }
-    
-    for(int i=0; i<MAX_CORES; i++){
-        if(cpu_mask & (1 << i)){
-            pthread_join(threads[i], NULL);
-        }
-    }
-    
+       for (int i = 0; i < MAX_CORES; i++) {
+               if (cpu_mask & (1 << i)) {
+                       cpu_count++;
+               }
+       }
+
+       printf("CPU count:%d  CPU mask:%#x\n", cpu_count, cpu_mask);
+       int s = pthread_barrier_init(&barrier, NULL, cpu_count);
+       if (s != 0)
+               error(1, s, "pthread_barrier_init");
+
+       for (intptr_t i = 0; i < MAX_CORES; i++) {
+               if (cpu_mask & (1 << i))
+                       pthread_create(&threads[i], NULL, test_thread, (void *)i);
+       }
+
+       for (int i = 0; i < MAX_CORES; i++) {
+               if (cpu_mask & (1 << i)) {
+                       pthread_join(threads[i], NULL);
+               }
+       }
+
        return 0;
 }