PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/base/Applications/Tests/ClockTest/ClockTest.cs

#
C# | 89 lines | 63 code | 17 blank | 9 comment | 4 complexity | a491ea0c6ad22a0600e70b68d0662598 MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Research Singularity
  4. //
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. // Note: Simple Singularity test program.
  8. //
  9. using System;
  10. using Microsoft.Singularity.V1.Services;
  11. using Microsoft.Singularity.Channels;
  12. using Microsoft.Contracts;
  13. using Microsoft.SingSharp.Reflection;
  14. using Microsoft.Singularity.Applications;
  15. using Microsoft.Singularity.Io;
  16. using Microsoft.Singularity.Configuration;
  17. [assembly: Transform(typeof(ApplicationResourceTransform))]
  18. namespace Microsoft.Singularity.Applications
  19. {
  20. [ConsoleCategory(DefaultAction=true)]
  21. internal class Parameters {
  22. [InputEndpoint("data")]
  23. public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
  24. [OutputEndpoint("data")]
  25. public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
  26. reflective internal Parameters();
  27. internal int AppMain() {
  28. return ClockTest.AppMain(this);
  29. }
  30. }
  31. public class ClockTest
  32. {
  33. //[ShellCommand("clocktest", "Run clock test")]
  34. internal static int AppMain(Parameters! config)
  35. {
  36. Console.WriteLine("CPU TSC as reference for delay yields:");
  37. for (uint divisor = 512; divisor > 0; divisor >>= 1) {
  38. ulong deltaTSC = (ulong) (ProcessService.GetCyclesPerSecond() / divisor);
  39. long endKernelTicks = 0;
  40. ulong endTSC;
  41. long startKernelTicks = ProcessService.GetUpTime().Ticks;
  42. ulong startTSC = (ulong) (ProcessService.GetCycleCount());
  43. ulong finalTSC = startTSC + deltaTSC;
  44. do {
  45. endKernelTicks = ProcessService.GetUpTime().Ticks;
  46. endTSC = (ulong) (ProcessService.GetCycleCount());
  47. } while (endTSC < finalTSC);
  48. long usKernel = (endKernelTicks - startKernelTicks) / 10;
  49. ulong usTSC = 1000000u * (endTSC - startTSC) / (ulong) (ProcessService.GetCyclesPerSecond());
  50. Console.Write(" Target {0,7} us TSC {1,7} us HW {2,7} us\n",
  51. 1000000 / divisor, (int)usTSC, (int)usKernel);
  52. }
  53. Console.WriteLine("\nHW Clock as reference for delay yields:");
  54. for (uint divisor = 512; divisor > 0; divisor >>= 1) {
  55. long endKernelTicks = 0;
  56. ulong endTSC;
  57. long startKernelTicks = ProcessService.GetUpTime().Ticks;
  58. ulong startTSC = (ulong) (ProcessService.GetCycleCount());
  59. long finalKernelTicks = startKernelTicks + 10000000 / divisor;
  60. do {
  61. endKernelTicks = ProcessService.GetUpTime().Ticks;
  62. endTSC = (ulong) (ProcessService.GetCycleCount());
  63. } while (endKernelTicks < finalKernelTicks);
  64. long usKernel = (endKernelTicks - startKernelTicks) / 10;
  65. ulong usTSC = 1000000u * (endTSC - startTSC) / (ulong) (ProcessService.GetCyclesPerSecond());
  66. Console.Write(" Target {0,7} us TSC {1,7} us HW {2,7} us\n",
  67. 1000000 / divisor, (int)usTSC, (int)usKernel);
  68. }
  69. return 0;
  70. }
  71. }
  72. }