diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index 64b7e8b..9da0ec5 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -136,6 +136,7 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr name, return {}; } orbis::SysResult orbis::sys_evf_delete(Thread *thread, sint id) { + ORBIS_LOG_WARNING(__FUNCTION__, id); Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { return ErrorCode::SRCH; @@ -176,8 +177,8 @@ orbis::SysResult orbis::sys_evf_wait(Thread *thread, sint id, uint64_t patternSet, uint64_t mode, ptr pPatternSet, ptr pTimeout) { - ORBIS_LOG_TRACE(__FUNCTION__, thread, id, patternSet, mode, pPatternSet, - pTimeout); + ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, patternSet, mode, pPatternSet, + pTimeout); if ((mode & (kEvfWaitModeAnd | kEvfWaitModeOr)) == 0 || (mode & ~(kEvfWaitModeAnd | kEvfWaitModeOr | kEvfWaitModeClearAll | kEvfWaitModeClearPat)) != 0 || @@ -197,7 +198,7 @@ orbis::SysResult orbis::sys_evf_wait(Thread *thread, sint id, pPatternSet != nullptr ? &resultPattern : nullptr, pTimeout != nullptr ? &resultTimeout : nullptr); - ORBIS_LOG_TRACE("sys_evf_wait wakeup", thread, resultPattern, resultTimeout); + ORBIS_LOG_NOTICE("sys_evf_wait wakeup", thread, resultPattern, resultTimeout); if (pPatternSet != nullptr) { uwrite(pPatternSet, (uint64_t)resultPattern); @@ -212,7 +213,7 @@ orbis::SysResult orbis::sys_evf_wait(Thread *thread, sint id, orbis::SysResult orbis::sys_evf_trywait(Thread *thread, sint id, uint64_t patternSet, uint64_t mode, ptr pPatternSet) { - ORBIS_LOG_TRACE(__FUNCTION__, thread, id, patternSet, mode, pPatternSet); + ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, patternSet, mode, pPatternSet); if ((mode & (kEvfWaitModeAnd | kEvfWaitModeOr)) == 0 || (mode & ~(kEvfWaitModeAnd | kEvfWaitModeOr | kEvfWaitModeClearAll | kEvfWaitModeClearPat)) != 0 || @@ -237,7 +238,7 @@ orbis::SysResult orbis::sys_evf_trywait(Thread *thread, sint id, return result; } orbis::SysResult orbis::sys_evf_set(Thread *thread, sint id, uint64_t value) { - ORBIS_LOG_TRACE(__FUNCTION__, thread, id, value); + ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, value); Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { @@ -248,7 +249,7 @@ orbis::SysResult orbis::sys_evf_set(Thread *thread, sint id, uint64_t value) { return {}; } orbis::SysResult orbis::sys_evf_clear(Thread *thread, sint id, uint64_t value) { - ORBIS_LOG_TRACE(__FUNCTION__, thread, id, value); + ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, value); Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { @@ -260,7 +261,7 @@ orbis::SysResult orbis::sys_evf_clear(Thread *thread, sint id, uint64_t value) { } orbis::SysResult orbis::sys_evf_cancel(Thread *thread, sint id, uint64_t value, ptr pNumWaitThreads) { - ORBIS_LOG_TRACE(__FUNCTION__, thread, id, value, pNumWaitThreads); + ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, value, pNumWaitThreads); Ref evf = thread->tproc->evfMap.get(id); if (evf == nullptr) { diff --git a/orbis-kernel/src/umtx.cpp b/orbis-kernel/src/umtx.cpp index 36a1c5c..4b907b1 100644 --- a/orbis-kernel/src/umtx.cpp +++ b/orbis-kernel/src/umtx.cpp @@ -48,19 +48,19 @@ uint UmtxChain::notify_all(const UmtxKey &key) { orbis::ErrorCode orbis::umtx_lock_umtx(Thread *thread, ptr umtx, ulong id, std::uint64_t ut) { - ORBIS_LOG_TODO(__FUNCTION__, umtx, id, ut); + ORBIS_LOG_TODO(__FUNCTION__, thread->tid, umtx, id, ut); return ErrorCode::NOSYS; } orbis::ErrorCode orbis::umtx_unlock_umtx(Thread *thread, ptr umtx, ulong id) { - ORBIS_LOG_TODO(__FUNCTION__, umtx, id); + ORBIS_LOG_TODO(__FUNCTION__, thread->tid, umtx, id); return ErrorCode::NOSYS; } orbis::ErrorCode orbis::umtx_wait(Thread *thread, ptr addr, ulong id, std::uint64_t ut, bool is32) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, addr, id, ut, is32); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, addr, id, ut, is32); auto [chain, key, lock] = g_context.getUmtxChain0(thread->tproc->pid, addr); auto node = chain.enqueue(key, thread); ErrorCode result = {}; @@ -93,7 +93,7 @@ orbis::ErrorCode orbis::umtx_wait(Thread *thread, ptr addr, ulong id, } orbis::ErrorCode orbis::umtx_wake(Thread *thread, ptr addr, sint n_wake) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, addr, n_wake); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, addr, n_wake); auto [chain, key, lock] = g_context.getUmtxChain0(thread->tproc->pid, addr); std::size_t count = chain.sleep_queue.count(key); // TODO: check this @@ -128,7 +128,7 @@ void log_class_string::format(std::string &out, } static ErrorCode do_lock_normal(Thread *thread, ptr m, uint flags, std::uint64_t ut, umutex_lock_mode mode) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, m, flags, ut, mode); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, m, flags, ut, mode); ErrorCode error = {}; while (true) { @@ -182,7 +182,7 @@ static ErrorCode do_lock_pp(Thread *thread, ptr m, uint flags, return ErrorCode::NOSYS; } static ErrorCode do_unlock_normal(Thread *thread, ptr m, uint flags) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, m, flags); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, m, flags); int owner = m->owner.load(std::memory_order_acquire); if ((owner & ~kUmutexContested) != thread->tid) @@ -204,7 +204,6 @@ static ErrorCode do_unlock_normal(Thread *thread, ptr m, uint flags) { return {}; } static ErrorCode do_unlock_pi(Thread *thread, ptr m, uint flags) { - ORBIS_LOG_TODO(__FUNCTION__, m, flags); return do_unlock_normal(thread, m, flags); } static ErrorCode do_unlock_pp(Thread *thread, ptr m, uint flags) { @@ -215,7 +214,7 @@ static ErrorCode do_unlock_pp(Thread *thread, ptr m, uint flags) { } // namespace orbis orbis::ErrorCode orbis::umtx_trylock_umutex(Thread *thread, ptr m) { - ORBIS_LOG_TRACE(__FUNCTION__, m); + ORBIS_LOG_TRACE(__FUNCTION__, thread->tid, m); uint flags; if (ErrorCode err = uread(flags, &m->flags); err != ErrorCode{}) return err; @@ -232,7 +231,7 @@ orbis::ErrorCode orbis::umtx_trylock_umutex(Thread *thread, ptr m) { orbis::ErrorCode orbis::umtx_lock_umutex(Thread *thread, ptr m, std::uint64_t ut) { - ORBIS_LOG_TRACE(__FUNCTION__, m, ut); + ORBIS_LOG_TRACE(__FUNCTION__, thread->tid, m, ut); uint flags; if (ErrorCode err = uread(flags, &m->flags); err != ErrorCode{}) return err; @@ -248,7 +247,7 @@ orbis::ErrorCode orbis::umtx_lock_umutex(Thread *thread, ptr m, } orbis::ErrorCode orbis::umtx_unlock_umutex(Thread *thread, ptr m) { - ORBIS_LOG_TRACE(__FUNCTION__, m); + ORBIS_LOG_TRACE(__FUNCTION__, thread->tid, m); uint flags; if (ErrorCode err = uread(flags, &m->flags); err != ErrorCode{}) return err; @@ -273,7 +272,7 @@ orbis::ErrorCode orbis::umtx_set_ceiling(Thread *thread, ptr m, orbis::ErrorCode orbis::umtx_cv_wait(Thread *thread, ptr cv, ptr m, std::uint64_t ut, ulong wflags) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, cv, m, ut, wflags); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, cv, m, ut, wflags); uint flags; if (ErrorCode err = uread(flags, &m->flags); err != ErrorCode{}) return err; @@ -327,7 +326,7 @@ orbis::ErrorCode orbis::umtx_cv_wait(Thread *thread, ptr cv, } orbis::ErrorCode orbis::umtx_cv_signal(Thread *thread, ptr cv) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, cv); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, cv); auto [chain, key, lock] = g_context.getUmtxChain0(thread->tproc->pid, cv); std::size_t count = chain.sleep_queue.count(key); if (chain.notify_one(key) >= count) @@ -336,7 +335,7 @@ orbis::ErrorCode orbis::umtx_cv_signal(Thread *thread, ptr cv) { } orbis::ErrorCode orbis::umtx_cv_broadcast(Thread *thread, ptr cv) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, cv); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, cv); auto [chain, key, lock] = g_context.getUmtxChain0(thread->tproc->pid, cv); chain.notify_all(key); cv->has_waiters.store(0, std::memory_order::relaxed); @@ -423,7 +422,7 @@ orbis::ErrorCode orbis::umtx_sem_wake(Thread *thread, ptr obj, orbis::ErrorCode orbis::umtx_nwake_private(Thread *thread, ptr uaddrs, std::int64_t count) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, uaddrs, count); + ORBIS_LOG_NOTICE(__FUNCTION__, thread->tid, uaddrs, count); while (count-- > 0) { void *uaddr; auto error = uread(uaddr, uaddrs++); diff --git a/rpcsx-os/backtrace.cpp b/rpcsx-os/backtrace.cpp index 4d4f9a6..7b8d33d 100644 --- a/rpcsx-os/backtrace.cpp +++ b/rpcsx-os/backtrace.cpp @@ -33,10 +33,12 @@ void rx::printStackTrace(ucontext_t *context, int fileno) { char buffer[1024]; + flockfile(stderr); if (int r = unw_init_local2(&cursor, context, UNW_INIT_SIGNAL_FRAME)) { int len = snprintf(buffer, sizeof(buffer), "unw_init_local: %s\n", unw_strerror(r)); write(fileno, buffer, len); + funlockfile(stderr); return; } @@ -67,6 +69,7 @@ void rx::printStackTrace(ucontext_t *context, int fileno) { write(fileno, buffer, len); count++; } while (unw_step(&cursor) > 0 && count < 32); + funlockfile(stderr); } void rx::printStackTrace(ucontext_t *context, orbis::Thread *thread, diff --git a/rpcsx-os/main.cpp b/rpcsx-os/main.cpp index ad02216..475bc19 100644 --- a/rpcsx-os/main.cpp +++ b/rpcsx-os/main.cpp @@ -486,6 +486,7 @@ int main(int argc, const char *argv[]) { // rx::vm::printHostStats(); auto initProcess = orbis::g_context.createProcess(10); + pthread_setname_np(pthread_self(), "10.MAINTHREAD"); initProcess->sysent = &orbis::ps4_sysvec; initProcess->onSysEnter = onSysEnter; initProcess->onSysExit = onSysExit; diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index bd27628..708749e 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -472,6 +472,8 @@ SysResult thr_new(orbis::Thread *thread, orbis::ptr param, std::printf("Starting child thread %lu\n", (long)(proc->pid + baseId)); std::thread{[=, childThread = Ref(childThread)] { + pthread_setname_np(pthread_self(), + std::to_string(childThread->tid).c_str()); stack_t ss; auto sigStackSize = std::max(