ittnotify-zca.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (C) 2005-2019 Intel Corporation
  3. SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
  4. */
  5. /**
  6. * Zero Cost Annotations (ZCA)
  7. *
  8. * Intel Compiler supports two intrinsics that could be used for code annotations
  9. * without incurring significant run-time costs when the tools are not in use.
  10. * Each annotation is more than a mere mark in the instruction stream.
  11. * It can accept an expression argument like a call to a routine does.
  12. * There are two forms of the intrinsic, with the following signatures:
  13. *
  14. * extern "C" void __notify_intrinsic( const char *annotation, const volatile void *tag);
  15. * extern "C" void __notify_zc_intrinsic(const char *annotation, const volatile void *tag);
  16. *
  17. * The string annotation must be a compile-time constant. It specifies the type of the annotation.
  18. * The pointer tag is computed at run time. It specifies the data associated with the annotation.
  19. * Each intrinsic implies a compiler fence: the compiler must not move any memory
  20. * operation across it. The reason for this restriction is that annotation might denote an
  21. * event that must be precisely placed with respect to memory operations.
  22. *
  23. * The difference between the two intrinsics is that __notify_intrinsic must leave a
  24. * probe-ready instruction sequence in the instruction stream where the instrinsic
  25. * occurs. The __notify_zc_intrinsic does not leave such a sequence, and hence is closer to "zero cost".
  26. **/
  27. #pragma once
  28. #include "ittnotify.h"
  29. #ifndef INTEL_NO_ITTNOTIFY_API
  30. #if (defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)) && (ITT_PLATFORM == ITT_PLATFORM_WIN || ITT_PLATFORM == ITT_PLATFORM_POSIX)
  31. #define ITT_ENABLE_LOW_OVERHEAD_ANNOTATIONS
  32. #else
  33. #error Zero cost (low overhead) annotations are not supported on this platform
  34. #endif
  35. #endif
  36. /**
  37. * Zero cost annotations for memory allocation and deallocation
  38. **/
  39. #ifdef ITT_ENABLE_LOW_OVERHEAD_ANNOTATIONS
  40. #pragma pack(push, 1)
  41. typedef struct ___itt_zca_allocation_info {
  42. size_t size; /*!< Size of allocated memory */
  43. void** ptr; /*!< Pointer to allocated memory pointer */
  44. int initialized; /*!< Is allocated memory initialized */
  45. } __itt_zca_allocation_info;
  46. #pragma pack(pop)
  47. #define __itt_zca_mem_allocate_begin() __notify_intrinsic((char*)"mem_allocate_begin", 0)
  48. #define __itt_zca_mem_allocate_end(ptr, size, init) { __itt_zca_allocation_info __itt_zca_alloc_info = { size, ptr, init }; __notify_intrinsic((char*)"mem_allocate_end", (void*)&__itt_zca_alloc_info); }
  49. #define __itt_zca_mem_free_begin(ptr) __notify_intrinsic((char*)"mem_free_begin", (void*)ptr)
  50. #define __itt_zca_mem_free_end() __notify_intrinsic((char*)"mem_free_end", 0)
  51. #else
  52. #define __itt_zca_mem_allocate_begin()
  53. #define __itt_zca_mem_allocate_end(ptr, size, init)
  54. #define __itt_zca_mem_free_begin(ptr)
  55. #define __itt_zca_mem_free_end()
  56. #endif
  57. /**
  58. * Zero cost annotations for threading
  59. **/
  60. #ifdef ITT_ENABLE_LOW_OVERHEAD_ANNOTATIONS
  61. #define __itt_zca_suppress_push(id) __notify_zc_intrinsic((char*)"__itt_suppress_push", (void*)id);
  62. #define __itt_zca_suppress_pop(id) __notify_zc_intrinsic((char*)"__itt_suppress_pop", (void*)id);
  63. #define __itt_zca_sync_create(id) __notify_zc_intrinsic((char*)"__itt_sync_create", (void*)id)
  64. #define __itt_zca_sync_acquired(id) __notify_zc_intrinsic((char*)"__itt_sync_acquired", (void*)id)
  65. #define __itt_zca_sync_releasing(id) __notify_zc_intrinsic((char*)"__itt_sync_releasing", (void*)id)
  66. #define __itt_zca_sync_destroy(id) __notify_zc_intrinsic((char*)"__itt_sync_destroy", (void*)id)
  67. #else
  68. #define __itt_zca_suppress_push(id)
  69. #define __itt_zca_suppress_pop(id)
  70. #define __itt_zca_sync_create(id)
  71. #define __itt_zca_sync_acquired(id)
  72. #define __itt_zca_sync_releasing(id)
  73. #define __itt_zca_sync_destroy(id)
  74. #endif