Fix getting TID on Fuchsia
Fuchsia TIDs are 64-bits, so we need to change the type of the fields.
This patch is needed for LIBVA_TRACE to initialize the output files
properly.
Change-Id: I1c09a7df2ff42da478388d1dda3239c7360f58d9
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/github.com/intel/libva/+/683704
Reviewed-by: Craig Stout <cstout@google.com>
diff --git a/meson.build b/meson.build
index 65ba44b..add90df 100644
--- a/meson.build
+++ b/meson.build
@@ -116,6 +116,8 @@
libmagma_dep = dependency('magma', version : '>= 1.0', required: true)
endif
+zircon_dep = cc.find_library('zircon', required: false)
+
va_c_args = []
if get_option('enable_va_messaging')
va_c_args += ['-DENABLE_VA_MESSAGING=1']
diff --git a/va/meson.build b/va/meson.build
index 988e9c0..eab4b95 100644
--- a/va/meson.build
+++ b/va/meson.build
@@ -70,7 +70,7 @@
link_args : '-Wl,-version-script,' + libva_sym_path,
link_depends : libva_sym,
install : true,
- dependencies : [ dl_dep ])
+ dependencies : [ dl_dep, zircon_dep ])
libva_dep = declare_dependency(
link_with : libva,
diff --git a/va/va_trace.c b/va/va_trace.c
index 52a4a7c..e8e09c2 100644
--- a/va/va_trace.c
+++ b/va/va_trace.c
@@ -61,10 +61,19 @@
#include <lwp.h>
#elif defined(__sun)
#include <thread.h>
+#elif defined(__Fuchsia__)
+#include <zircon/syscalls.h>
+#include <zircon/threads.h>
+#endif
+
+#if defined(__Fuchsia__)
+typedef uintptr_t tracing_pid_t;
+#else
+typedef pid_t tracing_pid_t;
#endif
/* bionic, glibc >= 2.30, musl >= 1.3 have gettid(), so add va_ prefix */
-static pid_t va_gettid()
+static tracing_pid_t va_gettid()
{
#if defined(__linux__)
return syscall(__NR_gettid);
@@ -77,14 +86,20 @@
#elif defined(__sun)
return thr_self();
#elif defined(__Fuchsia__)
- // Not implemented; Fuchsia needs 64 bits for thread ID
+ zx_info_handle_basic_t info;
+ zx_status_t status =
+ zx_object_get_info(thrd_get_zx_handle(thrd_current()), ZX_INFO_HANDLE_BASIC, &info, sizeof(info), NULL, NULL);
+ if (status != ZX_OK)
return 0;
+
+ return info.koid;
#else
#warning "Cannot get kernel thread identifier on this platform."
return (intptr_t)pthread_self();
#endif
}
+
/*
* Env. to debug some issue, e.g. the decode/encode issue in a video conference scenerio:
* .LIBVA_TRACE=log_file: general VA parameters saved into log_file
@@ -122,7 +137,7 @@
};
struct trace_log_file {
- pid_t thread_id;
+ tracing_pid_t thread_id;
int used;
char *fn_log;
@@ -166,7 +181,7 @@
unsigned int pts; /* IVF header information */
- pid_t created_thd_id;
+ tracing_pid_t created_thd_id;
};
struct trace_config_info {
@@ -176,7 +191,7 @@
VAProfile trace_profile;
VAEntrypoint trace_entrypoint;
- pid_t created_thd_id;
+ tracing_pid_t created_thd_id;
};
struct va_trace {
@@ -319,7 +334,7 @@
{
struct trace_config_info *pconfig_info;
int idx = 0;
- pid_t thd_id = va_gettid();
+ tracing_pid_t thd_id = va_gettid();
LOCK_RESOURCE(pva_trace);
@@ -611,7 +626,7 @@
static int open_tracing_log_file(
struct va_trace *pva_trace,
struct trace_log_file *plog_file,
- pid_t thd_id)
+ tracing_pid_t thd_id)
{
FILE *pfp = NULL;
int new_fn_flag = 0;
@@ -671,7 +686,7 @@
static int get_log_file_idx_by_thd(
struct trace_log_files_manager *plog_files_mgr,
- pid_t thd_id)
+ tracing_pid_t thd_id)
{
struct trace_log_file *plog_file = plog_files_mgr->log_file;
int first_free_idx = MAX_TRACE_THREAD_NUM;
@@ -696,7 +711,7 @@
{
struct trace_log_files_manager *plog_files_mgr = NULL;
struct trace_log_file *plog_file = NULL;
- pid_t thd_id = va_gettid();
+ tracing_pid_t thd_id = va_gettid();
int i = 0;
LOCK_RESOURCE(pva_trace);
@@ -735,7 +750,7 @@
struct trace_context *ptra_ctx)
{
struct trace_log_file *plog_file = NULL;
- pid_t thd_id = va_gettid();
+ tracing_pid_t thd_id = va_gettid();
int i = 0;
plog_file = ptra_ctx->plog_file;
@@ -1259,7 +1274,7 @@
{
struct trace_context *trace_ctx = NULL;
int i = 0, delete = 1;
- pid_t thd_id = va_gettid();
+ tracing_pid_t thd_id = va_gettid();
if (tra_ctx_idx >= MAX_TRACE_CTX_NUM)
return;