From b1b2138753be4a0c9dc50975b080f8e7743b78a9 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Fri, 14 Jan 2022 15:37:30 +0000 Subject: linux-user: Remove unnecessary 'aligned' attribute from TaskState The linux-user struct TaskState has an 'aligned(16)' attribute. When the struct was first added in commit 851e67a1b46f in 2003, there was a justification in a comment (still present in the source today): /* NOTE: we force a big alignment so that the stack stored after is aligned too */ because the final field in the struct was "uint8_t stack[0];" But that field was removed in commit 48e15fc2d in 2010 which switched us to allocating the stack and the TaskState separately. Because we allocate the structure with g_new0() rather than as a local variable, the attribute made no difference to the alignment of the structure anyway. Remove the unnecessary attribute, and the corresponding comment. Signed-off-by: Peter Maydell Message-Id: <20220114153732.3767229-2-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/qemu.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'linux-user/qemu.h') diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 7910ce59cc..9d2b3119d1 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -94,10 +94,6 @@ struct emulated_sigtable { target_siginfo_t info; }; -/* - * NOTE: we force a big alignment so that the stack stored after is - * aligned too - */ typedef struct TaskState { pid_t ts_tid; /* tid (or pid) of this task */ #ifdef TARGET_ARM @@ -158,7 +154,7 @@ typedef struct TaskState { /* This thread's sigaltstack, if it has one */ struct target_sigaltstack sigaltstack_used; -} __attribute__((aligned(16))) TaskState; +} TaskState; abi_long do_brk(abi_ulong new_brk); -- cgit 1.4.1 From eb33cdaeda55d951f915152ad23816d47aca9955 Mon Sep 17 00:00:00 2001 From: Cameron Esfahani Date: Thu, 27 Jan 2022 16:12:51 -0800 Subject: linux-user: Implement starttime field in self stat emulation Instead of always returning 0, return actual starttime. Signed-off-by: Cameron Esfahani Reviewed-by: Laurent Vivier Message-Id: <20220128001251.45165-1-dirty@apple.com> Signed-off-by: Laurent Vivier --- linux-user/main.c | 14 ++++++++++++++ linux-user/qemu.h | 3 +++ linux-user/syscall.c | 3 +++ 3 files changed, 20 insertions(+) (limited to 'linux-user/qemu.h') diff --git a/linux-user/main.c b/linux-user/main.c index 16def5215d..fbc9bcfd5f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -190,12 +190,26 @@ void stop_all_tasks(void) /* Assumes contents are already zeroed. */ void init_task_state(TaskState *ts) { + long ticks_per_sec; + struct timespec bt; + ts->used = 1; ts->sigaltstack_used = (struct target_sigaltstack) { .ss_sp = 0, .ss_size = 0, .ss_flags = TARGET_SS_DISABLE, }; + + /* Capture task start time relative to system boot */ + + ticks_per_sec = sysconf(_SC_CLK_TCK); + + if ((ticks_per_sec > 0) && !clock_gettime(CLOCK_BOOTTIME, &bt)) { + /* start_boottime is expressed in clock ticks */ + ts->start_boottime = bt.tv_sec * (uint64_t) ticks_per_sec; + ts->start_boottime += bt.tv_nsec * (uint64_t) ticks_per_sec / + NANOSECONDS_PER_SECOND; + } } CPUArchState *cpu_copy(CPUArchState *env) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 9d2b3119d1..98dfbf2096 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -154,6 +154,9 @@ typedef struct TaskState { /* This thread's sigaltstack, if it has one */ struct target_sigaltstack sigaltstack_used; + + /* Start time of task after system boot in clock ticks */ + uint64_t start_boottime; } TaskState; abi_long do_brk(abi_ulong new_brk); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 84cfa223df..b3948d13a9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8077,6 +8077,9 @@ static int open_self_stat(void *cpu_env, int fd) } else if (i == 3) { /* ppid */ g_string_printf(buf, FMT_pid " ", getppid()); + } else if (i == 21) { + /* starttime */ + g_string_printf(buf, "%" PRIu64 " ", ts->start_boottime); } else if (i == 27) { /* stack bottom */ g_string_printf(buf, TARGET_ABI_FMT_ld " ", ts->info->start_stack); -- cgit 1.4.1