• open vswitch源代码解析(二)flow table解析函数入口ovs_flow_tbl_lookup_stats


    flow table解析函数入口ovs_flow_tbl_lookup_stats

    flow table解析函数ovs_flow_tbl_lookup_stats主要完成从flow table db中寻找可用于key的flow rule,其中用到了hash机制首先快速查找,如果miss再进行full lookup;

    首先咱们注解一下hash查找的过程:

    ce = NULL;
    entries = this_cpu_ptr(tbl->mask_cache);
    
    /* Find the cache entry 'ce' to operate on. */
    for (seg = 0; seg < MC_HASH_SEGS; seg++) {
    int index = hash & (MC_HASH_ENTRIES - 1);
    struct mask_cache_entry *e;
    
    e = &entries[index];
    if (e->skb_hash == skb_hash) {
    struct sw_flow_mask *cache;
    int i = e->mask_index;
    
    if (likely(i < ma->max)) {
    cache = rcu_dereference(ma->masks[i]);
    if (cache) {
    flow = masked_flow_lookup(ti, key,
    cache, n_mask_hit);
    /*cache contains avaliable sector to find all hit*/
    if (flow)
    return flow;
    }
    }
    
    /* Cache miss. This is the best cache
     * replacement candidate.  */
    e->skb_hash = 0;
    ce = e;
    break;
    }
    
    if (!ce || e->skb_hash < ce->skb_hash)
    ce = e;  /* A better replacement cache candidate. */
    
    hash >>= MC_HASH_SHIFT;
    }
    


    该代码片断即为hash查找的主要过程,

    hash = flow_hash(&masked_key, key_start, key_end);
    head = find_bucket(ti, hash);
    (*n_mask_hit)++;
    hlist_for_each_entry_rcu(flow, head, hash_node[ti->node_ver]) {
    if (flow->mask == mask && flow->hash == hash &&
        flow_cmp_masked_key(flow, &masked_key,
      key_start, key_end))
    return flow;
    }

  • 相关阅读:
    3种常见的数据脱敏方案
    Linux xfs文件系统stat命令Birth字段为空的原因探究
    CentOS7 安装MySQL 图文详细教程
    Opencv图像暗通道调优
    Docker入门
    docker 常用命令
    【深入理解C++】vector
    【二叉树】输出二叉树
    CMake官方教程3--对库加入使用限制
    sql 脚本 WITH 作用
  • 原文地址:https://blog.csdn.net/G11176593/article/details/127855505