yagl: Print PID/TID where cur_ts is unavailable (3/3) 20/243120/1
authorLukasz Kostyra <l.kostyra@samsung.com>
Tue, 18 Aug 2020 11:51:18 +0000 (13:51 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Thu, 3 Sep 2020 07:49:50 +0000 (09:49 +0200)
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
hw/yagl/yagl_log.h
hw/yagl/yagl_util.c [new file with mode: 0644]
hw/yagl/yagl_util.h [new file with mode: 0644]

index fcd358f7d291a48fb516e1ce514eff76310e61fa..7f017bd5bf80fe8016593d4d4521651fa8e291a8 100644 (file)
@@ -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
index 38ab24e8abcfc05c00b3518964129887df507701..c4176e2a63441354d2966e5e6a0d871f67a73a8b 100644 (file)
@@ -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 (file)
index 0000000..3d345d4
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * yagl
+ *
+ * Copyright (c) 2000 - 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Stanislav Vorobiov <s.vorobiov@samsung.com>
+ * Jinhyung Jo <jinhyung.jo@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * Lukasz Kostyra <l.kostyra@samsung.com>
+ *
+ * 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 <Windows.h>
+#else
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#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 (file)
index 0000000..228b479
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * yagl
+ *
+ * Copyright (c) 2000 - 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Stanislav Vorobiov <s.vorobiov@samsung.com>
+ * Jinhyung Jo <jinhyung.jo@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * Lukasz Kostyra <l.kostyra@samsung.com>
+ *
+ * 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