Use while_system_locked() in more places, turn cpu alarm on in after_switch() to avoid race with cpu alarm