Problem with bus clock setting on slim 3.71

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
aeolusc
Posts: 18
Joined: Sat Oct 14, 2006 12:17 pm

Problem with bus clock setting on slim 3.71

Post by aeolusc »

Here's some test result(Set bus clock to 50):
Function/Result
scePowerSetClockFrequency(in both scePower and scePower_driver)/Bus clock reset to about 95
scePowerSetBusClockFrequency(in both scePower and scePower_driver)/Bus clock's still 111
sctrlHENSetSpeed/Bus clock reset to about 95

It seems system or M33 driver locked bus clock minimum value to 95?

PS: the sceSysReg series function nids are changed without known alias so that i cannot test them
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

It's worse... with the MediaEngine running, trying to change the clock freezes the Slim. I'm still trying to figure out how to turn the ME off to change the clock. I posted a request for the nid for disabling the clock to the ME, but no response yet. I tried getting the value myself, but I don't know if it was correct.

Anyway, the set clock function also ignores calls with paramters it doesn't like. For example, scePowerSetClockFrequency(333, 333, 167) is ignored completely, while scePowerSetClockFrequency(333, 333, 166) works fine. That's why the clock doesn't change on some homebrew - the values they send are no longer acceptable. One rule I found - round down when dividing by two.
aeolusc
Posts: 18
Joined: Sat Oct 14, 2006 12:17 pm

Post by aeolusc »

scePowerSetClockFrequency rule:
pll>=cpu>=bus*2
so if you set bus to 167, cpu should be at least 334

PS: i heard that pll&cpu could be set to 366 on slim, xD
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

I've seen code that rounded up instead of down, and those will all be ignored on the Slim. I hadn't really thought about it until I noticed that programs weren't changing speed and did some experimenting on my own.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)

I'm having problems with scePowerSetBusClockFrequency (only in kernel 3.71)
I used the following code to test CPU/BUS combination.
In kernel 3.52 all the combination are valid, but in kernel 3.71 the bus is always at 111.
I thought the values that follows the rule pll>=cpu>=bus*2 should work.

Code: Select all

int main(){
    int cpu, curCpu, resetCpu;
    int bus, curBus, resetBus;
    int ok = 0;
    char text[30];
    SceUID logFile;
          
	pspDebugScreenInit(); 
	SetupCallbacks();

    pspDebugScreenPrintf("Clock test for 3.71\n\n");

	logFile = sceIoOpen("./test.log", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
	if (!logFile){
        pspDebugScreenPrintf("Error opening log file!\n");
        sceKernelDelayThread(10000);
		return -1;
	}

    resetCpu = 222;
    resetBus = 111;
    pspDebugScreenPrintf("Testing:\n");
    for (cpu=resetCpu; cpu > 10; cpu--){
        pspDebugScreenPrintf(".");
        for (bus=resetBus; bus > 10; bus--){
            scePowerSetClockFrequency(resetCpu, resetCpu, resetBus);
        	scePowerSetCpuClockFrequency(cpu);
            if &#40;scePowerGetCpuClockFrequency&#40;&#41; < cpu&#41;&#123;
                scePowerSetCpuClockFrequency&#40;cpu + 1&#41;;
            &#125;
        	scePowerSetBusClockFrequency&#40;bus&#41;;
            if &#40;scePowerGetBusClockFrequency&#40;&#41; < bus&#41;&#123;
                scePowerSetBusClockFrequency&#40;bus + 1&#41;;
            &#125;       
            //Check result&#58;                
            curCpu = scePowerGetCpuClockFrequency&#40;&#41;;
            curBus = scePowerGetBusClockFrequency&#40;&#41;;
            if &#40;curCpu == cpu && curBus == bus&#41;&#123;
               snprintf&#40;text, sizeof&#40;text&#41;, "OK&#58; cpu %i bus %i \n", cpu, bus&#41;;
               sceIoWrite&#40;logFile, text, strlen&#40;text&#41;&#41;;
               ok++;
            &#125;else if &#40;curCpu != resetCpu && curBus != resetBus&#41;&#123;
               snprintf&#40;text, sizeof&#40;text&#41;, "CHANGED&#58; cpu %i &#40;%i&#41; bus %i &#40;%i&#41;\n", curCpu, cpu, curBus, bus&#41;;
               sceIoWrite&#40;logFile, text, strlen&#40;text&#41;&#41;;                 
            &#125;
        &#125;
    &#125;    

    sceIoClose&#40;logFile&#41;;
    pspDebugScreenPrintf&#40;"\n\nFound %i valid combination\n", ok&#41;;        
    pspDebugScreenPrintf&#40;"Check the log\n"&#41;;    
    pspDebugScreenPrintf&#40;"Press X to quit\n"&#41;;

    SceCtrlData pad;
    while&#40;runningFlag&#41;&#123;
        sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
        if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
            break;
        &#125;
    &#125;
	sceKernelExitGame&#40;&#41;;
    return 0;

&#125;
P.S. Another "quick" question. I tried to use sctrlHENSetSpeed in a kernel prx.
I included systemctrl.h and linked pspsystemctrl_kernel, but I get and "undefined reference" error during compilation.
Where's the function sctrlHENSetSpeed? :)

Many thanks.

Ciaooo
Sakya
aeolusc
Posts: 18
Joined: Sat Oct 14, 2006 12:17 pm

Post by aeolusc »

if you import function in c++, please add

Code: Select all

extern "C"
before your extern imported functions.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)
aeolusc wrote:if you import function in c++, please add

Code: Select all

extern "C"
before your extern imported functions.
Sorry, I cannot understand. :)
My code is C not C++, what are you referring to?

Ciaooo
Sakya
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)
J.F. wrote:I posted a request for the nid for disabling the clock to the ME
sceSysregMeBusClockDisable should be sceSysreg_driver_07881A0B in kernel 3.71

Ciaooo
Sakya
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

sakya wrote:Hi! :)
J.F. wrote:I posted a request for the nid for disabling the clock to the ME
sceSysregMeBusClockDisable should be sceSysreg_driver_07881A0B in kernel 3.71

Ciaooo
Sakya
Thanks. So the value I was using is right. Good to know. I might have to disassemble the clock code to see what the bloody hell is going on. Exiting to the XMB is enough to turn off the ME where you can change the clock again, so there is SOME way to turn off the ME to change the clock.
aeolusc
Posts: 18
Joined: Sat Oct 14, 2006 12:17 pm

Post by aeolusc »

disasm sctrlHenSetSpeed, translated to C codes:

Code: Select all

int &#40;* scePowerSetClockFrequency2&#41;&#40;int cpufreq, int ramfreq, int busfreq&#41;;
int &#40;* scePowerIsBatteryCharging&#41;&#40;void&#41;;
void &#40;* scePower_driver_A09FC577&#41;&#40;int&#41;;
void &#40;* scePower_driver_191A3848&#41;&#40;int&#41;;

void sctrlHENSetSpeed&#40;int cpu, int bus&#41;
&#123;
	static int inited = 0;

	if&#40;!inited&#41;
	&#123;
		scePowerSetClockFrequency2 = &#40;void *&#41;FindProc&#40;"scePower_Service", "scePower", 0x545A7F3C&#41;;
		scePowerIsBatteryCharging = &#40;void *&#41;FindProc&#40;"scePower_Service", "scePower", 0x1E490401&#41;;
		scePower_driver_A09FC577 = &#40;void *&#41;FindProc&#40;"scePower_Service", "scePower_driver", 0xA09FC577&#41;;
		scePower_driver_191A3848 = &#40;void *&#41;FindProc&#40;"scePower_Service", "scePower_driver", 0x191A3848&#41;;
		inited = 1;
	&#125;

	scePowerSetClockFrequency2&#40;cpu, cpu, bus&#41;;
	if&#40;scePowerIsBatteryCharging&#40;&#41; != 0&#41;
		return;
	static int ps1 = 0;
	if&#40;ps1 == 0&#41;
	&#123;
		scePower_driver_A09FC577&#40;1&#41;;
		ps1 = 1;
		return;
	&#125;

	static int ps2 = 0;
	if&#40;ps2 == 0&#41;
	&#123;
		ps1 = 0;
		ps2 = 1;
		return;
	&#125;
	scePower_driver_191A3848&#40;0&#41;;
	ps1 = 0;
	ps2 = 0;
&#125;
I'm curious about what does the 2 unnamed functions do....
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

you have disassembled more than that function and you have gone through the slim usb charge code. Since the function is not called directly, but is done through a systimer, probably prxtool couldn't detect it as a function. (that's something tyranid has to look ;), and you thought it was part of same function.

Btw, those functions nids prior to 3.71 were:

0x733F973B -> scePowerBatteryEnableUsbCharging
0x90285886 -> scePowerBatteryDisableUsbCharging

I'm attacking power.prx with the nidcracker today, 7 results atm :D
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)
moonlight wrote:I'm attacking power.prx with the nidcracker today, 7 results atm :D
Many thanks for your help, I'm going crazy with this bus clock problem. :D
I tried with sceSysreg_driver, sctrlHENSetSpeed, scePowerSetClockFrequency, scePowerSetBusClockFrequency... ;)

Ciaooo
Sakya
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Here's my test program. It shows that the bus clock does change, but has a very limited range on the Slim. If you always try to set the clock(s) using scePowerSetClockFrequency(cpu, cpu, cpu/2); the cpu clock will basically follow whatever value you're passing in. the bus clock will change as well, but not as widely as the cpu clock. The mimum value for the bus seems to be 95, and the maximum 166. The cpu clock will go down to 18 (with the bus staying at 95), and I've gone up to 333. I haven't tried going beyond 333, but I've heard the slim will go farther.

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspdebug.h>
#include <psppower.h>
#include <pspdisplay.h>
#include <psprtc.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>


#define printf pspDebugScreenPrintf


#define VERS    1
#define REVS    0


PSP_MODULE_INFO&#40;"CPUClockTest", 0, VERS, REVS&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;


void wait_release&#40;unsigned int buttons&#41;
&#123;
    SceCtrlData pad;

    sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
    while &#40;pad.Buttons & buttons&#41;
    &#123;
        sceKernelDelayThread&#40;100000&#41;;
        sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
    &#125;
&#125;


unsigned int wait_press&#40;unsigned int buttons&#41;
&#123;
    SceCtrlData pad;

    sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
    while &#40;1&#41;
    &#123;
        if &#40;pad.Buttons & buttons&#41;
            return pad.Buttons & buttons;
        sceKernelDelayThread&#40;100000&#41;;
        sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
    &#125;
    return 0;   /* never reaches here, again, just to suppress warning */
&#125;


int main&#40;void&#41;
&#123;
    u32 b;
	int cpu, bus, bmark;

    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenSetBackColor&#40;0x00000000&#41;;
    pspDebugScreenSetTextColor&#40;0x00ffffff&#41;;
    pspDebugScreenClear&#40;&#41;;
    sceCtrlSetSamplingCycle&#40;0&#41;;
    sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;



	while &#40;1&#41;
	&#123;
		pspDebugScreenClear&#40;&#41;;
		printf&#40;"\n CPU Clock Test - press O to exit\n\n"&#41;;
		cpu = scePowerGetCpuClockFrequency&#40;&#41;;
		bus = scePowerGetBusClockFrequency&#40;&#41;;
		printf&#40;" The current CPU/BUS speed is %d/%d MHz\n", cpu, bus&#41;;

		b = wait_press&#40;0xffff&#41;;
		wait_release&#40;b&#41;;
		if &#40;b & PSP_CTRL_CIRCLE&#41;
			break;
		if &#40;b & PSP_CTRL_RTRIGGER&#41;
			scePowerSetClockFrequency&#40;333, 333, 166&#41;;
		if &#40;b & PSP_CTRL_LTRIGGER&#41;
			scePowerSetClockFrequency&#40;33, 33, 16&#41;;
		if &#40;b & PSP_CTRL_RIGHT&#41;
		&#123;
			cpu++;
			scePowerSetClockFrequency&#40;cpu, cpu, cpu/2&#41;;
		&#125;
		if &#40;b & PSP_CTRL_LEFT&#41;
		&#123;
			cpu--;
			scePowerSetClockFrequency&#40;cpu, cpu, cpu/2&#41;;
		&#125;
		if &#40;b & PSP_CTRL_UP&#41;
		&#123;
			cpu += 10;
			scePowerSetClockFrequency&#40;cpu, cpu, cpu/2&#41;;
		&#125;
		if &#40;b & PSP_CTRL_DOWN&#41;
		&#123;
			cpu -= 10;
			scePowerSetClockFrequency&#40;cpu, cpu, cpu/2&#41;;
		&#125;

		sceKernelDelayThread&#40;100*1000&#41;;
	&#125;

    sceKernelDelayThread&#40;3*1000*1000&#41;;
    sceKernelExitGame&#40;&#41;;

    return 0;   /* never reaches here, again, just to suppress warning */
&#125;
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)
J.F. wrote:Here's my test program. It shows that the bus clock does change, but has a very limited range on the Slim.
In my tests also I can change the bus, but only from 111 to 95 (nevere tried higer values), the problem is that I want to set it at 54mhz. :)
I'm not on a slim PSP, it's a kernel 3.71 "function". :D

Ciaooo
Sakya
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

sakya wrote:Hi! :)
J.F. wrote:Here's my test program. It shows that the bus clock does change, but has a very limited range on the Slim.
In my tests also I can change the bus, but only from 111 to 95 (nevere tried higer values), the problem is that I want to set it at 54mhz. :)
I'm not on a slim PSP, it's a kernel 3.71 "function". :D

Ciaooo
Sakya
It's quite possible that Sony found that decreasing the bus clock didn't save any power, so there was no reason to allow a full range like with the CPU clock. It could also be a Slim problem - lower than 95 MHz makes the Slim unstable and Sony was too lazy to make the function discern between the Slim and Phat.
jas0nuk
Posts: 137
Joined: Thu Apr 27, 2006 8:00 am

Post by jas0nuk »

Does the clock change properly, using a Slim under Pandora (you might need to use 2.71 power.prx)?
Kreationz
Posts: 52
Joined: Sun May 18, 2008 11:01 am

Sorry to reopen and old thread.

Post by Kreationz »

I have a quick question. I'm likely doing something stupid and not realizing it.

Like this I can hit Home and exit fine:

Code: Select all

//*************************************************************************************
// Sets up the CPU Frequency
//*************************************************************************************
static void SetCPUSpeed&#40;&#41;
&#123;
	printf&#40; "Cpu was&#58; %dMHz, Bus&#58; %dMHz\n", scePowerGetCpuClockFrequency&#40;&#41;, scePowerGetBusClockFrequency&#40;&#41; &#41;;
	if &#40;scePowerSetClockFrequency&#40;333, 333, 166&#41; != 0&#41;
	&#123;
		printf&#40; "Could not set CPU to 333MHz\n" &#41;;
	&#125;
	printf&#40; "Cpu now&#58; %dMHz, Bus&#58; %dMHz\n", scePowerGetCpuClockFrequency&#40;&#41;, scePowerGetBusClockFrequency&#40;&#41; &#41;;
&#125;

//*************************************************************************************
// Do All of our pre-app initialisation
//*************************************************************************************
static bool	Initialise&#40;&#41;
&#123;
//	SetCPUSpeed&#40;&#41;;
	SetupCallbacks&#40;&#41;;
    sceCtrlSetSamplingCycle&#40;0&#41;;
    sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;

	return true;
&#125;

//*************************************************************************************
//
//*************************************************************************************
int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	if&#40; Initialise&#40;&#41; &#41;
	&#123;
		sceKernelSleepThread&#40;&#41;;
	&#125;
	
	return 0; //Should never reach here just to suppress the warning.
&#125;
But if I uncomment SetCPUSpeed(); in Initialise(); then upon actually trying to exit via the home button it freezes. This is on a Slim just for reference. I'm starting a new project along with the one I'm currently working on and just wondering if there's something I'm missing.

Edit: If I change "sceKernelSleepThread();" to:

while(1)
{
sceKernelDelayThread(1);
}

It works as it should... this seems like odd behavior to me.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

ExitDelete useless threads, don't sleep them.
Kreationz
Posts: 52
Joined: Sun May 18, 2008 11:01 am

Post by Kreationz »

Well, I don't plan on sleeping the thread in the final version. This is just a basic test.
Post Reply