From 1879e7206d29ac2cd4dcadc4d793bcbc3974d6ec Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Fri, 19 May 2023 15:43:13 +0800 Subject: [PATCH] The data used for decoding does not require to be compressed --- DSView/pv/data/decoderstack.cpp | 10 ++-- DSView/pv/data/logicsnapshot.cpp | 85 +++++++++++--------------------- DSView/pv/data/logicsnapshot.h | 12 ++--- DSView/pv/sigsession.cpp | 15 ++++-- 4 files changed, 53 insertions(+), 69 deletions(-) diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 63e298fb..54decf79 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -540,7 +540,7 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod if (!bCheckEnd){ bCheckEnd = true; - uint64_t mipmap_sample_count = _snapshot->get_mipmap_sample_count(); + uint64_t mipmap_sample_count = _snapshot->get_ring_sample_count(); if (end_index >= mipmap_sample_count){ end_index = mipmap_sample_count - 1; @@ -548,14 +548,14 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod } } } - else if (i >= _snapshot->get_mipmap_sample_count()) + else if (i >= _snapshot->get_ring_sample_count()) { // Wait the data is ready. std::this_thread::sleep_for(std::chrono::milliseconds(100)); continue; } - if (_is_capture_end && i == _snapshot->get_mipmap_sample_count()){ + if (_is_capture_end && i == _snapshot->get_ring_sample_count()){ break; } @@ -570,7 +570,7 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod } else { if (_snapshot->has_data(sig_index)) { - auto data_ptr = _snapshot->get_decode_samples(i, chunk_end, sig_index); + auto data_ptr = _snapshot->get_samples(i, chunk_end, sig_index); chunk.push_back(data_ptr); chunk_const.push_back(_snapshot->get_sample(i, sig_index)); } @@ -663,7 +663,7 @@ void DecoderStack::execute_decode_stack() assert(session); // Get the intial sample count - _sample_count = _snapshot->get_mipmap_sample_count(); + _sample_count = _snapshot->get_ring_sample_count(); // Create the decoders for(auto dec : _stack) diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index 02fa9bff..e4b13118 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -55,6 +55,7 @@ LogicSnapshot::LogicSnapshot() : _total_sample_count = 0; _is_loop = false; _loop_offset = 0; + _able_free = true; } LogicSnapshot::~LogicSnapshot() @@ -77,6 +78,11 @@ void LogicSnapshot::free_data() } _ch_data.clear(); _sample_count = 0; + + for(void *p : _free_block_list){ + free(p); + } + _free_block_list.clear(); } void LogicSnapshot::init() @@ -94,8 +100,8 @@ void LogicSnapshot::init_all() _dest_ptr = NULL; _memory_failed = false; _last_ended = true; - _mipmap_sample_count = 0; _loop_offset = 0; + _able_free = true; } void LogicSnapshot::clear() @@ -106,10 +112,16 @@ void LogicSnapshot::clear() _have_data = false; } -void LogicSnapshot::first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, GSList *channels) +void LogicSnapshot::first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, GSList *channels, bool able_free) { bool channel_changed = false; uint16_t channel_num = 0; + _able_free = able_free; + + for(void *p : _free_block_list){ + free(p); + } + _free_block_list.clear(); for (const GSList *l = channels; l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; @@ -172,7 +184,6 @@ void LogicSnapshot::first_payload(const sr_datafeed_logic &logic, uint64_t total _sample_count = 0; _ring_sample_count = 0; - _mipmap_sample_count = 0; assert(logic.data); uint64_t *rd_data = (uint64_t*)logic.data; @@ -268,7 +279,6 @@ void LogicSnapshot::append_cross_payload(const sr_datafeed_logic &logic) if (_ring_sample_count % LeafBlockSamples == 0){ calc_mipmap(_channel_num - 1, index0, index1, LeafBlockSamples, true); - _mipmap_sample_count = _ring_sample_count - _loop_offset; } break; } @@ -327,9 +337,6 @@ void LogicSnapshot::append_cross_payload(const sr_datafeed_logic &logic) { calc_mipmap(fill_chan, index0, index1, LeafBlockSamples, true); - if (fill_chan + 1 == _channel_num) - _mipmap_sample_count = _ring_sample_count - _loop_offset; - chans_read_addr[fill_chan] = read_ptr; fill_chan = (fill_chan + 1) % _channel_num; @@ -428,8 +435,6 @@ void LogicSnapshot::capture_ended() Snapshot::capture_ended(); _sample_count = _ring_sample_count; - _mipmap_sample_count = _ring_sample_count; - _ring_sample_count += _loop_offset; uint64_t index0 = _ring_sample_count / LeafBlockSamples / RootScale; @@ -540,7 +545,12 @@ void LogicSnapshot::calc_mipmap(unsigned int order, uint8_t index0, uint8_t inde _ch_data[order][index0].tog |= 1ULL << index1; } else if (isEnd){ - free(_ch_data[order][index0].lbp[index1]); + + if (_able_free) + free(_ch_data[order][index0].lbp[index1]); + else + _free_block_list.push_back(_ch_data[order][index0].lbp[index1]); + _ch_data[order][index0].lbp[index1] = NULL; } @@ -587,43 +597,6 @@ const uint8_t *LogicSnapshot::get_samples(uint64_t start_sample, uint64_t &end_s return (uint8_t*)_ch_data[order][index0].lbp[index1] + offset; } -const uint8_t *LogicSnapshot::get_decode_samples(uint64_t start_sample, uint64_t &end_sample, int sig_index) -{ - std::lock_guard lock(_mutex); - - uint64_t sample_count = _mipmap_sample_count; - - assert(start_sample < sample_count); - - if (end_sample >= sample_count) - end_sample = sample_count - 1; - - assert(end_sample <= sample_count); - assert(start_sample <= end_sample); - - start_sample += _loop_offset; - _ring_sample_count += _loop_offset; - - int order = get_ch_order(sig_index); - uint64_t index0 = start_sample >> (LeafBlockPower + RootScalePower); - uint64_t index1 = (start_sample & RootMask) >> LeafBlockPower; - uint64_t offset = (start_sample & LeafMask) / 8; - - end_sample = (index0 << (LeafBlockPower + RootScalePower)) + - (index1 << LeafBlockPower) + - ~(~0ULL << LeafBlockPower); - - end_sample = min(end_sample + 1, sample_count); - - end_sample -= _loop_offset; - _ring_sample_count -= _loop_offset; - - if (order == -1 || _ch_data[order][index0].lbp[index1] == NULL) - return NULL; - else - return (uint8_t*)_ch_data[order][index0].lbp[index1] + offset; -} - bool LogicSnapshot::get_sample(uint64_t index, int sig_index) { index += _loop_offset; @@ -1073,8 +1046,6 @@ bool LogicSnapshot::pattern_search_self(int64_t start, int64_t end, int64_t &ind int count = 0; bool bEdgeFlag = false; - - int64_t to = isNext ? end + 1 : start - 1; int64_t step = isNext ? 1 : -1; @@ -1223,12 +1194,6 @@ int LogicSnapshot::get_ch_order(int sig_index) return -1; } -uint64_t LogicSnapshot::get_mipmap_sample_count() -{ - std::lock_guard lock(_mutex); - return _mipmap_sample_count; -} - void LogicSnapshot::move_first_node_to_last() { for (unsigned int i=0; i<_channel_num; i++) @@ -1251,5 +1216,15 @@ void LogicSnapshot::move_first_node_to_last() } } +void LogicSnapshot::decode_end() +{ + std::lock_guard lock(_mutex); + + for(void *p : _free_block_list){ + free(p); + } + _free_block_list.clear(); +} + } // namespace data } // namespace pv diff --git a/DSView/pv/data/logicsnapshot.h b/DSView/pv/data/logicsnapshot.h index 6c4dea72..5fa60544 100644 --- a/DSView/pv/data/logicsnapshot.h +++ b/DSView/pv/data/logicsnapshot.h @@ -90,14 +90,12 @@ public: void init(); - void first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, GSList *channels); + void first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, GSList *channels, bool able_free); void append_payload(const sr_datafeed_logic &logic); const uint8_t * get_samples(uint64_t start_sample, uint64_t& end_sample, int sig_index); - const uint8_t * get_decode_samples(uint64_t start_sample, uint64_t& end_sample, int sig_index); - bool get_sample(uint64_t index, int sig_index); void capture_ended(); @@ -122,8 +120,6 @@ public: bool pattern_search(int64_t start, int64_t end, int64_t& index, std::map &pattern, bool isNext); - uint64_t get_mipmap_sample_count(); - inline void set_loop(bool bLoop){ _is_loop = bLoop; } @@ -132,6 +128,8 @@ public: return _is_loop; } + void decode_end(); + private: bool get_sample_self(uint64_t index, int sig_index); bool get_nxt_edge_self(uint64_t &index, bool last_sample, uint64_t end, @@ -144,6 +142,7 @@ private: std::map &pattern, bool isNext); int get_ch_order(int sig_index); + void calc_mipmap(unsigned int order, uint8_t index0, uint8_t index1, uint64_t samples, bool isEnd); void append_cross_payload(const sr_datafeed_logic &logic); @@ -215,9 +214,10 @@ private: uint64_t _last_sample[CHANNEL_MAX_COUNT]; uint64_t _last_calc_count[CHANNEL_MAX_COUNT]; - uint64_t _mipmap_sample_count; bool _is_loop; uint64_t _loop_offset; + bool _able_free; + std::vector _free_block_list; friend class LogicSnapshotTest::Pow2; friend class LogicSnapshotTest::Basic; diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 4c6b499d..7b9e9eae 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -1103,9 +1103,16 @@ namespace pv } if (_capture_data->get_logic()->last_ended()) - { + { _capture_data->get_logic()->set_loop(is_loop_mode()); - _capture_data->get_logic()->first_payload(o, _device_agent.get_sample_limit(), _device_agent.get_channels()); + + bool bNotFree = _is_decoding && _view_data == _capture_data; + + _capture_data->get_logic()->first_payload(o, + _device_agent.get_sample_limit(), + _device_agent.get_channels(), + !bNotFree); + // @todo Putting this here means that only listeners querying // for logic will be notified. Currently the only user of // frame_began is DecoderStack, but in future we need to signal @@ -1850,8 +1857,10 @@ namespace pv task = get_top_decode_task(); } + _view_data->get_logic()->decode_end(); + dsv_info("%s", "------->decode thread end"); - _is_decoding = false; + _is_decoding = false; } Snapshot *SigSession::get_signal_snapshot()