mirror of https://gitee.com/bigwinds/arangodb
added thread affinity for MacOSX
This commit is contained in:
parent
0118b15f1c
commit
24db83573a
|
@ -1,6 +1,8 @@
|
|||
devel
|
||||
-----
|
||||
|
||||
* fixed thread affinity
|
||||
|
||||
* replaced require("internal").db by require("@arangodb").db
|
||||
|
||||
* added option `--skip-lines` for arangoimp
|
||||
|
|
|
@ -184,6 +184,8 @@ void Dispatcher::reportStatus() {
|
|||
|
||||
void Dispatcher::setProcessorAffinity(size_t id,
|
||||
std::vector<size_t> const& cores) {
|
||||
LOG_TOPIC(DEBUG, Logger::THREADS) << "dispatcher cores: " << cores;
|
||||
|
||||
DispatcherQueue* queue;
|
||||
|
||||
if (id >= _queues.size() || (queue = _queues[id]) == nullptr) {
|
||||
|
|
|
@ -167,6 +167,7 @@ void DispatcherFeature::unprepare() {
|
|||
|
||||
void DispatcherFeature::buildDispatcher() {
|
||||
_dispatcher = new Dispatcher(SchedulerFeature::SCHEDULER);
|
||||
_dispatcher->setProcessorAffinity(Dispatcher::STANDARD_QUEUE, _affinityCores);
|
||||
DISPATCHER = _dispatcher;
|
||||
}
|
||||
|
||||
|
@ -189,7 +190,5 @@ void DispatcherFeature::buildAqlQueue() {
|
|||
}
|
||||
|
||||
void DispatcherFeature::setProcessorAffinity(std::vector<size_t> const& cores) {
|
||||
#ifdef TRI_HAVE_THREAD_AFFINITY
|
||||
_dispatcher->setProcessorAffinity(Dispatcher::STANDARD_QUEUE, cores);
|
||||
#endif
|
||||
_affinityCores = cores;
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ class DispatcherFeature final
|
|||
void buildStandardQueue();
|
||||
|
||||
private:
|
||||
std::vector<size_t> _affinityCores;
|
||||
rest::Dispatcher* _dispatcher;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "DispatcherQueue.h"
|
||||
|
||||
#include "Basics/ConditionLocker.h"
|
||||
#include "Logger/Logger.h"
|
||||
#include "Basics/MutexLocker.h"
|
||||
#include "Dispatcher/DispatcherThread.h"
|
||||
#include "Dispatcher/Job.h"
|
||||
#include "Logger/Logger.h"
|
||||
|
||||
using namespace arangodb::rest;
|
||||
|
||||
|
@ -38,7 +39,8 @@ using namespace arangodb::rest;
|
|||
DispatcherQueue::DispatcherQueue(Scheduler* scheduler, Dispatcher* dispatcher,
|
||||
size_t id,
|
||||
Dispatcher::newDispatcherThread_fptr creator,
|
||||
size_t nrThreads, size_t nrExtra, size_t maxSize)
|
||||
size_t nrThreads, size_t nrExtra,
|
||||
size_t maxSize)
|
||||
: _id(id),
|
||||
_nrThreads(nrThreads),
|
||||
_nrExtra(nrExtra),
|
||||
|
@ -65,7 +67,7 @@ DispatcherQueue::DispatcherQueue(Scheduler* scheduler, Dispatcher* dispatcher,
|
|||
_jobs(),
|
||||
_jobPositions(_maxSize) {
|
||||
// keep a list of all jobs
|
||||
_jobs = new std::atomic<Job*>[maxSize];
|
||||
_jobs = new std::atomic<Job*>[ maxSize ];
|
||||
|
||||
// and a list of positions into this array
|
||||
for (size_t i = 0; i < maxSize; ++i) {
|
||||
|
@ -361,8 +363,8 @@ void DispatcherQueue::startQueueThread(bool force) {
|
|||
if (!_affinityCores.empty()) {
|
||||
size_t c = _affinityCores[_affinityPos];
|
||||
|
||||
LOG(DEBUG) << "using core " << c << " for standard dispatcher thread";
|
||||
|
||||
LOG_TOPIC(DEBUG, Logger::THREADS) << "using core " << c
|
||||
<< " for standard dispatcher thread";
|
||||
thread->setProcessorAffinity(c);
|
||||
|
||||
++_affinityPos;
|
||||
|
|
|
@ -63,12 +63,20 @@ void AffinityFeature::prepare() {
|
|||
return;
|
||||
}
|
||||
|
||||
DispatcherFeature* dispatcher =
|
||||
#if !(defined(ARANGODB_HAVE_THREAD_AFFINITY) || \
|
||||
defined(ARANGODB_HAVE_THREAD_POLICY))
|
||||
|
||||
LOG(WARN) << "thread affinity is not supported on this operating system";
|
||||
_threadAffinity = 0;
|
||||
|
||||
#else
|
||||
|
||||
DispatcherFeature* dispatcher =
|
||||
ApplicationServer::getFeature<DispatcherFeature>("Dispatcher");
|
||||
|
||||
_nd = (dispatcher != nullptr) ? dispatcher->concurrency() : 0;
|
||||
|
||||
SchedulerFeature* scheduler =
|
||||
SchedulerFeature* scheduler =
|
||||
ApplicationServer::getFeature<SchedulerFeature>("Scheduler");
|
||||
|
||||
_ns = (scheduler != nullptr) ? scheduler->concurrency() : 0;
|
||||
|
@ -158,30 +166,24 @@ void AffinityFeature::prepare() {
|
|||
dispatcher->setProcessorAffinity(_pd);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void AffinityFeature::start() {
|
||||
if (0 < _threadAffinity) {
|
||||
LOG(INFO) << "the server has " << _n << " (hyper) cores, using " << _ns
|
||||
<< " scheduler thread(s), " << _nd << " dispatcher thread(s)";
|
||||
|
||||
if (0 < _ns) {
|
||||
LOG(DEBUG) << "scheduler cores: " << _ps;
|
||||
}
|
||||
|
||||
if (0 < _nd) {
|
||||
LOG(DEBUG) << "dispatcher cores: " << _pd;
|
||||
}
|
||||
} else {
|
||||
DispatcherFeature* dispatcher =
|
||||
DispatcherFeature* dispatcher =
|
||||
ApplicationServer::getFeature<DispatcherFeature>("Dispatcher");
|
||||
SchedulerFeature* scheduler =
|
||||
SchedulerFeature* scheduler =
|
||||
ApplicationServer::getFeature<SchedulerFeature>("Scheduler");
|
||||
|
||||
size_t nd = (dispatcher == nullptr ? 0 : dispatcher->concurrency());
|
||||
size_t ns = (scheduler == nullptr ? 0 : scheduler->concurrency());
|
||||
|
||||
LOG(INFO) << "the server has " << _n << " (hyper) cores, using " << ns
|
||||
<< " scheduler thread(s), " << nd << " dispatcher thread(s)";
|
||||
<< " scheduler thread(s), " << nd << " dispatcher thread(s)";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ Scheduler::Scheduler(size_t nrThreads)
|
|||
|
||||
// report status
|
||||
if (multiThreading) {
|
||||
LOG(TRACE) << "scheduler is multi-threaded, number of threads: " << nrThreads;
|
||||
LOG(TRACE) << "scheduler is multi-threaded, number of threads: "
|
||||
<< nrThreads;
|
||||
} else {
|
||||
LOG(TRACE) << "scheduler is single-threaded";
|
||||
}
|
||||
|
@ -84,7 +85,22 @@ bool Scheduler::start(ConditionVariable* cv) {
|
|||
bool ok = threads[i]->start(cv);
|
||||
|
||||
if (!ok) {
|
||||
LOG(FATAL) << "cannot start threads"; FATAL_ERROR_EXIT();
|
||||
LOG(FATAL) << "cannot start threads";
|
||||
FATAL_ERROR_EXIT();
|
||||
}
|
||||
|
||||
if (!_affinityCores.empty()) {
|
||||
size_t c = _affinityCores[_affinityPos];
|
||||
|
||||
LOG_TOPIC(DEBUG, Logger::THREADS) << "using core " << c
|
||||
<< " for scheduler thread " << i;
|
||||
threads[i]->setProcessorAffinity(c);
|
||||
|
||||
++_affinityPos;
|
||||
|
||||
if (_affinityPos >= _affinityCores.size()) {
|
||||
_affinityPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,9 +128,7 @@ bool Scheduler::start(ConditionVariable* cv) {
|
|||
/// @brief checks if the scheduler threads are up and running
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Scheduler::isStarted() {
|
||||
return true;
|
||||
}
|
||||
bool Scheduler::isStarted() { return true; }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks if scheduler is still running
|
||||
|
@ -313,8 +327,8 @@ int Scheduler::unregisterTask(Task* task) {
|
|||
if (stopping) {
|
||||
return TRI_ERROR_SHUTTING_DOWN;
|
||||
}
|
||||
SchedulerThread* thread = nullptr;
|
||||
|
||||
SchedulerThread* thread = nullptr;
|
||||
std::string const taskName(task->name());
|
||||
|
||||
{
|
||||
|
@ -324,12 +338,14 @@ int Scheduler::unregisterTask(Task* task) {
|
|||
task); // TODO(fc) XXX remove this! This should be in the Task
|
||||
|
||||
if (it == task2thread.end()) {
|
||||
LOG(WARN) << "unregisterTask called for an unknown task " << (void*)task << " (" << taskName << ")";
|
||||
LOG(WARN) << "unregisterTask called for an unknown task " << (void*)task
|
||||
<< " (" << taskName << ")";
|
||||
|
||||
return TRI_ERROR_TASK_NOT_FOUND;
|
||||
}
|
||||
|
||||
LOG(TRACE) << "unregisterTask for task " << (void*)task << " (" << taskName << ")";
|
||||
LOG(TRACE) << "unregisterTask for task " << (void*)task << " (" << taskName
|
||||
<< ")";
|
||||
|
||||
thread = (*it).second;
|
||||
|
||||
|
@ -350,6 +366,7 @@ int Scheduler::destroyTask(Task* task) {
|
|||
if (stopping) {
|
||||
return TRI_ERROR_SHUTTING_DOWN;
|
||||
}
|
||||
|
||||
SchedulerThread* thread = nullptr;
|
||||
std::string const taskName(task->name());
|
||||
|
||||
|
@ -359,12 +376,14 @@ int Scheduler::destroyTask(Task* task) {
|
|||
auto it = task2thread.find(task);
|
||||
|
||||
if (it == task2thread.end()) {
|
||||
LOG(WARN) << "destroyTask called for an unknown task " << (void*)task << " (" << taskName << ")";
|
||||
LOG(WARN) << "destroyTask called for an unknown task " << (void*)task
|
||||
<< " (" << taskName << ")";
|
||||
|
||||
return TRI_ERROR_TASK_NOT_FOUND;
|
||||
}
|
||||
|
||||
LOG(TRACE) << "destroyTask for task " << (void*)task << " (" << taskName << ")";
|
||||
LOG(TRACE) << "destroyTask for task " << (void*)task << " (" << taskName
|
||||
<< ")";
|
||||
|
||||
thread = (*it).second;
|
||||
|
||||
|
@ -387,10 +406,9 @@ void Scheduler::reportStatus() {}
|
|||
/// @brief sets the process affinity
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Scheduler::setProcessorAffinity(size_t i, size_t c) {
|
||||
MUTEX_LOCKER(mutexLocker, schedulerLock);
|
||||
|
||||
threads[i]->setProcessorAffinity(c);
|
||||
void Scheduler::setProcessorAffinity(std::vector<size_t> const& cores) {
|
||||
LOG_TOPIC(DEBUG, Logger::THREADS) << "scheduler cores: " << cores;
|
||||
_affinityCores = cores;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -189,7 +189,7 @@ class Scheduler : private TaskManager {
|
|||
/// @brief sets the process affinity
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setProcessorAffinity(size_t i, size_t c);
|
||||
void setProcessorAffinity(std::vector<size_t> const& cores);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the task for a task id
|
||||
|
@ -364,6 +364,18 @@ class Scheduler : private TaskManager {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool _active;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief cores to use for affinity
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::vector<size_t> _affinityCores;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief next affinity core to use
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
size_t _affinityPos = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include "SchedulerFeature.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "ApplicationFeatures/ApplicationServer.h"
|
||||
|
@ -98,8 +98,7 @@ void SchedulerFeature::validateOptions(
|
|||
|
||||
if (n <= 4) {
|
||||
_nrSchedulerThreads = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_nrSchedulerThreads = 2;
|
||||
}
|
||||
}
|
||||
|
@ -152,9 +151,7 @@ void SchedulerFeature::stop() {
|
|||
}
|
||||
}
|
||||
|
||||
void SchedulerFeature::unprepare() {
|
||||
SCHEDULER = nullptr;
|
||||
}
|
||||
void SchedulerFeature::unprepare() { SCHEDULER = nullptr; }
|
||||
|
||||
#ifdef _WIN32
|
||||
bool CtrlHandler(DWORD eventType) {
|
||||
|
@ -272,7 +269,10 @@ class HangupTask : public SignalTask {
|
|||
#endif
|
||||
|
||||
void SchedulerFeature::buildScheduler() {
|
||||
_scheduler = new SchedulerLibev(static_cast<size_t>(_nrSchedulerThreads), static_cast<int>(_backend));
|
||||
_scheduler = new SchedulerLibev(static_cast<size_t>(_nrSchedulerThreads),
|
||||
static_cast<int>(_backend));
|
||||
_scheduler->setProcessorAffinity(_affinityCores);
|
||||
|
||||
SCHEDULER = _scheduler;
|
||||
}
|
||||
|
||||
|
@ -313,21 +313,5 @@ void SchedulerFeature::buildHangupHandler() {
|
|||
}
|
||||
|
||||
void SchedulerFeature::setProcessorAffinity(std::vector<size_t> const& cores) {
|
||||
#ifdef TRI_HAVE_THREAD_AFFINITY
|
||||
size_t j = 0;
|
||||
|
||||
for (uint32_t i = 0; i < _nrSchedulerThreads; ++i) {
|
||||
size_t c = cores[j];
|
||||
|
||||
LOG(DEBUG) << "using core " << c << " for scheduler thread " << i;
|
||||
|
||||
_scheduler->setProcessorAffinity(i, c);
|
||||
|
||||
++j;
|
||||
|
||||
if (j >= cores.size()) {
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_affinityCores = cores;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ class SchedulerFeature final : public application_features::ApplicationFeature {
|
|||
void buildScheduler();
|
||||
|
||||
private:
|
||||
std::vector<size_t> _affinityCores;
|
||||
rest::Scheduler* _scheduler;
|
||||
std::vector<rest::Task*> _tasks;
|
||||
};
|
||||
|
|
|
@ -36,12 +36,11 @@
|
|||
// --Section-- processor features
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief padding
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// padding
|
||||
|
||||
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \
|
||||
defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) || defined(__aarch64__)
|
||||
defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) || \
|
||||
defined(__aarch64__)
|
||||
#undef TRI_PADDING_32
|
||||
#else
|
||||
#define TRI_PADDING_32 1
|
||||
|
@ -55,9 +54,7 @@
|
|||
|
||||
#define TRI_PLATFORM "solaris"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief necessary defines and includes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// necessary defines and includes
|
||||
|
||||
#define TRI_UNDEF_ERR 1
|
||||
|
||||
|
@ -65,16 +62,12 @@
|
|||
|
||||
#define TRI_HAVE_PSTACK 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enabled features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// enabled features
|
||||
|
||||
#define ARANGODB_ENABLE_SYSLOG 1
|
||||
#define ARANGODB_ENABLE_SYSLOG_STRINGS 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available include files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available include files
|
||||
|
||||
#define TRI_HAVE_ARPA_INET_H 1
|
||||
#define TRI_HAVE_DIRENT_H 1
|
||||
|
@ -96,11 +89,7 @@
|
|||
#define TRI_HAVE_TERMIOS_H 1
|
||||
#define TRI_HAVE_UNISTD_H 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#undef TRI_HAVE_GETLINE /* TODO(fc) remove when we are using the new ProgramOptions */
|
||||
// available functions
|
||||
|
||||
#define ARANGODB_HAVE_FORK 1
|
||||
#define ARANGODB_HAVE_GETGRGID 1
|
||||
|
@ -109,7 +98,7 @@
|
|||
#define ARANGODB_HAVE_GETPWNAM 1
|
||||
#define ARANGODB_HAVE_GETPWUID 1
|
||||
#define ARANGODB_HAVE_GETRUSAGE 1
|
||||
#undef ARANGODB_HAVE_GETTID
|
||||
#undef ARANGODB_HAVE_GETTID
|
||||
#define ARANGODB_HAVE_GMTIME_R 1
|
||||
#undef ARANGODB_HAVE_GMTIME_S
|
||||
#undef ARANGODB_HAVE_INITGROUPS
|
||||
|
@ -121,9 +110,7 @@
|
|||
#define TRI_srandom ::srand
|
||||
#define TRI_random ::rand
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available features
|
||||
|
||||
#define TRI_HAVE_POSIX 1
|
||||
|
||||
|
@ -139,9 +126,7 @@
|
|||
|
||||
#define TRI_MISSING_MEMRCHR 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// files
|
||||
|
||||
#define TRI_DIR_SEPARATOR_CHAR '/'
|
||||
#define TRI_DIR_SEPARATOR_STR "/"
|
||||
|
@ -176,9 +161,7 @@
|
|||
#define TRI_SYSTEM_ERROR() \
|
||||
{}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sockets
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sockets
|
||||
|
||||
#define TRI_CONNECT_AI_FLAGS (AI_PASSIVE | AI_NUMERICSERV | AI_ALL)
|
||||
|
||||
|
@ -188,9 +171,7 @@
|
|||
#define TRI_READ_SOCKET(a, b, c, d) TRI_readsocket((a), (b), (c), (d))
|
||||
#define TRI_WRITE_SOCKET(a, b, c, d) TRI_writesocket((a), (b), (c), (d))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user and group types
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// user and group types
|
||||
|
||||
#define TRI_uid_t uid_t
|
||||
#define TRI_gid_t gid_t
|
||||
|
@ -205,23 +186,17 @@
|
|||
|
||||
#define TRI_PLATFORM "darwin"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief necessary defines and includes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// necessary defines and includes
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ARANGODB_GETRUSAGE_MAXRSS_UNIT 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enabled features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// enabled features
|
||||
|
||||
#define ARANGODB_ENABLE_SYSLOG 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available include files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available include files
|
||||
|
||||
#define TRI_HAVE_ARPA_INET_H 1
|
||||
#define TRI_HAVE_DIRENT_H 1
|
||||
|
@ -243,14 +218,11 @@
|
|||
#define TRI_HAVE_TERMIOS_H 1
|
||||
#define TRI_HAVE_UNISTD_H 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available functions
|
||||
|
||||
#define ARANGODB_HAVE_FORK 1
|
||||
#define ARANGODB_HAVE_GETGRGID 1
|
||||
#define ARANGODB_HAVE_GETGRNAM 1
|
||||
#undef TRI_HAVE_GETLINE
|
||||
#define ARANGODB_HAVE_GETPPID 1
|
||||
#define ARANGODB_HAVE_GETPWNAM 1
|
||||
#define ARANGODB_HAVE_GETPWUID 1
|
||||
|
@ -267,13 +239,12 @@
|
|||
#define TRI_random random
|
||||
#define TRI_srandom srandom
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available features
|
||||
|
||||
#define TRI_HAVE_POSIX 1
|
||||
|
||||
#define ARANGODB_HAVE_DOMAIN_SOCKETS 1
|
||||
#define ARANGODB_HAVE_THREAD_POLICY 1
|
||||
#define TRI_HAVE_MACH 1
|
||||
#define TRI_HAVE_MACOS_MEM_STATS 1
|
||||
#define TRI_HAVE_POSIX_MMAP 1
|
||||
|
@ -288,17 +259,11 @@
|
|||
|
||||
#define TRI_SC_NPROCESSORS_ONLN 1
|
||||
|
||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
|
||||
#define TRI_HAVE_GETLINE 1
|
||||
#endif
|
||||
|
||||
#if __llvm__ == 1
|
||||
#define thread_local __thread
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief alignment and limits
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// alignment and limits
|
||||
|
||||
#if __WORDSIZE == 64
|
||||
#define TRI_SIZEOF_SIZE_T (8)
|
||||
|
@ -316,9 +281,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// files
|
||||
|
||||
#define TRI_DIR_SEPARATOR_CHAR '/'
|
||||
#define TRI_DIR_SEPARATOR_STR "/"
|
||||
|
@ -353,9 +316,7 @@
|
|||
#define TRI_SYSTEM_ERROR() \
|
||||
{}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sockets
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sockets
|
||||
|
||||
#define TRI_CONNECT_AI_FLAGS (AI_PASSIVE | AI_NUMERICSERV | AI_ALL)
|
||||
|
||||
|
@ -365,9 +326,7 @@
|
|||
#define TRI_READ_SOCKET(a, b, c, d) TRI_readsocket((a), (b), (c), (d))
|
||||
#define TRI_WRITE_SOCKET(a, b, c, d) TRI_writesocket((a), (b), (c), (d))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user and group types
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// user and group types
|
||||
|
||||
#define TRI_uid_t uid_t
|
||||
#define TRI_gid_t gid_t
|
||||
|
@ -380,9 +339,7 @@
|
|||
|
||||
#ifdef __FreeBSD__
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief necessary defines and includes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// necessary defines and includes
|
||||
|
||||
#define TRI_PLATFORM "freebsd"
|
||||
|
||||
|
@ -396,15 +353,11 @@
|
|||
|
||||
#define ARANGODB_GETRUSAGE_MAXRSS_UNIT 1024
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enabled features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// enabled features
|
||||
|
||||
#define ARANGODB_ENABLE_SYSLOG 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available include files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available include files
|
||||
|
||||
#define TRI_HAVE_DIRENT_H 1
|
||||
#define TRI_HAVE_DLFCN_H 1
|
||||
|
@ -426,13 +379,10 @@
|
|||
#define TRI_HAVE_SYS_TYPES_H 1
|
||||
#define TRI_HAVE_SYS_WAIT_H 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available functions
|
||||
|
||||
#define ARANGODB_HAVE_GETGRGID 1
|
||||
#define ARANGODB_HAVE_GETGRNAM 1
|
||||
#define TRI_HAVE_GETLINE 1
|
||||
#define ARANGODB_HAVE_GETPPID 1
|
||||
#define ARANGODB_HAVE_GETPWNAM 1
|
||||
#define ARANGODB_HAVE_GETPWUID 1
|
||||
|
@ -449,9 +399,7 @@
|
|||
#define TRI_random ::rand
|
||||
#define TRI_srandom ::srand
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available features
|
||||
|
||||
#define TRI_HAVE_POSIX 1
|
||||
|
||||
|
@ -465,9 +413,7 @@
|
|||
|
||||
#define TRI_HAVE_ANONYMOUS_MMAP 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief alignment and limits
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// alignment and limits
|
||||
|
||||
#if __WORDSIZE == 64
|
||||
#define TRI_SIZEOF_SIZE_T (8)
|
||||
|
@ -477,9 +423,7 @@
|
|||
#define TRI_ALIGNOF_VOIDP (4)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// files
|
||||
|
||||
#define TRI_DIR_SEPARATOR_CHAR '/'
|
||||
#define TRI_DIR_SEPARATOR_STR "/"
|
||||
|
@ -514,9 +458,7 @@
|
|||
#define TRI_SYSTEM_ERROR() \
|
||||
{}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sockets
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sockets
|
||||
|
||||
#define TRI_CONNECT_AI_FLAGS (AI_PASSIVE | AI_NUMERICSERV)
|
||||
|
||||
|
@ -526,9 +468,7 @@
|
|||
#define TRI_READ_SOCKET(a, b, c, d) TRI_readsocket((a), (b), (c), (d))
|
||||
#define TRI_WRITE_SOCKET(a, b, c, d) TRI_writesocket((a), (b), (c), (d))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user and group types
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// user and group types
|
||||
|
||||
#define TRI_uid_t uid_t
|
||||
#define TRI_gid_t gid_t
|
||||
|
@ -541,9 +481,7 @@
|
|||
|
||||
#ifdef __linux__
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief necessary defines and includes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// necessary defines and includes
|
||||
|
||||
#define TRI_PLATFORM "linux"
|
||||
|
||||
|
@ -567,15 +505,11 @@
|
|||
|
||||
#define ARANGODB_GETRUSAGE_MAXRSS_UNIT 1024
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enabled features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// enabled features
|
||||
|
||||
#define ARANGODB_ENABLE_SYSLOG 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available include files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available include files
|
||||
|
||||
#define TRI_HAVE_ARPA_INET_H 1
|
||||
#define TRI_HAVE_DIRENT_H 1
|
||||
|
@ -598,14 +532,11 @@
|
|||
#define TRI_HAVE_TERMIOS_H 1
|
||||
#define TRI_HAVE_UNISTD_H 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available functions
|
||||
|
||||
#define ARANGODB_HAVE_FORK 1
|
||||
#define ARANGODB_HAVE_GETGRGID 1
|
||||
#define ARANGODB_HAVE_GETGRNAM 1
|
||||
#define TRI_HAVE_GETLINE 1
|
||||
#define ARANGODB_HAVE_GETPPID 1
|
||||
#define ARANGODB_HAVE_GETPWNAM 1
|
||||
#define ARANGODB_HAVE_GETPWUID 1
|
||||
|
@ -621,21 +552,19 @@
|
|||
|
||||
#define TRI_HAVE_PRCTL 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available features
|
||||
|
||||
#define TRI_GCC_THREAD_LOCAL_STORAGE 1
|
||||
|
||||
#define TRI_HAVE_POSIX 1
|
||||
|
||||
#define TRI_HAVE_LINUX_PROC 1
|
||||
#define ARANGODB_HAVE_DOMAIN_SOCKETS 1
|
||||
#define ARANGODB_HAVE_THREAD_AFFINITY 1
|
||||
#define TRI_HAVE_LINUX_PROC 1
|
||||
#define TRI_HAVE_POSIX_MMAP 1
|
||||
#define TRI_HAVE_POSIX_PWD_GRP 1
|
||||
#define TRI_HAVE_POSIX_THREADS 1
|
||||
#define TRI_HAVE_SC_PHYS_PAGES 1
|
||||
#define TRI_HAVE_THREAD_AFFINITY 1
|
||||
#define TRI_HAVE_SETLK 1
|
||||
|
||||
#define TRI_HAVE_ANONYMOUS_MMAP 1
|
||||
|
@ -645,9 +574,7 @@
|
|||
#define TRI_random ::rand
|
||||
#define TRI_srandom ::srand
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief alignment and limits
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// alignment and limits
|
||||
|
||||
#if __WORDSIZE == 64
|
||||
#define TRI_SIZEOF_SIZE_T (8)
|
||||
|
@ -657,9 +584,7 @@
|
|||
#define TRI_ALIGNOF_VOIDP (4)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// files
|
||||
|
||||
#define TRI_DIR_SEPARATOR_CHAR '/'
|
||||
#define TRI_DIR_SEPARATOR_STR "/"
|
||||
|
@ -694,9 +619,7 @@
|
|||
#define TRI_SYSTEM_ERROR() \
|
||||
{}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sockets
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sockets
|
||||
|
||||
#define TRI_CONNECT_AI_FLAGS (AI_PASSIVE | AI_NUMERICSERV | AI_ALL)
|
||||
|
||||
|
@ -706,9 +629,7 @@
|
|||
#define TRI_READ_SOCKET(a, b, c, d) TRI_readsocket((a), (b), (c), (d))
|
||||
#define TRI_WRITE_SOCKET(a, b, c, d) TRI_writesocket((a), (b), (c), (d))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user and group types
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// user and group types
|
||||
|
||||
#define TRI_uid_t uid_t
|
||||
#define TRI_gid_t gid_t
|
||||
|
@ -721,9 +642,7 @@
|
|||
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief necessary defines and includes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// necessary defines and includes
|
||||
|
||||
#ifdef _WIN64
|
||||
#define TRI_PLATFORM "win64"
|
||||
|
@ -749,26 +668,18 @@
|
|||
|
||||
//#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
|
||||
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
#include <WinSock2.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enabled features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available include files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available include files
|
||||
|
||||
#define TRI_HAVE_DIRECT_H 1
|
||||
#define TRI_HAVE_PROCESS_H 1
|
||||
#define TRI_HAVE_SIGNAL_H 1
|
||||
#define TRI_HAVE_WINSOCK2_H 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available functions
|
||||
|
||||
#undef ARANGODB_HAVE_GETGRGID
|
||||
#undef ARANGODB_HAVE_GETGRNAM
|
||||
|
@ -802,9 +713,7 @@
|
|||
#define tzset _tzset
|
||||
#define usleep TRI_usleep
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief available features
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// available features
|
||||
|
||||
#define YY_NO_UNISTD_H 1
|
||||
|
||||
|
@ -851,9 +760,7 @@ typedef unsigned char bool;
|
|||
|
||||
#define thread_local __declspec(thread)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief alignment and limits
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// alignment and limits
|
||||
|
||||
#if __WORDSIZE == 64
|
||||
#define TRI_SIZEOF_SIZE_T (8)
|
||||
|
@ -863,9 +770,7 @@ typedef unsigned char bool;
|
|||
#define TRI_ALIGNOF_VOIDP (4)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// files
|
||||
|
||||
#define TRI_DIR_SEPARATOR_CHAR '\\'
|
||||
#define TRI_DIR_SEPARATOR_STR "\\"
|
||||
|
@ -908,20 +813,18 @@ typedef unsigned char bool;
|
|||
|
||||
// system error string macro requires ERRORBUF to instantiate its buffer before.
|
||||
|
||||
#define TRI_SYSTEM_ERROR() \
|
||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, \
|
||||
windowsErrorBuf, sizeof(windowsErrorBuf), NULL) == 0) { \
|
||||
memcpy(&windowsErrorBuf[0], "unknown error\0", strlen("unknown error\0")); \
|
||||
} \
|
||||
#define TRI_SYSTEM_ERROR() \
|
||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, \
|
||||
windowsErrorBuf, sizeof(windowsErrorBuf), NULL) == 0) { \
|
||||
memcpy(&windowsErrorBuf[0], "unknown error\0", strlen("unknown error\0")); \
|
||||
} \
|
||||
errno = TRI_MapSystemError(GetLastError())
|
||||
|
||||
#define STDERR_FILENO 2
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sockets
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sockets
|
||||
|
||||
#define TRI_CONNECT_AI_FLAGS (AI_PASSIVE | AI_NUMERICSERV | AI_ALL)
|
||||
|
||||
|
@ -931,16 +834,14 @@ typedef unsigned char bool;
|
|||
#define TRI_READ_SOCKET(a, b, c, d) TRI_readsocket((a), (b), (c), (d))
|
||||
#define TRI_WRITE_SOCKET(a, b, c, d) TRI_writesocket((a), (b), (c), (d))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief user and group types
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// user and group types
|
||||
|
||||
// under windows group identifiers and user identifiers are
|
||||
// security identifiers (SID) which is a variable length structure
|
||||
// which can (should) not be accessed directly.
|
||||
|
||||
#define TRI_uid_t void *
|
||||
#define TRI_gid_t void *
|
||||
#define TRI_uid_t void*
|
||||
#define TRI_gid_t void*
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -103,64 +103,6 @@ int gettimeofday(struct timeval* tv, void* tz) {
|
|||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gets a line
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(TRI_HAVE_GETLINE)
|
||||
|
||||
static int const line_size = 256;
|
||||
|
||||
ssize_t getline(char** lineptr, size_t* n, FILE* stream) {
|
||||
// sanity checks
|
||||
if (lineptr == nullptr || n == nullptr || stream == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// allocate the line the first time
|
||||
if (*lineptr == nullptr) {
|
||||
*lineptr = (char*)TRI_SystemAllocate(line_size, false);
|
||||
|
||||
if (*lineptr == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*n = line_size;
|
||||
}
|
||||
|
||||
// clear the line
|
||||
memset(*lineptr, '\0', *n);
|
||||
|
||||
size_t indx = 0;
|
||||
int c;
|
||||
while ((c = getc(stream)) != EOF) {
|
||||
// check if more memory is needed
|
||||
if (indx >= *n) {
|
||||
*lineptr = (char*)realloc(*lineptr, *n + line_size);
|
||||
|
||||
if (*lineptr == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// clear the rest of the line
|
||||
memset(*lineptr + *n, '\0', line_size);
|
||||
*n += line_size;
|
||||
}
|
||||
|
||||
// push the result in the line
|
||||
(*lineptr)[indx++] = c;
|
||||
|
||||
// bail out
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (c == EOF) ? -1 : (ssize_t)indx;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief safe localtime
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -29,8 +29,12 @@
|
|||
#include <sys/prctl.h>
|
||||
#endif
|
||||
|
||||
#include "Logger/Logger.h"
|
||||
#ifdef ARANGODB_HAVE_THREAD_POLICY
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Logger/Logger.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief data block for thread starter
|
||||
|
@ -118,7 +122,9 @@ bool TRI_StartThread(TRI_thread_t* thread, TRI_tid_t* threadId,
|
|||
/// @brief waits for a thread to finish
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_JoinThread(TRI_thread_t* thread) { return pthread_join(*thread, nullptr); }
|
||||
int TRI_JoinThread(TRI_thread_t* thread) {
|
||||
return pthread_join(*thread, nullptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks if we are the thread
|
||||
|
@ -141,7 +147,7 @@ void TRI_AllowCancelation() {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetProcessorAffinity(TRI_thread_t* thread, size_t core) {
|
||||
#ifdef TRI_HAVE_THREAD_AFFINITY
|
||||
#ifdef ARANGODB_HAVE_THREAD_AFFINITY
|
||||
|
||||
cpu_set_t cpuset;
|
||||
|
||||
|
@ -151,7 +157,22 @@ void TRI_SetProcessorAffinity(TRI_thread_t* thread, size_t core) {
|
|||
int s = pthread_setaffinity_np(*thread, sizeof(cpu_set_t), &cpuset);
|
||||
|
||||
if (s != 0) {
|
||||
LOG(ERR) << "cannot set affinity to core " << core << ": " << strerror(errno);
|
||||
LOG(ERR) << "cannot set affinity to core " << core << ": "
|
||||
<< strerror(errno);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ARANGODB_HAVE_THREAD_POLICY
|
||||
|
||||
thread_affinity_policy_data_t policy = {(int)core};
|
||||
auto mach_thread = pthread_mach_thread_np(*thread);
|
||||
auto res = thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY,
|
||||
(thread_policy_t)&policy, 1);
|
||||
|
||||
if (res != KERN_SUCCESS) {
|
||||
LOG(ERR) << "cannot set affinity to core " << core << ": "
|
||||
<< strerror(errno);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue