Compute resource manager
Compute resource manager API
HAP_compute_res.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------
2  Copyright (c) 2019-2020-2022,2024 QUALCOMM Technologies, Incorporated.
3  All Rights Reserved.
4  QUALCOMM Proprietary.
5 -----------------------------------------------------------------------------*/
6 
7 #ifndef HAP_COMPUTE_RES_H_
8 #define HAP_COMPUTE_RES_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
20 #define HAP_COMPUTE_RES_NOT_SUPPORTED 0x80000404
21 
22 #define HAP_COMPUTE_RES_MAX_NUM_THREADS 16
23 
32 typedef struct {
33  unsigned long long attributes[8];
35 
39 typedef struct {
40  unsigned int page_size;
41  unsigned int num_pages;
43 
47 typedef struct {
48  unsigned int block_size;
49  unsigned int page_list_len;
52 
56 typedef enum {
60 
64 typedef enum {
67 
71 #define HAP_COMPUTE_RES_COOPERATIVE_PREEMPTION 1
72 
77 #define HAP_COMPUTE_RES_AUTONOMOUS_PREEMPTION 2
78 
85 #define HAP_COMPUTE_RES_THREADS_FOR_AUTONOMOUS_PREEMPTION 4
86 
99 typedef enum {
111 
115 typedef struct {
116  void *mutex;
120  void (*lock)(void *mutex);
124  void (*unlock)(void *mutex);
129 
133 typedef struct {
134  unsigned int num_preemptions;
136  unsigned long long preempted_duration;
138  unsigned long long preemption_overhead;
141 
149 int __attribute__((weak)) compute_resource_attr_init(
150  compute_res_attr_t* attr);
151 
152 int __attribute__((weak)) compute_resource_attr_set_serialize(
153  compute_res_attr_t* attr,
154  unsigned char b_enable);
155 
156 int __attribute__((weak)) compute_resource_attr_set_hmx_param(
157  compute_res_attr_t* attr,
158  unsigned char b_enable);
159 
160 int __attribute__((weak)) compute_resource_attr_set_vtcm_param(
161  compute_res_attr_t* attr,
162  unsigned int vtcm_size,
163  unsigned char b_single_page);
164 
165 int __attribute__((weak)) compute_resource_attr_set_vtcm_param_v2(
166  compute_res_attr_t* attr,
167  unsigned int vtcm_size,
168  unsigned int min_page_size,
169  unsigned int min_vtcm_size);
170 
171 int __attribute__((weak)) compute_resource_attr_set_app_type(
172  compute_res_attr_t* attr,
173  unsigned int application_id);
174 
175 int __attribute__((weak)) compute_resource_attr_set_cache_mode(
176  compute_res_attr_t* attr,
177  unsigned char b_enable);
178 
179 int __attribute__((weak)) compute_resource_attr_set_release_callback(
180  compute_res_attr_t* attr,
181  int (*release_callback)(
182  unsigned int context_id,
183  void* client_context),
184  void* client_context);
185 
186 void* __attribute__((weak)) compute_resource_attr_get_vtcm_ptr(
187  compute_res_attr_t* attr);
188 
189 int __attribute__((weak)) compute_resource_attr_get_vtcm_ptr_v2(
190  compute_res_attr_t* attr,
191  void** vtcm_ptr,
192  unsigned int* vtcm_size);
193 
194 int __attribute__((weak)) compute_resource_query_VTCM(
195  unsigned int application_id,
196  unsigned int* total_block_size,
197  compute_res_vtcm_page_t* total_block_layout,
198  unsigned int* avail_block_size,
199  compute_res_vtcm_page_t* avail_block_layout);
200 
201 unsigned int __attribute__((weak)) compute_resource_acquire(
202  compute_res_attr_t* attr,
203  unsigned int timeout_us);
204 
205 int __attribute__((weak)) compute_resource_release(
206  unsigned int context_id);
207 
208 int __attribute__((weak)) compute_resource_acquire_cached(
209  unsigned int context_id,
210  unsigned int timeout_us);
211 
212 int __attribute__((weak)) compute_resource_release_cached(
213  unsigned int context_id);
214 
215 int __attribute__((weak)) compute_resource_hmx_lock(
216  unsigned int context_id);
217 
218 int __attribute__((weak)) compute_resource_hmx_unlock(
219  unsigned int context_id);
220 
221 int __attribute__((weak)) compute_resource_check_release_request(
222  unsigned int context_id);
223 
224 int __attribute__((weak)) compute_resource_hmx_lock2(
225  unsigned int context_id,
227 
228 int __attribute__((weak)) compute_resource_hmx_unlock2(
229  unsigned int context_id,
231 
232 int __attribute__((weak)) compute_resource_update_priority(
233  unsigned int context_id,
234  unsigned short priority);
235 
236 int __attribute__((weak)) crm_hmx_lock3(unsigned int context_id,
239  unsigned int timeout_us);
240 
241 int __attribute__((weak)) crm_hmx_unlock3(unsigned int context_id,
243  compute_res_hmx_mutex_t *mutex);
244 
245 int __attribute__ ((weak)) crm_attr_set_vtcm_backup(
246  compute_res_attr_t* attr,
247  void *buffer,
248  unsigned int buffer_size);
249 
250 int __attribute__ ((weak)) crm_attr_set_threads(
251  compute_res_attr_t* attr,
252  unsigned int *threads,
253  unsigned int num_threads);
254 
255 int __attribute__ ((weak)) crm_attr_set_vtcm_clear_on_release(
256  compute_res_attr_t* attr,
257  unsigned char enable);
258 
259 int __attribute__ ((weak)) crm_cached_set_threads(compute_res_threads_cmd_id command,
260  unsigned int context_id,
261  unsigned int *threads,
262  unsigned int num_threads);
263 
264 int __attribute__((weak)) crm_query_capability(compute_res_capability_id capability_id,
265  unsigned int* data);
266 
267 int __attribute__((weak)) crm_get_preempt_data(unsigned int context_id,
269 
270 int __attribute__((weak)) crm_tid_preemption_lock(void);
271 
272 int __attribute__((weak)) crm_tid_preemption_unlock(void);
298 {
299  if (compute_resource_attr_init)
300  return compute_resource_attr_init(attr);
301 
303 }
304 
331  compute_res_attr_t* attr,
332  unsigned char b_serialize)
333 {
334  if (compute_resource_attr_set_serialize)
335  {
336  return compute_resource_attr_set_serialize(attr,
337  b_serialize);
338  }
339 
341 }
342 
365  compute_res_attr_t* attr,
366  unsigned int vtcm_size,
367  unsigned char b_single_page)
368 {
369  if (compute_resource_attr_set_vtcm_param)
370  {
371  return compute_resource_attr_set_vtcm_param(attr,
372  vtcm_size,
373  b_single_page);
374  }
375 
377 }
378 
395 {
396  if (compute_resource_attr_get_vtcm_ptr)
397  {
398  return compute_resource_attr_get_vtcm_ptr(attr);
399  }
400 
401  return 0;
402 }
403 
431  compute_res_attr_t* attr,
432  unsigned int vtcm_size,
433  unsigned int min_page_size,
434  unsigned int min_vtcm_size)
435 {
436  if (compute_resource_attr_set_vtcm_param_v2)
437  {
438  return compute_resource_attr_set_vtcm_param_v2(attr,
439  vtcm_size,
440  min_page_size,
441  min_vtcm_size);
442  }
443 
445 }
446 
477  compute_res_attr_t* attr,
478  void *buffer,
479  unsigned int buffer_size)
480 {
481  if (crm_attr_set_vtcm_backup)
482  {
483  return crm_attr_set_vtcm_backup(attr, buffer, buffer_size);
484  }
485 
487 }
488 
515  compute_res_attr_t* attr,
516  unsigned int *threads,
517  unsigned int num_threads)
518 {
519  if (crm_attr_set_threads)
520  {
521  return crm_attr_set_threads(attr, threads, num_threads);
522  }
523 
525 }
526 
561  unsigned int context_id,
562  unsigned int *threads,
563  unsigned int num_threads)
564 {
565  if (crm_cached_set_threads)
566  {
567  return crm_cached_set_threads(command, context_id, threads, num_threads);
568  }
569 
571 }
572 
595  compute_res_attr_t* attr,
596  unsigned char enable)
597 {
598  if (crm_attr_set_vtcm_clear_on_release)
599  {
600  return crm_attr_set_vtcm_clear_on_release(attr, enable);
601  }
602 
604 }
605 
626  compute_res_attr_t* attr,
627  void** vtcm_ptr,
628  unsigned int* vtcm_size)
629 {
630  if (compute_resource_attr_get_vtcm_ptr_v2)
631  {
632  return compute_resource_attr_get_vtcm_ptr_v2(attr,
633  vtcm_ptr,
634  vtcm_size);
635  }
636 
638 }
639 
657  compute_res_attr_t* attr,
658  unsigned char b_enable)
659 {
660  if (compute_resource_attr_set_hmx_param)
661  {
662  return compute_resource_attr_set_hmx_param(attr,
663  b_enable);
664  }
665 
667 }
668 
699  compute_res_attr_t* attr,
700  unsigned char b_enable)
701 {
702  if (compute_resource_attr_set_cache_mode)
703  {
704  return compute_resource_attr_set_cache_mode(attr,
705  b_enable);
706  }
707 
709 }
710 
733  compute_res_attr_t* attr,
734  unsigned int application_id)
735 {
736  if (compute_resource_attr_set_app_type)
737  {
738  return compute_resource_attr_set_app_type(attr,
739  application_id);
740  }
741 
743 }
744 
775 static inline int HAP_compute_res_query_VTCM(
776  unsigned int application_id,
777  unsigned int* total_block_size,
778  compute_res_vtcm_page_t* total_block_layout,
779  unsigned int* avail_block_size,
780  compute_res_vtcm_page_t* avail_block_layout)
781 {
782  if (compute_resource_query_VTCM)
783  {
784  return compute_resource_query_VTCM(application_id,
785  total_block_size,
786  total_block_layout,
787  avail_block_size,
788  avail_block_layout);
789  }
790 
792 }
793 
828  unsigned int context_id)
829 {
830  if (compute_resource_check_release_request)
831  {
832  return compute_resource_check_release_request(context_id);
833  }
834 
836 }
837 
854 static inline unsigned int HAP_compute_res_acquire(
855  compute_res_attr_t* attr,
856  unsigned int timeout_us)
857 {
858  if (compute_resource_acquire)
859  {
860  return compute_resource_acquire(attr, timeout_us);
861  }
862 
863  return 0;
864 }
865 
879 static inline int HAP_compute_res_release(unsigned int context_id)
880 {
881  if (compute_resource_release)
882  {
883  return compute_resource_release(context_id);
884  }
885 
887 }
888 
908  unsigned int context_id,
909  unsigned int timeout_us)
910 {
911  if (compute_resource_acquire_cached)
912  {
913  return compute_resource_acquire_cached(context_id, timeout_us);
914  }
915 
917 }
918 
935 static inline int HAP_compute_res_release_cached(unsigned int context_id)
936 {
937  if (compute_resource_release_cached)
938  {
939  return compute_resource_release_cached(context_id);
940  }
941 
943 }
944 
975  compute_res_attr_t* attr,
976  int (*release_callback)(
977  unsigned int context_id,
978  void* client_context),
979  void* client_context)
980 {
981  if (compute_resource_attr_set_release_callback)
982  {
983  return compute_resource_attr_set_release_callback(attr,
984  release_callback,
985  client_context);
986  }
987 
989 }
990 
1018 static inline int HAP_compute_res_update_priority(unsigned int context_id,
1019  unsigned short priority)
1020 {
1021  if (compute_resource_update_priority)
1022  {
1023  return compute_resource_update_priority(context_id, priority);
1024  }
1025 
1027 }
1028 
1075 {
1076  if (crm_tid_preemption_lock)
1077  {
1078  return crm_tid_preemption_lock();
1079  }
1080 
1082 }
1083 
1094 {
1095  if (crm_tid_preemption_unlock)
1096  {
1097  return crm_tid_preemption_unlock();
1098  }
1099 
1101 }
1102 
1130  unsigned int* data)
1131 {
1132  if (crm_query_capability)
1133  {
1134  return crm_query_capability(capability_id, data);
1135  }
1136 
1138 }
1139 
1158 static inline int HAP_compute_res_get_preempt_data(unsigned int context_id,
1160 {
1161  if (crm_get_preempt_data)
1162  {
1163  return crm_get_preempt_data(context_id, data);
1164  }
1165 
1167 }
1168 
1201 static inline int HAP_compute_res_hmx_lock(unsigned int context_id)
1202 {
1203  if (compute_resource_hmx_lock)
1204  {
1205  return compute_resource_hmx_lock(context_id);
1206  }
1207 
1209 }
1210 
1228 static inline int HAP_compute_res_hmx_unlock(unsigned int context_id)
1229 {
1230  if (compute_resource_hmx_unlock)
1231  {
1232  return compute_resource_hmx_unlock(context_id);
1233  }
1234 
1236 }
1237 
1264 static inline int HAP_compute_res_hmx_lock2(unsigned int context_id,
1266 {
1267  if (compute_resource_hmx_lock2)
1268  {
1269  return compute_resource_hmx_lock2(context_id, type);
1270  }
1271 
1273 }
1274 
1294 static inline int HAP_compute_res_hmx_unlock2(unsigned int context_id,
1296 {
1297  if (compute_resource_hmx_unlock2)
1298  {
1299  return compute_resource_hmx_unlock2(context_id, type);
1300  }
1301 
1303 }
1304 
1362 static inline int HAP_compute_res_hmx_lock3(unsigned int context_id,
1364  compute_res_hmx_mutex_t *hmx_mutex,
1365  unsigned int timeout_us)
1366 {
1367  if (crm_hmx_lock3)
1368  {
1369  return crm_hmx_lock3(context_id, type, hmx_mutex, timeout_us);
1370  }
1371 
1373 }
1374 
1394 static inline int HAP_compute_res_hmx_unlock3(unsigned int context_id,
1396  compute_res_hmx_mutex_t *hmx_mutex)
1397 {
1398  if (crm_hmx_unlock3)
1399  {
1400  return crm_hmx_unlock3(context_id, type, hmx_mutex);
1401  }
1402 
1404 }
1405 
1410 #ifdef __cplusplus
1411 }
1412 #endif
1413 
1414 #endif //HAP_COMPUTE_RES_H_
unsigned int num_preemptions
Definition: HAP_compute_res.h:134
unsigned int num_pages
Definition: HAP_compute_res.h:41
void * mutex
Definition: HAP_compute_res.h:116
Definition: HAP_compute_res.h:39
Definition: HAP_compute_res.h:57
static int HAP_compute_res_attr_set_vtcm_backup(compute_res_attr_t *attr, void *buffer, unsigned int buffer_size)
Definition: HAP_compute_res.h:476
static int HAP_compute_res_hmx_lock2(unsigned int context_id, compute_res_hmx_type_t type)
Definition: HAP_compute_res.h:1264
unsigned long long preemption_overhead
Definition: HAP_compute_res.h:138
unsigned int block_size
Definition: HAP_compute_res.h:48
static int HAP_compute_res_cached_set_threads(compute_res_threads_cmd_id command, unsigned int context_id, unsigned int *threads, unsigned int num_threads)
Definition: HAP_compute_res.h:560
Definition: HAP_compute_res.h:102
Definition: HAP_compute_res.h:115
unsigned int page_list_len
Definition: HAP_compute_res.h:49
static unsigned int HAP_compute_res_acquire(compute_res_attr_t *attr, unsigned int timeout_us)
Definition: HAP_compute_res.h:854
static int HAP_compute_res_update_priority(unsigned int context_id, unsigned short priority)
Definition: HAP_compute_res.h:1018
static int HAP_compute_res_hmx_lock(unsigned int context_id)
Definition: HAP_compute_res.h:1201
static int HAP_compute_res_tid_preemption_lock(void)
Definition: HAP_compute_res.h:1074
static void * HAP_compute_res_attr_get_vtcm_ptr(compute_res_attr_t *attr)
Definition: HAP_compute_res.h:394
Definition: HAP_compute_res.h:58
static int HAP_compute_res_attr_set_serialize(compute_res_attr_t *attr, unsigned char b_serialize)
Definition: HAP_compute_res.h:330
Definition: HAP_compute_res.h:106
static int HAP_compute_res_hmx_lock3(unsigned int context_id, compute_res_hmx_type_t type, compute_res_hmx_mutex_t *hmx_mutex, unsigned int timeout_us)
Definition: HAP_compute_res.h:1362
static int HAP_compute_res_attr_set_release_callback(compute_res_attr_t *attr, int(*release_callback)(unsigned int context_id, void *client_context), void *client_context)
Definition: HAP_compute_res.h:974
static int HAP_compute_res_attr_set_threads(compute_res_attr_t *attr, unsigned int *threads, unsigned int num_threads)
Definition: HAP_compute_res.h:514
#define HAP_COMPUTE_RES_NOT_SUPPORTED
Definition: HAP_compute_res.h:20
static int HAP_compute_res_get_preempt_data(unsigned int context_id, compute_res_preempt_data_t *data)
Definition: HAP_compute_res.h:1158
static int HAP_compute_res_attr_get_vtcm_ptr_v2(compute_res_attr_t *attr, void **vtcm_ptr, unsigned int *vtcm_size)
Definition: HAP_compute_res.h:625
Definition: HAP_compute_res.h:65
static int HAP_compute_res_release_cached(unsigned int context_id)
Definition: HAP_compute_res.h:935
Definition: HAP_compute_res.h:47
static int HAP_compute_res_attr_set_vtcm_clear_on_release(compute_res_attr_t *attr, unsigned char enable)
Definition: HAP_compute_res.h:594
static int HAP_compute_res_attr_init(compute_res_attr_t *attr)
Definition: HAP_compute_res.h:297
static int HAP_compute_res_attr_set_vtcm_param(compute_res_attr_t *attr, unsigned int vtcm_size, unsigned char b_single_page)
Definition: HAP_compute_res.h:364
static int HAP_compute_res_attr_set_hmx_param(compute_res_attr_t *attr, unsigned char b_enable)
Definition: HAP_compute_res.h:656
static int HAP_compute_res_attr_set_app_type(compute_res_attr_t *attr, unsigned int application_id)
Definition: HAP_compute_res.h:732
Definition: HAP_compute_res.h:133
static int HAP_compute_res_attr_set_cache_mode(compute_res_attr_t *attr, unsigned char b_enable)
Definition: HAP_compute_res.h:698
compute_res_threads_cmd_id
Definition: HAP_compute_res.h:99
static int HAP_compute_res_hmx_unlock2(unsigned int context_id, compute_res_hmx_type_t type)
Definition: HAP_compute_res.h:1294
Definition: HAP_compute_res.h:32
static int HAP_compute_res_query_capability(compute_res_capability_id capability_id, unsigned int *data)
Definition: HAP_compute_res.h:1129
compute_res_hmx_type_t
Definition: HAP_compute_res.h:56
static int HAP_compute_res_hmx_unlock(unsigned int context_id)
Definition: HAP_compute_res.h:1228
static int HAP_compute_res_hmx_unlock3(unsigned int context_id, compute_res_hmx_type_t type, compute_res_hmx_mutex_t *hmx_mutex)
Definition: HAP_compute_res.h:1394
static int HAP_compute_res_query_VTCM(unsigned int application_id, unsigned int *total_block_size, compute_res_vtcm_page_t *total_block_layout, unsigned int *avail_block_size, compute_res_vtcm_page_t *avail_block_layout)
Definition: HAP_compute_res.h:775
static int HAP_compute_res_release(unsigned int context_id)
Definition: HAP_compute_res.h:879
unsigned int page_size
Definition: HAP_compute_res.h:40
static int HAP_compute_res_check_release_request(unsigned int context_id)
Definition: HAP_compute_res.h:827
unsigned long long preempted_duration
Definition: HAP_compute_res.h:136
compute_res_capability_id
Definition: HAP_compute_res.h:64
Definition: HAP_compute_res.h:100
static int HAP_compute_res_acquire_cached(unsigned int context_id, unsigned int timeout_us)
Definition: HAP_compute_res.h:907
static int HAP_compute_res_attr_set_vtcm_param_v2(compute_res_attr_t *attr, unsigned int vtcm_size, unsigned int min_page_size, unsigned int min_vtcm_size)
Definition: HAP_compute_res.h:430
static int HAP_compute_res_tid_preemption_unlock(void)
Definition: HAP_compute_res.h:1093