Removes old documentation
[akaros.git] / user / utest / pvcalarm.c
index c589f7d..c562de3 100644 (file)
@@ -1,60 +1,91 @@
 #include <utest.h>
-#include <vcore.h>
-#include <uthread.h>
-#include <event.h>
+#include <pthread.h>
 #include <pvcalarm.h>
+#include <profalarm.h>
 
 TEST_SUITE("PVCALARMS");
 
-void pvcalarm_vcore_entry()
-{
-       uint32_t vcoreid= vcore_id();
-
-       /* Poke the pvcalarm to see if we need to enable it. */
-       /* This function is only non-null if the pvcalarm service is enabled */
-       if (vcore_poke_pvcalarm)
-               vcore_poke_pvcalarm();
-
-       /* Drop back into main thread  for core 0 */
-       if (current_uthread) {
-               assert(vcoreid == 0);
-               run_current_uthread();
-       }
-
-       /* Other vcores get here, so enable notifs so they can get their alarm
-        * events */
-       enable_notifs(vcoreid);
-       while(1);
-}
-struct schedule_ops pvcalarm_sched_ops = {
-       .sched_entry = pvcalarm_vcore_entry,
-};
-struct schedule_ops *sched_ops = &pvcalarm_sched_ops;
-
 /* <--- Begin definition of test cases ---> */
 bool test_pvcalarms(void) {
        const int INTERVAL = 10000;
-       const int ITERATIONS = 100;
-       int count[max_vcores() - num_vcores()];
+       const int ITERS = 100;
+       int count[max_vcores()];
        void pvcalarm_callback()
        {
                __sync_fetch_and_add(&count[vcore_id()], 1);
        }
 
-       struct uthread dummy = {0};
-       uthread_lib_init(&dummy);
+       pthread_lib_init();
+       pthread_can_vcore_request(FALSE);
        vcore_request(max_vcores() - num_vcores());
+       for (int i=0; i<max_vcores(); i++)
+               count[i] = 0;
        
        uint64_t now, then;
        now = tsc2usec(read_tsc());
        enable_pvcalarms(PVCALARM_PROF, INTERVAL, pvcalarm_callback);
-       for (int i=0; i<num_vcores(); i++)
-               while(count[i] < ITERATIONS)
+       for (int i=0; i<max_vcores(); i++)
+               while(count[i] < ITERS)
                        cpu_relax();
+       disable_pvcalarms();
        then = tsc2usec(read_tsc());
+
+       UT_ASSERT_M("Alarms finished too soon", then > (now + INTERVAL*ITERS));
+       UT_ASSERT_M("Alarms finished too late", then < (now + 2*INTERVAL*ITERS));
+       return true;
+}
+
+bool test_sigperf(void)
+{
+       const int INTERVAL = 10000;
+       const int ITERATIONS = 100;
+       const int NUM_PTHREADS = 10;
+       int count[NUM_PTHREADS];
+       pthread_t threads[NUM_PTHREADS];
+       static __thread int *__count;
+
+       void *thread_handler(void *arg)
+       {
+               __count = (int*)arg;
+               sigset_t s;
+               sigemptyset(&s);
+               sigaddset(&s, SIGPROF);
+               pthread_sigmask(SIG_UNBLOCK, &s, NULL);
+               int old_count = 0, new_count = 0;
+               while(1) {
+                       while((new_count = atomic_read((atomic_t)__count)) <= old_count);
+                       if (new_count >= ITERATIONS) break;
+                       old_count = new_count;
+                       pthread_yield();
+               }
+       }
+       void signal_handler(int signo)
+       {
+               assert(signo == SIGPROF);
+               __sync_fetch_and_add(__count, 1);
+       }
+
+       pthread_lib_init();
+       pthread_can_vcore_request(TRUE);
+
+       sigset_t s;
+       sigemptyset(&s);
+       sigaddset(&s, SIGPROF);
+       pthread_sigmask(SIG_BLOCK, &s, NULL);
+       struct sigaction sigact = {.sa_handler = signal_handler, 0};
+       sigaction(SIGPROF, &sigact, 0);
+       for (int i=0; i<NUM_PTHREADS; i++)
+               count[i] = 0;
+
+       enable_profalarm(INTERVAL);
+       for (int i=0; i<NUM_PTHREADS; i++)
+               pthread_create(&threads[i], NULL, thread_handler, &count[i]);
+
+       for (int i=0; i<NUM_PTHREADS; i++)
+               while(count[i] < ITERATIONS)
+                       cpu_relax();
+
        disable_pvcalarms();
-       UT_ASSERT_M("Alarms finished too soon", then > (now + INTERVAL*count[0]));
-       UT_ASSERT_M("Alarms finished too late", then < (now + 2*INTERVAL*count[0]));
        return true;
 }
 
@@ -62,6 +93,7 @@ bool test_pvcalarms(void) {
 
 struct utest utests[] = {
        UTEST_REG(pvcalarms),
+       UTEST_REG(sigperf),
 };
 int num_utests = sizeof(utests) / sizeof(struct utest);