> I took your patch and fixed it up quite a bit to accomodate for some 
> other changes that went into git. Can you pull the latest git, apply 
> below modified patch and give this a test and see if it does what you
> want it to?
> 

Thanks. I had to slightly modify your patch to apply, because there
were mismatches in whitespaces, line breaks and one line was listed
twice (probably by mistake).

But it seems not to work correctly. The last line of C and P states is 
not shown in interactive mode on my test machine. On the other machine
the C/P state window is not correctly placed. I think there are 
several problems. The window size for C states is probably not 
correctly computed, because the maxcstate can be 4 or 6, but there 
need not be C3 or C5 thus the maxcstate need not correspond to the 
number of lines - I added code that tries to find out number of lines. 
I also removed maxfreq as maxpstate seems to be alias. 
I tried to simplify/correct show_c_and_p_states as it missed one state
on my testing machine. The problem - now there is no trim for high
number of C states in interactive mode, but I think that the previous
code was not correct as well. I also added newlines to 
"no C/P states info", because there were not correctly wrapped in dump
mode. Now it works OK on my testing machines, but maybe there are still
some hidden problems

Jaroslav
diff --git a/cpufreqstats.c b/cpufreqstats.c
index 6e948cd..41c4d50 100644
--- a/cpufreqstats.c
+++ b/cpufreqstats.c
@@ -107,9 +107,10 @@ void  do_cpufreq_stats(void)
 	char line[1024];
 
 	int ret = 0;
-	int maxfreq = 0;
 	uint64_t total_time = 0;
 
+	maxpstate = 0;
+
 	memcpy(&oldfreqs, &freqs, sizeof(freqs));
 	memset(&cpufreqstrings, 0, sizeof(cpufreqstrings));
 	sprintf(cpufreqstrings[0], _("P-states (frequencies)\n"));
@@ -150,8 +151,8 @@ void  do_cpufreq_stats(void)
 			freqs[i].frequency = f;
 			freqs[i].count += count;
 
-			if (f && maxfreq < i)
-				maxfreq = i;
+			if (f && maxpstate < i)
+				maxpstate = i;
 			i++;
 			if (i >= MAX_NUM_PSTATES)
 				break;
@@ -173,17 +174,19 @@ void  do_cpufreq_stats(void)
 	if (!total_time)
 		return;
 
-	qsort(&delta, maxfreq+1, sizeof(struct cpufreqdata), sort_by_count);
-	if (maxfreq>4)
-		maxfreq=4;
-	maxpstate = maxfreq;
-	qsort(&delta, maxfreq+1, sizeof(struct cpufreqdata), sort_by_freq);
+	if (!dump) {
+		qsort(&delta, maxpstate+1, sizeof(struct cpufreqdata),
+		sort_by_count);
+		if (maxpstate>4)
+			maxpstate=4;
+	}
+	qsort(&delta, maxpstate+1, sizeof(struct cpufreqdata), sort_by_freq);
 
 	if (delta[0].frequency == delta[1].frequency + 1000)
 		turbo_hz = delta[0].frequency;
 
 	topfreq = -1;
-	for (ret = 0 ; ret<=maxfreq; ret++) {
+	for (ret = 0 ; ret<=maxpstate; ret++) {
 		sprintf(cpufreqstrings[ret+1], "%6s   %5.1f%%\n", HzToHuman(delta[ret].frequency), delta[ret].count * 100.0 / total_time);
 		if (delta[ret].count > total_time/2)
 			topfreq = ret;
diff --git a/display.c b/display.c
index 6682d34..8b030ed 100644
--- a/display.c
+++ b/display.c
@@ -97,7 +97,13 @@ int maxwidth = 200;
 
 void setup_windows(void)
 {
-	int yline = (maxcstate >= maxpstate) ? maxcstate+1 : maxpstate;
+	int i, yline, maxcstateline = -2;
+	for (i = 0; i <= MAX_CSTATE_LINES; i++) {
+		if (strlen(cstate_lines[i]))
+			maxcstateline++;
+	}
+
+	yline = (maxcstateline >= maxpstate) ? maxcstateline: maxpstate;
 
 	/* number of states is one more than the MAX state! */
 	if (!maxcstate && !maxpstate)
@@ -178,25 +184,21 @@ void show_title_bar(void)
 void show_c_and_p_states(void)
 {
 	int i, count = 0;
-	int maxcstatelines = (maxcstate >= maxpstate) ? maxcstate+1 : maxpstate;
-
-	/* Number of states is one more than the MAX state! */
-	maxcstatelines++;
 
 	p_werase(cstate_window);
 
-	for (i = 0; i < maxcstatelines; i++) {
+	for (i = 0; i <= MAX_CSTATE_LINES; i++) {
 		if (i == topcstate+1)
 			p_wattron(cstate_window, A_BOLD);
 		else
 			p_wattroff(cstate_window, A_BOLD);
-		if (strlen(cstate_lines[i]) && count <= maxcstatelines) {
+		if (strlen(cstate_lines[i])) {
 			print(cstate_window, count, 0, "%s", cstate_lines[i]);
 			count++;
 		}
 	}
 
-	for (i = 0; i <= (maxpstate+1); i++) {
+	for (i = 0; i <= (dump ? MAX_NUM_PSTATES : maxpstate + 1); i++) {
 		if (i == topfreq+1)
 			p_wattron(cstate_window, A_BOLD);
 		else
@@ -211,14 +213,14 @@ void show_cstates(void)
 {
 
 	if (!maxcstate) {
-		strcpy(cstate_lines[0], "<C-state information is unavailable>");
+		strcpy(cstate_lines[0], "<C-state information is unavailable>\n");
 		strcpy(cstate_lines[1], "");
 		topcstate = 99; /* Dummy value, to avoid "bold" text */
 	}
 
 	if (!maxpstate) {
 		strcpy(cpufreqstrings[0],
-		       "<P-state information is unavailable>");
+		       "<P-state information is unavailable>\n");
 		strcpy(cpufreqstrings[1], "");
 		topfreq = 99; /* Dummy value, to avoid "bold" text */
 	}
_______________________________________________
Power mailing list
[email protected]
http://www.bughost.org/mailman/listinfo/power

Reply via email to