浏览代码

s390/cpuinfo: simplify locking and skip offline cpus early

Move the get_online_cpus() and put_online_cpus() to the start and stop
operation of the seqfile ops. This way there is no need to lock cpu
hotplug again and again for each single cpu.

This way we can also skip offline cpus early if we simply use
cpumask_next() within the next operation.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Heiko Carstens 9 年之前
父节点
当前提交
281eaa8cb6
共有 1 个文件被更改,包括 11 次插入4 次删除
  1. 11 4
      arch/s390/kernel/processor.c

+ 11 - 4
arch/s390/kernel/processor.c

@@ -84,7 +84,6 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 		seq_puts(m, "\n");
 		seq_puts(m, "\n");
 		show_cacheinfo(m);
 		show_cacheinfo(m);
 	}
 	}
-	get_online_cpus();
 	if (cpu_online(n)) {
 	if (cpu_online(n)) {
 		struct cpuid *id = &per_cpu(cpu_id, n);
 		struct cpuid *id = &per_cpu(cpu_id, n);
 		seq_printf(m, "processor %li: "
 		seq_printf(m, "processor %li: "
@@ -93,23 +92,31 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 			   "machine = %04X\n",
 			   "machine = %04X\n",
 			   n, id->version, id->ident, id->machine);
 			   n, id->version, id->ident, id->machine);
 	}
 	}
-	put_online_cpus();
 	return 0;
 	return 0;
 }
 }
 
 
+static inline void *c_update(loff_t *pos)
+{
+	if (*pos)
+		*pos = cpumask_next(*pos - 1, cpu_online_mask);
+	return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
+}
+
 static void *c_start(struct seq_file *m, loff_t *pos)
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
 {
-	return *pos < nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
+	get_online_cpus();
+	return c_update(pos);
 }
 }
 
 
 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
 {
 {
 	++*pos;
 	++*pos;
-	return c_start(m, pos);
+	return c_update(pos);
 }
 }
 
 
 static void c_stop(struct seq_file *m, void *v)
 static void c_stop(struct seq_file *m, void *v)
 {
 {
+	put_online_cpus();
 }
 }
 
 
 const struct seq_operations cpuinfo_op = {
 const struct seq_operations cpuinfo_op = {