BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Better support for asymmetric CPU cores

Open huoyaoyuan opened this issue 10 months ago • 3 comments

When running benchmark on my Raptor Lake processor, I find the time of each iteration shifts between two values if I switch the console window to background.

This is probably due to the "smart" scheduling for P/E cores of Windows. I've also heard that thread affinity API getting ignored by the system in some situations.

It would also be interesting to see the results on E-cores. To be more general, there can be a configuration to set thread affinity for benchmarks. This can also help benchmarking for arbitrary core counts.

huoyaoyuan avatar Apr 09 '24 07:04 huoyaoyuan

We already support --affinity command line arg and Job.WithAffinity config option. Does that do what you need?

I've also heard that thread affinity API getting ignored by the system in some situations.

If that's true, that would be an issue for runtime or the OS, not BDN.

timcassell avatar Apr 09 '24 19:04 timcassell

We already support --affinity command line arg and Job.WithAffinity config option. Does that do what you need?

--affinity 1 and --affinity 65536 give me significant comparison of P/E cores.

Is there more handy way to compare different affinities? Job is just heavier to use. I can't find affinity setting in attributes.

huoyaoyuan avatar Apr 10 '24 08:04 huoyaoyuan

I don't think there is another built-in way to do it. You could create your own attribute to do it, though.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public class AffinitizedJobAttribute : JobConfigBaseAttribute
{
    // Add whatever other settings you need.
    public AffinitizedJobAttribute(int affinity) : base(Job.Default.WithAffinity((IntPtr) affinity)) { }
}

timcassell avatar Apr 10 '24 20:04 timcassell

I don't think there is anything actionable here, so closing this out. Let me know if you disagree.

timcassell avatar Jun 07 '24 21:06 timcassell