[Crash-utility] [PATCH] Fix display processor speed on ppc/ppc64

Pavan Naregundi pavan at linux.vnet.ibm.com
Thu Mar 25 05:40:57 UTC 2010


On Wed, 2010-03-24 at 09:31 -0400, Dave Anderson wrote:

> 
> This patch doesn't seem like it would be backwards-compatible for older
> systems which do *not* have the "have_of" symbol.  Can you confirm
> that this patch will still work for them?
> 
> Thanks,
>   Dave

Hi Dave,

I think systems you are referring are, systems which do not have OF. I
don't have a system of that type here to test.. Just to be safe I have
prepared a new patch.. 

Changes are, patch assumes that system is having the OF and tries to
find the processor speed.. If the speed was not found, then if would go
will the code of finding the processor speed in system without OF. I
think this will makes sure of backwards-compatibility in older system.

Thanks
Pavan

---
diff -Naur a/ppc64.c b/ppc64.c
--- a/ppc64.c	2010-03-25 10:47:54.000000000 +0530
+++ b/ppc64.c	2010-03-25 10:48:15.000000000 +0530
@@ -742,7 +742,7 @@
 ppc64_processor_speed(void)
 {
         ulong res, value, ppc_md, md_setup_res;
-        ulong we_have_of, prep_setup_res;
+        ulong prep_setup_res;
         ulong node, type, name, properties;
 	char str_buf[32];
 	uint len;
@@ -751,22 +751,7 @@
         if (machdep->mhz)
                 return(machdep->mhz);
 
-        /* first, check if the have_of variable a) exists, and b) is
TRUE */
-        if(symbol_exists("have_of")) {
-                get_symbol_data("have_of", sizeof(void *),
&we_have_of);
-        } else {
-                we_have_of = 0;
-        }
-
-        if(we_have_of) {
-                /* we have a machine with open firmware, so search the
OF nodes
-                 * for cpu nodes.
-                 * Too bad we can't call kernel helper functions
here :)
-                 */
-
-                if(!symbol_exists("allnodes"))
-                        return (machdep->mhz = 0);
-
+        if(symbol_exists("allnodes")) {
                 get_symbol_data("allnodes", sizeof(void *), &node);
                 while(node) {
                         readmem(node+OFFSET(device_node_type),
@@ -842,54 +827,54 @@
                         }
                         if(!properties) {
                                 /* didn't find the cpu speed for some
reason */
-                                mhz = 0;
+				return (machdep->mhz = 0);
                         }
                 }
-        } else {
-                /* for machines w/o OF */
-                /* untested, but in theory this should work on prep
machines */
+	} 
 
-                if (symbol_exists("res")) {
-                        get_symbol_data("res", sizeof(void *), &res);
+	/* for machines w/o OF */
+        /* untested, but in theory this should work on prep machines */
 
-                        if (symbol_exists("prep_setup_residual")) {
-                                get_symbol_data("prep_setup_residual",
-                                        sizeof(void *),
&prep_setup_res);
-                                get_symbol_data("ppc_md", sizeof(void
*),
-                                        &ppc_md);
-                                readmem(ppc_md +
-
OFFSET(machdep_calls_setup_residual),
-                                    KVADDR, &md_setup_res,
-                                    sizeof(ulong), "ppc_md
setup_residual",
-                                    FAULT_ON_ERROR);
-
-                                if(prep_setup_res == md_setup_res) {
-                                /* PREP machine */
-                                        readmem(res+
-
OFFSET(RESIDUAL_VitalProductData)+
-                                            OFFSET(VPD_ProcessorHz),
-                                            KVADDR, &mhz,
sizeof(ulong),
-                                            "res VitalProductData",
-                                            FAULT_ON_ERROR);
+        if (symbol_exists("res") && !mhz) {
+        	get_symbol_data("res", sizeof(void *), &res);
 
-                                        mhz = (mhz > 1024) ? mhz >>
20 : mhz;
-                                }
-                        }
+                if (symbol_exists("prep_setup_residual")) {
+                	get_symbol_data("prep_setup_residual",
+                        	sizeof(void *), &prep_setup_res);
+                        get_symbol_data("ppc_md", sizeof(void *),
+                        	&ppc_md);
+                        readmem(ppc_md +
+                        	OFFSET(machdep_calls_setup_residual),
+                                KVADDR, &md_setup_res,
+                                sizeof(ulong), "ppc_md setup_residual",
+                                FAULT_ON_ERROR);
 
-                        if(!mhz) {
-                          /* everything else seems to do this the same
way... */
-                                readmem(res +
-                                    OFFSET(bd_info_bi_intfreq),
-                                    KVADDR, &mhz, sizeof(ulong),
-                                    "bd_info bi_intfreq",
FAULT_ON_ERROR);
+			if(prep_setup_res == md_setup_res) {
+                        	/* PREP machine */
+                                readmem(res+
+                                	OFFSET(RESIDUAL_VitalProductData)+
+                                        OFFSET(VPD_ProcessorHz),
+                                        KVADDR, &mhz, sizeof(ulong),
+                                        "res VitalProductData",
+                                        FAULT_ON_ERROR);
 
-                                mhz /= 1000000;
-                        }
-                }
-                /* else...well, we don't have OF, or a residual
structure, so
-                 * just print unknown MHz
-                */
-        }
+                        	mhz = (mhz > 1024) ? mhz >> 20 : mhz;
+                	}
+		}
+
+		if(!mhz) {
+                        /* everything else seems to do this the same
way... */
+                        readmem(res +
+                        	OFFSET(bd_info_bi_intfreq),
+                                KVADDR, &mhz, sizeof(ulong),
+                                "bd_info bi_intfreq", FAULT_ON_ERROR);
+
+                	mhz /= 1000000;
+        	}
+	}
+        /* else...well, we don't have OF, or a residual structure, so
+         * just print unknown MHz
+         */
 
         return (machdep->mhz = (ulong)mhz);
 }
diff -Naur a/ppc.c b/ppc.c
--- a/ppc.c	2010-03-25 10:47:54.000000000 +0530
+++ b/ppc.c	2010-03-25 10:48:15.000000000 +0530
@@ -461,7 +461,7 @@
 ppc_processor_speed(void)
 {
 	ulong res, value, ppc_md, md_setup_res;
-	ulong we_have_of, prep_setup_res;
+	ulong prep_setup_res;
 	ulong node, type, name, properties;
 	char str_buf[16];
 	ulong len, mhz = 0;
@@ -469,22 +469,7 @@
 	if (machdep->mhz)
 		return(machdep->mhz);
 
-	/* first, check if the have_of variable a) exists, and b) is TRUE */
-	if(symbol_exists("have_of")) {
-		get_symbol_data("have_of", sizeof(void *), &we_have_of);
-	} else {
-		we_have_of = 0;
-	}
-
-	if(we_have_of) {
-		/* we have a machine with open firmware, so search the OF nodes 
-		 * for cpu nodes.
-		 * Too bad we can't call kernel helper functions here :)
-		 */
-		
-		if(!symbol_exists("allnodes"))
-			return (machdep->mhz = 0);
-		
+	if(symbol_exists("allnodes")) {
 		get_symbol_data("allnodes", sizeof(void *), &node);
 		while(node) {
 			readmem(node+OFFSET(device_node_type),
@@ -545,54 +530,53 @@
 			}
 			if(!properties) {
 				/* didn't find the cpu speed for some reason */
-				mhz = 0;
+				return (machdep->mhz = 0);
 			}
 		}
-	} else {
-		/* for machines w/o OF */
-		/* untested, but in theory this should work on prep machines */
+	}
+	/* for machines w/o OF */
+	/* untested, but in theory this should work on prep machines */
 
-		if (symbol_exists("res")) {
-			get_symbol_data("res", sizeof(void *), &res);
+	if (symbol_exists("res") && !mhz) {
+		get_symbol_data("res", sizeof(void *), &res);
 			
-			if (symbol_exists("prep_setup_residual")) {
-				get_symbol_data("prep_setup_residual", 
-					sizeof(void *), &prep_setup_res);
-				get_symbol_data("ppc_md", sizeof(void *), 
-					&ppc_md);
-				readmem(ppc_md + 
-			 	    OFFSET(machdep_calls_setup_residual), 
-				    KVADDR, &md_setup_res, 
-				    sizeof(ulong), "ppc_md setup_residual",
-				    FAULT_ON_ERROR);
+		if (symbol_exists("prep_setup_residual")) {
+			get_symbol_data("prep_setup_residual", 
+				sizeof(void *), &prep_setup_res);
+			get_symbol_data("ppc_md", sizeof(void *), 
+				&ppc_md);
+			readmem(ppc_md + 
+		 	    OFFSET(machdep_calls_setup_residual), 
+			    KVADDR, &md_setup_res, 
+			    sizeof(ulong), "ppc_md setup_residual",
+			    FAULT_ON_ERROR);
 				
-				if(prep_setup_res == md_setup_res) {
-				/* PREP machine */
-					readmem(res+
-					    OFFSET(RESIDUAL_VitalProductData)+
-					    OFFSET(VPD_ProcessorHz),
-					    KVADDR, &mhz, sizeof(ulong), 
-					    "res VitalProductData", 
-					    FAULT_ON_ERROR);
+			if(prep_setup_res == md_setup_res) {
+			/* PREP machine */
+				readmem(res+
+				    OFFSET(RESIDUAL_VitalProductData)+
+				    OFFSET(VPD_ProcessorHz),
+				    KVADDR, &mhz, sizeof(ulong), 
+				    "res VitalProductData", 
+				    FAULT_ON_ERROR);
 					
-					mhz = (mhz > 1024) ? mhz >> 20 : mhz;
-				}
+				mhz = (mhz > 1024) ? mhz >> 20 : mhz;
 			}
+		}
 			
-			if(!mhz) {
-			  /* everything else seems to do this the same way... */
-				readmem(res + 
-				    OFFSET(bd_info_bi_intfreq),
-				    KVADDR, &mhz, sizeof(ulong), 
-				    "bd_info bi_intfreq", FAULT_ON_ERROR);
+		if(!mhz) {
+			/* everything else seems to do this the same way... */
+			readmem(res + 
+				OFFSET(bd_info_bi_intfreq),
+				KVADDR, &mhz, sizeof(ulong), 
+				"bd_info bi_intfreq", FAULT_ON_ERROR);
 				
-				mhz /= 1000000;
-			}
+			mhz /= 1000000;
 		}
-		/* else...well, we don't have OF, or a residual structure, so
-		 * just print unknown MHz
-		 */
 	}
+	/* else...well, we don't have OF, or a residual structure, so
+	 * just print unknown MHz
+	 */
 
 	return (machdep->mhz = mhz);
 }






More information about the Crash-utility mailing list