[Defy Android Development] YetAnotherForumUser:
How to get cpu stats working, bug in power_omap3.c causes lag, fmradio-related bugs

For those of you who absolutely need to see how much time their processor has spent on which clock speed I have some good news. These statistics have been missing since the move to 2nd-boot but it is really easy to get them back - just load the cpufreq_stats.ko module. This is best done in /system/bootmenu/scripts/overclock.sh, in the [FONT="Monospace, Courier New"]get_address() [/FONT]function. This makes sure the module gets loaded before overclock.ko which depends on some symbols exported by this module for exporting statistics. I'll add some more details on this later/earlier, suffice to say it works and it gets rid of some log spam from overclock.ko ([FONT="Monospace, Courier New"]overclock: cpufreq_stats_table address not configured, aborting action[/FONT]). You'll need the following patches to get this to work as intended:

diff --git a/bootmenu/script/overclock.sh b/bootmenu/script/overclock.sh
index b98975e..6cd5f79 100755
--- a/bootmenu/script/overclock.sh
+++ b/bootmenu/script/overclock.sh
@@ -85,8 +85,9 @@ param_safe()

get_address()
{
+ insmod $MODULE_DIR/cpufreq_stats.ko
cpufreq_table=`grep -e omap2_clk_init_cpufreq_table /proc/kallsyms | sed -e "s/\([0-9A-Fa-f]\{8\}\).*/\1/"`
- stats_update=`grep -e cpufreq_stats_update$ /proc/kallsyms | sed -e "s/\([0-9A-Fa-f]\{8\}\).*/\1/"`
+ stats_update=`grep -e cpufreq_stats_freq_update /proc/kallsyms | sed -e "s/\([0-9A-Fa-f]\{8\}\).*/\1/"`
}

#############################################################
diff --git a/modules/sources/overclock/Makefile b/modules/sources/overclock/Makefile
index da91e9b..200ed69 100644
--- a/modules/sources/overclock/Makefile
+++ b/modules/sources/overclock/Makefile
@@ -1,7 +1,7 @@
# Modules

#obj-m += cpufreq_conservative.o cpufreq_interactive.o cpufreq_powersave.o
-#obj-m += cpufreq_stats.o
+obj-m += cpufreq_stats.o
#obj-m += cpufreq_smartass.o cpufreq_boosted.o

#sio_iosched-objs = sio-iosched.o
diff --git a/modules/sources/overclock/cpufreq_stats.c b/modules/sources/overclock/cpufreq_stats.c
index 4047872..1464a99 100644
--- a/modules/sources/overclock/cpufreq_stats.c
+++ b/modules/sources/overclock/cpufreq_stats.c
@@ -23,6 +23,8 @@

static spinlock_t cpufreq_stats_lock;

+static int cpufreq_stats_freq_update(unsigned int cpu, int index, unsigned int freq);
+
#define CPUFREQ_STATDEVICE_ATTR(_name, _mode, _show) \
static struct freq_attr _attr_##_name = {\
.attr = {.name = __stringify(_name), .mode = _mode, }, \

There is a bug in commit 76189f17f91f4f2c1dc7e09c44bd251287680c6c (power hal: fix "atoi", fix freq list") which makes the phone go to the lowest available frequency (instead of allowing it to reach the highest available when needed) whenever the screen is on. This makes the current build lag like never before. To observe the effect of this bug, just open a shell through adb and watch /proc/overclock/info. Switch the screen on and off, and you'll see the usermax and max go from 300000 (screen on) to whatever you have set as the second-to-highest clock frequency (screen off).

$ watch -n 1 cat /proc/overclock/info

The following patch fixes this bug:

diff --git a/power/power_omap3.c b/power/power_omap3.c
index 95a119e..1fa3cb7 100644
--- a/power/power_omap3.c
+++ b/power/power_omap3.c
@@ -130,7 +130,7 @@ static void omap3_power_init(struct power_module *module)
return;
}

- max_freq = freq_list[freq_num - 1];
+ max_freq = freq_list[0];
tmp = (NOM_FREQ_INDEX > freq_num) ? freq_num : NOM_FREQ_INDEX;
nom_freq = freq_list[tmp - 1];

The fmradio stuff crashes the system server when the device is switched into airplane mode, complaining about a missing FM transmitter reset method. This is of course both correct - it does not contain an FM transmitter - as well as silly - it does not need to contain an FM transmitter. Even though the fmradio stuff compiles after applying the patch I posted earlier it is probably best to revert it for the time being. The proof is in the pudding:

D/FmTransmitterService( 1592): onReceive:ACTION_AIRPLANE_MODE_CHANGED
W/dalvikvm( 1592): No implementation found for native Lcom/stericsson/hardware/fm/FmTransmitterService;._fm_transmitter_reset:()I
W/dalvikvm( 1592): threadid=11: thread exiting with uncaught exception (group=0x40a9f300)
I/Process ( 1592): Sending signal. PID: 1592 SIG: 9
E/AndroidRuntime( 1592): *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
E/AndroidRuntime( 1592): java.lang.UnsatisfiedLinkError: Native method not found: com.stericsson.hardware.fm.FmTransmitterService._fm_transmitter_reset:()I
E/AndroidRuntime( 1592):	at com.stericsson.hardware.fm.FmTransmitterService._fm_transmitter_reset(Native Method)
E/AndroidRuntime( 1592):	at com.stericsson.hardware.fm.FmTransmitterService.access$800(FmTransmitterService.java:45)
E/AndroidRuntime( 1592):	at com.stericsson.hardware.fm.FmTransmitterService$1.onReceive(FmTransmitterService.java:351)
E/AndroidRuntime( 1592):	at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:755)
E/AndroidRuntime( 1592):	at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime( 1592):	at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1592):	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1592):	at com.android.server.ServerThread.run(SystemServer.java:1020)

I have made a new build containing the JellyX kernel. I'll test it for a bit, if it performs OK I'll post it here.

---------- Post added at 02:23 AM ---------- Previous post was at 02:20 AM ----------

The lag in your build will be caused by the bug in power_omap3.c I described in my previous post. Apply the relevant patch (included in that post) and build again...