Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Little tip to boost performance

Author
Message
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 12th Jan 2012 22:09 Edited at: 12th Jan 2012 22:23
I just discovered you can alter the task priority of your programs, as well as set the affinity of the processor core it works with. As follows:

The code "2" assigns the current program to core 1 (list at bottom). Oddly, my program runs faster when it's restricted to a single core. The code "128" for the priority is for high.

CORE CODES
0=all cores
1=core 0
2=core 1
3=cores 0 & 1
4=core 2
5=cores 0 & 2
6=cores 1 & 2
7=cores 0,1 & 2
8=core 3
9=cores 0 & 3
10=cores 1 & 3
11=cores 0,1 & 3
12=cores 2 & 3
13=cores 0, 2 & 3
14=cores 1, 2 & 3

Sorry, I only have a quad core, but the rest are prob along a similar pattern. However, any invalid entry automatically sets it back to all cores (zero value). Invaluable for multi-tasking purposes such as background loading and running multiple exe files.

1beginner1
16
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 12th Jan 2012 22:25 Edited at: 12th Jan 2012 22:35
http://www.evga.com/forums/tm.aspx?m=60505&mpage=1

On this site is information about the numbers to use with SetProcessAffinityMask.

EDIT: your numbers are correct found it confusing that you started with core 0 instead of 1 sorry.
And maybe your program is slower with 2 cores because one is a normal core and the other one is hyperthreaded (one core acting like 2, that's why a i7 process shows 8 cores at the task manager while inside your pc are only 4). Just guessing
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 12th Jan 2012 22:33
Actually, I'm not worng at all, you're just a bit too quick to shout at me. Go back and read the site, that's a selection of flag settings, which when added together for each core give the results as I published.

EG: On that sire it says that 11=cores 4,2 & 1 (or 3,1 and 0 as I put). Now, these are assigned values of 8, 2 & 1. Add them up and you get.....11.

I just made it a little bit more simple for people by doing the working for them, but thanks for the input, it was much appreciated.
1beginner1
16
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 12th Jan 2012 22:45
Sorry I started typing my response before you edited your post and didn't refreshed page and then there was standing core 1 = 2 which I thought was a mistake because I started counting from core 1 instead of core 0 like you.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 12th Jan 2012 22:48 Edited at: 12th Jan 2012 22:52
That's ok, I should technically have started at core 1, but task manager starts at core 0 so I was following that (yes, I tested each core one at a time....laboursome!!)

Possible about the cores, it's an AMD quad though, so I think it actually has four dedicated cores. Only Win 7 onwards lets you call DLL functions to find numbers of logical and physical cores (tried for an hour before I read the flippin Microsoft web page!!), and I have Vista. I don;t know enough about C to check the DBPro code, but lots of people say it just doesn't like to multi-thread, so it's possibly not using more than one anyway, and simply changing the core number put it back to full speed???
DarkDISCUSSION
14
Years of Service
User Offline
Joined: 6th Jul 2011
Location: Ft Madison, IA
Posted: 13th Jan 2012 00:10
Does this work on XP or Vista? Sounds useful. Can doing this harm my machine's registry?

Just because I'm related to John Wayne doesn't mean I'm Rich.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Jan 2012 00:51
According to Microsoft's website you need windows 2000 plus to use this particular dll return, but who knows - there may be an XP alternative if you look.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686223%28v=VS.85%29.aspx

As for damaging your registry, no - this doesn't affect your registry, nor is it persistent. As soon as you exit and restart your program, it will default to all cores unless you tell it not to again.
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2012 08:50
Interesting...

May tri this when I get my system back up...

BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jan 2012 09:00
The highest n-core usage I have managed with DBP is 2%, although I couldn't tell you what triggered it. Only plugins like DarkLIGHTS, DarkPHYSICS and possibly DarkAI will use more than one core.

MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2012 09:13
BatVink could you post the link to that intel app you used? Thanks...

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jan 2012 14:07
Quote: "And maybe your program is slower with 2 cores because one is a normal core and the other one is hyperthreaded"

No, hyperthreading doesn't work like that.

Quote: "Oddly, my program runs faster when it's restricted to a single core."

You are likely forcing most everything else to run on the other core(s), and you reduce the time wasted on task swapping on your core. However, if you use one of the plug-ins that use threads, then you are also forcing them to run on the same core as DBPro instead of running on other cores.

As for priority, you should avoid raising your priority to HIGH or REALTIME - if you do so, you could lock out most everything on your system. Stick to NORMAL or ABOVE_NORMAL if you mush change your priority.

Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Jan 2012 23:54
Thanks for the heads up IanM, but as I've game coding and am looking for as much speed as possible, don't I want to lock out everything that isn't my game??? As it happens, it made little difference anyway. One question though - when you instruct your program to start another, you can also specify it's priority, yet this doesn't seem to actually work. Am I missing something on this point?

I don't use the plug-ins either and tend to stick to custom, specific procedures for most things, but in theory, as I have a quad core, if I stick to my system of running two .exe files side by side, limiting the background loader to one core, and still allow the main game .exe access to all the other cores, then the plug-ins would have access to those cores also, would they not?

BatVink - I'm working on a silent background loading system, so I run two .exe files, the main one starting a sub process. This way, I get usage one more than one core quite comfortably.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jan 2012 18:19 Edited at: 14th Jan 2012 18:20
Quote: "don't I want to lock out everything that isn't my game"

No. You don't want to lock out the OS processes that, just for instance, handle the keyboard/mouse/joystick for input, handle networking for communication, handle DMA transfers to get your sounds to play and your graphics to appear, handle disk accesses (reads and flushes) etc.

In addition, you also don't want to lock the multi-threaded plug-ins (DarkPhysics, DarkLights etc) onto the same core as your main game - you want them spread out.

Remember you are not in the world of the C64, Spectrum, Amiga or ST where you can simply take over the machine and do everything yourself - you are in the multitasking world of the Windows PC where the operating system still has to operate alongside your game because it's also doing things FOR your game.

Quote: "as I have a quad core"

In that case, as long as you take care, you are probably OK... but the people who you ship your game to may not be.

As Windows itself runs at HIGH priority, you are guaranteed to be OK running at ABOVE_NORMAL or lower priority. Any higher than that and all bets are off.

Quote: "Am I missing something on this point?"

Possibly - Windows dynamically drops the priority of processes that do not have focus. Setting the priority of a process is in most cases simply a request, not an instruction.

Read: http://msdn.microsoft.com/en-us/library/windows/desktop/ms685100(v=vs.85).aspx

Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2012 23:09
Thanks for the input IanM, it's much appreciated and food for thought. AS it happens, my current project actually doesn't need the secondary process, I was just playing to see what's possible, but as I don't use any of the other plugins (as of yet) I'm confident I'll be ok, but important for others to note.

But as for the comment about missing something, I meant the DBPro command "EXECUTE EXECUTABLE" - it has a priority parameter which states "The priority to run the executable at, the default is zero and higher priority is one.", but no matter the setting it always seems to run at normal priority in task manager and have no impact at all on performance. Is this a refernce to the priority of the DBPro programs only, and the priority of the started task as opposed to the running one, and the system share they get? For example, if a launcher started the main game as high, then the sub process as normal before exiting, would the main game get more processor time? It certainly doesn't seem to affect windows in any way???
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Jan 2012 12:17
Yes, you still missing something, and that is that Windows does not work like you think it works.

1. Priority changes set the base priority of your process, and Windows can and does dynamically adjust this as it goes, boosting it up for your process when needed, and dropping it back down over time as your process completes each time-slice (but never lowering back past the base you set). You can specify priority levels from 0 to 15 (assuming you set your thread priority at the same time) - Windows' actual priorities can range from 0 to 31.

2. Higher priorities give processes a better chance to run when they are ready to run, ie it doesn't determine how fast they run, but how often they get chosen to run. A single non-threaded process running flat out cannot run faster with a higher priority on a multi-core system. The most it can use is 1 single-cores worth of processing, no matter what priority you set it at. Only if you are multi-threading or have multiple cooperating processes can you have more than 1 cores worth of processing power being used at one time.

3. On a multi-core system, Windows will tend to schedule your DBPro task onto a single core, and move all other processes to other cores anyway. You can see this and prove it to yourself in Task Manager under the Performance tab.

In summary, for a single-threaded single process:
Single-core system - you have to cooperate with the OS (keyboard/mouse/file IO etc), so don't change the priority - if you do, then you may adversely affect the system, and Windows will eventually drop your priority for you and raise the priority of other processes giving a net result of no change.
Multi-core system - Windows will tend to give your DBPro process its own core, so you don't need to change the priority - if you do then you'll get, at most, a dedicated core which you probably had anyway.

Basically, you don't need to change your process priority - better method and algorithms are how you make you code run faster.

Mage
Valued Member
18
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 7th Feb 2012 03:53 Edited at: 7th Feb 2012 03:57
Modern AMD and Intel processors will shutdown unused cores and up the wattage (and frequency), on active cores for a performance boost.
Multi-Core processors operate at a maximum overall wattage to reduce heat. This is why you are seeing your performance boost.

Relevant Links:

Intel Turbo Boost - http://www.intel.com/content/www/us/en/architecture-and-technology/turbo-boost/turbo-boost-technology.html

AMD Turbo Core - http://www.amd.com/us/products/desktop/processors/phenom-ii/Pages/phenom-ii-key-architectural-features.aspx

Login to post a reply

Server time is: 2025-08-08 19:16:58
Your offset time is: 2025-08-08 19:16:58