Hello,
The library uses no explicit thread-safe design - and has not been tested in a multi-threaded program. I have conducted a brief review and have the following comments.
The majority of decode objects do not store any data in static variables - all data is private and local to each object, with the following exceptions:
1) When using the C API, the C++ objects created when calling decoder instance creation and destruction API calls, are saved into a statically declared map. Any multi-threaded application using C-API should ensure that decoder creation and initialisation is appropriately protected by mutex etc, to ensure that decoder instances are not created in parallel.
2) The opcode analyser used in trace decode, is not a C++ object and has a pair of static variables used while decoding. This design would need a minor revision to enable thread safe operation.
3) The packet printing objects use a couple of static arrays to build output strings. These objects are not essential to the correct use of the decoder, so may not be needed by an application. Otherwise this needs addressing too.
Looking at your design - keeping decode tree handle instances and contexts separate on a per thread basis looks sound - assuming each thread is decoding a trace stream from a different source.
Again, I stress that this has not been tested in a multi-threaded environment, but I would be happy to discuss any issues that might arise.
Regards
Mike
On Tue, 28 Apr 2020 at 20:32, subhasish Karmakar subhasish.k2301@gmail.com wrote:
Hello, Can anybody tell whether OpenCSD library is thread safe? I have given example code in my earlier email.
I appritiate your help. Thank you.
On Mon, Apr 20, 2020 at 3:41 PM subhasish Karmakar subhasish.k2301@gmail.com wrote:
Hi,
Can I use OpenCSD library in a Multi-Threaded application? I maintain decode tree handle per thread.
Code Example:/********* Initialization code *********/
//dcdtree_handle_ and p_context is maintained per thread dcdtree_handle_ = ocsd_create_dcd_tree(OCSD_TRC_SRC_FRAME_FORMATTED, OCSD_DFRMTR_FRAME_MEM_ALIGN);
ret = ocsd_dt_create_decoder(dcdtree_handle_, p_name, OCSD_CREATE_FLG_FULL_DECODER, p_cfg, &CSID);
ret = ocsd_dt_attach_packet_callback( dcdtree_handle_, CSID, OCSD_C_API_CB_PKT_MON, (void *)packetMonitorCallBack, p_context); ret = ocsd_dt_set_gen_elem_outfn( dcdtree_handle_, genTraceElemCallBack, p_context);
/********* Packet Processing *********/
//Each thread uses below function to process incoming CoreSight packet while ((bytes_done < (uint32_t)block_size) && (ret == OCSD_OK)) { if (OCSD_DATA_RESP_IS_CONT(dp_ret)) { dp_ret = ocsd_dt_process_data( dcdtree_handle_, OCSD_OP_DATA, block_index + bytes_done, block_size - bytes_done, ((uint8_t *)p_block) + bytes_done, &bytes_this_time); //Example code from
Kindly respond to my query.
Thank you, Subhasish
CoreSight mailing list CoreSight@lists.linaro.org https://lists.linaro.org/mailman/listinfo/coresight