The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipc: Create dedicated ipc_shared_memory for each client

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2576>

authored by

E1int and committed by
Marge Bot
ba579e4a d85ca13d

+48 -19
+20 -2
src/xrt/ipc/server/ipc_server.h
··· 157 157 struct xrt_device **plane_detection_xdev; 158 158 159 159 int server_thread_index; 160 + 161 + xrt_shmem_handle_t ism_handle; 160 162 }; 161 163 162 164 enum ipc_thread_state ··· 363 365 struct ipc_device idevs[XRT_SYSTEM_MAX_DEVICES]; 364 366 struct xrt_tracking_origin *xtracks[XRT_SYSTEM_MAX_DEVICES]; 365 367 366 - struct ipc_shared_memory *ism; 367 - xrt_shmem_handle_t ism_handle; 368 + struct ipc_shared_memory *isms[IPC_MAX_CLIENTS]; 368 369 369 370 struct ipc_server_mainloop ml; 370 371 ··· 530 531 return &ics->server->idevs[device_id]; 531 532 } 532 533 534 + /*! 535 + * Get the data in the shared memory of the given client. 536 + */ 537 + static inline struct ipc_shared_memory * 538 + get_ism(volatile struct ipc_client_state *ics) 539 + { 540 + return ics->server->isms[ics->server_thread_index]; 541 + } 542 + 543 + /*! 544 + * Get the handle for the shared memory of the given client. 545 + */ 546 + static inline xrt_shmem_handle_t 547 + get_ism_handle(volatile struct ipc_client_state *ics) 548 + { 549 + return ics->ism_handle; 550 + } 533 551 534 552 #ifdef __cplusplus 535 553 }
+6 -6
src/xrt/ipc/server/ipc_server_handler.c
··· 301 301 302 302 assert(max_handle_capacity >= 1); 303 303 304 - out_handles[0] = ics->server->ism_handle; 304 + out_handles[0] = get_ism_handle(ics); 305 305 *out_handle_count = 1; 306 306 307 307 return XRT_SUCCESS; ··· 1326 1326 return XRT_ERROR_IPC_SESSION_NOT_CREATED; 1327 1327 } 1328 1328 1329 - struct ipc_shared_memory *ism = ics->server->ism; 1329 + struct ipc_shared_memory *ism = get_ism(ics); 1330 1330 struct ipc_layer_slot *slot = &ism->slots[slot_id]; 1331 1331 xrt_graphics_sync_handle_t sync_handle = XRT_GRAPHICS_SYNC_HANDLE_INVALID; 1332 1332 ··· 1394 1394 1395 1395 struct xrt_compositor_semaphore *xcsem = ics->xcsems[semaphore_id]; 1396 1396 1397 - struct ipc_shared_memory *ism = ics->server->ism; 1397 + struct ipc_shared_memory *ism = get_ism(ics); 1398 1398 struct ipc_layer_slot *slot = &ism->slots[slot_id]; 1399 1399 1400 1400 // Copy current slot data. ··· 1863 1863 { 1864 1864 // To make the code a bit more readable. 1865 1865 uint32_t device_id = id; 1866 - struct ipc_shared_memory *ism = ics->server->ism; 1866 + struct ipc_shared_memory *ism = get_ism(ics); 1867 1867 struct ipc_device *idev = get_idev(ics, device_id); 1868 1868 struct xrt_device *xdev = idev->xdev; 1869 1869 struct ipc_shared_device *isdev = &ism->isdevs[device_id]; ··· 1903 1903 static struct xrt_input * 1904 1904 find_input(volatile struct ipc_client_state *ics, uint32_t device_id, enum xrt_input_name name) 1905 1905 { 1906 - struct ipc_shared_memory *ism = ics->server->ism; 1906 + struct ipc_shared_memory *ism = get_ism(ics); 1907 1907 struct ipc_shared_device *isdev = &ism->isdevs[device_id]; 1908 1908 struct xrt_input *io = &ism->inputs[isdev->first_input_index]; 1909 1909 ··· 2104 2104 ics->plane_detection_size = new_count; 2105 2105 } 2106 2106 2107 - struct xrt_plane_detector_begin_info_ext *begin_info = &ics->server->ism->plane_begin_info_ext; 2107 + struct xrt_plane_detector_begin_info_ext *begin_info = &get_ism(ics)->plane_begin_info_ext; 2108 2108 2109 2109 enum xrt_result xret = 2110 2110 xrt_device_begin_plane_detection_ext(xdev, begin_info, plane_detection_id, out_plane_detection_id);
+5
src/xrt/ipc/server/ipc_server_per_client_thread.c
··· 11 11 #include "util/u_misc.h" 12 12 #include "util/u_trace_marker.h" 13 13 14 + #include "shared/ipc_protocol.h" 15 + #include "shared/ipc_shmem.h" 14 16 #include "shared/ipc_utils.h" 15 17 #include "server/ipc_server.h" 16 18 #include "ipc_server_generated.h" ··· 69 71 os_mutex_lock(&ics->server->global_state.lock); 70 72 71 73 ipc_message_channel_close((struct ipc_message_channel *)&ics->imc); 74 + 75 + ipc_shmem_destroy((xrt_shmem_handle_t *)&ics->ism_handle, (void **)&ics->server->isms[ics->server_thread_index], 76 + sizeof(struct ipc_shared_memory)); 72 77 73 78 ics->server->threads[ics->server_thread_index].state = IPC_THREAD_STOPPING; 74 79 ics->server_thread_index = -1;
+17 -11
src/xrt/ipc/server/ipc_server_process.c
··· 30 30 31 31 #include "util/u_git_tag.h" 32 32 33 + #include "shared/ipc_protocol.h" 33 34 #include "shared/ipc_shmem.h" 34 35 #include "server/ipc_server.h" 35 36 #include "server/ipc_server_interface.h" ··· 209 210 210 211 u_process_destroy(s->process); 211 212 212 - ipc_shmem_destroy(&s->ism_handle, (void **)&s->ism, sizeof(struct ipc_shared_memory)); 213 - 214 213 // Destroyed last. 215 214 os_mutex_destroy(&s->global_state.lock); 216 215 } ··· 281 280 } 282 281 283 282 XRT_CHECK_RESULT static xrt_result_t 284 - init_shm(struct ipc_server *s) 283 + init_shm(struct ipc_server *s, volatile struct ipc_client_state *cs) 285 284 { 286 285 const size_t size = sizeof(struct ipc_shared_memory); 287 286 xrt_shmem_handle_t handle; 288 287 289 - xrt_result_t xret = ipc_shmem_create(size, &handle, (void **)&s->ism); 288 + xrt_result_t xret = ipc_shmem_create(size, &handle, (void **)&s->isms[cs->server_thread_index]); 290 289 IPC_CHK_AND_RET(s, xret, "ipc_shmem_create"); 291 290 292 291 // we have a filehandle, we will pass this to our client 293 - s->ism_handle = handle; 292 + cs->ism_handle = handle; 294 293 295 294 296 295 /* ··· 300 299 */ 301 300 302 301 uint32_t count = 0; 303 - struct ipc_shared_memory *ism = s->ism; 302 + struct ipc_shared_memory *ism = s->isms[cs->server_thread_index]; 304 303 305 304 ism->startup_timestamp = os_monotonic_get_ns(); 306 305 ··· 418 417 ism->hmd.blend_mode_count = s->xsysd->static_roles.head->hmd->blend_mode_count; 419 418 420 419 // Finally tell the client how many devices we have. 421 - s->ism->isdev_count = count; 420 + ism->isdev_count = count; 422 421 423 422 // Assign all of the roles. 424 423 ism->roles.head = find_xdev_index(s, s->xsysd->static_roles.head); ··· 433 432 #undef SET_HT_ROLE 434 433 435 434 // Fill out git version info. 436 - snprintf(s->ism->u_git_tag, IPC_VERSION_NAME_LEN, "%s", u_git_tag); 435 + snprintf(ism->u_git_tag, IPC_VERSION_NAME_LEN, "%s", u_git_tag); 437 436 438 437 return XRT_SUCCESS; 439 438 } ··· 496 495 // Always succeeds. 497 496 init_idevs(s); 498 497 init_tracking_origins(s); 499 - 500 - xret = init_shm(s); 501 - IPC_CHK_WITH_GOTO(s, xret, "init_shm", error); 502 498 503 499 ret = ipc_server_mainloop_init(&s->ml); 504 500 if (ret < 0) { ··· 958 954 ics->plane_detection_count = 0; 959 955 ics->plane_detection_ids = NULL; 960 956 ics->plane_detection_xdev = NULL; 957 + 958 + xrt_result_t xret = init_shm(vs, ics); 959 + if (xret != XRT_SUCCESS) { 960 + 961 + // Unlock when we are done. 962 + os_mutex_unlock(&vs->global_state.lock); 963 + 964 + U_LOG_E("Failed to allocate shared memory!"); 965 + return; 966 + } 961 967 962 968 os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics); 963 969