diff options
author | Nay <dnpd.dd@gmail.com> | 2013-07-28 18:58:12 +0100 |
---|---|---|
committer | Nay <dnpd.dd@gmail.com> | 2013-07-28 18:58:12 +0100 |
commit | e3f7be12efbef67a0d6c7213fba79d09941b2197 (patch) | |
tree | 1e454ed9309985b8d3ec9972559a4528dc5d220d /src/server/worldserver/Master.cpp | |
parent | f71d894a215ed7cd9052913c9b07c8f62f0e99ca (diff) |
Servers: Enable UseProcessors and ProcessPriority settings to be used on Linux
Diffstat (limited to 'src/server/worldserver/Master.cpp')
-rw-r--r-- | src/server/worldserver/Master.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index c65fc903ffc..b5ef2ad3b9b 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -186,12 +186,14 @@ int Master::Run() ACE_Based::Thread rarThread(new RARunnable); - ///- Handle affinity for multiple processors and process priority on Windows -#ifdef _WIN32 + ///- Handle affinity for multiple processors and process priority + uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0); + bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false); + +#ifdef _WIN32 // Windows { HANDLE hProcess = GetCurrentProcess(); - uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0); if (affinity > 0) { ULONG_PTR appAff; @@ -210,7 +212,7 @@ int Master::Run() } } - if (bool priority = sConfigMgr->GetBoolDefault("ProcessPriority", false)) + if (highPriority) { if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS)) TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "worldserver process priority class set to HIGH"); @@ -218,6 +220,35 @@ int Master::Run() TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Can't set worldserver process priority class."); } } +#elif __linux__ // Linux + + if (affinity > 0) + { + cpu_set_t mask; + CPU_ZERO(&mask); + + for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i) + if (affinity & (1 << i)) + CPU_SET(i, &mask); + + if (int err = sched_setaffinity(0, sizeof(mask), &mask)) + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Can't set used processors (hex): %x, error: %s", affinity, strerror(errno)); + else + { + CPU_ZERO(&mask); + sched_getaffinity(0, sizeof(mask), &mask); + TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Using processors (bitmask, hex): %x", *(uint32*)(&mask)) + } + } + + if (highPriority) + { + if (int err = setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY)) + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Can't set worldserver process priority class, error: %s", strerror(errno)); + else + TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "worldserver process priority class set to %i", getpriority(PRIO_PROCESS, 0)); + } + #endif //Start soap serving thread |