LCOV - code coverage report
Current view: top level - root/contrail/vrouter/include - vr_btable.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 10 16 62.5 %
Date: 2026-11-09 02:10:49 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * vr_btable.h --
       3             :  *
       4             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       5             :  * Copyright Contributors to the OpenSDN project
       6             :  */
       7             : #ifndef __VR_BTABLE_H__
       8             : #define __VR_BTABLE_H__
       9             : 
      10             : #define VB_FLAG_MEMORY_ATTACHED 0x1
      11             : 
      12             : #define VR_SINGLE_ALLOC_LIMIT   (4 * 1024 * 1024)
      13             : 
      14             : struct vr_btable_partition {
      15             :     unsigned int vb_offset;
      16             :     unsigned int vb_mem_size;
      17             : };
      18             : 
      19             : struct vr_btable {
      20             :     unsigned int    vb_entries;
      21             :     unsigned short  vb_esize;
      22             :     unsigned short  vb_partitions;
      23             :     unsigned int    vb_flags;
      24             :     unsigned int    vb_alloc_limit;
      25             :     unsigned short  vb_alloc_limit_log;
      26             :     unsigned int    vb_alloc_limit_mask;
      27             :     void            **vb_mem;
      28             :     struct vr_btable_partition *vb_table_info;
      29             : };
      30             : 
      31             : struct vr_btable_partition *vr_btable_get_partition(struct vr_btable *,
      32             :         unsigned int);
      33             : void *vr_btable_get_address(struct vr_btable *, unsigned int);
      34             : 
      35             : void vr_btable_free(struct vr_btable *);
      36             : struct vr_btable *vr_btable_alloc(unsigned int, unsigned int);
      37             : struct vr_btable *vr_btable_attach(struct iovec *, unsigned int, unsigned short);
      38             : 
      39             : static inline unsigned int
      40           0 : vr_btable_entries(struct vr_btable *table)
      41             : {
      42           0 :     return table->vb_entries;
      43             : }
      44             : 
      45             : static inline unsigned int
      46           0 : vr_btable_size(struct vr_btable *table)
      47             : {
      48           0 :     return table->vb_entries * table->vb_esize;
      49             : }
      50             : 
      51             : static inline void *
      52   150060489 : vr_btable_get(struct vr_btable *table, unsigned int entry)
      53             : {
      54             :     unsigned int t_index, t_offset, entry_cont;
      55             : 
      56   150060489 :     if (entry >= table->vb_entries)
      57           0 :         return NULL;
      58             : 
      59   150060489 :     entry_cont = entry * table->vb_esize;
      60             : 
      61   150060489 :     if (table->vb_alloc_limit_mask) {
      62   131865033 :         t_index = entry_cont >> table->vb_alloc_limit_log;
      63   131865033 :         t_offset = entry_cont & table->vb_alloc_limit_mask;
      64             :     } else {
      65    18195456 :         t_index = entry_cont / table->vb_alloc_limit;
      66    18195456 :         t_offset = entry_cont % table->vb_alloc_limit;
      67             :     }
      68             : 
      69   150060489 :     if (t_index >= table->vb_partitions)
      70           0 :         return NULL;
      71             : 
      72   150060489 :     return ((char *)table->vb_mem[t_index] + t_offset);
      73             : }
      74             : 
      75             : #endif /* __VR_BTABLE_H__ */

Generated by: LCOV version 1.14