LRU caches replace records when requested table bucket is full. There
is, however, no information about this happenning in either the return
value or the statistics. This commit introduces a counter for such
cases.

Signed-off-by: Kamil Vojanec <voja...@cesnet.cz>
---
 lib/table/rte_table.h            | 1 +
 lib/table/rte_table_hash_key16.c | 4 ++++
 lib/table/rte_table_hash_key32.c | 4 ++++
 lib/table/rte_table_hash_key8.c  | 4 ++++
 lib/table/rte_table_hash_lru.c   | 4 ++++
 5 files changed, 17 insertions(+)

diff --git a/lib/table/rte_table.h b/lib/table/rte_table.h
index 9a5faf0e32..e097e25868 100644
--- a/lib/table/rte_table.h
+++ b/lib/table/rte_table.h
@@ -33,6 +33,7 @@ struct rte_mbuf;
 struct rte_table_stats {
        uint64_t n_pkts_in;
        uint64_t n_pkts_lookup_miss;
+       uint64_t n_pkts_insert_victims;
 };
 
 /**
diff --git a/lib/table/rte_table_hash_key16.c b/lib/table/rte_table_hash_key16.c
index 67b77c16a0..f97d9c1266 100644
--- a/lib/table/rte_table_hash_key16.c
+++ b/lib/table/rte_table_hash_key16.c
@@ -27,11 +27,14 @@
        table->stats.n_pkts_in += val
 #define RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(table, val) \
        table->stats.n_pkts_lookup_miss += val
+#define RTE_TABLE_HASH_KEY16_STATS_PKTS_INSERT_VICTIMS_ADD(table, val) \
+       table->stats.n_pkts_insert_victims += val
 
 #else
 
 #define RTE_TABLE_HASH_KEY16_STATS_PKTS_IN_ADD(table, val)
 #define RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(table, val)
+#define RTE_TABLE_HASH_KEY16_STATS_PKTS_INSERT_VICTIMS_ADD(table, val)
 
 #endif
 
@@ -304,6 +307,7 @@ rte_table_hash_entry_add_key16_lru(
        }
 
        /* Bucket full: replace LRU entry */
+       RTE_TABLE_HASH_KEY16_STATS_PKTS_INSERT_VICTIMS_ADD(f, 1);
        pos = lru_pos(bucket);
        bucket->signature[pos] = signature;
        keycpy(&bucket->key[pos], key, f->key_mask);
diff --git a/lib/table/rte_table_hash_key32.c b/lib/table/rte_table_hash_key32.c
index 1aa86c6a49..37ad87bb85 100644
--- a/lib/table/rte_table_hash_key32.c
+++ b/lib/table/rte_table_hash_key32.c
@@ -27,11 +27,14 @@
        table->stats.n_pkts_in += val
 #define RTE_TABLE_HASH_KEY32_STATS_PKTS_LOOKUP_MISS(table, val) \
        table->stats.n_pkts_lookup_miss += val
+#define RTE_TABLE_HASH_KEY32_STATS_PKTS_INSERT_VICTIMS_ADD(table, val) \
+       table->stats.n_pkts_insert_victims += val
 
 #else
 
 #define RTE_TABLE_HASH_KEY32_STATS_PKTS_IN_ADD(table, val)
 #define RTE_TABLE_HASH_KEY32_STATS_PKTS_LOOKUP_MISS(table, val)
+#define RTE_TABLE_HASH_KEY32_STATS_PKTS_INSERT_VICTIMS_ADD(table, val)
 
 #endif
 
@@ -312,6 +315,7 @@ rte_table_hash_entry_add_key32_lru(
        }
 
        /* Bucket full: replace LRU entry */
+       RTE_TABLE_HASH_KEY32_STATS_PKTS_INSERT_VICTIMS_ADD(f, 1);
        pos = lru_pos(bucket);
        bucket->signature[pos] = signature;
        keycpy(&bucket->key[pos], key, f->key_mask);
diff --git a/lib/table/rte_table_hash_key8.c b/lib/table/rte_table_hash_key8.c
index c8d72b333d..c5722f3709 100644
--- a/lib/table/rte_table_hash_key8.c
+++ b/lib/table/rte_table_hash_key8.c
@@ -25,11 +25,14 @@
        table->stats.n_pkts_in += val
 #define RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(table, val) \
        table->stats.n_pkts_lookup_miss += val
+#define RTE_TABLE_HASH_KEY8_STATS_PKTS_INSERT_VICTIMS_ADD(table, val) \
+       table->stats.n_pkts_insert_victims += val
 
 #else
 
 #define RTE_TABLE_HASH_KEY8_STATS_PKTS_IN_ADD(table, val)
 #define RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(table, val)
+#define RTE_TABLE_HASH_KEY8_STATS_PKTS_INSERT_VICTIMS_ADD(table, val)
 
 #endif
 
@@ -292,6 +295,7 @@ rte_table_hash_entry_add_key8_lru(
        }
 
        /* Bucket full: replace LRU entry */
+       RTE_TABLE_HASH_KEY8_STATS_PKTS_INSERT_VICTIMS_ADD(f, 1);
        pos = lru_pos(bucket);
        keycpy(&bucket->key[pos], key, &f->key_mask);
        memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
diff --git a/lib/table/rte_table_hash_lru.c b/lib/table/rte_table_hash_lru.c
index 801e48f5ba..bcf9c34f8e 100644
--- a/lib/table/rte_table_hash_lru.c
+++ b/lib/table/rte_table_hash_lru.c
@@ -23,11 +23,14 @@
        table->stats.n_pkts_in += val
 #define RTE_TABLE_HASH_LRU_STATS_PKTS_LOOKUP_MISS(table, val) \
        table->stats.n_pkts_lookup_miss += val
+#define RTE_TABLE_HASH_LRU_STATS_PKTS_INSERT_VICTIMS_ADD(table, val) \
+       table->stats.n_pkts_insert_victims += val
 
 #else
 
 #define RTE_TABLE_HASH_LRU_STATS_PKTS_IN_ADD(table, val)
 #define RTE_TABLE_HASH_LRU_STATS_PKTS_LOOKUP_MISS(table, val)
+#define RTE_TABLE_HASH_LRU_STATS_PKTS_INSERT_VICTIMS_ADD(table, val)
 
 #endif
 
@@ -340,6 +343,7 @@ rte_table_hash_lru_entry_add(void *table, void *key, void 
*entry,
 
        /* Bucket full */
        {
+               RTE_TABLE_HASH_LRU_STATS_PKTS_INSERT_VICTIMS_ADD(t, 1);
                uint64_t pos = lru_pos(bkt);
                uint32_t bkt_key_index = bkt->key_pos[pos];
                uint8_t *bkt_key = &t->key_mem[bkt_key_index <<
-- 
2.43.5

Reply via email to