switchbrew / nx-hbloader

Host process for loading Switch homebrew NROs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrent thread limit

H0neyBadger opened this issue · comments

Hello,
I m currently facing an issue with the pthread interface.

Despite mutex/barrier and sched_yield some threads never execute after reaching a specific number. Some threads are like frozen (hanged).

The number of running concurrent threads look limited for the homebrew process.
Is there a way to increase this limit ?

I created the following snippet to test this problem.
https://gist.github.com/H0neyBadger/c080dd00c0dd77439bd8d41826d49d0c#file-main-cpp-L131
With thread count to 68, the job is running as expected.
With thread count to 69 (or greater) one or many threads are frozen. The thread barrier is never reached.

I m using nxlink and homebrew netloader to test my projects (with the latest devkitpro pacman on arch).

I spent a lot of time on this issue, and I m out of idea.
I hope you can help

P.S: I initially posted my issue on newlib project
devkitPro/newlib#20

commented

We are looking into it right now, it looks like AMS might be the source of this bug. I have a question for you, are you running homebrew in applet mode, or are you using an application?

I m running in applet mode (by default)
(applet mode)
"thread_cur_value: 28, thread_lim_value: 96"
(application)
"thread_cur_value: 1, thread_lim_value: 96"

but with count of 69, threads remain frozen in application mode.
(but it might be an other issue related to printf consoleUpdate high rate. I m triple checking my code currently)

Using application mode do the trick for the gist snippet.
But my WIP project still freezing on thread allocation (with ~5 threads)
Getting rid of the "nxlink" part is usually enough to let the code run normally.
Is there another metric test to watch like stack/heap/socket usage ?
thanks

my current socket config there is currently 2 sockets/thread (~10 socket total):

static const SocketInitConfig g_chiakiSocketInitConfig = {
    .bsdsockets_version = 1,

    .tcp_tx_buf_size = 0x8000,
    .tcp_rx_buf_size = 0x10000,
    .tcp_tx_buf_max_size = 0x40000,
    .tcp_rx_buf_max_size = 0x40000,

    .udp_tx_buf_size = 0x40000,
    .udp_rx_buf_size = 0x40000,

    .sb_efficiency = 8,

    .num_bsd_sessions = 16,
    .bsd_service_type = BsdServiceType_User,
};