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 

HELP: sceKernelCreateThread: error 80020190

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



Joined: 12 Jul 2006
Posts: 160

PostPosted: Sat Oct 11, 2008 2:10 am    Post subject: HELP: sceKernelCreateThread: error 80020190 Reply with quote

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:

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]
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Oct 11, 2008 6:07 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
pegasus2000



Joined: 12 Jul 2006
Posts: 160

PostPosted: Sat Oct 11, 2008 6:12 am    Post subject: Reply with quote

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... :))))
Back to top
View user's profile Send private message
pegasus2000



Joined: 12 Jul 2006
Posts: 160

PostPosted: Sat Oct 11, 2008 5:19 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Oct 11, 2008 6:17 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Oct 11, 2008 6:30 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
pegasus2000



Joined: 12 Jul 2006
Posts: 160

PostPosted: Sat Oct 11, 2008 7:17 pm    Post subject: Reply with quote

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....
Back to top
View user's profile Send private message
pegasus2000



Joined: 12 Jul 2006
Posts: 160

PostPosted: Sat Oct 11, 2008 8:16 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
pegasus2000



Joined: 12 Jul 2006
Posts: 160

PostPosted: Sun Oct 12, 2008 2:46 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Coldbird



Joined: 08 Feb 2007
Posts: 155

PostPosted: Thu Jan 28, 2010 7:09 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message MSN Messenger
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