tcp_ofo.c revision 47eb00f2
1/*
2 * Copyright (c) 2016  Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include <rte_malloc.h>
16#include <rte_errno.h>
17
18#include "tcp_stream.h"
19#include "tcp_rxq.h"
20
21#define	OFO_FRACTION	4
22
23#define OFO_DB_MAX	0x20U
24
25#define OFODB_OBJ_MIN	8U
26#define OFODB_OBJ_MAX	0x20U
27
28#define OFO_OBJ_MAX	(OFODB_OBJ_MAX * OFO_DB_MAX)
29
30static uint32_t
31calc_ofo_size(uint32_t nobj, uint32_t ndb)
32{
33	uint32_t dsz, osz, sz;
34	const struct ofo *ofo = NULL;
35
36	osz = sizeof(*ofo) + sizeof(ofo->db[0]) * ndb;
37	dsz = sizeof(ofo->db[0].obj[0]) * nobj * ndb;
38	sz = osz + dsz;
39	return sz;
40}
41
42void
43tcp_ofo_calc_elems(uint32_t nbufs, uint32_t *nobj, uint32_t *ndb, uint32_t *sz)
44{
45	uint32_t n, nd, no;
46
47	n = nbufs / OFO_FRACTION;
48	n = RTE_MAX(n, OFODB_OBJ_MIN);
49	n = RTE_MIN(n, OFO_OBJ_MAX);
50
51	no = OFODB_OBJ_MIN / 2;
52	do {
53		no *= 2;
54		nd = n / no;
55	} while (nd > OFO_DB_MAX);
56
57	*nobj = no;
58	*ndb = nd;
59	*sz = calc_ofo_size(no, nd);
60}
61
62void
63tcp_ofo_init(struct ofo *ofo, uint32_t nobj, uint32_t ndb)
64{
65	uint32_t i;
66	struct rte_mbuf **obj;
67
68	obj = (struct rte_mbuf **)&ofo->db[ndb];
69	for (i = 0; i != ndb; i++) {
70		ofo->db[i].nb_max = nobj;
71		ofo->db[i].obj = obj + i * nobj;
72	}
73
74	ofo->nb_max = ndb;
75}
76
77