From d983c361846ae677663128d25a7b342309deff53 Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Tue, 18 Aug 2020 13:51:18 +0200 Subject: [PATCH] yagl: Print PID/TID where cur_ts is unavailable (3/3) In cases where yagl_thread_state pointer is unavailable (main server thread, initialization, etc.) PID/TID for logs is extracted the slow way - via yagl_get_pid/yagl_get_tid calls, which extract these IDs via system-specific calls. Change-Id: I63f35ff195793f1d0a363e754a8256083e8d0685 --- hw/yagl/Makefile.objs | 1 + hw/yagl/yagl_log.h | 5 ++-- hw/yagl/yagl_util.c | 63 +++++++++++++++++++++++++++++++++++++++++++ hw/yagl/yagl_util.h | 40 +++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 hw/yagl/yagl_util.c create mode 100644 hw/yagl/yagl_util.h diff --git a/hw/yagl/Makefile.objs b/hw/yagl/Makefile.objs index fcd358f7d2..7f017bd5bf 100644 --- a/hw/yagl/Makefile.objs +++ b/hw/yagl/Makefile.objs @@ -1,5 +1,6 @@ obj-y += yagl_device.o obj-y += yagl_log.o +obj-y += yagl_util.o obj-y += yagl_process.o obj-y += yagl_thread.o obj-y += yagl_server.o diff --git a/hw/yagl/yagl_log.h b/hw/yagl/yagl_log.h index 38ab24e8ab..c4176e2a63 100644 --- a/hw/yagl/yagl_log.h +++ b/hw/yagl/yagl_log.h @@ -35,6 +35,7 @@ #endif #include "yagl_types.h" +#include "yagl_util.h" //#define YAGL_LOG_DISABLE @@ -130,8 +131,8 @@ bool yagl_log_is_enabled_for_func_tracing(void); #define YAGL_LOG_FUNC_SET_TS(__func, __ts) \ const char* _yagl_log_current_func = #__func; \ - yagl_pid _yagl_log_current_pid = (__ts ? __ts->ps->id : 0); \ - yagl_tid _yagl_log_current_tid = (__ts ? __ts->id : 0) + yagl_pid _yagl_log_current_pid = (__ts ? __ts->ps->id : yagl_get_pid()); \ + yagl_tid _yagl_log_current_tid = (__ts ? __ts->id : yagl_get_tid()) #define YAGL_LOG_FUNC_SET(__func) YAGL_LOG_FUNC_SET_TS(__func, cur_ts) diff --git a/hw/yagl/yagl_util.c b/hw/yagl/yagl_util.c new file mode 100644 index 0000000000..3d345d43b9 --- /dev/null +++ b/hw/yagl/yagl_util.c @@ -0,0 +1,63 @@ +/* + * yagl + * + * Copyright (c) 2000 - 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Stanislav Vorobiov + * Jinhyung Jo + * YeongKyoon Lee + * Lukasz Kostyra + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "yagl_util.h" + +#ifdef CONFIG_WIN32 +#include +#else +#include +#include + +#ifdef CONFIG_DARWIN +#define SYSCALL_GET_TID SYS_thread_selfid +#else +#define SYSCALL_GET_TID SYS_gettid +#endif + +#endif + +yagl_pid yagl_get_pid(void) +{ +#ifdef CONFIG_WIN32 + return (yagl_pid)GetCurrentProcessId(); +#else + return (yagl_pid)getpid(); +#endif +} + +yagl_tid yagl_get_tid(void) +{ +#ifdef CONFIG_WIN32 + return (yagl_tid)GetCurrentThreadId(); +#else + return (yagl_tid)syscall(SYSCALL_GET_TID); +#endif +} \ No newline at end of file diff --git a/hw/yagl/yagl_util.h b/hw/yagl/yagl_util.h new file mode 100644 index 0000000000..228b4799b8 --- /dev/null +++ b/hw/yagl/yagl_util.h @@ -0,0 +1,40 @@ +/* + * yagl + * + * Copyright (c) 2000 - 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Stanislav Vorobiov + * Jinhyung Jo + * YeongKyoon Lee + * Lukasz Kostyra + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef _QEMU_YAGL_UTIL_H +#define _QEMU_YAGL_UTIL_H + +#include "yagl_types.h" + +yagl_pid yagl_get_pid(void); + +yagl_tid yagl_get_tid(void); + +#endif // _QEMU_YAGL_UTIL_H -- 2.34.1