HELP: sceKernelCreateThread: error 80020190

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

Moderators: cheriff, TyRaNiD

Post Reply
pegasus2000
Posts: 160
Joined: Wed Jul 12, 2006 7:09 am

HELP: sceKernelCreateThread: error 80020190

Post by pegasus2000 »

I was working on the next version of nd 0.3.5....

I've tried to recompile the current version of Blind Assistant.
A trouble that I cannot understand happens.

sceKernelCreateThread returns an error code 80020190.

nd memory manager allocates the heap at startup in the
following way: it asks to sceKernelMaxFreeMemSize() the
amount of the memory that is available and it allocates
it - 1024*1024 bytes.

Code: Select all

static inline int FixedKernelMaxFreeMemSize (void)
{
    char string [256];
    
    ndINFO_GetValue (NDGET_OPERATINGSYSTEM, &string, 0, 0);
    // Determina il tipo di sistema operativo presente
    
    if (!strcmp (string, "Sony Playstation Portable CFW"))      // Siamo su custom firmware
    {
         return sceKernelMaxFreeMemSize() - 1*1024*1024;
         // Un 1 Mb di Heap viene riservato allo stack dei vari thread        
    }
    else           // Normale applicazione per firmware 1.5
    {
         return sceKernelMaxFreeMemSize();          
    }
}


static inline void * _sbrk(ptrdiff_t incr)
{
	static void * heap_bottom = NULL;
	static void * heap_top = NULL;
	static void * heap_ptr = NULL;

	/* Has our heap been initialized? */
	if (heap_bottom == NULL) 
    {
		/* No, initialize the heap. */
		SceSize heap_size;

        if (&sce_newlib_heap_kb_size != NULL) 
        {
			heap_size = sce_newlib_heap_kb_size * 1024;
		} 
        else 
        {
			if (&__pspsdk_is_prx != NULL) 
            {
				heap_size = DEFAULT_PRX_HEAP_SIZE_KB * 1024;
			} 
            else 
            {
				
                
                heap_size = FixedKernelMaxFreeMemSize();
			}
		}
		              
		__psp_heap_blockid = sceKernelAllocPartitionMemory(2, "block", PSP_SMEM_Low, heap_size, NULL);
	
In this way, the system could have the memory for the stack
spaces of the single threads. The strange thing is that the system
refuses to create other threads with the error 80020190 (no
memory). (sceKernelCreateThread is used to create user threads)

The situation doesn't change if I try to increase the memory that
is reserved to the system outside the heap.

There is another strange thing: if I reserved only 512 kb of ram
outside the heap, the routines of network initialization fail but the
trouble with sceKernelCreateThread disappears. This suggests to
me that network consumes part of the kernel memory.

Please, can anyone help me ?

It is possible to see the situation of kernel memory using any
particular function ? And is it possible to increase the kernel
memory ?
[/code]
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Newlib has already been altered to use MAX-some_amount for the heap. Just use "PSP_HEAP_SIZE_KB(-1024);" to make the heap maxfree-1024KB.

It looks from the code that you were altering an old copy of newlib. Are you using the latest toolchain? I know you use Windows, so you should be using Heimdall's pre-compiled toolchain if you don't want to (or can't) compile it yourself with CygWin.
pegasus2000
Posts: 160
Joined: Wed Jul 12, 2006 7:09 am

Post by pegasus2000 »

J.F. wrote:Newlib has already been altered to use MAX-some_amount for the heap. Just use "PSP_HEAP_SIZE_KB(-1024);" to make the heap maxfree-1024KB.

It looks from the code that you were altering an old copy of newlib. Are you using the latest toolchain? I know you use Windows, so you should be using Heimdall's pre-compiled toolchain if you don't want to (or can't) compile it yourself with CygWin.

No. Nd uses an own memory manager (no newlibc, we use NanoCore
Memory Manager). In any case, we're investigating:
we have found a trouble in our new HAL. Probably the thing is
an internal trouble.

P.S. The next version of nd fully supports Linux so... do you remember
that the other time you've done a promise to me ? :)))))))

If you're free, welcome to the nd team... :))))
pegasus2000
Posts: 160
Joined: Wed Jul 12, 2006 7:09 am

Post by pegasus2000 »

No result. The trouble is very very strange, it seems to appear and
disappear in base of the order in which the usb drivers are
loaded.

J.F., where is allocated the stack area of each thread ? If it is
allocated outside the heap, why when we allocate all the space
in area 2 using sceKernelAllocPartitionMemory, the firmware is
able to create other threads ?

In theory, if all space is allocated for the heap, sceKernelCreateThread
should stop to work. And this is not what we see.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

pegasus2000 wrote:No result. The trouble is very very strange, it seems to appear and
disappear in base of the order in which the usb drivers are
loaded.

J.F., where is allocated the stack area of each thread ? If it is
allocated outside the heap, why when we allocate all the space
in area 2 using sceKernelAllocPartitionMemory, the firmware is
able to create other threads ?

In theory, if all space is allocated for the heap, sceKernelCreateThread
should stop to work. And this is not what we see.
I remember saying I'd help if you got it working in linux. :) I look forward to that since it IS an interesting framework for the PSP. I just didn't care for the Windows setup you have to use currently to build anything.

As far as I know, the stack for threads is allocated outside the heap. Most threads use SMALL stacks, so you don't have to have much free to still be able to create a thread. The routines that calculate the amount of free memory don't work down to the byte (as far as I remember), they just get within a certain range (normally hundreds of KB). So allocating "all" the memory doesn't really allocate it all. How much it really is will vary according to the accuracy of the routine, the PRXs loaded, the size of the app itself, what else is allocated (like stacks, etc), yada, yada, yada. Most folks just tend to be a little generous in how much space they leave free in the heap... just in case.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Dump the UID table when you threads are failing with out of memory errors and you can see what has been allocated in the SysMem block (they should all have half sensible names if you are lucky :P), of course it could also be FPL/VPLs and all manner of other things eating memory space.
pegasus2000
Posts: 160
Joined: Wed Jul 12, 2006 7:09 am

Post by pegasus2000 »

Other news....

I've traced the memory usage of area outside the heap.

In a point of the program, there is a free memory (outside the heap) of 421.000
bytes, but sceKernelCreateThread refuses to allocate a thread with
a stack of 16.000 bytes....
pegasus2000
Posts: 160
Joined: Wed Jul 12, 2006 7:09 am

Post by pegasus2000 »

Tyranid, do you have a routine or an utility that can I use to
obtain the complete memory map, in way to understand
what is happening ?

Now, there are 1,500,000 byte free outside the heap but
sceKernelCreateThread refuses to create an user thread with
a stack of 16.384 bytes.
pegasus2000
Posts: 160
Joined: Wed Jul 12, 2006 7:09 am

Post by pegasus2000 »

SOLVED:

It was a very very complex incorrect interaction between the
firmware 3.71 M33-4, the nd sound system and blind assistant.

This trouble will have consequences however: starting from next
version of Blind Assistant, a control shall have to check if the
firmware is at least a 3.80 M33 version and, if this requirement
isn't satisfied, it will have to refuse to continue the execution.
User avatar
Coldbird
Posts: 97
Joined: Thu Feb 08, 2007 7:22 am

Post by Coldbird »

Hijacking a old topic cause creating a new one wouldnt be worth it.

Same problem, different function, can't start a really small (10kb) usermodule via sceKernelStartModule, kernel modules work fine though.

I need the usermodule to initialize some networking stuff.
Any suggestions on the matter?
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Post Reply