x86_64: supporting cpu hot remove

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Dave,

This patchset is used to fix some bug and modify display of some commands.
When some cpus are removed, the related data is not reasonable to be displayed,
so hide them.

Please check the patches to see detailed information.

--
Regards
Qiao Nuohan
From d32974518c8920c0d3163d6672a434d1cbbeb429 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 10:16:11 +0800
Subject: [PATCH 01/23] x86_64: add an API to check an offline cpu

on x86_64, when a cpu is hot removed(offline), this function will check
it out

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 defs.h   |  1 +
 kernel.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/defs.h b/defs.h
index 44df6ae..a751813 100755
--- a/defs.h
+++ b/defs.h
@@ -4883,6 +4883,7 @@ int get_cpus_online(void);
 int get_cpus_active(void);
 int get_cpus_present(void);
 int get_cpus_possible(void);
+int check_offline_cpu(int);
 int get_highest_cpu_online(void);
 int get_highest_cpu_present(void);
 int get_cpus_to_display(void);
diff --git a/kernel.c b/kernel.c
index 2a1e0a8..736ede0 100755
--- a/kernel.c
+++ b/kernel.c
@@ -7973,6 +7973,24 @@ get_cpus_online()
 	return online;
 }
 
+int
+check_offline_cpu(int cpu)
+{
+	/*
+	 * currently, only x86_64 is taken into consideration.
+	 */
+	if (!machine_type("X86_64"))
+		return FALSE;
+
+	if (!cpu_map_addr("online"))
+		return FALSE;
+
+	if (in_cpu_map(ONLINE_MAP, cpu))
+		return FALSE;
+
+	return TRUE;
+}
+
 /*
  *  If it exists, return the highest cpu number in the cpu_online_map.
  */
-- 
1.8.5.3

From 8b535909b83701b0495479f874696c00104f1e2a Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 10:18:10 +0800
Subject: [PATCH 02/23] x86_64: modify help -m/-M only to display online cpu's
 data

help -m/-M will display current task address/crash nmi rsp/exception
stack/irq stack, and these data of offline cpu will be hide with this
patch

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 x86_64.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/x86_64.c b/x86_64.c
index f4a3e8b..98c587f 100755
--- a/x86_64.c
+++ b/x86_64.c
@@ -575,7 +575,7 @@ x86_64_init(int when)
 void
 x86_64_dump_machdep_table(ulong arg)
 {
-	int c, i, cpus;
+	int c, i, cpus, r;
         int others; 
         struct machine_specific *ms;
 
@@ -762,23 +762,37 @@ x86_64_dump_machdep_table(ulong arg)
    ((C) < 10 ? 3 : (C) < 100 ? 2 : (C) < 1000 ? 1 : 0)
 
 	fprintf(fp, "%s            current[%d]:%s", 
-		space(CPU_SPACES(kt->cpus)), kt->cpus,
+		space(CPU_SPACES(get_cpus_to_display())), get_cpus_to_display(),
 		ms->current ? "\n   " : " (unused)\n");
+
+	r = 0;
 	for (c = 0; ms->current && (c < kt->cpus); c++) { 
-		if (c && !(c%4))
+		if (check_offline_cpu(c))
+			continue;
+
+		if (r && !(r%4))
 			fprintf(fp, "\n   ");
 		fprintf(fp, "%016lx ", ms->current[c]);
+
+		r++;
 	}
 	if (ms->current)
 		fprintf(fp, "\n");
 
 	fprintf(fp, "%s      crash_nmi_rsp[%d]:%s", 
-		space(CPU_SPACES(kt->cpus)), kt->cpus, 
+		space(CPU_SPACES(get_cpus_to_display())), get_cpus_to_display(),
 		ms->crash_nmi_rsp ? "\n   " : " (unused)\n");
+
+	r = 0;
 	for (c = 0; ms->crash_nmi_rsp && (c < kt->cpus); c++) { 
-		if (c && !(c%4))
+		if (check_offline_cpu(c))
+			continue;
+
+		if (r && !(r%4))
 			fprintf(fp, "\n   ");
 		fprintf(fp, "%016lx ", ms->crash_nmi_rsp[c]);
+
+		r++;
 	}
 	if (ms->crash_nmi_rsp)
 		fprintf(fp, "\n");
@@ -802,6 +816,9 @@ x86_64_dump_machdep_table(ulong arg)
 		arg ? "NR_CPUS" : "cpus", MAX_EXCEPTION_STACKS);
 	cpus = arg ? NR_CPUS : kt->cpus;
 	for (c = 0; c < cpus; c++) {
+		if (!arg && check_offline_cpu(c))
+			continue;
+
 		fprintf(fp, "\n  %s[%d]: ", c < 10 ? " " : "", c);
 		for (i = 0; i < MAX_EXCEPTION_STACKS; i++) { 
 			fprintf(fp, "%016lx ", ms->stkinfo.ebase[c][i]);
@@ -811,10 +828,17 @@ x86_64_dump_machdep_table(ulong arg)
 	}
 	fprintf(fp, "\n                           ibase[%s]:\n   ",
 		arg ? "NR_CPUS" : "cpus");
+
+	r = 0;
 	for (c = 0; c < cpus; c++) {
-		if (c && !(c%4))
+		if (!arg && check_offline_cpu(c))
+			continue;
+
+		if (r && !(r%4))
 			fprintf(fp, "\n   ");
 		fprintf(fp, "%016lx ", ms->stkinfo.ibase[c]);
+
+		r++;
 	}
 	fprintf(fp, "\n");
 }
-- 
1.8.5.3

From 51727dfc6aea3ad52e08fac2dcfefb73a87456e0 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 10:19:32 +0800
Subject: [PATCH 03/23] x86_64: modify bt -E only to display online cpu's data

bt -E will search all irq stacks and exception stacks for possible
exception frames. With this patch offline cpus will be ignore.

This patch also fix x86_64_in_exception_stack and x86_64_in_irqstack.
Only online cpus' exception stacks and irq stacks will be searched.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 x86_64.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/x86_64.c b/x86_64.c
index 98c587f..439e447 100755
--- a/x86_64.c
+++ b/x86_64.c
@@ -2346,6 +2346,9 @@ x86_64_eframe_search(struct bt_info *bt)
         	ms = machdep->machspec;
 
         	for (c = 0; c < kt->cpus; c++) {
+			if (check_offline_cpu(c))
+				continue;
+
                 	if (ms->stkinfo.ibase[c] == 0)
                         	break;
                                 bt->hp->esp = ms->stkinfo.ibase[c];
@@ -2357,6 +2360,9 @@ x86_64_eframe_search(struct bt_info *bt)
                 }
 
         	for (c = 0; c < kt->cpus; c++) {
+			if (check_offline_cpu(c))
+				continue;
+
                 	for (i = 0; i < MAX_EXCEPTION_STACKS; i++) {
                         	if (ms->stkinfo.ebase[c][i] == 0)
                                 	break;
@@ -2794,6 +2800,9 @@ x86_64_in_exception_stack(struct bt_info *bt, int *estack_index)
 	estack = 0;
 
         for (c = 0; !estack && (c < kt->cpus); c++) {
+		if (check_offline_cpu(c))
+			continue;
+
 		for (i = 0; i < MAX_EXCEPTION_STACKS; i++) {
 			if (ms->stkinfo.ebase[c][i] == 0)
 				break;
@@ -2831,6 +2840,9 @@ x86_64_in_irqstack(struct bt_info *bt)
         irqstack = 0;
 
         for (c = 0; !irqstack && (c < kt->cpus); c++) {
+		if (check_offline_cpu(c))
+			continue;
+
                 if (ms->stkinfo.ibase[c] == 0)
                  	break;
                 if ((rsp >= ms->stkinfo.ibase[c]) &&
-- 
1.8.5.3

From de13eb846a997ebf3dcc428829116e777808ebdc Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 10:21:15 +0800
Subject: [PATCH 04/23] x86_64: modify mach only to display online cpu's data

mach will display number of cpus and cpus' irq stacks and exception
stacks. This patch will ignore offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 x86_64.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/x86_64.c b/x86_64.c
index 439e447..33045c9 100755
--- a/x86_64.c
+++ b/x86_64.c
@@ -5069,7 +5069,7 @@ x86_64_display_machine_stats(void)
 
 	fprintf(fp, "          MACHINE TYPE: %s\n", uts->machine);
 	fprintf(fp, "           MEMORY SIZE: %s\n", get_memory_size(buf));
-	fprintf(fp, "                  CPUS: %d\n", kt->cpus);
+	fprintf(fp, "                  CPUS: %d\n", get_cpus_to_display());
 	if (!STREQ(kt->hypervisor, "(undetermined)") &&
 	    !STREQ(kt->hypervisor, "bare hardware"))
 		fprintf(fp, "            HYPERVISOR: %s\n",  kt->hypervisor);
@@ -5092,6 +5092,8 @@ x86_64_display_machine_stats(void)
 	fprintf(fp, "        IRQ STACK SIZE: %d\n", machdep->machspec->stkinfo.isize);
 	fprintf(fp, "            IRQ STACKS:\n");
 	for (c = 0; c < kt->cpus; c++) {
+		if (check_offline_cpu(c))
+			continue;
 		sprintf(buf, "CPU %d", c);
 		fprintf(fp, "%22s: %016lx\n", 
 			buf, machdep->machspec->stkinfo.ibase[c]);
@@ -5108,6 +5110,9 @@ x86_64_display_machine_stats(void)
 		for (c = 0; c < kt->cpus; c++) {
 			if (machdep->machspec->stkinfo.ebase[c][i] == 0)
 				break;
+			if(check_offline_cpu(c))
+				continue;
+
 			sprintf(buf, "CPU %d", c);
 			fprintf(fp, "%22s: %016lx\n", 
 				buf, machdep->machspec->stkinfo.ebase[c][i]);
-- 
1.8.5.3

From 56b429bce1fe972ee8f876cc2294723fef72df71 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 10:22:58 +0800
Subject: [PATCH 05/23] x86_64: modify mach -c only to display online cpu's
 data

mach -c will display some per-cpu structures. This patch will ignore
offline cpus' structures.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 x86_64.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/x86_64.c b/x86_64.c
index 33045c9..41f4890 100755
--- a/x86_64.c
+++ b/x86_64.c
@@ -5159,23 +5159,30 @@ x86_64_display_cpu_data(unsigned int radix)
         for (cpu = 0; cpu < cpus; cpu++) {
 		if (boot_cpu)
                 	fprintf(fp, "BOOT CPU:\n");
-		else
-                	fprintf(fp, "%sCPU %d:\n", cpu ? "\n" : "", cpu);
+		else {
+			if (!check_offline_cpu(cpu))
+				fprintf(fp, "%sCPU %d:\n", cpu ? "\n" : "", cpu);
+		}
 
 		if (per_cpu)
 			cpu_data = per_cpu->value + kt->__per_cpu_offset[cpu];
 
-                dump_struct("cpuinfo_x86", cpu_data, radix);
+		if (!check_offline_cpu(cpu))
+	                dump_struct("cpuinfo_x86", cpu_data, radix);
 
 		if (_cpu_pda) {
 			readmem(cpu_pda, KVADDR, &cpu_pda_addr,
 				sizeof(unsigned long), "_cpu_pda addr", FAULT_ON_ERROR);
-			fprintf(fp, "\n");
-			dump_struct("x8664_pda", cpu_pda_addr, radix);
+			if (!check_offline_cpu(cpu)) {
+				fprintf(fp, "\n");
+				dump_struct("x8664_pda", cpu_pda_addr, radix);
+			}
 			cpu_pda += sizeof(void *);
 		} else if (VALID_STRUCT(x8664_pda)) {
-			fprintf(fp, "\n");
-			dump_struct("x8664_pda", cpu_pda, radix);
+			if (!check_offline_cpu(cpu)) {
+				fprintf(fp, "\n");
+				dump_struct("x8664_pda", cpu_pda, radix);
+			}
 			cpu_pda += SIZE(x8664_pda);
 		}
 
-- 
1.8.5.3

From 0192dc985b00e9451738da6ecd4aa5fceaaa9892 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 10:47:09 +0800
Subject: [PATCH 06/23] x86_64: modify help -r only to display online cpu's
 registers

help -r can display registers on three types of vmcore:
1. qemu memoly-only dump
2. kdump(kdump-compressed format)
3. kdump(elf format)

This patch will hide the offline cpus' registers.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 diskdump.c |  3 +++
 netdump.c  | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/diskdump.c b/diskdump.c
index e230c1f..d462492 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2057,6 +2057,9 @@ dump_registers_for_compressed_kdump(void)
 		error(FATAL, "-r option not supported for this dumpfile\n");
 
 	for (c = 0; c < kt->cpus; c++) {
+		if (check_offline_cpu(c))
+			continue;
+
 		fprintf(fp, "%sCPU %d:\n", c ? "\n" : "", c);
 		diskdump_display_regs(c, fp);
 	}
diff --git a/netdump.c b/netdump.c
index c86a992..644807b 100644
--- a/netdump.c
+++ b/netdump.c
@@ -2354,8 +2354,19 @@ display_regs_from_elf_notes(int cpu)
 	Elf64_Nhdr *note64;
 	size_t len;
 	char *user_regs;
+	int c, skipped_count;
 
-	if (cpu >= nd->num_prstatus_notes) {
+	/*
+	 * NT_PRSTATUS notes are only related to online cpus, offline cpus
+	 * should be skipped.
+	 */
+	skipped_count = 0;
+	for (c = 0; c < cpu; c++) {
+		if (check_offline_cpu(c))
+			skipped_count++;
+	}
+
+	if ((cpu - skipped_count) >= nd->num_prstatus_notes) {
 		error(INFO, "registers not collected for cpu %d\n", cpu);
 		return;
 	}
@@ -2462,6 +2473,9 @@ dump_registers_for_elf_dumpfiles(void)
 	}
 
         for (c = 0; c < kt->cpus; c++) {
+		if (check_offline_cpu(c))
+			continue;
+
                 fprintf(fp, "%sCPU %d:\n", c ? "\n" : "", c);
                 display_regs_from_elf_notes(c);
         }
@@ -3756,6 +3770,9 @@ dump_registers_for_qemu_mem_dump(void)
 	nd->ofp = fp;
 
 	for (i=0; i<nd->num_qemu_notes; i++) {
+		if (check_offline_cpu(i))
+			continue;
+
 		ptr = (QEMUCPUState *)nd->nt_qemu_percpu[i];
 
 		if (i)
-- 
1.8.5.3

From c5288f1a1a21f0208c44c7d78dc340120a83b184 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 11:12:02 +0800
Subject: [PATCH 07/23] x86_64: modify bt -c only to display online cpu's
 registers

bt -c will display the stack trace of the active task on specified cpus.
This patch will skip offline cpus and print a message like below to
indicate the skip(xx is the id of the offline cpu).

<cut>
bt: CPU xx is offline.
<cut>

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel.c b/kernel.c
index 736ede0..6f675c2 100755
--- a/kernel.c
+++ b/kernel.c
@@ -2259,6 +2259,11 @@ cmd_bt(void)
 
 		for (i = 0; i < kt->cpus; i++) {
 			if (NUM_IN_BITMAP(cpus, i)) {
+				if (check_offline_cpu(i)) {
+					error(INFO, "\nCPU %d is offline.\n", i);
+					continue;
+				}
+
 				if ((task = get_active_task(i)))
 					tc = task_to_context(task);
 				else
-- 
1.8.5.3

From 0a9950478fcb4f84ed6028bd9c5bd50f22c72cd3 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 11:27:58 +0800
Subject: [PATCH 08/23] x86_64: modify display_sys_stats() only to display
 online cpus' number

function display_sys_stats will display the cpus' total number at initiation
when crash is executed or when command sys is called. With this patch, only
the total number of online cpus will be displayed.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel.c b/kernel.c
index 6f675c2..6fc44c2 100755
--- a/kernel.c
+++ b/kernel.c
@@ -4781,7 +4781,8 @@ display_sys_stats(void)
 	}
 	
 	fprintf(fp, "        CPUS: %d\n",
-		machine_type("PPC64") ? get_cpus_to_display() : kt->cpus);
+		(machine_type("PPC64") || machine_type("X86_64")) ?
+			get_cpus_to_display() : kt->cpus);
 	if (ACTIVE())
 		get_xtime(&kt->date);
         fprintf(fp, "        DATE: %s\n", 
-- 
1.8.5.3

From c83c09f2d02b2b822c0b933af725d9c7d48ce9a4 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 14:58:20 +0800
Subject: [PATCH 09/23] x86_64: modify help -k only to display online cpus'
 number

help -k will display total number of cpus. This patch skips offline
cpu and only calculates online cpus' number.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel.c b/kernel.c
index 6fc44c2..127bf3a 100755
--- a/kernel.c
+++ b/kernel.c
@@ -5229,7 +5229,8 @@ dump_kernel_table(int verbose)
         fprintf(fp, "    init_begin: %lx\n", kt->init_begin);
         fprintf(fp, "      init_end: %lx\n", kt->init_end);
         fprintf(fp, "           end: %lx\n", kt->end);
-        fprintf(fp, "          cpus: %d\n", kt->cpus);
+        fprintf(fp, "          cpus: %d\n", machine_type("X86_64") ?
+		get_cpus_to_display() : kt->cpus);
         fprintf(fp, " cpus_override: %s\n", kt->cpus_override);
         fprintf(fp, "       NR_CPUS: %d (compiled-in to this version of %s)\n",
 		NR_CPUS, pc->program_name); 
-- 
1.8.5.3

From f31c9f8ad9fbadcc9722b09f180f6d01b2165c97 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 15:01:06 +0800
Subject: [PATCH 10/23] x86_64: modify set -c only be available on online cpus

With this patch, set -c cannot set to an offline cpu. If so, only a
message like below will be printed.

<cut>
set invalid cpu number: cpu xx is offline
<cut>

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel.c b/kernel.c
index 127bf3a..ff1f2e1 100755
--- a/kernel.c
+++ b/kernel.c
@@ -5469,6 +5469,10 @@ set_cpu(int cpu)
 	if (cpu >= kt->cpus)
 		error(FATAL, "invalid cpu number: system has only %d cpu%s\n", 
 			kt->cpus, kt->cpus > 1 ? "s" : "");
+
+	if (check_offline_cpu(cpu))
+		error(FATAL, "invalid cpu number: cpu %d is offline\n", cpu);
+
 	if ((task = get_active_task(cpu))) 
 		set_context(task, NO_PID);
 	else
-- 
1.8.5.3

From 6cf7291ff1c72f47a8b2d628d7cf47a7d2813564 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 15:22:51 +0800
Subject: [PATCH 11/23] x86_64: modify irq -s only to display online cpus' data

irq -s will display kernel irq stats. This patch will skip offline cpus

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel.c b/kernel.c
index ff1f2e1..329c786 100755
--- a/kernel.c
+++ b/kernel.c
@@ -5612,6 +5612,9 @@ cmd_irq(void)
 		fprintf(fp, "     ");
 		BZERO(buf, 10);
 		for (i = 0; i < kt->cpus; i++) {
+			if (check_offline_cpu(i))
+				continue;
+
 			if (NUM_IN_BITMAP(cpus, i)) {
 				sprintf(buf, "CPU%d", i);
 				fprintf(fp, "%10s ", buf);
@@ -6409,6 +6412,9 @@ generic_show_interrupts(int irq, ulong *cpus)
 	fprintf(fp, "%3d: ", irq);
 
 	for (i = 0; i < kt->cpus; i++) {
+		if (check_offline_cpu(i))
+			continue;
+
 		if (NUM_IN_BITMAP(cpus, i))
 			fprintf(fp, "%10u ", kstat_irqs[i]);
 	}
-- 
1.8.5.3

From 007c0653be5d211c146047f63c17343eb451ae08 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 15:27:46 +0800
Subject: [PATCH 12/23] x86_64: modify irq -a only to display online cpus' data

irq -a will dump cpu affinity for irqs. This patch will skip offline
cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel.c b/kernel.c
index 329c786..ea3b65c 100755
--- a/kernel.c
+++ b/kernel.c
@@ -5714,14 +5714,19 @@ get_irq_desc_addr(int irq)
 static void
 display_cpu_affinity(ulong *mask)
 {
-	int cpu, seq, start, count;
+	int cpu, seq, start, count, cpu_exist;
 
 	seq = FALSE;
 	start = 0;
 	count = 0;
 
 	for (cpu = 0; cpu < kt->cpus; ++cpu) {
-		if (NUM_IN_BITMAP(mask, cpu)) {
+		/*
+		 * on X86_64, offline cpu should not be displayed.
+		 */
+		cpu_exist = !check_offline_cpu(cpu) && NUM_IN_BITMAP(mask, cpu);
+
+		if (cpu_exist) {
 			if (seq)
 				continue;
 			start = cpu;
@@ -5738,6 +5743,9 @@ display_cpu_affinity(ulong *mask)
 		}
 	}
 
+	/*
+	 * when seq is TRUE, the following cpus cannot be offline.
+	 */
 	if (seq) {
 		if (count)
 			fprintf(fp, ",");
-- 
1.8.5.3

From 2f4f08b860047bc1df6267bdfc35e78e889ed1be Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 16:28:33 +0800
Subject: [PATCH 13/23] x86_64: modify timer -r only to display online cpus'
 data

timer -r will display hrtimer. This patch will skip offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel.c b/kernel.c
index ea3b65c..60cbfa8 100755
--- a/kernel.c
+++ b/kernel.c
@@ -6724,7 +6724,7 @@ cmd_timer(void)
 static void
 dump_hrtimer_data(void)
 {
-	int i, j;
+	int i, j, first_cpu;
 	int hrtimer_max_clock_bases, max_hrtimer_bases;
 	struct syment * hrtimer_bases;
 
@@ -6746,9 +6746,17 @@ dump_hrtimer_data(void)
 		option_not_supported('r');
 
 	hrtimer_bases = per_cpu_symbol_search("hrtimer_bases");
+
+	first_cpu = 1;
 	for (i = 0; i < kt->cpus; i++) {
-		if (i)
+		if (check_offline_cpu(i))
+			continue;
+
+		if (first_cpu)
+			first_cpu = 0;
+		else
 			fprintf(fp, "\n");
+
 		fprintf(fp, "CPU: %d  ", i);
 		if (VALID_STRUCT(hrtimer_clock_base)) {
 			fprintf(fp, "HRTIMER_CPU_BASE: %lx\n",
-- 
1.8.5.3

From d902bfe895de8e199139f7ddd7aeaa4a93dac72e Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 16:44:33 +0800
Subject: [PATCH 14/23] x86_64: modify timer only to display online cpus' data

This patch will skip offline cpus and only display timer queue entries
on online cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 kernel.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel.c b/kernel.c
index 60cbfa8..f83d0bc 100755
--- a/kernel.c
+++ b/kernel.c
@@ -7417,6 +7417,11 @@ dump_timer_data_tvec_bases_v2(void)
 	cpu = 0;
 
 next_cpu:
+	if (check_offline_cpu(cpu)) {
+		if (++cpu < kt->cpus)
+			goto next_cpu;
+	}
+
 
 	count = 0;
 	td = (struct timer_data *)NULL;
-- 
1.8.5.3

From b2ef639175ddb4c9552dbcd1f5c2891e084951cf Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 16:48:13 +0800
Subject: [PATCH 15/23] x86_64: modify ptov offset:cpuspec only to display
 online cpus' data

ptov offset:cpuspec can be used to translate per-cpu offset to kernel
virtual address. This patch will skip offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/memory.c b/memory.c
index c97dd39..8527483 100755
--- a/memory.c
+++ b/memory.c
@@ -3181,6 +3181,9 @@ cmd_ptov(void)
 		    		mkstring(buf1, len, LJUST, "CPU"),
 		    		mkstring(buf2, VADDR_PRLEN, LJUST, "VIRTUAL"));
 			for (c = 0; c < kt->cpus; c++) {
+				if (check_offline_cpu(c))
+					continue;
+
 				if (!NUM_IN_BITMAP(cpus, c))
 					continue;
 				vaddr = paddr + kt->__per_cpu_offset[c];
-- 
1.8.5.3

From c359e13374e1d5c399b3e53c2270f7612f11d7dd Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 16:53:30 +0800
Subject: [PATCH 16/23] x86_64: fix max_cpudata_limit() when offlined cpu
 exists

When determining the largest cpudata limit for kmem_cache, the member,
limit, of kmem_cache.array[NR_CPUS] is needed, and the process will
stop when kmem_cache.array[cpu] equals to NULL. However, when offline
cpus exist, kmem_cache.array[cpu] of offline cpus are NULL. Then the
process of determining the largest cpudata limit will ignore the cpus
after the offlined cpu.

This patch is used to fix the above problem.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 memory.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index 8527483..01f0839 100755
--- a/memory.c
+++ b/memory.c
@@ -9106,7 +9106,13 @@ kmem_cache_s_array_nodes:
             "array cache array", RETURN_ON_ERROR))
 		goto bail_out;
 
-	for (i = max_limit = 0; (i < kt->cpus) && cpudata[i]; i++) {
+	for (i = max_limit = 0; i < kt->cpus; i++) {
+		if (check_offline_cpu(i))
+			continue;
+
+		if (!cpudata[i])
+			break;
+
                 if (!readmem(cpudata[i]+OFFSET(array_cache_limit),
                     KVADDR, &limit, sizeof(int),
                     "array cache limit", RETURN_ON_ERROR)) {
-- 
1.8.5.3

From 568361d6f8e1b69fa908b966426ba77f8d88cbfc Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 17:02:07 +0800
Subject: [PATCH 17/23] x86_64: modify kmem -o only to display online cpus'
 data

kmem -o is used to display each cpu's offset value that is added
to per-cpu symbol values to translate them into kernel virtual
addresses. This patch will skip offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/memory.c b/memory.c
index 01f0839..65447c9 100755
--- a/memory.c
+++ b/memory.c
@@ -16936,6 +16936,9 @@ dump_per_cpu_offsets(void)
 	fprintf(fp, "PER-CPU OFFSET VALUES:\n");
 
 	for (c = 0; c < kt->cpus; c++) {
+		if (check_offline_cpu(c))
+			continue;
+
 		sprintf(buf, "CPU %d", c);
 		fprintf(fp, "%7s: %lx\n", buf, kt->__per_cpu_offset[c]);
 	}
-- 
1.8.5.3

From ed64a2fcf1fff6af24043bbe5d60b33b80381982 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sat, 23 Aug 2014 17:04:55 +0800
Subject: [PATCH 18/23] x86_64: modify kmem -S(SLUB) only to display online
 cpus' data

if SLUB is configured, kmem -S will display per-cpu data. This patch
will skip offline cpu.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/memory.c b/memory.c
index 65447c9..ce524ba 100755
--- a/memory.c
+++ b/memory.c
@@ -17349,6 +17349,9 @@ do_kmem_cache_slub(struct meminfo *si)
 	per_cpu = (ulong *)GETBUF(sizeof(ulong) * vt->numnodes);
 
         for (i = 0; i < kt->cpus; i++) {
+		if (check_offline_cpu(i))
+			continue;
+
 		cpu_slab_ptr = get_cpu_slab_ptr(si, i, NULL);
 
 		fprintf(fp, "CPU %d SLAB:\n%s", i, 
-- 
1.8.5.3

From 84a646f855c30981aa04e999ce16365d4ef3760e Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sun, 24 Aug 2014 10:47:01 +0800
Subject: [PATCH 19/23] x86_64: modify struct/union/* [:cpuspec] only to
 display online cpus' data

with [:cpuspec] struct/union/* will display per-cpu structure/union of the
specified cpus. This patch will skip offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 symbols.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/symbols.c b/symbols.c
index 4c6fbf4..d1109a8 100755
--- a/symbols.c
+++ b/symbols.c
@@ -6135,6 +6135,9 @@ cmd_datatype_common(ulong flags)
 		do_datatype_declaration(dm, flags | (dm->flags & TYPEDEF));
 	} else if (cpus) {
 		for (c = 0; c < kt->cpus; c++) {
+			if (check_offline_cpu(c))
+				continue;
+
 			ulong cpuaddr;
 
 			if (!NUM_IN_BITMAP(cpus, c))
-- 
1.8.5.3

From 02f589705cba9abe828bc670196efeac32a9a790 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Sun, 24 Aug 2014 10:56:50 +0800
Subject: [PATCH 20/23] x86_64: modify command p only to display online cpus'
 data

command p can be used to display data of per-cpu symbol. This patch is
used to skip offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 symbols.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/symbols.c b/symbols.c
index d1109a8..55e71d5 100755
--- a/symbols.c
+++ b/symbols.c
@@ -6836,6 +6836,9 @@ display_per_cpu_info(struct syment *sp, int radix, char *cpuspec)
 		module_symbol(sp->value, NULL, NULL, NULL, *gdb_output_radix);
 
 	for (c = 0; c < kt->cpus; c++) {
+		if (check_offline_cpu(c))
+			continue;
+
 		if (cpus && !NUM_IN_BITMAP(cpus, c))
 			continue;
 		addr = sp->value + kt->__per_cpu_offset[c];
-- 
1.8.5.3

From daf10b5a0b1de3f80989f3d9f0a0894ac4fbabec Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Mon, 25 Aug 2014 10:21:15 +0800
Subject: [PATCH 21/23] x86_64: modify ps only to display online cpus' idle
 tasks

this patch fix get_idle_threads and get_active_set to ignore tasks on
offline cpus, then command ps will not display idle tasks on offline
cpus

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 task.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/task.c b/task.c
index 75b1964..65d7ebb 100755
--- a/task.c
+++ b/task.c
@@ -1051,6 +1051,8 @@ retry_pidhash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -1268,6 +1270,8 @@ retry_pid_hash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -1516,6 +1520,8 @@ retry_pid_hash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -1745,6 +1751,8 @@ retry_pid_hash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -2199,6 +2207,8 @@ retry_active:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->active_set[i]))
 			cnt++;
 		else
@@ -6958,6 +6968,9 @@ get_idle_threads(ulong *tasklist, int nr_cpus)
 	    VALID_MEMBER(runqueue_idle)) {
 		runqbuf = GETBUF(SIZE(runqueue));
 		for (i = 0; i < nr_cpus; i++) {
+			if (check_offline_cpu(i))
+				continue;
+
 			if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF))
 				runq = rq_sp->value + kt->__per_cpu_offset[i];
 			else
@@ -7147,6 +7160,9 @@ get_active_set(void)
 		FREEBUF(vcpu_struct_buf);
 	} else if (VALID_MEMBER(runqueue_curr) && rq_sp) {
                	for (i = 0; i < kt->cpus; i++) {
+			if (check_offline_cpu(i))
+				continue;
+
                         if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF))
                                 runq = rq_sp->value + kt->__per_cpu_offset[i];
                         else
-- 
1.8.5.3

From 86e71c88dcf774729c72eaf737cbf7e09f828367 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Mon, 25 Aug 2014 10:45:34 +0800
Subject: [PATCH 22/23] x86_64: modify ps -l/-m -C cpu only to display online
 cpus' data

ps -l/-m -C cpu is used to dump most-recently run tasks on specified
cpus. This patch is used to skip offline cpus.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 task.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/task.c b/task.c
index 65d7ebb..192cef0 100755
--- a/task.c
+++ b/task.c
@@ -3290,6 +3290,8 @@ show_last_run(struct task_context *tc, struct psinfo *psi)
 
 	if (psi) {
 		for (c = others = 0; c < kt->cpus; c++) {
+			if (check_offline_cpu(c))
+				continue;
 			if (!NUM_IN_BITMAP(psi->cpus, c))
 				continue;
 			fprintf(fp, "%sCPU: %d\n", 
@@ -3372,6 +3374,9 @@ show_milliseconds(struct task_context *tc, struct psinfo *psi)
 
 	if (psi) {
 		for (c = others = 0; c < kt->cpus; c++) {
+			if (check_offline_cpu(c))
+				continue;
+
 			if (!NUM_IN_BITMAP(psi->cpus, c))
 				continue;
 
-- 
1.8.5.3

From f8e3cb124dca859ea6e68860d1195ddfb0aee576 Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
Date: Mon, 25 Aug 2014 13:13:51 +0800
Subject: [PATCH 23/23] x86_64: modify runq only to display online cpus' data

runq [-t/-m/-g/-d] is used to display data on run queues of each cpu.
This patch is used to skip offline cpus' run queues.

Signed-off-by: Qiao Nuohan <qiaonuohan@xxxxxxxxxxxxxx>
---
 task.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/task.c b/task.c
index 192cef0..676beec 100755
--- a/task.c
+++ b/task.c
@@ -7551,6 +7551,9 @@ dump_on_rq_timestamp(void)
 		option_not_supported('t');
 
 	for (cpu = 0; cpu < kt->cpus; cpu++) {
+		if (check_offline_cpu(cpu))
+			continue;
+
 		if ((kt->flags & SMP) && (kt->flags &PER_CPU_OFF))
 			runq = rq_sp->value + kt->__per_cpu_offset[cpu];
 		else
@@ -7619,6 +7622,9 @@ dump_on_rq_milliseconds(void)
 	max_days = days = 0;
 
 	for (cpu = 0; cpu < kt->cpus; cpu++) {
+		if (check_offline_cpu(cpu))
+			continue;
+
 		if ((kt->flags & SMP) && (kt->flags &PER_CPU_OFF))
 			runq = rq_sp->value + kt->__per_cpu_offset[cpu];
 		else
@@ -7762,6 +7768,9 @@ dump_runqueues(void)
         runqbuf = GETBUF(SIZE(runqueue));
 
 	for (cpu = 0; cpu < kt->cpus; cpu++, runq += SIZE(runqueue)) {
+		if (check_offline_cpu(cpu))
+			continue;
+
 		if (rq_sp) {
 			if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF))
 				runq = rq_sp->value + kt->__per_cpu_offset[cpu];
@@ -8224,6 +8233,8 @@ dump_on_rq_tasks(void)
 	}
 
 	for (cpu = 0; cpu < kt->cpus; cpu++) {
+		if (check_offline_cpu(cpu))
+			continue;
 
                 fprintf(fp, "%sCPU %d\n", cpu ? "\n" : "", cpu);
 
@@ -8353,6 +8364,9 @@ dump_CFS_runqueues(void)
 	get_active_set();
 
         for (cpu = 0; cpu < kt->cpus; cpu++) {
+		if (check_offline_cpu(cpu))
+			continue;
+
 		if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF))
 			runq = rq_sp->value + kt->__per_cpu_offset[cpu];
 		else
@@ -8847,6 +8861,9 @@ dump_tasks_by_task_group(void)
 	get_active_set();
 
 	for (cpu = 0; cpu < kt->cpus; cpu++) {
+		if (check_offline_cpu(cpu))
+			continue;
+
 		readmem(rt_rq + cpu * sizeof(ulong), KVADDR, &rt_rq_p,
 			sizeof(ulong), "task_group rt_rq", FAULT_ON_ERROR);
 		readmem(cfs_rq + cpu * sizeof(ulong), KVADDR, &cfs_rq_p,
-- 
1.8.5.3

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux