DF-4260 / pincpu.c
#include <sys/types.h> #include <sys/usched.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <stdio.h> /* * DF-4260 per-CPU timer witness: pin this process to <cpu> with * usched_set(2) (4-arg form: pid, cmd, data, bytes) and sleep 3s. * On a CPU whose softclock thread is wedged by the deadlock, the * sleep never wakes (its tsleep timeout callout is queued on the * dead softclock) and only timeout(1)'s SIGTERM ends the process * (rc=124 after 8s). Healthy CPUs: rc=0 after ~3s. */ int main(int argc, char **argv) { int cpu; if (argc != 2) return 2; cpu = atoi(argv[1]); if (usched_set(0, USCHED_SET_CPU, &cpu, sizeof(cpu)) != 0) { fprintf(stderr, "usched_set: %s\n", strerror(errno)); return 2; } sleep(3); return 0; } |