工具类分析-rak::partial_queue

介绍了一种名为玲珑宝塔的算法,该算法用于将不同稀缺度的chunk分层存储。通过对chunk的统计数进行排序并分配到不同层级,使得稀缺度较高的chunk位于较低层级,便于高效管理和检索。

说明:通过ChunkStatistics统计出所有chunk的供应数后,下一步就是要针对peer将其拥有的chunk按照稀缺度分layer,形象一点就是将chunk按照贵重程度放到7(num_layers)层玲珑宝塔(m_layers)中,不过这个宝塔有点特别,越往下越贵重。(重的东西是应该放下面)。每层的区间范围分别为 第0层到第7层

[0,1) [1,3) [3,7) [7,15) [15,31) [31,63) [63,127) [127,255)

注意:
1. 每层(layer)的数目有限m_maxLayerSize,seeder 32个,leecher 8个,但是在同一层中的chunk可能大于m_maxLayerSize,这称为overflowing,算法的处理是不弹出上一层的chunk,而是返回false,参考prepare_pop函数
2. 第0层(最底层)含义:chunk统计数为0的(只有seeder才可能插入)

成员变量:

  mapped_type*        m_data;        //按层排列的chunk index列表
  size_type           m_maxLayerSize;//每层的最大个数
  size_type           m_index;       //当前拥有成员的最底层,从第0层开始
  size_type           m_ceiling;     //可插入层的最大统计值,从最高层的最大值开始
  size_pair_type      m_layers[num_layers];//first 本层已经pop的chunk数,second 本层总共的chunk数
核心函数:
//构造,ls: 每层最大允许的chunk index数
inline void partial_queue::enable(size_type ls) {
  if (ls == 0)
    throw std::logic_error("partial_queue::enable(...) ls == 0.");

  delete [] m_data;
  m_data = new mapped_type[ls * num_layers];

  m_maxLayerSize = ls;
}
//销毁
inline void partial_queue::disable() {
  delete [] m_data;
  m_data = NULL;

  m_maxLayerSize = 0;
}
//清空
inline void partial_queue::clear() {
  if (m_data == NULL)
    return;

  m_index = 0;
  m_ceiling = ceiling(num_layers - 1);

  std::memset(m_layers, 0, num_layers * sizeof(size_pair_type));
}

/************************************************************************
增加一个成员
参数:            key:   成员身价,chunk的统计数,值越少越值钱  
                   value: 成员ID号,chunk index
说明:
    本算法按照chunk统计数,将chunk放到不同的层,如果中间某一层满了,继续往低一层放,直到使最低层满了,则整个queue满了(只有seeder可能做到),插入后m_index指向有chunk的最低层,m_ceiling表示可插入的层最高统计值
    本函数由ChunkSelector调用
************************************************************************/
inline bool partial_queue::insert(key_type key, mapped_type value) {
  if(key>= m_ceiling)
    return false;

  size_type idx= 0; 

  //找到layer
 
while(key>= ceiling(idx))
    ++idx;

  m_index= std::min(m_index, idx);

  // Currently don't allow overflow.
 
if(is_layer_full(idx))
    throwstd::logic_error("partial_queue::insert(...) layer already full."); 
    //记录chunk index
 
m_data[m_maxLayerSize* idx+ m_layers[idx].second] = value;
  m_layers[idx].second++;

  if(is_layer_full(idx))
    // 如果是第0层满了,则表示整个queue满了,否则到低一层
  
m_ceiling= idx> 0 ? ceiling(idx- 1) : 0;

  return true;
}

//定位到有un-popped chunk的最低层 
inline bool partial_queue::prepare_pop() {
  while (m_layers[m_index].first == m_layers[m_index].second) {
        //is_layer_full(m_index)表示overflowed,表示在当前layer的chunk大于m_maxLayerSize
    if (is_layer_full(m_index) || m_index + 1 == num_layers)
      return false;

    m_index++;
  }

  return true;
}
//获得chunk index
inline partial_queue::mapped_type partial_queue::pop() {
  if (m_index >= num_layers || m_layers[m_index].first >= m_layers[m_index].second)
    throw std::logic_error("partial_queue::pop() bad state.");

  return m_data[m_index * m_maxLayerSize + m_layers[m_index].first++];
}
分析以下打印说明保存原因和解决办法 [root@anyka ~]$ ./usr/bin/ak_svp2_sample -n 1000 -g 3 -f /mnt/rtsp/isp_gc4653_mi pi_2lane_av100.conf -c /usr/sbin/model_0x0A000008_V2.0.00.bin -m 0 -d 1 -e 0 [Application][2000-01-01 00:18:52 061] *************************camera_set_vclk **************** [Application][2000-01-01 00:18:52 062] ** svp camera_set_vclk isp_clk:348160000 demo version: libmpi_svp2 V1.0.06 ** [Application][2000-01-01 00:18:52 062] ***************************************** [ VI][2000-01-01 00:18:52 062] [ak_vi_open:458] register device, device id:[0] [ VI][2000-01-01 00:18:52 063] new device [ VI][2000-01-01 00:18:52 063] [vi_register_device:333] new dev=0x1758008 ispsdk_lib version:libplat_isp_sdk V8.0.01 open isp dev: /dev/isp-param-0 --- AK_ISP_sdk_init g_isp_fd[0]=5 --- [ VI][2000-01-01 00:18:52 080] [vi_dev_opgc4653_core_g_ctrl cmd:8204 not support en:248] vi device open DEV0! [ VI][2000-01-01 00gc4653_cropcap bounds.width:2560, bounds.height:1440 gc4653_cropcap bounds.width:2560, bounds.height:1440v4l-subdev0 [ VI][2000-01-01 00:18:52 081] [vi_dev_open:279]priv_dma_alloc req_len:6914048, dma_addr:2168455168, act_len:6914048 --- vi_dev_open g_sensor_fd[0]=6 --- [ VI][2000isp_param_file_mmap 6938 vm_iomap_memory ok. vm_start:0xb66a7000 dma_addr:0x81400000, size:6914048 -01-01 00:18:52 082] [vi_dev_open_td_chn:178] vi third chn devicgc4653_s_crop 933, left:0, top:0, width:2560, height:1440 e open CHN16! [ VI][2000-01-01 00:18:52 083] register vgc4653_cropcap bounds.width:2560, bounds.height:1440 i device ok, dev_count=1 [ VPSS][2000-01-01 00:18:52 084] [isp_open:108] dev:0 already opened! [ VPSS][2000-01-01set_done_mode input#0 chn#0 done_mode:0 00:18:52 087] [isp.conf]version: 6.011, sensor id: 0x4653, stylgc4653_cropcap bounds.width:2560, bounds.height:1440 e id: 0 [ VPSS][2000-01-01 00:18:52 090] isp subfile 0, modify time: 2024-4-1 17:30:56 [ VPSS][2000-01-01 00:18:52 090] 20221026 1. 2. 3. 4. GC4653 20240401 1.֡ [ VPSS][2000-01-01 00:18:52 091] isp subfile 1, modify time: 2024-4-1 17:30:50 [ VPSS][2000-01-01 00:18:52 092] 20221026 1. 2. GC4653 20240401 1.֡ [ VPSS][2000-01-01 00:18:52 092] [check_file:445] check isp cfg: /mnt/rtsp/isp_gc4653_mipi_2lane_av100.conf OK [ VPSS][2000-01-01 00:18:52 095] [isp_set_attr:1999] isp_set_attr module_id:0 [ VPSS][2000-01-01 00:18:52 096] [isp_set_attr:1999] isp_set_attr module_id:1 [ VPSS][2000-01-01 00:18:52 097] [isp_set_attr:1999] isp_set_attr module_id:2 [ VPSS][2000-01-01 00:18:52 097] [isp_set_attr:1999] isp_set_attr module_id:3 [ VPSS][2000-01-01 00:18:52 098] [isp_set_attr:1999] isp_set_attr module_id:4 [ VPSS][2000-01-01 00:18:52 099] [isp_set_attr:1999] isp_set_attr module_id:5 [ VPSS][2000-01-01 00:18:52 100] [isp_set_attr:1999] isp_set_attr module_id:6 [ VPSS][2000-01-01 00:18:52 100] [isp_set_attr:1999] isp_set_attr module_id:7 [ VPSS][2000-01-01 00:18:52 101] [isp_set_attr:1999] isp_set_attr module_id:8 [ VPSS][2000-01-01 00:18:52 102] [isp_set_attr:1999] isp_set_attr module_id:9 [ VPSS][2000-01-01 00:18:52 103] [isp_set_attr:1999] isp_set_attr module_id:10 [ VPSS][2000-01-01 00:18:52 104] [isp_set_attr:1999] isp_set_attr module_id:11 [ VPSS][2000-01-01 00:18:52 106] [isp_set_attr:1999] isp_set_attr module_id:12 [ VPSS][2000-01-01 00:18:52 107] [isp_set_attr:1999] isp_set_attr module_id:13 [ VPSS][2000-01-01 00:18:52 107] [isp_set_attr:1999] isp_set_attr module_id:14 [ VPSS][2000-01-01 00:18:52 108] [isp_set_attr:1999] isp_set_attr module_id:15 [ VPSS][2000-01-01 00:18:52 109] [isp_set_attr:1999] isp_set_attr module_id:16 [ VPSS][2000-01-01 00:18:52 109] [isp_set_attr:1999] isp_set_attr module_id:17 [ VPSS][2000-01-01 00:18:52 110] [isp_set_attr:1999] isp_set_attr module_id:18 [ VPSS][2000-01-01 00:18:52 111] [isp_set_attr:1999] isp_set_attr module_id:19 [ VPSS][2000-01-01 00:18:52 112] [isp_set_attr:1999] isp_set_attr module_id:20 [ VPSS][2000-01-01 00:18:52 113] [check_fps_para:426] hight light: frame_rate=20 max_exp_time=1124 low_light_gain=48 [ VPSS][2000-01-01 00:18:52 113] [check_fps_para:431] low light: frame_rate=8 max_exp_time=2812 light_gain=12 [ VPSS][2000-01-01 00:18:52 114] [init_fps_info:569] hight light fps: 20 [ VPSS][2000-01-01 00:18:52 114] [isp_set_sensor_fps:2614] set sensor fps: 20 [ VPSS][2000-01-01 00:18:52 115] [set_fps:244] set dev:0 fps:20 ok [ VPSS][2000-01-01 00:18:52 116] [isp_set_attr:1999] isp_set_attr module_id:21 [ VPSS][2000-01-01 00:18:52 127] [isp_set_attr:1999] isp_set_attr module_id:22 [ VPSS][2000-01-01 00:18:52 128] [isp_set_attr:1999] isp_set_attr module_id:23 [ VPSS][2000-01-01 00:18:52 128] [isp_module_init:1575] before load_sensor_conf [ VPSS][2000-01-01 00:18:52 129] [isp_module_init:1577] after load_sensor_conf [ VI][2000-01-01 00:18:52 137] vi_dev_get_sensor_crop 166, ret:0, w:2560, h:1440 [Application][2000-01-01 00:18:52 138] [start_vi:324] get dev res w:[2560]h:[1440] [ VI][2000-01-01 00:18:52 148] vi_dev_get_sensor_crop 166, ret:0, w:2560, h:1440 [ VI][2000-01-01 00:18:52 176] [vi_dev_set_frame_rate:542] Set dev [0] frame_rate [0] [ VI][2000-01-01 00:18:52 198] init CROP succeedded! reset to CROP[2560, 1440] [ VI][2000-01-01 00:18:52 203] [ak_vi_set_chn_attr_ex:1764] success register vi channel[0] [ VI][2000-01-01 00:18:52 213] Set chn mode [0] [ VI][2000-01-01 00:18:52 213] [vi_setset_done_mode input#0 chn#1 done_mode:0 _channel_attr:1081] set vi channel[0] mode:[0], slice_num[0] fragc4653_cropcap bounds.width:2560, bounds.height:1440 me_depth[2] [ VI][2000-01-01 00:18:52 224] init CROP succeedded! reset to CROP[2560, 1440] [ VI][2000-01-01 00:18:52 225] [vi_set_channel_attr:1094] set vi channel[0] crop: left[0]set_done_mode input#0 chn#2 done_mode:0 top[0] w[2560] h[1440] [ VI][2000-01-01 00:18:52 558] [vigc4653_cropcap bounds.width:2560, bounds.height:1440 _dev_set_chn_res:946] chn id is[0], fd is:[7] [ VI][2000-01-01 00:18:52 559] [vi_dev_set_chn_res:989] vi_dev_set_chn_res w:2560, h:1440 [ VI][2000-01-01 00:18:52 560] [vi_set_channak_vb2_dc_alloc 1710 size:5529600 el_attr:1108] set vi channel[0] res w[2560] h[1440] [ VI][ak_vb2_dc_alloc chn#0-0 alloc big_dma_addr data_size:11059200=2*5529600 (num*size), total_alloc_size=11059200+0 (alloc_size+alloc_size_other) 2000-01-01 00:18:52 560] [vi_dev_set_chn_buf_size:586] Set Chn [priv_dma_alloc req_len:11059200, dma_addr:2175369216, act_len:11059200 0] buf size [5529600] [ VI][2000-01-01 00:18:52 561] [vi_sak_vb2_dc_alloc vaddr:cb0d8000, dma_addr:0x81a98000, size:5529600, users:0/2 et_channel_attr:1120] set vi channel[0] buf size[5529600] [Applak_vb2_dc_cookie 2071 ication][2000-01-01 00:18:52 567] [start_vi:363] vi device 0 maiak_vb2_dc_vaddr 2079 n sub channel attribute [ VI][2000-01-01 00:18:52 568] [akak_vb2_dc_alloc 1710 size:5529600 _vi_set_chn_attr_ex:1764] success register vi channel[1] [ ak_vb2_dc_alloc vaddr:cb61e000, dma_addr:0x81fde000, size:5529600, users:1/2 VI][2000-01-01 00:18:52 573] Set chn mode [0] [ VI][2000-ak_vb2_dc_cookie 2071 01-01 00:18:52 574] [vi_set_channel_attr:1081] set vi channel[1]ak_vb2_dc_vaddr 2079 mode:[0], slice_num[0] frame_depth[2] [ VI][2000-01-01 00ak_vb2_dc_mmap 2051 vm_iomap_memory ok. vm_start:0xb6161000 dma_addr:0x81a98000,size:5529600 :18:52 585] init CROP succeedded! reset to CROP[2560, 1440] [ ak_vb2_dc_mmap 2051 vm_iomap_memory ok. vm_start:0xb5c1b000 dma_addr:0x81fde000,size:5529600 VI][2000-01-01 00:18:52 585] [vi_set_channel_attr:1094] set ak_vb2_dc_alloc 1710 size:348160 vi channel[1] crop: left[0] top[0] w[2560] h[1440] [ VI][2ak_vb2_dc_alloc chn#0-1 alloc big_dma_addr data_size:691200=2*345600 (num*size), total_alloc_size=696320+0 (alloc_size+alloc_size_other) 000-01-01 00:18:52 586] [vi_dev_set_chn_res:946] chn id is[1], fpriv_dma_alloc req_len:696320, dma_addr:2186428416, act_len:696320 d is:[8] [ VI][2000-01-01 00:18:52 586] [vi_dev_set_chn_reak_vb2_dc_alloc vaddr:cad44000, dma_addr:0x82524000, size:348160, users:0/2 s:989] vi_dev_set_chn_res w:640, h:360 [ VI][2000-01-01 00ak_vb2_dc_cookie 2071 :18:52 587] [vi_set_channel_attr:1108] set vi channel[1] res w[6ak_vb2_dc_vaddr 2079 40] h[360] [ VI][2000-01-01 00:18:52 588] [vi_dev_set_chn_ak_vb2_dc_alloc 1710 size:348160 buf_size:586] Set Chn [1] buf size [345600] [ VI][2000-01-ak_vb2_dc_alloc vaddr:cad99000, dma_addr:0x82579000, size:348160, users:1/2 01 00:18:52 588] [vi_set_channel_attr:1120] set vi channel[1] buak_vb2_dc_cookie 2071 f size[345600] [Application][2000-01-01 00:18:52 595] [start_viak_vb2_dc_vaddr 2079 :383] vi device 0 set sub channel attribute [ VI][2000-01-ak_vb2_dc_mmap 2051 vm_iomap_memory ok. vm_start:0xb5bc6000 dma_addr:0x82524000,size:348160 01 00:18:52 596] [ak_vi_set_chn_attr_ex:1764] success register vak_vb2_dc_mmap 2051 vm_iomap_memory ok. vm_start:0xb5b71000 dma_addr:0x82579000,size:348160 i channel[16] [ VI][2000-01-01 00:18:52 605] Set chn mode ak_vb2_dc_alloc 1710 size:176128 [0] [ VI][2000-01-01 00:18:52 605] [vi_set_channel_attr:10ak_vb2_dc_alloc chn#0-2 alloc big_dma_addr data_size:345600=2*172800 (num*size), total_alloc_size=352256+0 (alloc_size+alloc_size_other) 81] set vi channel[16] mode:[0], slice_num[0] frame_depth[2] [ priv_dma_alloc req_len:352256, dma_addr:2187124736, act_len:352256 VI][2000-01-01 00:18:52 616] init CROP succeedded! reset toak_vb2_dc_alloc vaddr:cadef000, dma_addr:0x825ce000, size:176128, users:0/2 CROP[2560, 1440] [ VI][2000-01-01 00:18:52 617] [vi_set_cak_vb2_dc_cookie 2071 hannel_attr:1094] set vi channel[16] crop: left[0] top[0] w[2560ak_vb2_dc_vaddr 2079 ] h[1440] [ VI][2000-01-01 00:18:52 617] [vi_dev_set_chn_rak_vb2_dc_alloc 1710 size:176128 es:946] chn id is[16], fd is:[9] [ VI][2000-01-01 00:18:52ak_vb2_dc_alloc vaddr:cae1a000, dma_addr:0x825f9000, size:176128, users:1/2 618] [vi_dev_set_chn_res:989] vi_dev_set_chn_res w:320, h:180 ak_vb2_dc_cookie 2071 [ VI][2000-01-01 00:18:52 619] [vi_set_channel_attr:1108] sak_vb2_dc_vaddr 2079 et vi channel[16] res w[320] h[180] [ VI][2000-01-01 00:18ak_vb2_dc_mmap 2051 vm_iomap_memory ok. vm_start:0xb5b46000 dma_addr:0x825ce000,size:176128 :52 619] [vi_dev_set_chn_buf_size:586] Set Chn [16] buf size [17ak_vb2_dc_mmap 2051 vm_iomap_memory ok. vm_start:0xb5b1b000 dma_addr:0x825f9000,size:176128 2800] [ VI][2000-01-01 00:18:52 620] [vi_set_channel_attr:camera_set_pp_chn_buffer_addr_default 2940 1120] set vi channel[16] buf size[172800] [Application][2000-010014: mipi_top_clk_init 97 44ab087f -01 00:18:52 627] [start_vi:417] vi device 0 set td channel attrcamera_input_interface_init mipi ibute [ VI][2000-01-01 00:18:52 764] [vi_set_capturcamera_set_sharepin e_on:1876] vi channel [0] is started! [ VI][2000gc4653_sen_set_power_on_func 1751 -01-01 00:18:52 899] [vi_set_capture_on:1876] vi channel [1] is gc4653_sen_set_power_on_func 1758 started! [ VI][2000-01-01 00:18:53 035] [vi_set_capture_on:1876] vi channel [16] is started! [ VI][2000-01-01 00:18:53 036] [set_v4l2_qbuf:1712] i:0, userptr:0xb6161000, length:5529600 [ VI][2000-01-01 00:18:53 037] [set_v4l2_qbuf:1712] i:1, userptr:0xb5c1b000, length:5529600 gc4653_read client:c78f6700, addr:10 gc4653_read client:c78f6700, addr:10 id:4653 gc4653_read client:c78f6700, addr:10 R0x326:0x6c gc4653_read client:c78f6700, addr:10 R0x343:0x60 gc4653_sen_get_parameter_func param:8199 not support gc4653_sen_get_parameter_func param:8200 not support gc4653_sen_get_parameter_func param:8201 not support gc4653_core_g_ctrl cmd:8204 not support [ VI][2000-01-01 00:18:53 363] [ak_vi_enable_chn:2061] set camera_set_pp_chn_buffer_addr_default 2940 channel [0] capture on [ VI][2000-01-01 00:18:53 364] [setcamera_set_pp_chn_buffer_addr_default 2940 _v4l2_qbuf:1712] i:0, userptr:0xb5bc6000, length:348160 [ VI][2000-01-01 00:18:53 365] [set_v4l2_qbuf:1712] i:1, userptr:0xb5b71000, length:348160 [ VI][2000-01-01 00:18:53 374] [ak_vi_enable_chn:2061] set channel [1] capture on [ VI][2000-01-01 00:18:53 384] [ak_vi_enable_chn:2061] set channel [16] capture on [ SVP][2000-01-01 00:18:53 385] [nna_cb_init_reg:213] mapping, start: 0x21300000, len: 0x00001000 [ DRV][2000-01-01 00:18:53 386] Found uio0 mapping for 0x21300000 [ SVP][2000-01-01 00:18:53 387] [nna_cb_init_reg:233] init cnn reg, va: 0xb6fcd000, pa: 0x21300000, len: 0x00001000 [ AKV_CNN][2000-01-01 00:18:53 411] net_handle->hw_featuak_vb2_dc_put chn0#0 priv_dma_free re_buffer->size=4730880 [ AKV_CNN][2000-01-01 00:18:53 412] netset_chn_bufs_release chn0#0 _handle->hw_param_buffer->size=560000 [ AKV_CNN][2000-01-01 00:ak_vb2_dc_put chn0#1 priv_dma_free 18:53 412] NNA_Check_Model: model_id[0x0a000000] and header.modeset_chn_bufs_release chn0#1 l_label[0x0a000008] conflict. [ AKV_CNN][2000-01-01 00:18:53 41ak_vb2_dc_put chn0#2 priv_dma_free 3] NNA_Load: NNA_Check_Model fail! Please check model file. et_chn_bufs_release chn0#2 ;31m[ SVP][2000-01-01 00:18:53 425] [load_and_set_param_hd_180p:694] Load face detect model file failed! [ SVP][2000-01-01 00:18:53 425] [ak_svp2_create_chn:1375] handle 0 nna_load_and_set_param failed! [Application][2000-01-01 00:18:53 426] [start_svp:519] Create SVP chn failed [ SVP][2000-01-01 00:18:53 427] [nna_cb_exit_reg:249] unmapping, start: 0x21300000, len: 0x00001000 [ SVP][2000-01-01 00:18:53 428] [nna_cb_exit_reg:259] uninit cnn reg, va: 0xb6fcd000, pa: 0x21300000, len: 0x00001000 [ VI][2000-01-01 00:18:53 457] [vi_dev_release_chn_buffer:667] Set Chn [0] release chn buffer ok. [ VI][2000-01-01 00:18:53 457] [vi_set_capture_off:1922] channel [0] capture off, ret [0], pchn->status[0] [ VI][2000-01-01 00:18:53 474] [vi_dev_release_chn_buffer:667] Set Chn [1] release chn buffer ok. [ VI][2000-01-01 00:18:53 475] [vi_set_capture_off:1922] channel [1] capture off, ret [0], pchn->status[0] [ VI][2000-01-01 00:18:53 493] [vi_dev_release_chn_buffer:667] Set Chn [16] release chn buffer ok. [ VI][2000-01-01 00:18:53 494] [vi_set_capture_off:1922] channel [16] capture off, ret [0], pchn->status[0] [ VI][2000-01-01 00:18:53 495] [ak_vi_close:494] enter close vi --- AK_ISP_sdk_exit g_isp_fd[0]=5 closed --- camera_mipi_deinit 944 camera_mipi_deinit 960 [ VI][2000-01-01 00:18:53 655] [vi_dev_close:360] --- vi_dev_close g_sensor_fd[0]=6 closed --- [ VI][2000-01-01 00:18:53 656] [vi_unregister_device:439] unregister done [Application][2000-01-01 00:18:53 657] exit vi demo [root@anyka ~]$ udhcpc: sending discover udhcpc: sending discover
10-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值