mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-18 08:49:57 -04:00
test: move thread into realtime class even on EVENT__DISABLE_THREAD_SUPPORT
(cherry picked from commit ca2b72c546d80dfb4fa255b20ef4a829ed102a70)
This commit is contained in:
parent
5a400c1f28
commit
0ef87f5f0e
@ -33,6 +33,14 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* move_pthread_to_realtime_scheduling_class() */
|
||||||
|
#ifdef EVENT__HAVE_MACH_MACH_H
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
#ifdef EVENT__HAVE_MACH_MACH_TIME_H
|
||||||
|
#include <mach/mach_time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
|
#if defined(__APPLE__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
|
||||||
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 && \
|
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 && \
|
||||||
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)
|
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)
|
||||||
@ -188,6 +196,45 @@ ignore_log_cb(int s, const char *msg)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put into the real time scheduling class for better timers latency.
|
||||||
|
* https://developer.apple.com/library/archive/technotes/tn2169/_index.html#//apple_ref/doc/uid/DTS40013172-CH1-TNTAG6000
|
||||||
|
*/
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
static void move_pthread_to_realtime_scheduling_class(pthread_t pthread)
|
||||||
|
{
|
||||||
|
mach_timebase_info_data_t info;
|
||||||
|
mach_timebase_info(&info);
|
||||||
|
|
||||||
|
const uint64_t NANOS_PER_MSEC = 1000000ULL;
|
||||||
|
double clock2abs =
|
||||||
|
((double)info.denom / (double)info.numer) * NANOS_PER_MSEC;
|
||||||
|
|
||||||
|
thread_time_constraint_policy_data_t policy;
|
||||||
|
policy.period = 0;
|
||||||
|
policy.computation = (uint32_t)(5 * clock2abs); // 5 ms of work
|
||||||
|
policy.constraint = (uint32_t)(10 * clock2abs);
|
||||||
|
policy.preemptible = FALSE;
|
||||||
|
|
||||||
|
int kr = thread_policy_set(pthread_mach_thread_np(pthread),
|
||||||
|
THREAD_TIME_CONSTRAINT_POLICY,
|
||||||
|
(thread_policy_t)&policy,
|
||||||
|
THREAD_TIME_CONSTRAINT_POLICY_COUNT);
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
mach_error("thread_policy_set:", kr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void thread_setup(THREAD_T pthread)
|
||||||
|
{
|
||||||
|
move_pthread_to_realtime_scheduling_class(pthread);
|
||||||
|
}
|
||||||
|
#else /** \__APPLE__ */
|
||||||
|
void thread_setup(THREAD_T pthread) {}
|
||||||
|
#endif /** \!__APPLE__ */
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
basic_test_setup(const struct testcase_t *testcase)
|
basic_test_setup(const struct testcase_t *testcase)
|
||||||
{
|
{
|
||||||
@ -195,9 +242,7 @@ basic_test_setup(const struct testcase_t *testcase)
|
|||||||
evutil_socket_t spair[2] = { -1, -1 };
|
evutil_socket_t spair[2] = { -1, -1 };
|
||||||
struct basic_test_data *data = NULL;
|
struct basic_test_data *data = NULL;
|
||||||
|
|
||||||
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
|
||||||
thread_setup(THREAD_SELF());
|
thread_setup(THREAD_SELF());
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (testcase->flags & TT_ENABLE_IOCP_FLAG)
|
if (testcase->flags & TT_ENABLE_IOCP_FLAG)
|
||||||
|
@ -66,51 +66,6 @@
|
|||||||
#include "time-internal.h"
|
#include "time-internal.h"
|
||||||
#include "regress_thread.h"
|
#include "regress_thread.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Put into the real time scheduling class for better timers latency.
|
|
||||||
* https://developer.apple.com/library/archive/technotes/tn2169/_index.html#//apple_ref/doc/uid/DTS40013172-CH1-TNTAG6000
|
|
||||||
*/
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#ifdef EVENT__HAVE_MACH_MACH_H
|
|
||||||
#include <mach/mach.h>
|
|
||||||
#endif
|
|
||||||
#ifdef EVENT__HAVE_MACH_MACH_TIME_H
|
|
||||||
#include <mach/mach_time.h>
|
|
||||||
#endif
|
|
||||||
static void move_pthread_to_realtime_scheduling_class(pthread_t pthread)
|
|
||||||
{
|
|
||||||
mach_timebase_info_data_t info;
|
|
||||||
mach_timebase_info(&info);
|
|
||||||
|
|
||||||
const uint64_t NANOS_PER_MSEC = 1000000ULL;
|
|
||||||
double clock2abs =
|
|
||||||
((double)info.denom / (double)info.numer) * NANOS_PER_MSEC;
|
|
||||||
|
|
||||||
thread_time_constraint_policy_data_t policy;
|
|
||||||
policy.period = 0;
|
|
||||||
policy.computation = (uint32_t)(5 * clock2abs); // 5 ms of work
|
|
||||||
policy.constraint = (uint32_t)(10 * clock2abs);
|
|
||||||
policy.preemptible = FALSE;
|
|
||||||
|
|
||||||
int kr = thread_policy_set(pthread_mach_thread_np(pthread),
|
|
||||||
THREAD_TIME_CONSTRAINT_POLICY,
|
|
||||||
(thread_policy_t)&policy,
|
|
||||||
THREAD_TIME_CONSTRAINT_POLICY_COUNT);
|
|
||||||
if (kr != KERN_SUCCESS) {
|
|
||||||
mach_error("thread_policy_set:", kr);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void thread_setup(THREAD_T pthread)
|
|
||||||
{
|
|
||||||
move_pthread_to_realtime_scheduling_class(pthread);
|
|
||||||
}
|
|
||||||
#else /** \__APPLE__ */
|
|
||||||
void thread_setup(THREAD_T pthread) {}
|
|
||||||
#endif /** \!__APPLE__ */
|
|
||||||
|
|
||||||
|
|
||||||
struct cond_wait {
|
struct cond_wait {
|
||||||
void *lock;
|
void *lock;
|
||||||
void *cond;
|
void *cond;
|
||||||
|
@ -27,9 +27,18 @@
|
|||||||
#ifndef REGRESS_THREAD_H_INCLUDED_
|
#ifndef REGRESS_THREAD_H_INCLUDED_
|
||||||
#define REGRESS_THREAD_H_INCLUDED_
|
#define REGRESS_THREAD_H_INCLUDED_
|
||||||
|
|
||||||
#include "regress.h"
|
#if defined(_WIN32) /** _WIN32 */
|
||||||
|
#define THREAD_T void * /* HANDLE */
|
||||||
#ifdef EVENT__HAVE_PTHREADS /** PTHREADS */
|
#define THREAD_FN unsigned __stdcall
|
||||||
|
#define THREAD_RETURN() return (0)
|
||||||
|
#define THREAD_SELF() GetCurrentThreadId()
|
||||||
|
#define THREAD_START(threadvar, fn, arg) do { \
|
||||||
|
uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \
|
||||||
|
(threadvar) = (THREAD_T)threadhandle; \
|
||||||
|
thread_setup(threadvar); \
|
||||||
|
} while (0)
|
||||||
|
#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE)
|
||||||
|
#else /* !_WIN32 */
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#define THREAD_T pthread_t
|
#define THREAD_T pthread_t
|
||||||
#define THREAD_FN void *
|
#define THREAD_FN void *
|
||||||
@ -40,21 +49,8 @@
|
|||||||
thread_setup(threadvar); \
|
thread_setup(threadvar); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define THREAD_JOIN(th) pthread_join(th, NULL)
|
#define THREAD_JOIN(th) pthread_join(th, NULL)
|
||||||
#elif defined(_WIN32) /** _WIN32 */
|
|
||||||
#define THREAD_T HANDLE
|
|
||||||
#define THREAD_FN unsigned __stdcall
|
|
||||||
#define THREAD_RETURN() return (0)
|
|
||||||
#define THREAD_SELF() GetCurrentThreadId()
|
|
||||||
#define THREAD_START(threadvar, fn, arg) do { \
|
|
||||||
uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \
|
|
||||||
(threadvar) = (HANDLE) threadhandle; \
|
|
||||||
thread_setup(threadvar); \
|
|
||||||
} while (0)
|
|
||||||
#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE)
|
|
||||||
#endif /* \!_WIN32 */
|
#endif /* \!_WIN32 */
|
||||||
|
|
||||||
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
|
||||||
void thread_setup(THREAD_T pthread);
|
void thread_setup(THREAD_T pthread);
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user