]> git.proxmox.com Git - ceph.git/blame - ceph/src/dpdk/lib/librte_ip_frag/rte_ip_frag_common.c
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / dpdk / lib / librte_ip_frag / rte_ip_frag_common.c
CommitLineData
7c673cae
FG
1/*-
2 * BSD LICENSE
3 *
4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <stddef.h>
35#include <stdio.h>
36
37#include <rte_memory.h>
38#include <rte_log.h>
39
40#include "ip_frag_common.h"
41
42#define IP_FRAG_HASH_FNUM 2
43
44/* free mbufs from death row */
45void
46rte_ip_frag_free_death_row(struct rte_ip_frag_death_row *dr,
47 uint32_t prefetch)
48{
49 uint32_t i, k, n;
50
51 k = RTE_MIN(prefetch, dr->cnt);
52 n = dr->cnt;
53
54 for (i = 0; i != k; i++)
55 rte_prefetch0(dr->row[i]);
56
57 for (i = 0; i != n - k; i++) {
58 rte_prefetch0(dr->row[i + k]);
59 rte_pktmbuf_free(dr->row[i]);
60 }
61
62 for (; i != n; i++)
63 rte_pktmbuf_free(dr->row[i]);
64
65 dr->cnt = 0;
66}
67
68/* create fragmentation table */
69struct rte_ip_frag_tbl *
70rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries,
71 uint32_t max_entries, uint64_t max_cycles, int socket_id)
72{
73 struct rte_ip_frag_tbl *tbl;
74 size_t sz;
75 uint64_t nb_entries;
76
77 nb_entries = rte_align32pow2(bucket_num);
78 nb_entries *= bucket_entries;
79 nb_entries *= IP_FRAG_HASH_FNUM;
80
81 /* check input parameters. */
82 if (rte_is_power_of_2(bucket_entries) == 0 ||
83 nb_entries > UINT32_MAX || nb_entries == 0 ||
84 nb_entries < max_entries) {
85 RTE_LOG(ERR, USER1, "%s: invalid input parameter\n", __func__);
86 return NULL;
87 }
88
89 sz = sizeof (*tbl) + nb_entries * sizeof (tbl->pkt[0]);
90 if ((tbl = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE,
91 socket_id)) == NULL) {
92 RTE_LOG(ERR, USER1,
93 "%s: allocation of %zu bytes at socket %d failed do\n",
94 __func__, sz, socket_id);
95 return NULL;
96 }
97
98 RTE_LOG(INFO, USER1, "%s: allocated of %zu bytes at socket %d\n",
99 __func__, sz, socket_id);
100
101 tbl->max_cycles = max_cycles;
102 tbl->max_entries = max_entries;
103 tbl->nb_entries = (uint32_t)nb_entries;
104 tbl->nb_buckets = bucket_num;
105 tbl->bucket_entries = bucket_entries;
106 tbl->entry_mask = (tbl->nb_entries - 1) & ~(tbl->bucket_entries - 1);
107
108 TAILQ_INIT(&(tbl->lru));
109 return tbl;
110}
111
112/* dump frag table statistics to file */
113void
114rte_ip_frag_table_statistics_dump(FILE *f, const struct rte_ip_frag_tbl *tbl)
115{
116 uint64_t fail_total, fail_nospace;
117
118 fail_total = tbl->stat.fail_total;
119 fail_nospace = tbl->stat.fail_nospace;
120
121 fprintf(f, "max entries:\t%u;\n"
122 "entries in use:\t%u;\n"
123 "finds/inserts:\t%" PRIu64 ";\n"
124 "entries added:\t%" PRIu64 ";\n"
125 "entries deleted by timeout:\t%" PRIu64 ";\n"
126 "entries reused by timeout:\t%" PRIu64 ";\n"
127 "total add failures:\t%" PRIu64 ";\n"
128 "add no-space failures:\t%" PRIu64 ";\n"
129 "add hash-collisions failures:\t%" PRIu64 ";\n",
130 tbl->max_entries,
131 tbl->use_entries,
132 tbl->stat.find_num,
133 tbl->stat.add_num,
134 tbl->stat.del_num,
135 tbl->stat.reuse_num,
136 fail_total,
137 fail_nospace,
138 fail_total - fail_nospace);
139}