/*
* This itererator really needs some explanation since it is offset and has
* two passes, one of which is controlled by a config option.
- * In a hotplugged system some cpus, including cpu 0, may be missing so we have
- * to use cpumask_* to iterate over the cpus.
+ * In a hotpluggable systems some cpus, including cpu 0 and the last cpu, may
+ * be missing so we have to use cpumask_* to iterate over the cpus.
* For the first pass:
* It returns 1 for the header position.
* For cpu 0 it returns 2 and the final possible cpu would be nr_cpu_ids + 1.
* It returnes nr_cpu_ids + 1 for the second header position.
* For cpu 0 it returns nr_cpu_ids + 2
* The final possible cpu would be nr_cpu_ids + nr_cpu_ids + 2.
+ * It is also important to remember that cpumask_next returns >= nr_cpu_ids if
+ * no further cpus set.
*/
static void *timer_list_start(struct seq_file *file, loff_t *offset)
{
return (void *) 1;
if (n < nr_cpu_ids + 1) {
- n--;
- if (n > 0)
- n = cpumask_next(n - 1, cpu_online_mask);
- else
- n = cpumask_first(cpu_online_mask);
+ n = cpumask_next(n - 2, cpu_online_mask);
+ if (n >= nr_cpu_ids)
+ n = nr_cpu_ids;
*offset = n + 1;
return (void *)(unsigned long)(n + 2);
}
if (n < nr_cpu_ids * 2 + 2) {
n -= (nr_cpu_ids + 2);
- if (n > 0)
- n = cpumask_next(n - 1, cpu_online_mask);
- else
- n = cpumask_first(cpu_online_mask);
+ n = cpumask_next(n - 1, cpu_online_mask);
+ if (n >= nr_cpu_ids)
+ return NULL;
*offset = n + 2 + nr_cpu_ids;
return (void *)(unsigned long)(n + 3 + nr_cpu_ids);
}