reducing DarkPlaces dedicated CPU load

Want to get your hands Bloody?
Post Reply
The Nameless Player
Axe Zombie
Posts: 34
Joined: Sun Oct 28, 2012 02:35 am

reducing DarkPlaces dedicated CPU load

Post by The Nameless Player »

So I've been running a Transfusion server for a while, and I've been plagued constantly by high CPU load. Sometimes the load literally reaches 100% and players complain, why it lag. Finally I know why.

Muzzle flashes leak entities.
QC patch: http://pastebin.com/g3vAam8J

Before I concluded that there's a regression in the Transfusion QC, I noticed two ways the DarkPlaces engine wastes processor time.

First, it checks for console input on every main loop iteration. This is a tremendous waste for such an unimportant task. Checking once per second is sufficient, since input is buffered between each read.

Second, it hogs the CPU if it doesn't sleep at regular intervals. DarkPlaces spends much of its time sleeping or checking the time to schedule more sleeping, and the sleep schedule is very sensitive to timer accuracy. Two sources of time are supported on Windows: timeGetTime and QueryPerformanceCounter. Neither of these works well for me, as timeGetTime is inaccurate, QueryPerformanceCounter has a ridiculous amount of overhead, and only the time stamp counter in the CPU is both fast and accurate. So I patched DarkPlaces to use the TSC.

Engine patch: http://pastebin.com/mriWBiMX

This patch adds a cvar sys_usetimestampcounter.
Last edited by The Nameless Player on Thu Jan 15, 2015 05:16 am, edited 1 time in total.
User avatar
N0t_mINe
Acolyte
Posts: 629
Joined: Wed Nov 30, 2011 05:35 am
Location: LURKERS DON'T DRAMA.

Re: reducing DarkPlaces dedicated CPU load

Post by N0t_mINe »

Is this being added to the main sourcforge tfn build or are you waiting for a larger number of changes/test results?

I hope termit is watching this thread if that person is still around.
The Nameless Player
Axe Zombie
Posts: 34
Joined: Sun Oct 28, 2012 02:35 am

Re: reducing DarkPlaces dedicated CPU load

Post by The Nameless Player »

I'm just mentioning this stuff in case someone finds it useful. None of the changes I made to the QC in 2013 were merged into the Transfusion repository, and I hope termit found the Transfusion HUD patch because it was never merged into the DarkPlaces repository either.
User avatar
N0t_mINe
Acolyte
Posts: 629
Joined: Wed Nov 30, 2011 05:35 am
Location: LURKERS DON'T DRAMA.

Re: reducing DarkPlaces dedicated CPU load

Post by N0t_mINe »

If I missed something pardon this question.
When you say engine patch, do you mean the most recent build of DP or the version currently used by transfusion?
The Nameless Player
Axe Zombie
Posts: 34
Joined: Sun Oct 28, 2012 02:35 am

Re: reducing DarkPlaces dedicated CPU load

Post by The Nameless Player »

The engine patch is against recent DarkPlaces.

To get that geniune Transfusion experience with recent DarkPlaces, you need the HUD patch from Willis.

HUD patch: http://pastebin.com/2DkG0gtD
The Nameless Player
Axe Zombie
Posts: 34
Joined: Sun Oct 28, 2012 02:35 am

Re: reducing DarkPlaces dedicated CPU load

Post by The Nameless Player »

Ooops. Ironically I introduced a resource leak in the engine if ~MHz is not found in the registry. Fixed.
User avatar
N0t_mINe
Acolyte
Posts: 629
Joined: Wed Nov 30, 2011 05:35 am
Location: LURKERS DON'T DRAMA.

Re: reducing DarkPlaces dedicated CPU load

Post by N0t_mINe »

Again, it's probably a case of me not looking in the right places, but do you report these engine patches over at icculus? or do you have a thread at one of the multiplayer game forums that use darkplaces? A patch that cuts cpu cycles is surely of interest to all involved in maintaining dp. If tfn isn't the main site you link your work to, I do apologize un advance.
The Nameless Player
Axe Zombie
Posts: 34
Joined: Sun Oct 28, 2012 02:35 am

Re: reducing DarkPlaces dedicated CPU load

Post by The Nameless Player »

Haven't mentioned it on any other forum since the main problem I was having was Transfusion chewing the CPU, and most of the load was caused by a bug that's specific to Transfusion.

The TSC patch is of interest only if someone insists on running DarkPlaces-WinQuake on a Windows server with an unreliable interrupt timer, a broken performance counter, and an invariant time stamp counter. So basically, Amazon EC2 or similar virtualization on something like a Xeon E5.

I tried sys_usetimestampcounter on a Core 2 Duo and it had all the problems described in the DarkPlaces documentation: unstable across processor cores and throttled by power saving. I expect the default choice of timeGetTime is best except in special circumstances.
The Nameless Player
Axe Zombie
Posts: 34
Joined: Sun Oct 28, 2012 02:35 am

Re: reducing DarkPlaces dedicated CPU load

Post by The Nameless Player »

No one has trolled me to use Linux yet? Well let's see.
Use Linux, noob, M$ Windoze is teh suxxor.

Code: Select all

$ cat /sys/devices/system/clocksource/clocksource0/available_clocksource
xen tsc hpet acpi_pm
$ echo tsc | sudo dd of=/sys/devices/system/clocksource/clocksource0/current_clocksource
According to strace, with current_clocksource set to tsc, clock_gettime isn't a syscall anymore.

Code: Select all

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00    0.000011           0    129290           clock_gettime
  0.00    0.000000           0      1030           select
  0.00    0.000000           0      2000      2000 recvfrom
------ ----------- ----------- --------- --------- ----------------
100.00    0.000011                132320      2000 total

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
  0.00    0.000000           0      1030           select
  0.00    0.000000           0      2000      2000 recvfrom
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                  3030      2000 total
Unnecessary syscalls are so unnecessary.
Post Reply