[Skiboot] [PATCH v4 RESEND 1/8] slw: Simplify if-condition while adding idle states to device tree

Shreyas B. Prabhu shreyas at linux.vnet.ibm.com
Fri Jun 17 14:21:44 AEST 2016


if-condition in add_cpu_idle_state_properties which checks if a given idle
state is supported  is bloated with multiple  '&' and '||' operations.
Simplify by adding a mask variable and setting the relevant bits.
This patch does not change any functionality.

Acked-by: Michael Neuling <mikey at neuling.org>
Signed-off-by: Shreyas B. Prabhu <shreyas at linux.vnet.ibm.com>
---
Changes in v4:
==============
- Took Mikey's suggestion and changed the if condition to avoid
  extra indentation.

 hw/slw.c | 73 ++++++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/hw/slw.c b/hw/slw.c
index b67097c97ddd..53e02cc73cf5 100644
--- a/hw/slw.c
+++ b/hw/slw.c
@@ -500,6 +500,8 @@ void add_cpu_idle_state_properties(void)
 	bool can_sleep = true, can_winkle = true;
 	u8 i;
 
+	u32 supported_states_mask;
+
 	/* Buffers to hold idle state properties */
 	char *name_buf, *alloced_name_buf;
 	u32 *latency_ns_buf;
@@ -589,38 +591,49 @@ void add_cpu_idle_state_properties(void)
 	name_buf_len = 0;
 	num_supported_idle_states = 0;
 
+	/*
+	 * Create a mask with the flags of all supported idle states
+	 * set. Use this to only add supported idle states to the
+	 * device-tree
+	 */
+	supported_states_mask = OPAL_PM_NAP_ENABLED;
+	if (can_sleep)
+		supported_states_mask |= OPAL_PM_SLEEP_ENABLED |
+					OPAL_PM_SLEEP_ENABLED_ER1;
+	if (can_winkle)
+		supported_states_mask |= OPAL_PM_WINKLE_ENABLED;
+
 	for (i = 0; i < nr_states; i++) {
 		/* For each state, check if it is one of the supported states. */
-		if( (states[i].flags & OPAL_PM_NAP_ENABLED) ||
-		   ((states[i].flags & OPAL_PM_SLEEP_ENABLED) && can_sleep) ||
-		   ((states[i].flags & OPAL_PM_SLEEP_ENABLED_ER1) && can_sleep) ||
-		   ((states[i].flags & OPAL_PM_WINKLE_ENABLED) && can_winkle) ) {
-			/*
-			 * If a state is supported add each of its property
-			 * to its corresponding property buffer.
-			 */
-			strcpy(name_buf, states[i].name);
-			name_buf = name_buf + strlen(states[i].name) + 1;
-
-			*latency_ns_buf = cpu_to_fdt32(states[i].latency_ns);
-			latency_ns_buf++;
-
-			*residency_ns_buf = cpu_to_fdt32(states[i].residency_ns);
-			residency_ns_buf++;
-
-			*flags_buf = cpu_to_fdt32(states[i].flags);
-			flags_buf++;
-
-			*pmicr_buf = cpu_to_fdt64(states[i].pmicr);
-			pmicr_buf++;
-
-			*pmicr_mask_buf = cpu_to_fdt64(states[i].pmicr);
-			pmicr_mask_buf++;
-
-			/* Increment buffer length trackers */
-			name_buf_len += strlen(states[i].name) + 1;
-			num_supported_idle_states++;
-		}
+		if (!(states[i].flags & supported_states_mask))
+			continue;
+
+		/*
+		 * If a state is supported add each of its property
+		 * to its corresponding property buffer.
+		 */
+		strcpy(name_buf, states[i].name);
+		name_buf = name_buf + strlen(states[i].name) + 1;
+
+		*latency_ns_buf = cpu_to_fdt32(states[i].latency_ns);
+		latency_ns_buf++;
+
+		*residency_ns_buf = cpu_to_fdt32(states[i].residency_ns);
+		residency_ns_buf++;
+
+		*flags_buf = cpu_to_fdt32(states[i].flags);
+		flags_buf++;
+
+		*pmicr_buf = cpu_to_fdt64(states[i].pmicr);
+		pmicr_buf++;
+
+		*pmicr_mask_buf = cpu_to_fdt64(states[i].pmicr);
+		pmicr_mask_buf++;
+
+		/* Increment buffer length trackers */
+		name_buf_len += strlen(states[i].name) + 1;
+		num_supported_idle_states++;
+
 	}
 
 	/* Point buffer pointers back to beginning of the buffer */
-- 
1.9.3



More information about the Skiboot mailing list