From 166977a8c323c1aa7c99aabfd3356abd8053e033 Mon Sep 17 00:00:00 2001 From: Salikh Zakirov Date: Wed, 7 Mar 2007 20:01:53 +0300 Subject: [PATCH] replaced apr_get_thread_time(s) with hythread_get_thread_times --- vm/include/open/hythread_ext.h | 2 ++ vm/thread/src/hythr.def | 1 + vm/thread/src/hythr.exp | 1 + vm/thread/src/linux/os_thread.c | 27 +++++++++++++++++++++++++++ vm/thread/src/thread_native_basic.c | 13 +++++++++++++ vm/thread/src/thread_private.h | 1 + vm/thread/src/thread_ti_timing.c | 10 +++++----- vm/thread/src/win/os_thread.c | 34 ++++++++++++++++++++++++++++++++++ 8 files changed, 84 insertions(+), 5 deletions(-) diff --git a/vm/include/open/hythread_ext.h b/vm/include/open/hythread_ext.h index f599ed6..ad35a3c 100644 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -116,6 +116,7 @@ e between safe point function call overhead and suspension time overhead. #if !defined(HYTHREAD_EXT_H) #define HYTHREAD_EXT_H +#include "open/types.h" #if defined(__cplusplus) extern "C" { @@ -191,6 +192,7 @@ IDATA VMCALL hythread_set_private_data(hythread_t t, void* data); UDATA VMCALL hythread_tls_get_offset(hythread_tls_key_t key); UDATA VMCALL hythread_tls_get_suspend_request_offset(); +UDATA VMCALL hythread_get_thread_times(hythread_t thread, int64* pkernel, int64* puser); //@} diff --git a/vm/thread/src/hythr.def b/vm/thread/src/hythr.def index 0953cc5..89ae6ed 100644 --- a/vm/thread/src/hythr.def +++ b/vm/thread/src/hythr.def @@ -49,6 +49,7 @@ hythread_join_interruptable hythread_get_self_id hythread_get_id hythread_get_thread +hythread_get_thread_times hythread_struct_init hythread_cancel_all hythread_group_create diff --git a/vm/thread/src/hythr.exp b/vm/thread/src/hythr.exp index 226c2fd..a31eb94 100644 --- a/vm/thread/src/hythr.exp +++ b/vm/thread/src/hythr.exp @@ -48,6 +48,7 @@ hythread_join_interruptable; hythread_get_self_id; hythread_get_id; hythread_get_thread; +hythread_get_thread_times; hythread_struct_init; hythread_cancel_all; hythread_group_create; diff --git a/vm/thread/src/linux/os_thread.c b/vm/thread/src/linux/os_thread.c index d52cc20..63f10ee 100644 --- a/vm/thread/src/linux/os_thread.c +++ b/vm/thread/src/linux/os_thread.c @@ -20,6 +20,7 @@ #include // gettid() #include // sched_param #include +#include #include "thread_private.h" @@ -188,3 +189,29 @@ void os_thread_yield_other(osthread_t os_thread) { pthread_mutex_unlock(&yield_other_mutex); } + +/** + * Queries amount of user and kernel times consumed by the thread, + * in nanoseconds. + * + * @param os_thread thread handle + * @param[out] pkernel a pointer to a variable to store kernel time to + * @param[out] puser a pointer to a variable to store user time to + * + * @return 0 on success, system error otherwise + */ +int os_get_thread_times(osthread_t os_thread, int64* pkernel, int64* puser) +{ + clockid_t clock_id; + struct timespec tp; + int r; + + r = pthread_getcpuclockid(os_thread, &clock_id); + if (r) return r; + + r = clock_gettime(clock_id, &tp); + if (r) return r; + + *puser = tp.tv_sec * 1000000000ULL + tp.tv_nsec; + return 0; +} diff --git a/vm/thread/src/thread_native_basic.c b/vm/thread/src/thread_native_basic.c index 1167330..7ef6975 100644 --- a/vm/thread/src/thread_native_basic.c +++ b/vm/thread/src/thread_native_basic.c @@ -726,3 +726,16 @@ extern HY_CFUNC void VMCALL // unreachable statement abort(); } + +/** + * Queries user and kernel time of the thread, in nanoseconds. + * + * @param thread thread block pointer + * @param[out] pkernel pointer to a variable to store kernel time into + * @param[out] puser pointer to a variable to store user time into + * + * @returns 0 on success, system error code otherwise + */ +UDATA hythread_get_thread_times(hythread_t thread, int64* pkernel, int64* puser) { + return os_get_thread_times(thread->os_handle, pkernel, puser); +} diff --git a/vm/thread/src/thread_private.h b/vm/thread/src/thread_private.h index 2f9a160..d1313a4 100644 --- a/vm/thread/src/thread_private.h +++ b/vm/thread/src/thread_private.h @@ -628,6 +628,7 @@ int os_thread_cancel(osthread_t); int os_thread_join(osthread_t); void os_thread_exit(int status); void os_thread_yield_other(osthread_t); +int os_get_thread_times(osthread_t os_thread, int64* pkernel, int64* puser); int os_cond_timedwait(hycond_t *cond, hymutex_t *mutex, I_64 ms, IDATA nano); diff --git a/vm/thread/src/thread_ti_timing.c b/vm/thread/src/thread_ti_timing.c index 147f7f6..a99f9a3 100644 --- a/vm/thread/src/thread_ti_timing.c +++ b/vm/thread/src/thread_ti_timing.c @@ -62,6 +62,7 @@ IDATA VMCALL jthread_get_thread_blocked_time(jthread java_thread, jlong *nanos_p IDATA VMCALL jthread_get_thread_cpu_time(jthread java_thread, jlong *nanos_ptr) { hythread_t tm_native_thread; + int64 kernel_time; assert(nanos_ptr); if (NULL == java_thread) { @@ -70,8 +71,7 @@ IDATA VMCALL jthread_get_thread_cpu_time(jthread java_thread, jlong *nanos_ptr) tm_native_thread = vm_jthread_get_tm_data(java_thread); } - return CONVERT_ERROR(apr_get_thread_time(tm_native_thread->os_handle, - (apr_int64_t*) nanos_ptr)); + return hythread_get_thread_times(tm_native_thread, &kernel_time, nanos_ptr); } /** @@ -92,13 +92,13 @@ IDATA VMCALL jthread_get_thread_cpu_timer_info(jvmtiTimerInfo* info_ptr) { IDATA VMCALL jthread_get_thread_user_cpu_time(jthread java_thread, jlong *nanos_ptr) { hythread_t tm_native_thread; - apr_time_t kernel_time; - apr_time_t user_time; + int64 kernel_time; + int64 user_time; assert(java_thread); assert(nanos_ptr); tm_native_thread = vm_jthread_get_tm_data(java_thread); - apr_thread_times(tm_native_thread->os_handle, &user_time, &kernel_time); + hythread_get_thread_times(tm_native_thread, &kernel_time, &user_time); *nanos_ptr = user_time; return TM_ERROR_NONE; diff --git a/vm/thread/src/win/os_thread.c b/vm/thread/src/win/os_thread.c index d570e30..c042e31 100644 --- a/vm/thread/src/win/os_thread.c +++ b/vm/thread/src/win/os_thread.c @@ -153,3 +153,37 @@ void os_thread_yield_other(osthread_t os_thread) } LeaveCriticalSection(&yield_other_mutex); } + +/** + * Queries amount of user and kernel times consumed by the thread, + * in nanoseconds. + * + * @param os_thread thread handle + * @param[out] pkernel a pointer to a variable to store kernel time to + * @param[out] puser a pointer to a variable to store user time to + * + * @return 0 on success, system error otherwise + */ +int os_get_thread_times(osthread_t os_thread, int64* pkernel, int64* puser) +{ + FILETIME creation_time; + FILETIME exit_time; + FILETIME kernel_time; + FILETIME user_time; + int r; + + r = GetThreadTimes(os_thread, + &creation_time, &exit_time, &kernel_time, &user_time); + + if (r) { + // according to MSDN, time is counted in 100 ns units, so we need to multiply by 100 + *pkernel = 100 * + (((int64)kernel_time.dwHighDateTime << 32) + | kernel_time.dwLowDateTime); + *puser = 100 * + (((int64)user_time.dwHighDateTime << 32) + | user_time.dwLowDateTime); + return 0; + } else + return GetLastError(); +} -- 1.5.0.33.g1b20