runtime: SystemNative_GetCpuUtilization assert failure

https://mc.dot.net/#/user/dotnet-bot/pr~2Fdotnet~2Fcorefx~2Frefs~2Fpull~2F37996~2Fmerge/test~2Ffunctional~2Fcli~2Finnerloop~2F/20190528.42/workItem/System.Runtime.Extensions.Tests/wilogs

  Discovering: System.Runtime.Extensions.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Runtime.Extensions.Tests (found 805 of 887 test cases)
  Starting:    System.Runtime.Extensions.Tests (parallel test collections = on, max threads = 4)
    System.Tests.EnvironmentTests.GetFolderPath_UapExistAndAccessible [SKIP]
      Condition(s) not met: "IsWindows10Version1709OrGreater", "IsInAppContainer"
    System.Tests.EnvironmentTests.GetFolderPath_UapNotEmpty [SKIP]
      Condition(s) not met: "IsWindows10Version1709OrGreater", "IsInAppContainer"
Assertion failed: (cpuUtilization >= 0 && cpuUtilization <= 100), function SystemNative_GetCpuUtilization, file /Users/vsts/agent/2.150.3/work/1/s/src/Native/Unix/System.Native/pal_time.c, line 200.
./RunTests.sh: line 175: 51998 Abort trap: 6           (core dumped) "$RUNTIME_PATH/dotnet" xunit.console.dll System.Runtime.Extensions.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=nonnetcoreapptests -notrait category=nonosxtests -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing $RSP_FILE

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Good sleuthing @anipik

would it make sense to just right an interop for this function

I considered it, but this method is really just a compat implementation and performance here is not critical, and as such I preferred to just use the existing function that does a bit of unnecessary work rather than carry around additional code that also needs to be maintained.

Btw the assert error is due to the overflow that I mentioned

Great, that makes more sense. Thanks for tracking it down 😃

There are a couple of issues. The way we are using the interop here is not correct https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/AppDomain.Unix.cs#L14

The native function tells amount of cpu utilization by the process from the last recorded time(which could be previous call to this function or the process start time) to the current time. here the input cpuinfo ref is zero. We need to correct this implementation.

kernalTime  310000000
UserTime  3600000000
resolution  1000000000
timestamp  762054685492600
currentTime  1241063584
lastRecordedCurrentTime  0
lastRecordedKernelTime  0
lastRecordedUserTime  0
cpuTotalTime  1241063584
cpuTotalTime with processors  2482127168
cpuTotalTime  2482127168
cpuBusyTime  3910000000
ccpuUtilization  157
dotnet: /git/corefx/src/Native/Unix/System.Native/pal_time.c:215: int32_t SystemNative_GetCpuUtilization(ProcessCpuInformation *): Assertion `cpuUtilization >= 0 && cpuUtilization <= 100' failed.
Aborted

The other problem is an overflow problem https://github.com/dotnet/corefx/blob/master/src/Native/Unix/System.Native/pal_time.c#L172 the multiplication operation is leading to an overflow here.

We are using this code for polling in runtime. so we only care about difference there. The overflow code could be a recent bug as well.

@tannergooding can you take a look if you missed any scenario in your recent changes to this api ?