Further improve ipv4.games server

This commit is contained in:
Justine Tunney 2022-10-03 15:05:33 -07:00
parent 3b4fcd8575
commit 32321ab1e9
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
9 changed files with 307 additions and 113 deletions

View file

@ -554,6 +554,8 @@ static const uint16_t kPledgeStdio[] = {
__NR_linux_set_robust_list, //
__NR_linux_get_robust_list, //
__NR_linux_prlimit | STDIO, //
__NR_linux_sched_getaffinity, //
__NR_linux_sched_setaffinity, //
};
static const uint16_t kPledgeFlock[] = {
@ -705,8 +707,6 @@ static const uint16_t kPledgeProc[] = {
__NR_linux_sched_setscheduler, //
__NR_linux_sched_get_priority_min, //
__NR_linux_sched_get_priority_max, //
__NR_linux_sched_getaffinity, //
__NR_linux_sched_setaffinity, //
__NR_linux_sched_getparam, //
__NR_linux_sched_setparam, //
};

View file

@ -19,11 +19,11 @@
#include "libc/calls/calls.h"
#include "libc/calls/pledge.internal.h"
#include "libc/calls/state.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/promises.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
@ -110,7 +110,7 @@
* fcntl(F_SETFD), fcntl(F_GETFL), fcntl(F_SETFL), sched_yield,
* epoll_create, epoll_create1, epoll_ctl, epoll_wait, epoll_pwait,
* epoll_pwait2, clone(CLONE_THREAD), futex, set_robust_list,
* get_robust_list, sigpending.
* get_robust_list, setaffinity, sigpending.
*
* - "rpath" (read-only path ops) allows chdir, getcwd, open(O_RDONLY),
* openat(O_RDONLY), stat, fstat, lstat, fstatat, access, faccessat,

View file

@ -77,6 +77,6 @@ int sched_getaffinity(int tid, size_t size, cpu_set_t *bitset) {
}
rc = 0;
}
STRACE("sched_getaffinity(%d, %'zu, %p) → %d% m", tid, size, bitset);
STRACE("sched_getaffinity(%d, %'zu, %p) → %d% m", tid, size, bitset, rc);
return rc;
}

View file

@ -85,6 +85,6 @@ int sched_setaffinity(int tid, size_t size, const cpu_set_t *bitset) {
} else {
rc = sys_sched_setaffinity(tid, size, bitset);
}
STRACE("sched_setaffinity(%d, %'zu, %p) → %d% m", tid, size, bitset);
STRACE("sched_setaffinity(%d, %'zu, %p) → %d% m", tid, size, bitset, rc);
return rc;
}

View file

@ -52,6 +52,9 @@ enum PosixThreadStatus {
// - kPosixThreadZombie -> _pthread_free() will happen whenever
// convenient, e.g. pthread_create() entry or atexit handler.
kPosixThreadZombie,
// special main thread
kPosixThreadMain,
};
struct PosixThread {

View file

@ -36,7 +36,8 @@
*/
wontreturn void pthread_exit(void *rc) {
struct PosixThread *pt;
if ((pt = (struct PosixThread *)__get_tls()->tib_pthread)) {
pt = (struct PosixThread *)pthread_self();
if (pt->status != kPosixThreadMain) {
pt->rc = rc;
_gclongjmp(pt->exiter, 1);
} else {

View file

@ -29,7 +29,7 @@
*/
int pthread_join(pthread_t thread, void **value_ptr) {
struct PosixThread *pt;
if (thread == __get_tls()->tib_pthread) {
if (thread == pthread_self()) {
return EDEADLK;
}
if (!(pt = (struct PosixThread *)thread) || //

View file

@ -16,6 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/thread/posixthread.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
@ -25,3 +27,10 @@
pthread_t pthread_self(void) {
return __get_tls()->tib_pthread;
}
static struct PosixThread pthread_main;
__attribute__((__constructor__)) static void pthread_self_init(void) {
pthread_main.tid = gettid();
pthread_main.status = kPosixThreadMain;
__get_tls()->tib_pthread = (pthread_t)&pthread_main;
}