BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Add information to the docs about thread priority (Linux)

Open erichiller opened this issue 2 years ago • 1 comments

Some may wonder how to solve for the thread priority exception when optimizations validator is enabled. If you run with sudo or as a privileged user, it obviously solves this, but then all the compiled files are saved as root. It took me a bit, but the best solution I came up with to get around this is to put this into the Benchmark project's .csproj:

  • within .csproj add a target:
    • For non-interactive, but the user's password must be provided on the command line, eg export SUDOPASS=user_password_here && dotnet run or to keep your password from being in the global environment: (export SUDOPASS=user_password_here && dotnet run)
    Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="${SUDOPASS} | sudo --stdin setcap 'cap_sys_nice=eip' $(TargetDir)$(AssemblyName)" />
    /Target>
    
    • for a version which prompts the user for their password and can be run with a simple dotnet run:
    Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="sudo setcap 'cap_sys_nice=eip' $(TargetDir)$(AssemblyName)"/>
    /Target>
    

This would have helped me, maybe it would help others. I'm happy to submit a PR, but I was unsure where this should be placed or if you wanted this information added at all.

erichiller avatar Jun 25 '22 11:06 erichiller

Hello @erichiller, thanks for the report. PR is welcome! I think, /docs/articles/guides is a good place for such information. Just create a new file, describe the problem and the solution, and add this file to toc.yml (located in the same folder). You can find some additional information about our documentation workflow here.

AndreyAkinshin avatar Jul 08 '22 13:07 AndreyAkinshin