Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DP queue is a lockless circular buffer providing safe consumer/producer cached operations cross cores prerequisites: 1) incoming and outgoing data rate MUST be the same 2) Both data consumer and data producer declare max chunk sizes they want to use (IBS/OBS) required Buffer size: - 2*MAX(IBS,OBS) if the larger of IBS/OBS is multiplication of smaller - 3*MAX(IBS,OBS) otherwise The queue may work in 2 modes 1) local mode in case both receiver and sender are located on the same core and cache coherency does not matter. dp_queue structure is located in cached memory In this case DP Queue is a simple ring buffer 2) shared mode In this case we need to writeback cache when new data arrive and invalidate cache on secondary core. dp_queue structure is located in shared memory dpQueue is a lockless consumer/producer safe buffer. It is achieved by having only 2 shared variables: write_offset - can be modified by data producer only read_offset - can be modified by data consumer only as 32 bit operations are atomic, it is multi-thread and multi-core save There some explanation needed how free_space and available_data are calculated number of avail data in circular buffer may be calculated as: data_avail = write_offset - read_offset and check for wrap around if (data_avail < 0) data_avail = buffer_size + data_avail The problem is when write_offset == read_offset, !!! it may mean either that the buffer is empty or the buffer is completely filled !!! To solve the above issue having only 2 variables mentioned before: - allow both offsets to point from 0 to DOUBLE buffer_size - when calculating pointers to data, use: data_bufer[offset % buffer_size] - use double buffer size in wrap around check when calculating available data And now: - write_offset == read_offset always means "buffer empty" - write_offset == read_offset + buffer_size always means "buffer full" - data_avail = write_offset - read_offset if (data_avail < 0) data_avail = 2 * buffer_size + data_avail Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
- Loading branch information