forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

main thread stack size question for slim et fat

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Sat Aug 09, 2008 5:08 am    Post subject: main thread stack size question for slim et fat Reply with quote

how can i have a main thead stack size depending of the hardware slim or fat
in the sdk the PSP_MAIN_THREAD_ATTR(attr) is defined has unsigned int sce_newlib_attribute = (attr)

where attr is the number of k allocate for the heap ?
when i start/load a user prx can i specify his heap size ?
for my pdf reader when it is a fat i must use a PSP_MAIN_THREAD_ATTR of 20000
(it limit the zoom capability on the fat) and for the slim i use PSP_USER_LARGE_MEMORY and PSP_MAIN_THEAD_ATTR of 30000
so 2 makefiles 2 eboot.bpb what i wish is determine the hardware of the psp
slim or fat., load a prx with a custom heapsize depending of the hardware test
is it possible ? and how can i do this ?
Back to top
View user's profile Send private message Send e-mail MSN Messenger
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Aug 09, 2008 5:51 am    Post subject: Reply with quote

You can't set the stack size depending on the hardware. You can only set it, period.

Code:
PSP_MODULE_INFO("Program Name", PSP_MODULE_USER, ProgramVersion, ProgramRevision);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(HeapSizeInKB);
PSP_MAIN_THREAD_PRIORITY(Priority);
PSP_MAIN_THREAD_STACK_SIZE_KB(StackSizeInKB);


Those are the things you can set. PSP_HEAP_SIZE_MAX() is just PSP_HEAP_SIZE_KB(-1). With the current newlib (libc), you can pass other negative values like PSP_HEAP_SIZE_KB(-512). That tells newlib to set up the heap to be all the PSP user memory EXCEPT for 512 KB. That is recommended as it allows you to make one binary that gives you all the memory on a Phat or Slim while still leaving some memory for threads and prxs.

As you can see, the function for setting the stack size only takes a size parameter and cannot be varied depending on the hardware. If you want two different stack sizes, you'll have to make two different binaries. That seems silly to me as you only need as much stack as needed for all local variables, which doesn't change with the hardware, only the program variable usage.

Most devs leave the stack size and priority to the default settings... they're good for nearly everyone. You MIGHT have to increase the stacksize depending on the app. I recommend you set the heap size via PSP_HEAP_SIZE_KB(-256);. I recommend you have these lines in the makefile:

Code:
BUILD_PRX = 1
PSP_LARGE_MEMORY = 1


PSP_MAIN_THREAD_ATTR() MUST be PSP_THREAD_ATTR_USER to work in 3.xx, which is the only fw you should be writing for these days. That goes along with using PSP_MODULE_USER in PSP_MODULE_INFO().

EDIT: One more thing, use

Code:
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU);


if you use the vfpu in your app.
Back to top
View user's profile Send private message AIM Address
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Sat Aug 09, 2008 6:06 am    Post subject: Reply with quote

with the extra 32 meg of the psp slmiyou can use a zoom at a higher level it break
on 1.5 on fat with 20000K and at 1.7 on slim with 30000K when you render
a pdf to a ARGB device it use a lot of memory.
So the program run on the 2 hardwares but with degratation for the zoom function on the fat.

can i use this

the xmb launch a program that detect the hardware it launch a EBOOT.BPB
with a stack of 20000 or a EBOOT.BPB with a stack of30000
this 2 EBOOT.BPB just start and load the same prx containing the code of the pdf reader
so yes just 1 code for the reader but depending on the hardware we launch 2 bootstrap program
So i must maintain just one source
Back to top
View user's profile Send private message Send e-mail MSN Messenger
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Sat Aug 09, 2008 6:21 am    Post subject: Reply with quote

aka moonlight

Why don't you use PSP_HEAP_SIZE_MAX? It will already allocate max memory in both.
Anyways, you can change the hep before any malloc operations. In the file where you wrote PSP_HEAP
_SIZE_KB, do in main function "sce_newlib_heap_kb_size = desired_size;"

no need to do all this stuff before any malloc you can change the heap kb size
Back to top
View user's profile Send private message Send e-mail MSN Messenger
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Aug 09, 2008 8:16 am    Post subject: Reply with quote

sauron_le_noir wrote:
aka moonlight

Why don't you use PSP_HEAP_SIZE_MAX? It will already allocate max memory in both.
Anyways, you can change the hep before any malloc operations. In the file where you wrote PSP_HEAP
_SIZE_KB, do in main function "sce_newlib_heap_kb_size = desired_size;"

no need to do all this stuff before any malloc you can change the heap kb size


MAX uses ALL memory, so any attempt to spawn threads will fail, leading to unpredictable behavior. While you can do "sce_newlib_heap_kb_size = desired_size;" before doing anything else in main, that's a poor hack compared to just using PSP_HEAP_SIZE_KB(-amount);. Only use the hack if you're on an old toolchain. On the new toolchain and SDK, use the negative heap size.

I believe moonlight stated that his toolchain is pretty old, so it stands to reason that he's using the hack. You have no excuse. :)
Back to top
View user's profile Send private message AIM Address
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Sat Aug 09, 2008 4:05 pm    Post subject: Reply with quote

thx Jf i've just recompile the entire toolchain with a fresh svn co
and yes with PSP_HEAP_SIZE_KB(-256) the homebrew work on both
psp fat and slim without having 2 builds
The limitation of the zoom remains on the fat when the zoom is > 1.5 i"ve a out of memory error.
Do you know what are the best switches for gcc to optimize the code generated for a psp
Back to top
View user's profile Send private message Send e-mail MSN Messenger
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Aug 09, 2008 4:18 pm    Post subject: Reply with quote

Most folks use "-O3 -G0". Greater than O3 won't speed anything up. The -G0 avoids some small segment link errors, but can slow things just a smidgen. You might try it with various values like -G4 and see if it doesn't give any link errors. Another thing that might speed things up is "-falign-functions=64". That aligns all functions to the cache line size. These are all CFLAGS, by the way.
Back to top
View user's profile Send private message AIM Address
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Sat Aug 09, 2008 6:50 pm    Post subject: Reply with quote

agree but gcc is by essence a compiler design to run on different architecture so
some compilation flag wil generated overhead or even worse runtime errors
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 10, 2008 3:13 pm    Post subject: Reply with quote

Can someone tell me what the default priority for a thread is?
I think its 11 but I'm not sure.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun Aug 10, 2008 4:57 pm    Post subject: Reply with quote

DEFAULT_THREAD_PRIORITY is 32. That's in crt0.c.
Back to top
View user's profile Send private message AIM Address
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 10, 2008 5:28 pm    Post subject: Reply with quote

J.F. wrote:
DEFAULT_THREAD_PRIORITY is 32. That's in crt0.c.


If I use a priority above 13, my program doesn't even start and remains at a black screen. Its a replacement vshmain.prx.

At 13 it doesn't suspend. At 12 it works fine.
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Sun Aug 10, 2008 6:40 pm    Post subject: Reply with quote

That's probably because threading model of PSP software platform is non-preemptive. That means: every thread MUST know very well what it's doing and sleep every now and then.
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 10, 2008 8:39 pm    Post subject: Reply with quote

jean wrote:
That's probably because threading model of PSP software platform is non-preemptive. That means: every thread MUST know very well what it's doing and sleep every now and then.


So you mean Sony's coding is bad?
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Sun Aug 10, 2008 8:45 pm    Post subject: Reply with quote

Quote:
So you mean Sony's coding is bad?

NO, i mean that cooperative model needs you to care of your code timings, not scheduler. In such a scenario, priorities alone mean nothing.... try putting some sleep in your code every now and then
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 10, 2008 9:46 pm    Post subject: Reply with quote

jean wrote:
Quote:
So you mean Sony's coding is bad?

NO, i mean that cooperative model needs you to care of your code timings, not scheduler. In such a scenario, priorities alone mean nothing.... try putting some sleep in your code every now and then

It sleeps for 100*1000 in all the loops. Theres nothing much going on.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Aug 11, 2008 5:09 am    Post subject: Reply with quote

You gotta be missing a sleep somewhere - the threads I make for Basilisk II are:

20 - the ticks thread
21 - the buffer fill thread
22 - the audio playback thread

It works fine, suspending and resuming and running just peachy.
Back to top
View user's profile Send private message AIM Address
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Mon Aug 11, 2008 12:47 pm    Post subject: Reply with quote

J.F. wrote:
You gotta be missing a sleep somewhere - the threads I make for Basilisk II are:

20 - the ticks thread
21 - the buffer fill thread
22 - the audio playback thread

It works fine, suspending and resuming and running just peachy.


Theres only one continuously running thread. Its a plugin actually.
It has only one loop, which reads the control input and sleeps for 100*1000 everytime.

Maybe it needs a priority of 12 to run properly because of the XMB/Game running in the background.

I've also used the Suspend Sysevent handler that adrahil showed me.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Aug 11, 2008 3:59 pm    Post subject: Reply with quote

Torch wrote:
J.F. wrote:
You gotta be missing a sleep somewhere - the threads I make for Basilisk II are:

20 - the ticks thread
21 - the buffer fill thread
22 - the audio playback thread

It works fine, suspending and resuming and running just peachy.


Theres only one continuously running thread. Its a plugin actually.
It has only one loop, which reads the control input and sleeps for 100*1000 everytime.

Maybe it needs a priority of 12 to run properly because of the XMB/Game running in the background.

I've also used the Suspend Sysevent handler that adrahil showed me.


Quite possible. I don't really mess with plugins much. Other than helping on pikey, most of my work is on apps and the occasional library.
Back to top
View user's profile Send private message AIM Address
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Mon Aug 11, 2008 7:59 pm    Post subject: Reply with quote

J.F. wrote:
Quite possible. I don't really mess with plugins much. Other than helping on pikey, most of my work is on apps and the occasional library.


To avoid confusion -- I was referring to two of my programs without being very clear.

The 1st program is a replacement vshmain.prx which hence starts when the PSP is turned on. If I use a priority above 13, the program doesn't even start and remains at a black screen. At 13 it works fine but doesn't suspend. At 12 it works fine.

The 2nd program is a plugin with the loop thread priority at 12. It works fine at 12. At anything higher, it becomes really slow in the XMB/Games. It responds to button presses after a few seconds delay etc.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group