aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNay <dnpd.dd@gmail.com>2013-07-28 18:58:12 +0100
committerNay <dnpd.dd@gmail.com>2013-07-28 18:58:12 +0100
commite3f7be12efbef67a0d6c7213fba79d09941b2197 (patch)
tree1e454ed9309985b8d3ec9972559a4528dc5d220d /src
parentf71d894a215ed7cd9052913c9b07c8f62f0e99ca (diff)
Servers: Enable UseProcessors and ProcessPriority settings to be used on Linux
Diffstat (limited to 'src')
-rw-r--r--src/server/authserver/Main.cpp50
-rw-r--r--src/server/authserver/authserver.conf.dist7
-rw-r--r--src/server/worldserver/Master.cpp39
-rw-r--r--src/server/worldserver/worldserver.conf.dist7
4 files changed, 89 insertions, 14 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index 4a44dbfb1c4..94b2d3c7953 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
/**
* @file main.cpp
* @brief Authentication Server main program
@@ -40,6 +41,12 @@
#include "RealmList.h"
#include "RealmAcceptor.h"
+#ifdef __linux__
+#include <sched.h>
+#include <sys/resource.h>
+#define PROCESS_HIGH_PRIORITY -15 // [-20, 19], default is 0
+#endif
+
#ifndef _TRINITY_REALM_CONFIG
# define _TRINITY_REALM_CONFIG "authserver.conf"
#endif
@@ -49,7 +56,7 @@ void StopDB();
bool stopEvent = false; // Setting it to true stops the server
-LoginDatabaseWorkerPool LoginDatabase; // Accessor to the auth server database
+LoginDatabaseWorkerPool LoginDatabase; // Accessor to the authserver database
/// Handle authserver's termination signals
class AuthServerSignalHandler : public Trinity::SignalHandler
@@ -171,12 +178,14 @@ extern int main(int argc, char** argv)
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
- ///- 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;
@@ -187,7 +196,7 @@ extern int main(int argc, char** argv)
ULONG_PTR currentAffinity = affinity & appAff; // remove non accessible processors
if (!currentAffinity)
- TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the worldserver. Accessible processors bitmask (hex): %x", affinity, appAff);
+ TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff);
else if (SetProcessAffinityMask(hProcess, currentAffinity))
TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Using processors (bitmask, hex): %x", currentAffinity);
else
@@ -195,7 +204,7 @@ extern int main(int argc, char** argv)
}
}
- if (bool priority = sConfigMgr->GetBoolDefault("ProcessPriority", false))
+ if (highPriority)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "authserver process priority class set to HIGH");
@@ -203,6 +212,35 @@ extern int main(int argc, char** argv)
TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Can't set authserver 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_AUTHSERVER, "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_AUTHSERVER, "Using processors (bitmask, hex): %x", *(uint32*)(&mask))
+ }
+ }
+
+ if (highPriority)
+ {
+ if (int err = setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
+ TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Can't set authserver process priority class, error: %s", strerror(errno));
+ else
+ TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0));
+ }
+
#endif
// maximum counter for next ping
diff --git a/src/server/authserver/authserver.conf.dist b/src/server/authserver/authserver.conf.dist
index dda19c3b849..0a50601f86d 100644
--- a/src/server/authserver/authserver.conf.dist
+++ b/src/server/authserver/authserver.conf.dist
@@ -71,7 +71,9 @@ PidFile = ""
#
# UseProcessors
-# Description: Processors mask for Windows based multi-processor systems.
+# Description: Processors mask for Windows and Linux based multi-processor systems.
+# Example: A computer with 2 CPUs:
+# 1 - 1st CPU only, 2 - 2nd CPU only, 3 - 1st and 2nd CPU, because 1 | 2 is 3
# Default: 0 - (Selected by OS)
# 1+ - (Bit mask value of selected processors)
@@ -79,7 +81,8 @@ UseProcessors = 0
#
# ProcessPriority
-# Description: Process priority setting for Windows based systems.
+# Description: Process priority setting for Windows and Linux based systems.
+# Details: On Linux, a nice value of -15 is used. On Windows, process is set to HIGH class.
# Default: 1 - (High)
# 0 - (Normal)
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
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index 9577b3d841f..aac04fe9337 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -149,7 +149,9 @@ BindIP = "0.0.0.0"
# PERFORMANCE SETTINGS
#
# UseProcessors
-# Description: Processors mask for Windows based multi-processor systems.
+# Description: Processors mask for Windows and Linux based multi-processor systems.
+# Example: A computer with 2 CPUs:
+# 1 - 1st CPU only, 2 - 2nd CPU only, 3 - 1st and 2nd CPU, because 1 | 2 is 3
# Default: 0 - (Selected by OS)
# 1+ - (Bit mask value of selected processors)
@@ -157,7 +159,8 @@ UseProcessors = 0
#
# ProcessPriority
-# Description: Process priority setting for Windows based systems.
+# Description: Process priority setting for Windows and Linux based systems.
+# Details: On Linux, a nice value of -15 is used. On Windows, process is set to HIGH class.
# Default: 1 - (High)
# 0 - (Normal)