Thursday, September 6, 2012

Keeping a process below a certain total CPU % use

Keeping an process below a certain total CPU % use

So, you want to keep a process limited to using only a certain percentage of all available CPU time? For single core systems, it used to be I'd tell people this wasn't recommended, but if they really had to forcibly limit a process, then they would have to use Process Lasso's unsafe 'Hard Throttling'. Fortunately, these days, if you've got a multi-core system, you are in luck! The more cores, the more control you'll have.

By limiting the CPU affinity of a process to specific cores, you have the ability to control the available CPU time it has access to, out of the total CPU time pool. For example, in an optimal world of a quad core system with 4 fully independent physical cores, you can set increments 25%, 50%, 75%, or 100%. Now, when you throw in logical processors, the picture gets more complex. Since the logical processors won't perform well at all, the % limits are actually staggered in *effect*. While the scheduler may show an exact 50% for 2 of 4 logical cores (100% of the 2 cores time is being used), that may not mean those two cores are executing at 100% the capacity of two physical cores. In other words, the CPU time is used, but performance takes a hit. This is hard to quantify for logical processors, but ThreadRacer can help.

Remember, Intel has its HyperThreaded cores staggered, starting at the second core (core #1 if core #0 counted as the first), and goes from there. Similarly, AMD Bulldozer+ Modules have adjacent processor cores that share computational units. Processors #0 and #1 would share some computational units, so you wouldn't want to load them both up if other cores are available. The scheduler itself will try to avoid such situations, in fact. With this 'every other core' method, it is easy to distinguish processors that are co-dependent (AMD), or HyperThreaded (INTEL).

For the AMD Phenom II and below, all cores are true, physically independent cores, making the Phenom II the last processor made in this fashion. That is why the AMD Phenom II x6 continues to shine in benchmarks against the latest AMD generation, despite a deficiency in base clock speed. It has 6 fully independent cores, something no current AMD processor has - they instead of 8 co-dependent cores, counted as 4 physical cores and 4 additional logical cores in marketing and by the Windows OS CPU Scheduler.

You can do this with:

1. Process Lasso's Default CPU Affinity,
2. When ProBalance events occur
3. Via the Process Lasso Watchdog (so that the change is only induced when certain criteria are met)

More information is available here: When CPU Affinity Matters.

1 comment:

  1. Now that I think more about it, I believe it will always divide evenly in CPU Time - but not performance. I have updated my writings to say this, and that I am estimating % of total capable performance rather than % of total CPU time available. I was thinking of computational capacity, but not remembering that the CPU time would remain even as a % of total use. Imagine if you dropped a much slower core in, say one running at 500mhz. That core would still have either 50% or 100% of ITS time used - thus skewing computational capacity when looking at CPU time used vs CPU time available. This metric (CPU %) has never been perfect... Indeed, that is one reason you see the Load Average used in Linux.