PM / devfreq: memlat: Improve tracing of stats and votes

When the memlat governor votes for 0, it didn't generate any "update" trace
points to avoid spamming the trace buffer. But this can sometimes make it
harder to interpret some traces logs.

So, as a middle ground betweem making the trace harder to interpret vs
spamming the trace buffer, generate one trace point, when the vote
transitions from a non-zero value to a zero.

At the same time, the memlat governor was also generating "meas" trace
points for completely idle cores during every polling interval. This causes
a significant amount of spamming of the trace buffer. So, when a core is
idle, don't generate any "meas" trace points for it.

Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
Change-Id: I3c72cde87bf56e45e31cc04fc4f80c030eed1e1a
diff --git a/drivers/devfreq/governor_memlat.c b/drivers/devfreq/governor_memlat.c
index 81d98d1..1a8ef1f 100644
--- a/drivers/devfreq/governor_memlat.c
+++ b/drivers/devfreq/governor_memlat.c
@@ -36,6 +36,7 @@
 struct memlat_node {
 	unsigned int ratio_ceil;
 	bool mon_started;
+	bool already_zero;
 	struct list_head list;
 	void *orig_data;
 	struct memlat_hwmon *hw;
@@ -224,7 +225,7 @@
 static int devfreq_memlat_get_freq(struct devfreq *df,
 					unsigned long *freq)
 {
-	int i, lat_dev;
+	int i, lat_dev = 0;
 	struct memlat_node *node = df->data;
 	struct memlat_hwmon *hw = node->hw;
 	unsigned long max_freq = 0;
@@ -238,16 +239,16 @@
 		if (hw->core_stats[i].mem_count)
 			ratio /= hw->core_stats[i].mem_count;
 
+		if (!hw->core_stats[i].inst_count
+		    || !hw->core_stats[i].freq)
+			continue;
+
 		trace_memlat_dev_meas(dev_name(df->dev.parent),
 					hw->core_stats[i].id,
 					hw->core_stats[i].inst_count,
 					hw->core_stats[i].mem_count,
 					hw->core_stats[i].freq, ratio);
 
-		if (!hw->core_stats[i].inst_count
-		    || !hw->core_stats[i].freq)
-			continue;
-
 		if (ratio <= node->ratio_ceil
 		    && hw->core_stats[i].freq > max_freq) {
 			lat_dev = i;
@@ -255,8 +256,10 @@
 		}
 	}
 
-	if (max_freq) {
+	if (max_freq)
 		max_freq = core_to_dev_freq(node, max_freq);
+
+	if (max_freq || !node->already_zero) {
 		trace_memlat_dev_update(dev_name(df->dev.parent),
 					hw->core_stats[lat_dev].id,
 					hw->core_stats[lat_dev].inst_count,
@@ -265,6 +268,8 @@
 					max_freq);
 	}
 
+	node->already_zero = !max_freq;
+
 	*freq = max_freq;
 	return 0;
 }