1 /* 2 Copyright (c) 2023 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef _TBB_tcm_H 18 #define _TBB_tcm_H 19 20 #include <stdint.h> 21 #include <stdbool.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 // Support for the TCM API return value 28 29 typedef enum _tcm_result_t { 30 TCM_RESULT_SUCCESS = 0x0, 31 TCM_RESULT_ERROR_INVALID_ARGUMENT = 0x78000004, 32 TCM_RESULT_ERROR_UNKNOWN = 0x7ffffffe 33 } tcm_result_t; 34 35 // Support for permit states 36 37 enum tcm_permit_states_t { 38 TCM_PERMIT_STATE_VOID, 39 TCM_PERMIT_STATE_INACTIVE, 40 TCM_PERMIT_STATE_PENDING, 41 TCM_PERMIT_STATE_IDLE, 42 TCM_PERMIT_STATE_ACTIVE 43 }; 44 45 typedef uint8_t tcm_permit_state_t; 46 47 // Support for permit flags 48 49 typedef struct _tcm_permit_flags_t { 50 uint32_t stale : 1; 51 uint32_t rigid_concurrency : 1; 52 uint32_t exclusive : 1; 53 uint32_t reserved : 29; 54 } tcm_permit_flags_t; 55 56 typedef struct _tcm_callback_flags_t { 57 uint32_t new_concurrency : 1; 58 uint32_t new_state : 1; 59 uint32_t reserved : 30; 60 } tcm_callback_flags_t; 61 62 // Support for cpu masks 63 64 struct hwloc_bitmap_s; 65 typedef struct hwloc_bitmap_s* hwloc_bitmap_t; 66 typedef hwloc_bitmap_t tcm_cpu_mask_t; 67 68 // Support for ids 69 70 typedef uint64_t tcm_client_id_t; 71 72 // Support for permits 73 74 typedef struct _tcm_permit_t { 75 uint32_t* concurrencies; 76 tcm_cpu_mask_t* cpu_masks; 77 uint32_t size; 78 tcm_permit_state_t state; 79 tcm_permit_flags_t flags; 80 } tcm_permit_t; 81 82 // Support for permit handle 83 84 typedef struct tcm_permit_rep_t* tcm_permit_handle_t; 85 86 // Support for constraints 87 88 typedef int32_t tcm_numa_node_t; 89 typedef int32_t tcm_core_type_t; 90 91 const int8_t tcm_automatic = -1; 92 const int8_t tcm_any = -2; 93 94 #define TCM_PERMIT_REQUEST_CONSTRAINTS_INITIALIZER {tcm_automatic, tcm_automatic, NULL, \ 95 tcm_automatic, tcm_automatic, tcm_automatic} 96 97 typedef struct _tcm_cpu_constraints_t { 98 int32_t min_concurrency; 99 int32_t max_concurrency; 100 tcm_cpu_mask_t mask; 101 tcm_numa_node_t numa_id; 102 tcm_core_type_t core_type_id; 103 int32_t threads_per_core; 104 } tcm_cpu_constraints_t; 105 106 // Support for priorities 107 108 enum tcm_request_priorities_t { 109 TCM_REQUEST_PRIORITY_LOW = (INT32_MAX / 4) * 1, 110 TCM_REQUEST_PRIORITY_NORMAL = (INT32_MAX / 4) * 2, 111 TCM_REQUEST_PRIORITY_HIGH = (INT32_MAX / 4) * 3 112 }; 113 114 typedef int32_t tcm_request_priority_t; 115 116 // Support for requests 117 118 #define TCM_PERMIT_REQUEST_INITIALIZER {tcm_automatic, tcm_automatic, \ 119 NULL, 0, TCM_REQUEST_PRIORITY_NORMAL, {}, {}} 120 121 typedef struct _tcm_permit_request_t { 122 int32_t min_sw_threads; 123 int32_t max_sw_threads; 124 tcm_cpu_constraints_t* cpu_constraints; 125 uint32_t constraints_size; 126 tcm_request_priority_t priority; 127 tcm_permit_flags_t flags; 128 char reserved[4]; 129 } tcm_permit_request_t; 130 131 // Support for client callback 132 133 typedef tcm_result_t (*tcm_callback_t)(tcm_permit_handle_t p, void* callback_arg, tcm_callback_flags_t); 134 135 #if _WIN32 136 #define __TCM_EXPORT __declspec(dllexport) 137 #else 138 #define __TCM_EXPORT 139 #endif 140 141 142 __TCM_EXPORT tcm_result_t tcmConnect(tcm_callback_t callback, 143 tcm_client_id_t *client_id); 144 __TCM_EXPORT tcm_result_t tcmDisconnect(tcm_client_id_t client_id); 145 146 __TCM_EXPORT tcm_result_t tcmRequestPermit(tcm_client_id_t client_id, 147 tcm_permit_request_t request, 148 void* callback_arg, 149 tcm_permit_handle_t* permit_handle, 150 tcm_permit_t* permit); 151 152 __TCM_EXPORT tcm_result_t tcmGetPermitData(tcm_permit_handle_t permit_handle, 153 tcm_permit_t* permit); 154 155 __TCM_EXPORT tcm_result_t tcmReleasePermit(tcm_permit_handle_t permit); 156 157 __TCM_EXPORT tcm_result_t tcmIdlePermit(tcm_permit_handle_t permit_handle); 158 159 __TCM_EXPORT tcm_result_t tcmDeactivatePermit(tcm_permit_handle_t permit_handle); 160 161 __TCM_EXPORT tcm_result_t tcmActivatePermit(tcm_permit_handle_t permit_handle); 162 163 __TCM_EXPORT tcm_result_t tcmRegisterThread(tcm_permit_handle_t permit_handle); 164 165 __TCM_EXPORT tcm_result_t tcmUnregisterThread(); 166 167 __TCM_EXPORT tcm_result_t tcmGetVersionInfo(char* buffer, uint32_t buffer_size); 168 169 #ifdef __cplusplus 170 } // extern "C" 171 #endif 172 173 #endif /* _TBB_tcm_H */ 174