containing subkernel. Rename prev_sched_index to sched_item_index. Fix a case where the loop would exit too late.
mentioned in commit 875fabdc