Minor logging improvements

This commit is contained in:
Ivan Chikish 2023-07-13 17:53:13 +03:00
parent f11efcd324
commit aa00adc9ec
5 changed files with 27 additions and 21 deletions

View File

@ -136,6 +136,7 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr<const char[32]> name,
return {};
}
orbis::SysResult orbis::sys_evf_delete(Thread *thread, sint id) {
ORBIS_LOG_WARNING(__FUNCTION__, id);
Ref<EventFlag> 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<uint64_t> pPatternSet,
ptr<uint> 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<uint64_t> 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<EventFlag> 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<EventFlag> 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<sint> pNumWaitThreads) {
ORBIS_LOG_TRACE(__FUNCTION__, thread, id, value, pNumWaitThreads);
ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, value, pNumWaitThreads);
Ref<EventFlag> evf = thread->tproc->evfMap.get(id);
if (evf == nullptr) {

View File

@ -48,19 +48,19 @@ uint UmtxChain::notify_all(const UmtxKey &key) {
orbis::ErrorCode orbis::umtx_lock_umtx(Thread *thread, ptr<umtx> 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> 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<void> 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<void> addr, ulong id,
}
orbis::ErrorCode orbis::umtx_wake(Thread *thread, ptr<void> 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<umutex_lock_mode>::format(std::string &out,
}
static ErrorCode do_lock_normal(Thread *thread, ptr<umutex> 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<umutex> m, uint flags,
return ErrorCode::NOSYS;
}
static ErrorCode do_unlock_normal(Thread *thread, ptr<umutex> 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<umutex> m, uint flags) {
return {};
}
static ErrorCode do_unlock_pi(Thread *thread, ptr<umutex> m, uint flags) {
ORBIS_LOG_TODO(__FUNCTION__, m, flags);
return do_unlock_normal(thread, m, flags);
}
static ErrorCode do_unlock_pp(Thread *thread, ptr<umutex> m, uint flags) {
@ -215,7 +214,7 @@ static ErrorCode do_unlock_pp(Thread *thread, ptr<umutex> m, uint flags) {
} // namespace orbis
orbis::ErrorCode orbis::umtx_trylock_umutex(Thread *thread, ptr<umutex> 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<umutex> m) {
orbis::ErrorCode orbis::umtx_lock_umutex(Thread *thread, ptr<umutex> 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<umutex> m,
}
orbis::ErrorCode orbis::umtx_unlock_umutex(Thread *thread, ptr<umutex> 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<umutex> m,
orbis::ErrorCode orbis::umtx_cv_wait(Thread *thread, ptr<ucond> cv,
ptr<umutex> 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<ucond> cv,
}
orbis::ErrorCode orbis::umtx_cv_signal(Thread *thread, ptr<ucond> 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<ucond> cv) {
}
orbis::ErrorCode orbis::umtx_cv_broadcast(Thread *thread, ptr<ucond> 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<void> obj,
orbis::ErrorCode orbis::umtx_nwake_private(Thread *thread, ptr<void *> 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++);

View File

@ -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,

View File

@ -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;

View File

@ -472,6 +472,8 @@ SysResult thr_new(orbis::Thread *thread, orbis::ptr<thr_param> param,
std::printf("Starting child thread %lu\n", (long)(proc->pid + baseId));
std::thread{[=, childThread = Ref<Thread>(childThread)] {
pthread_setname_np(pthread_self(),
std::to_string(childThread->tid).c_str());
stack_t ss;
auto sigStackSize = std::max<std::size_t>(