Skip to content

Commit

Permalink
remove CPU time clocks
Browse files Browse the repository at this point in the history
These clocks were removed from WASI in snapshot2.

Refs: #59
  • Loading branch information
cjihrig committed Feb 21, 2020
1 parent 664a847 commit 1761729
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 202 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1299,20 +1299,11 @@ Possible values:
The epoch of this clock is undefined. The absolute
time value of this clock therefore has no meaning.

- <a href="#clockid.process_cputime_id" name="clockid.process_cputime_id"></a>**`UVWASI_CLOCK_PROCESS_CPUTIME_ID`**

The CPU-time clock associated with the current
process.

- <a href="#clockid.realtime" name="clockid.realtime"></a>**`UVWASI_CLOCK_REALTIME`**

The clock measuring real time. Time value
zero corresponds with 1970-01-01T00:00:00Z.

- <a href="#clockid.thread_cputime_id" name="clockid.thread_cputime_id"></a>**`UVWASI_CLOCK_THREAD_CPUTIME_ID`**

The CPU-time clock associated with the current thread.

### <a href="#device" name="device"></a>`uvwasi_device_t` (`uint64_t`)

Identifier for a device containing a file system. Can be used
Expand Down
2 changes: 0 additions & 2 deletions include/wasi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ typedef struct uvwasi_ciovec_s {
typedef uint32_t uvwasi_clockid_t;
#define UVWASI_CLOCK_REALTIME 0
#define UVWASI_CLOCK_MONOTONIC 1
#define UVWASI_CLOCK_PROCESS_CPUTIME_ID 2
#define UVWASI_CLOCK_THREAD_CPUTIME_ID 3

typedef uint64_t uvwasi_device_t;

Expand Down
178 changes: 0 additions & 178 deletions src/clocks.c
Original file line number Diff line number Diff line change
@@ -1,127 +1,9 @@
#ifndef _WIN32
# include <errno.h>
# include <sys/time.h>
# include <sys/resource.h>
# include <time.h>
#endif /* _WIN32 */

#include "uv.h"
#include "clocks.h"
#include "wasi_types.h"
#include "uv_mapping.h"


#define UVWASI__WIN_TIME_AND_RETURN(handle, time) \
do { \
FILETIME create; \
FILETIME exit; \
FILETIME system; \
FILETIME user; \
SYSTEMTIME sys_system; \
SYSTEMTIME sys_user; \
if (0 == GetProcessTimes((handle), &create, &exit, &system, &user)) { \
return uvwasi__translate_uv_error( \
uv_translate_sys_error(GetLastError()) \
); \
} \
\
if (0 == FileTimeToSystemTime(&system, &sys_system)) { \
return uvwasi__translate_uv_error( \
uv_translate_sys_error(GetLastError()) \
); \
} \
\
if (0 == FileTimeToSystemTime(&user, &sys_user)) { \
return uvwasi__translate_uv_error( \
uv_translate_sys_error(GetLastError()) \
); \
} \
\
(time) = (((sys_system.wHour * 3600) + (sys_system.wMinute * 60) + \
sys_system.wSecond) * NANOS_PER_SEC) + \
(sys_system.wMilliseconds * 1000000) + \
(((sys_user.wHour * 3600) + (sys_user.wMinute * 60) + \
sys_user.wSecond) * NANOS_PER_SEC) + \
(sys_user.wMilliseconds * 1000000); \
return UVWASI_ESUCCESS; \
} while (0)


#define UVWASI__CLOCK_GETTIME_AND_RETURN(clk, time) \
do { \
struct timespec ts; \
if (0 != clock_gettime((clk), &ts)) \
return uvwasi__translate_uv_error(uv_translate_sys_error(errno)); \
(time) = (ts.tv_sec * NANOS_PER_SEC) + ts.tv_nsec; \
return UVWASI_ESUCCESS; \
} while (0)


#define UVWASI__GETRUSAGE_AND_RETURN(who, time) \
do { \
struct rusage ru; \
if (0 != getrusage((who), &ru)) \
return uvwasi__translate_uv_error(uv_translate_sys_error(errno)); \
(time) = (ru.ru_utime.tv_sec * NANOS_PER_SEC) + \
(ru.ru_utime.tv_usec * 1000) + \
(ru.ru_stime.tv_sec * NANOS_PER_SEC) + \
(ru.ru_stime.tv_usec * 1000); \
return UVWASI_ESUCCESS; \
} while (0)


#define UVWASI__OSX_THREADTIME_AND_RETURN(time) \
do { \
mach_port_t thread; \
thread_basic_info_data_t info; \
mach_msg_type_number_t count; \
count = THREAD_BASIC_INFO_COUNT; \
thread = pthread_mach_thread_np(pthread_self()); \
if (KERN_SUCCESS != thread_info(thread, \
THREAD_BASIC_INFO, \
(thread_info_t) &info, \
&count)) { \
return UVWASI_ENOSYS; \
} \
(time) = (info.user_time.seconds * NANOS_PER_SEC) + \
(info.user_time.microseconds * 1000) + \
(info.system_time.seconds * NANOS_PER_SEC) + \
(info.system_time.microseconds * 1000); \
return UVWASI_ESUCCESS; \
} while (0)


#define UVWASI__WIN_GETRES_AND_RETURN(time) \
do { \
/* The GetProcessTimes() docs claim a resolution of 100 ns. */ \
(time) = 100; \
return UVWASI_ESUCCESS; \
} while (0)


#define UVWASI__CLOCK_GETRES_AND_RETURN(clk, time) \
do { \
struct timespec ts; \
/* Try calling clock_getres(). If it doesn't succeed, then default to \
1000000. We implement all of the clocks, and some platforms (such as \
SmartOS) don't support all of the clocks, even though they define \
the constants for them. */ \
if (0 != clock_getres((clk), &ts)) \
(time) = 1000000; \
else \
(time) = (ts.tv_sec * NANOS_PER_SEC) + ts.tv_nsec; \
return UVWASI_ESUCCESS; \
} while (0)


#define UVWASI__SLOW_GETRES_AND_RETURN(time) \
do { \
/* Assume a "worst case" of 1000000 ns resolution. */ \
(time) = 1000000; \
return UVWASI_ESUCCESS; \
} while (0)


uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time) {
uv_timeval64_t tv;
int r;
Expand All @@ -133,63 +15,3 @@ uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time) {
*time = (tv.tv_sec * NANOS_PER_SEC) + (tv.tv_usec * 1000);
return UVWASI_ESUCCESS;
}


uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {
#if defined(_WIN32)
UVWASI__WIN_TIME_AND_RETURN(GetCurrentProcess(), *time);
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && \
!defined(__APPLE__) && \
!defined(__sun)
UVWASI__CLOCK_GETTIME_AND_RETURN(CLOCK_PROCESS_CPUTIME_ID, *time);
#else
UVWASI__GETRUSAGE_AND_RETURN(RUSAGE_SELF, *time);
#endif
}


uvwasi_errno_t uvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t* time) {
#if defined(_WIN32)
UVWASI__WIN_TIME_AND_RETURN(GetCurrentThread(), *time);
#elif defined(__APPLE__)
UVWASI__OSX_THREADTIME_AND_RETURN(*time);
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun)
UVWASI__CLOCK_GETTIME_AND_RETURN(CLOCK_THREAD_CPUTIME_ID, *time);
#else
# if defined(RUSAGE_LWP)
UVWASI__GETRUSAGE_AND_RETURN(RUSAGE_LWP, *time);
# elif defined(RUSAGE_THREAD)
UVWASI__GETRUSAGE_AND_RETURN(RUSAGE_THREAD, *time);
# else
return UVWASI_ENOSYS;
# endif /* RUSAGE_LWP */
#endif
}


uvwasi_errno_t uvwasi__clock_getres_process_cputime(uvwasi_timestamp_t* time) {
#if defined(_WIN32)
UVWASI__WIN_GETRES_AND_RETURN(*time);
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && \
!defined(__APPLE__) && \
!defined(__sun)
UVWASI__CLOCK_GETRES_AND_RETURN(CLOCK_PROCESS_CPUTIME_ID, *time);
#else
UVWASI__SLOW_GETRES_AND_RETURN(*time);
#endif
}


uvwasi_errno_t uvwasi__clock_getres_thread_cputime(uvwasi_timestamp_t* time) {
#if defined(_WIN32)
UVWASI__WIN_GETRES_AND_RETURN(*time);
#elif defined(__APPLE__)
UVWASI__SLOW_GETRES_AND_RETURN(*time);
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun)
UVWASI__CLOCK_GETTIME_AND_RETURN(CLOCK_THREAD_CPUTIME_ID, *time);
#elif defined(RUSAGE_THREAD) || defined(RUSAGE_LWP)
UVWASI__SLOW_GETRES_AND_RETURN(*time);
#else
return UVWASI_ENOSYS;
#endif
}
5 changes: 0 additions & 5 deletions src/clocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
#include "wasi_types.h"

uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time);
uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time);
uvwasi_errno_t uvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t* time);

uvwasi_errno_t uvwasi__clock_getres_process_cputime(uvwasi_timestamp_t* time);
uvwasi_errno_t uvwasi__clock_getres_thread_cputime(uvwasi_timestamp_t* time);

#endif /* __UVWASI_CLOCKS_H__ */
8 changes: 0 additions & 8 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,6 @@ uvwasi_errno_t uvwasi_clock_res_get(uvwasi_t* uvwasi,
case UVWASI_CLOCK_REALTIME:
*resolution = 1; /* Nanosecond precision. */
return UVWASI_ESUCCESS;
case UVWASI_CLOCK_PROCESS_CPUTIME_ID:
return uvwasi__clock_getres_process_cputime(resolution);
case UVWASI_CLOCK_THREAD_CPUTIME_ID:
return uvwasi__clock_getres_thread_cputime(resolution);
default:
return UVWASI_EINVAL;
}
Expand All @@ -713,10 +709,6 @@ uvwasi_errno_t uvwasi_clock_time_get(uvwasi_t* uvwasi,
return UVWASI_ESUCCESS;
case UVWASI_CLOCK_REALTIME:
return uvwasi__clock_gettime_realtime(time);
case UVWASI_CLOCK_PROCESS_CPUTIME_ID:
return uvwasi__clock_gettime_process_cputime(time);
case UVWASI_CLOCK_THREAD_CPUTIME_ID:
return uvwasi__clock_gettime_thread_cputime(time);
default:
return UVWASI_EINVAL;
}
Expand Down

0 comments on commit 1761729

Please sign in to comment.