Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

librm_test.c 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * Real mode transition self-tests
  23. *
  24. * This file allows for easy measurement of the time taken to perform
  25. * real mode transitions, which may have a substantial overhead when
  26. * running under a hypervisor.
  27. *
  28. */
  29. /* Forcibly enable assertions */
  30. #undef NDEBUG
  31. #include <ipxe/test.h>
  32. #include <ipxe/profile.h>
  33. #include <realmode.h>
  34. /** Number of sample iterations for profiling */
  35. #define PROFILE_COUNT 4096
  36. /** Protected-to-real mode transition profiler */
  37. static struct profiler p2r_profiler __profiler = { .name = "p2r" };
  38. /** Real-to-protected mode transition profiler */
  39. static struct profiler r2p_profiler __profiler = { .name = "r2p" };
  40. /**
  41. * Perform real mode transition self-tests
  42. *
  43. */
  44. static void librm_test_exec ( void ) {
  45. unsigned int i;
  46. unsigned long timestamp;
  47. unsigned int discard_d;
  48. /* Profile mode transitions. We want to profile each
  49. * direction of the transition separately, so perform an RDTSC
  50. * while in real mode and tweak the profilers' start/stop
  51. * times appropriately.
  52. */
  53. for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
  54. profile_start ( &p2r_profiler );
  55. __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
  56. : "=a" ( timestamp ), "=d" ( discard_d )
  57. : );
  58. profile_start_at ( &r2p_profiler, timestamp );
  59. profile_stop ( &r2p_profiler );
  60. profile_stop_at ( &p2r_profiler, timestamp );
  61. }
  62. }
  63. /** Real mode transition self-test */
  64. struct self_test librm_test __self_test = {
  65. .name = "librm",
  66. .exec = librm_test_exec,
  67. };
  68. REQUIRE_OBJECT ( test );