improve tester
authorPierre Habouzit <pierre.habouzit@intersec.com>
Sun, 15 Jan 2012 20:13:30 +0000 (21:13 +0100)
committerPierre Habouzit <pierre.habouzit@intersec.com>
Sun, 15 Jan 2012 20:13:30 +0000 (21:13 +0100)
Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
kernel/pwqr.c
test/test.c

index c705dfa..233bd7a 100644 (file)
@@ -324,7 +324,6 @@ static void pwqr_task_detach(struct pwqr_task *pwqt, struct pwqr_sb *sb)
        } else {
                __pwqr_sb_update_state(sb, 0);
        }
-       pwqt->notifier.ops = &pwqr_preempt_noop_ops;
        pwqr_sb_unlock_irqrestore(sb, flags);
        pwqr_sb_put(sb);
        pwqt->sb = NULL;
@@ -352,6 +351,7 @@ static void pwqr_task_release(struct pwqr_task *pwqt, bool from_notifier)
        hlist_del(&pwqt->link);
        spin_unlock(&b->lock);
 #endif
+       pwqt->notifier.ops = &pwqr_preempt_noop_ops;
 
        if (from_notifier) {
                /* When called from sched_{out,in}, it's not allowed to
@@ -374,7 +374,7 @@ static void pwqr_task_noop_sched_in(struct preempt_notifier *notifier, int cpu)
 }
 
 static void pwqr_task_noop_sched_out(struct preempt_notifier *notifier,
-                                    struct task_struct *next)
+                                   struct task_struct *next)
 {
 }
 
@@ -386,6 +386,7 @@ static void pwqr_task_blocked_sched_in(struct preempt_notifier *notifier, int cp
 
        if (unlikely(sb->state < 0)) {
                pwqr_task_detach(pwqt, sb);
+               pwqr_task_release(pwqt, true);
                return;
        }
 
@@ -404,8 +405,7 @@ static void pwqr_task_sched_out(struct preempt_notifier *notifier,
 
        if (unlikely(p->state & TASK_DEAD) || unlikely(sb->state < 0)) {
                pwqr_task_detach(pwqt, sb);
-               if (p->state & TASK_DEAD)
-                       pwqr_task_release(pwqt, true);
+               pwqr_task_release(pwqt, true);
                return;
        }
        if (p->state == 0 || (p->state & (__TASK_STOPPED | __TASK_TRACED)))
index b4f2f67..242ba50 100644 (file)
@@ -27,6 +27,7 @@
 #include <sched.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <sys/ioctl.h>
 #include <sys/poll.h>
 #include <sys/time.h>
@@ -74,15 +75,34 @@ static int pwqr_ctl(int fd, int op, int val, void *uaddr)
 
 static int pwqr_fd_g = -1;
 static int pi_g;
+static int state_g;
 
-static void *thr_main(void *unused)
+#define trace(fmt, ...)   fprintf(stderr, fmt"\n", ##__VA_ARGS__)
+
+static void *thr_main(void *_who)
 {
+    int who = (long)_who;
+
     if (pwqr_ctl(pwqr_fd_g, PWQR_CTL_REGISTER, 0, NULL) < 0)
-        err(-1, "pwqr_ctl(PWQR_CTL_REGISTER)");
+        err(-1, "%d: pwqr_ctl(PWQR_CTL_REGISTER)", who);
+
+    /* busy-loop */
+    trace("%d: loop1", who);
+    do {
+        pthread_testcancel();
+    } while (!state_g);
+
+    trace("%d: tries to park", who);
+    if (pwqr_ctl(pwqr_fd_g, PWQR_CTL_PARK, 0, NULL) < 0)
+        trace("pwqr_ctl(PWQR_CTL_PARK)");
+    trace("%d: unparked", who);
 
     /* busy-loop */
-    for (;;)
+    trace("%d: loop2", who);
+    do {
         pthread_testcancel();
+    } while (state_g);
+
     return NULL;
 }
 
@@ -98,6 +118,8 @@ int main(void)
     struct timeval start, tv;
     int rc;
 
+    setlinebuf(stderr);
+
     pwqr_fd_g = pwqr_create(PWQR_FL_NONBLOCK);
     if (pwqr_fd_g < 0)
         err(-1, "pwqr_create");
@@ -107,7 +129,7 @@ int main(void)
         err(-1, "pwqr_ctl(PWQR_CTL_GET_CONC)");
 
     for (int i = 0; i < pi_g + 1; i++) {
-        pthread_create(&tids[i], NULL, thr_main, NULL);
+        pthread_create(&tids[i], NULL, thr_main, (void *)(long)i);
     }
 
     pfd.fd     = pwqr_fd_g;
@@ -126,10 +148,11 @@ int main(void)
                     warn("read");
                 } else {
                     gettimeofday(&tv, NULL);
-                    warnx("[%06jd.%06jd] overcommit of %d",
+                    trace("[%06jd.%06jd] overcommit of %d",
                           tv_diff(&tv, &start) / 1000000,
                           tv_diff(&tv, &start) % 1000000, rc);
                 }
+                state_g = 1;
             }
             if (pfd.revents & POLLHUP) {
                 errx(-1, "poll returned POLLHUP");