#include #include #include #include #include #include #include #include static int __aligned(CACHE_LINE_SIZE) val = -1; static int test_modevent(struct module *m, int what, void *arg __unused) { struct thread *td; int cpu, old, tmp; if (what == MOD_LOAD) { old = -1; td = curthread; CPU_FOREACH(cpu) { thread_lock(td); sched_bind(td, cpu); thread_unlock(td); tmp = old; if (!atomic_fcmpset_int(&val, &old, cpu)) { printf("fcmpset failed on cpu %d, old %d val %d\n", PCPU_GET(cpuid), tmp, val); if (!atomic_fcmpset_int(&val, &old, cpu)) { printf("fcmpset failed again, wtf!\n"); val = cpu; } } old = cpu; } thread_lock(td); sched_unbind(td); thread_unlock(td); } return (0); } static moduledata_t test_moddata = { "test", test_modevent, NULL, }; DECLARE_MODULE(test, test_moddata, SI_SUB_KLD, SI_ORDER_ANY);