#include <sched.h>
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/time.h>
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;
}
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");
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;
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");