1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #include <string.h> 6 7 #include <rte_mbuf.h> 8 #include <rte_malloc.h> 9 10 #include "rte_table_stub.h" 11 12 #ifdef RTE_TABLE_STATS_COLLECT 13 14 #define RTE_TABLE_LPM_STATS_PKTS_IN_ADD(table, val) \ 15 table->stats.n_pkts_in += val 16 #define RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(table, val) \ 17 table->stats.n_pkts_lookup_miss += val 18 19 #else 20 21 #define RTE_TABLE_LPM_STATS_PKTS_IN_ADD(table, val) 22 #define RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(table, val) 23 24 #endif 25 26 struct rte_table_stub { 27 struct rte_table_stats stats; 28 }; 29 30 static void * 31 rte_table_stub_create(__rte_unused void *params, 32 __rte_unused int socket_id, 33 __rte_unused uint32_t entry_size) 34 { 35 struct rte_table_stub *stub; 36 uint32_t size; 37 38 size = sizeof(struct rte_table_stub); 39 stub = rte_zmalloc_socket("TABLE", size, RTE_CACHE_LINE_SIZE, 40 socket_id); 41 if (stub == NULL) { 42 RTE_LOG(ERR, TABLE, 43 "%s: Cannot allocate %u bytes for stub table\n", 44 __func__, size); 45 return NULL; 46 } 47 48 return stub; 49 } 50 51 static int 52 rte_table_stub_lookup( 53 __rte_unused void *table, 54 __rte_unused struct rte_mbuf **pkts, 55 __rte_unused uint64_t pkts_mask, 56 uint64_t *lookup_hit_mask, 57 __rte_unused void **entries) 58 { 59 __rte_unused struct rte_table_stub *stub = (struct rte_table_stub *) table; 60 __rte_unused uint32_t n_pkts_in = __builtin_popcountll(pkts_mask); 61 62 RTE_TABLE_LPM_STATS_PKTS_IN_ADD(stub, n_pkts_in); 63 *lookup_hit_mask = 0; 64 RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(stub, n_pkts_in); 65 66 return 0; 67 } 68 69 static int 70 rte_table_stub_stats_read(void *table, struct rte_table_stats *stats, int clear) 71 { 72 struct rte_table_stub *t = table; 73 74 if (stats != NULL) 75 memcpy(stats, &t->stats, sizeof(t->stats)); 76 77 if (clear) 78 memset(&t->stats, 0, sizeof(t->stats)); 79 80 return 0; 81 } 82 83 struct rte_table_ops rte_table_stub_ops = { 84 .f_create = rte_table_stub_create, 85 .f_free = NULL, 86 .f_add = NULL, 87 .f_delete = NULL, 88 .f_add_bulk = NULL, 89 .f_delete_bulk = NULL, 90 .f_lookup = rte_table_stub_lookup, 91 .f_stats = rte_table_stub_stats_read, 92 }; 93