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