[Galaxy S III Android Development] ffolkes:
Something so weird is happening to me, I cannot even describe it. I noticed erratic downscaling and then I got stuck at 1600 MHz. I put some debug code in, flashed, and booted and things just got weirder.

I am totally puzzled.

Note: My table size is indeed 21, as I have extra frequencies added.

This code:

// Yank : We found where we currently are (i)
if(updown == SCALE_FREQ_UP) {

pr_info("[zzmoove] UP min(%d MHz [%d], %d). freq_table_size: %d\n", table[max_scaling_freq_soft].frequency, max_scaling_freq_soft, table[validate_min_max((i - 1 - smooth_up_steps - scaling_mode_up ) * freq_table_order, 0, freq_table_size)].frequency, freq_table_size);

return	min(	// Yank : Scale up, but don't go above softlimit
table[max_scaling_freq_soft ].frequency,
table[validate_min_max((i - 1 - smooth_up_steps - scaling_mode_up ) * freq_table_order, 0, freq_table_size)].frequency
);

} else {

pr_info("[zzmoove] DOWN max(%d MHz [%d], %d). freq_table_size: %d\n", table[min_scaling_freq].frequency, min_scaling_freq, table[validate_min_max((i + 1 + scaling_mode_down) * freq_table_order, 0, freq_table_size)].frequency, freq_table_size);

return	max(	// Yank : Scale down, but don't go below min. freq.
table[min_scaling_freq].frequency,
table[validate_min_max((i + 1 + scaling_mode_down) * freq_table_order, 0, freq_table_size)].frequency);

}

Yields this normal output:

<6>[ 103.520206] c0 [zzmoove] DOWN max(100000 MHz [21], 500000). freq_table_size: 21
<6>[ 103.635205] c0 [zzmoove] DOWN max(100000 MHz [21], 400000). freq_table_size: 21
<6>[ 103.865159] c0 [zzmoove] DOWN max(100000 MHz [21], 300000). freq_table_size: 21
<6>[ 103.935186] c0 [zzmoove] DOWN max(100000 MHz [21], 200000). freq_table_size: 21
<6>[ 104.260132] c0 [zzmoove] DOWN max(100000 MHz [21], 300000). freq_table_size: 21
<6>[ 104.430172] c0 [zzmoove] DOWN max(100000 MHz [21], 300000). freq_table_size: 21
<6>[ 104.480175] c0 [zzmoove] DOWN max(100000 MHz [21], 200000). freq_table_size: 21
<6>[ 104.540341] c0 [zzmoove] DOWN max(100000 MHz [21], 200000). freq_table_size: 21
<6>[ 104.820104] c0 [zzmoove] DOWN max(100000 MHz [21], 600000). freq_table_size: 21
<6>[ 104.920305] c0 [zzmoove] DOWN max(100000 MHz [21], 500000). freq_table_size: 21
<6>[ 105.020114] c0 [zzmoove] DOWN max(100000 MHz [21], 400000). freq_table_size: 21
<6>[ 105.160138] c0 [zzmoove] DOWN max(100000 MHz [21], 300000). freq_table_size: 21
<6>[ 105.330173] c0 [zzmoove] DOWN max(100000 MHz [21], 300000). freq_table_size: 21
<6>[ 105.395199] c0 [zzmoove] DOWN max(100000 MHz [21], 200000). freq_table_size: 21
<6>[ 105.590288] c0 [zzmoove] DOWN max(100000 MHz [21], 200000). freq_table_size: 21
<6>[ 105.731468] c0 [zzmoove] DOWN max(100000 MHz [21], 200000). freq_table_size: 21

However, I am totally baffled why this happens when I simply comment out that one line:

// Yank : We found where we currently are (i)
if(updown == SCALE_FREQ_UP) {

[COLOR="Red"][B]//[/B][/COLOR]pr_info("[zzmoove] UP min(%d MHz [%d], %d). freq_table_size: %d\n", table[max_scaling_freq_soft].frequency, max_scaling_freq_soft, table[validate_min_max((i - 1 - smooth_up_steps - scaling_mode_up ) * freq_table_order, 0, freq_table_size)].frequency, freq_table_size);

return	min(	// Yank : Scale up, but don't go above softlimit
table[max_scaling_freq_soft ].frequency,
table[validate_min_max((i - 1 - smooth_up_steps - scaling_mode_up ) * freq_table_order, 0, freq_table_size)].frequency
);

} else {

pr_info("[zzmoove] DOWN max(%d MHz [%d], %d). freq_table_size: %d\n", table[min_scaling_freq].frequency, min_scaling_freq, table[validate_min_max((i + 1 + scaling_mode_down) * freq_table_order, 0, freq_table_size)].frequency, freq_table_size);

return	max(	// Yank : Scale down, but don't go below min. freq.
table[min_scaling_freq].frequency,
table[validate_min_max((i + 1 + scaling_mode_down) * freq_table_order, 0, freq_table_size)].frequency);

}

:eek: All I did was comment out the UP pr_info() (as I didn't want to clutter kmsg with it anymore, since I was currently troubleshooting the down logic) and all of a sudden min_scaling_freq starts erratically changing its value (it is defined no where else but in the governor CPUFREQ_GOV_START case) which then causes the downscaling logic to go insane itself, as max() is being fed random data, causing it to randomly decide to send the frequency way higher than it was destined to.

<6>[ 108.820096] c0 [zzmoove] DOWN max(950000 MHz [420], 900000). freq_table_size: 21
<6>[ 108.920665] c0 [zzmoove] DOWN max(1000000 MHz [430], 900000). freq_table_size: 21
<6>[ 109.030113] c0 [zzmoove] DOWN max(1000000 MHz [440], 900000). freq_table_size: 21
<6>[ 109.126179] c0 [zzmoove] DOWN max(887500 MHz [450], 900000). freq_table_size: 21
<6>[ 109.225120] c0 [zzmoove] DOWN max(900000 MHz [460], 800000). freq_table_size: 21
<6>[ 109.320123] c0 [zzmoove] DOWN max(912500 MHz [470], 800000). freq_table_size: 21
<6>[ 109.425069] c0 [zzmoove] DOWN max(900000 MHz [480], 900000). freq_table_size: 21
<6>[ 109.525126] c0 [zzmoove] DOWN max(512 MHz [490], 800000). freq_table_size: 21
<6>[ 109.625138] c0 [zzmoove] DOWN max(1024 MHz [500], 700000). freq_table_size: 21
<6>[ 109.725149] c0 [zzmoove] DOWN max(72 MHz [510], 600000). freq_table_size: 21
<6>[ 109.825187] c0 [zzmoove] DOWN max(0 MHz [520], 500000). freq_table_size: 21
<6>[ 109.920197] c0 [zzmoove] DOWN max(21057 MHz [530], 400000). freq_table_size: 21
<6>[ 110.035142] c0 [zzmoove] DOWN max(18499 MHz [540], 300000). freq_table_size: 21
<6>[ 110.230132] c0 [zzmoove] DOWN max(21064 MHz [557], 300000). freq_table_size: 21
<6>[ 110.285149] c0 [zzmoove] DOWN max(22347 MHz [567], 200000). freq_table_size: 21
<6>[ 110.430184] c0 [zzmoove] DOWN max(21842 MHz [588], 200000). freq_table_size: 21
<6>[ 110.560277] c0 [zzmoove] DOWN max(-349962240 MHz [602], 200000). freq_table_size: 21
<6>[ 110.640064] c0 [zzmoove] DOWN max(2 MHz [609], 1500000). freq_table_size: 21
<6>[ 110.700663] c0 [zzmoove] DOWN max(2 MHz [619], 1400000). freq_table_size: 21
<6>[ 110.720079] c0 [zzmoove] DOWN max(1 MHz [629], 1300000). freq_table_size: 21

Another time min_scaling_freq got stuck at 0, which policy->max ultimately capped to 1600000. And since 1600000 is already policy->max, when the scaling down logic calculates max(1600000, whatever), it will always result in 1600 being the chosen frequency to scale down to. This has the effect of locking the frequency at policy->max since it can never downscale again.

Hardcoding [21] seems to fix it, but I am so perplexed why this is happening. :confused:

Any ideas?

PS. Imagine the battery life you'd get at -349962240 MHz ;P