[Crash-utility] [PATCH] Fix machdep->HZ calculation for kernel versions > 2.6.0

Bhupesh Sharma bhsharma at redhat.com
Tue Jan 12 05:40:06 UTC 2021


We have hard-coded the HZ value for some ARCHs to either 1000 or 100
(mainly for kernel versions > 2.6.0), which causes 'help -m' to show
an incorrect hz value for various architectures.

I tested this on ppc64le and x86_64 and the hz value reported is 1000,
whereas the kernel CONFIG_HZ_100 is set to Y. See some logs below:

crash> help -m
              flags: 124000f5 (KSYMS_START|MACHDEP_BT_TEXT|VM_4_LEVEL|VMEMMAP|VMEMMAP_AWARE|PHYS_ENTRY_L4|SWAP_ENTRY_L4|RADIX_MMU|OPAL_FW)
             kvbase: c000000000000000
  identity_map_base: c000000000000000
           pagesize: 65536
          pageshift: 16
           pagemask: ffffffffffff0000
         pageoffset: ffff
          stacksize: 16384
                 hz: 1000
                mhz: 2800

[host at rhel7]$ grep CONFIG_HZ_100= redhat/configs/kernel-3.10.0-ppc64le.config
CONFIG_HZ_100=y

Fix the same by using the sysconf(_SC_CLK_TCK) value instead of the
hardcoded HZ values depending on kernel versions.

Cc: k-hagio-ab at nec.com
Cc: lijiang at redhat.com
Cc: bhupesh.linux at gmail.com
Signed-off-by: Bhupesh Sharma <bhsharma at redhat.com>
---
 arm.c    | 2 +-
 arm64.c  | 2 +-
 ppc.c    | 5 +----
 ppc64.c  | 6 ++----
 x86.c    | 5 +----
 x86_64.c | 5 +----
 6 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/arm.c b/arm.c
index e52d29f04015..234feca7d1df 100644
--- a/arm.c
+++ b/arm.c
@@ -326,7 +326,7 @@ arm_init(int when)
 				   "pr_reg");
 	
 		if (!machdep->hz)
-			machdep->hz = 100;
+			machdep->hz = HZ;
 		break;
 
 	case POST_VM:
diff --git a/arm64.c b/arm64.c
index 37aed07edf1d..8226a8ed7929 100644
--- a/arm64.c
+++ b/arm64.c
@@ -457,7 +457,7 @@ arm64_init(int when)
 				&machdep->nr_irqs);
 
 		if (!machdep->hz)
-			machdep->hz = 100;
+			machdep->hz = HZ;
 
 		arm64_irq_stack_init();
 		arm64_stackframe_init();
diff --git a/ppc.c b/ppc.c
index cf5bf5688227..1c1c15a1fab3 100644
--- a/ppc.c
+++ b/ppc.c
@@ -401,11 +401,8 @@ ppc_init(int when)
 					&machdep->nr_irqs);
 		else
 			machdep->nr_irqs = 512; /* NR_IRQS (at least) */
-		if (!machdep->hz) {
+		if (!machdep->hz)
 			machdep->hz = HZ;
-			if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
-				machdep->hz = 1000;
-		}
 		if (symbol_exists("cur_cpu_spec")) {
 			get_symbol_data("cur_cpu_spec", sizeof(void *), &cur_cpu_spec);
 			readmem(cur_cpu_spec + MEMBER_OFFSET("cpu_spec", "cpu_user_features"), 
diff --git a/ppc64.c b/ppc64.c
index f368bf8e1a08..0cc82ffbba0e 100644
--- a/ppc64.c
+++ b/ppc64.c
@@ -694,11 +694,9 @@ ppc64_init(int when)
 			 */
 			BZERO(&machdep->machspec->hwintrstack,
 				NR_CPUS*sizeof(ulong));
-		if (!machdep->hz) {
+		if (!machdep->hz)
 			machdep->hz = HZ;
-			if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
-				machdep->hz = 1000;
-		}
+
 		/*
 		 * IRQ stacks are introduced in 2.6 and also configurable.
 		 */
diff --git a/x86.c b/x86.c
index de0d3d3114d0..ab34052da7af 100644
--- a/x86.c
+++ b/x86.c
@@ -1998,11 +1998,8 @@ x86_init(int when)
 				&machdep->nr_irqs);
 		else
 			machdep->nr_irqs = 224;  /* NR_IRQS */
-		if (!machdep->hz) {
+		if (!machdep->hz)
 			machdep->hz = HZ;
-			if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
-				machdep->hz = 1000;
-		}
 
 		if (machdep->flags & PAE) {
 			if (THIS_KERNEL_VERSION < LINUX(2,6,26))
diff --git a/x86_64.c b/x86_64.c
index 23a40a04bbc4..3e6750708659 100644
--- a/x86_64.c
+++ b/x86_64.c
@@ -660,11 +660,8 @@ x86_64_init(int when)
 		machdep->show_interrupts = x86_64_show_interrupts;
 		if (THIS_KERNEL_VERSION < LINUX(2,6,24))
 			machdep->line_number_hooks = x86_64_line_number_hooks;
-		if (!machdep->hz) {
+		if (!machdep->hz)
 			machdep->hz = HZ;
-			if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
-				machdep->hz = 1000;
-		}
 		machdep->section_size_bits = _SECTION_SIZE_BITS;
 		if (!machdep->max_physmem_bits) {
 			if ((string = pc->read_vmcoreinfo("NUMBER(MAX_PHYSMEM_BITS)"))) {
-- 
2.26.2




More information about the Crash-utility mailing list