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