[Crash-utility] [PATCH v2 2/4] crash: support cpu_active_mask

Liu Hua sdu.liu at huawei.com
Mon Apr 28 15:15:06 UTC 2014


This patch introduces cpu_active_mask related support for
crash. It is import for ARM platform to detemine the
number of online CPUs.

Signed-off-by: Liu Hua <sdu.liu at huawei.com>
---
 defs.h   |  4 +++-
 kernel.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ppc64.c  |  2 ++
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/defs.h b/defs.h
index c40cf8d..c02b69f 100644
--- a/defs.h
+++ b/defs.h
@@ -655,7 +655,8 @@ struct kernel_table {                   /* kernel data */
 #define POSSIBLE_MAP  (0x1)
 #define PRESENT_MAP   (0x2)
 #define ONLINE_MAP    (0x4)
-#define NMI       (0x8)
+#define ACTIVE_MAP    (0x8)
+#define NMI       (0x10)
 	int BUG_bytes;
 	ulong xen_flags;
 #define WRITABLE_PAGE_TABLES    (0x1)
@@ -4792,6 +4793,7 @@ void set_cpu(int);
 void clear_machdep_cache(void);
 struct stack_hook *gather_text_list(struct bt_info *);
 int get_cpus_online(void);
+int get_cpus_active(void);
 int get_cpus_present(void);
 int get_cpus_possible(void);
 int get_highest_cpu_online(void);
diff --git a/kernel.c b/kernel.c
index 87656fe..f3981ab 100644
--- a/kernel.c
+++ b/kernel.c
@@ -798,6 +798,7 @@ cpu_maps_init(void)
 		{ POSSIBLE_MAP, "possible" },
 		{ PRESENT_MAP, "present" },
 		{ ONLINE_MAP, "online" },
+		{ ACTIVE_MAP, "active" },
 	};
 
 	if ((len = STRUCT_SIZE("cpumask_t")) < 0)
@@ -884,6 +885,13 @@ in_cpu_map(int map, int cpu)
 			return FALSE;
 		}
 		return (kt->cpu_flags[cpu] & ONLINE_MAP);
+
+	case ACTIVE_MAP:
+		if (!cpu_map_addr("active")) {
+			error(INFO, "cpu_active_map does not exist\n");
+			return FALSE;
+		}
+		return (kt->cpu_flags[cpu] & ACTIVE_MAP);
 	}
 
 	return FALSE;
@@ -5306,6 +5314,15 @@ dump_kernel_table(int verbose)
 		fprintf(fp, "\n");
 	} else
 		fprintf(fp, "(does not exist)\n");
+	fprintf(fp, "         cpu_active_map: ");
+	if (cpu_map_addr("active")) {
+		for (i = 0; i < nr_cpus; i++) {
+			if (kt->cpu_flags[i] & ACTIVE_MAP)
+				fprintf(fp, "%d ", i);
+		}
+		fprintf(fp, "\n");
+	} else
+		fprintf(fp, "(does not exist)\n");
 
 no_cpu_flags:
 	fprintf(fp, "    vmcoreinfo: \n");
@@ -7935,6 +7952,40 @@ get_highest_cpu_online()
 }
 
 /*
+ *  If it exists, return the number of cpus in the cpu_active_map.
+ */
+int
+get_cpus_active()
+{
+	int i, len, active;
+	char *buf;
+	ulong *maskptr, addr;
+
+	if (!(addr = cpu_map_addr("active")))
+		return 0;
+
+	len = cpu_map_size("active");
+	buf = GETBUF(len);
+
+	active = 0;
+
+	if (readmem(addr, KVADDR, buf, len,
+		"cpu_active_map", RETURN_ON_ERROR)) {
+
+		maskptr = (ulong *)buf;
+		for (i = 0; i < (len/sizeof(ulong)); i++, maskptr++)
+			active += count_bits_long(*maskptr);
+
+		if (CRASHDEBUG(1))
+			error(INFO, "get_cpus_active: active: %d\n", active);
+	}
+
+	FREEBUF(buf);
+
+	return active;
+}
+
+/*
  *  If it exists, return the number of cpus in the cpu_present_map.
  */
 int
diff --git a/ppc64.c b/ppc64.c
index f414a58..7f2f0e2 100644
--- a/ppc64.c
+++ b/ppc64.c
@@ -2866,6 +2866,8 @@ ppc64_get_cpu_map(void)
 		map = PRESENT_MAP;
 	else if (cpu_map_addr("online"))
 		map = ONLINE_MAP;
+	else if (cpu_map_addr("active"))
+		map = ACTIVE_MAP;
 	else {
 		map = 0;
 		error(FATAL,
-- 
1.9.0




More information about the Crash-utility mailing list