/* // Copyright (c) 2010-2017 Intel Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. */ #include #include #include #include "rx_pkt.h" #include "task_base.h" #include "clock.h" #include "stats.h" #include "log.h" #include "mbuf_utils.h" #include "input.h" /* Needed for callback on dump */ /* _param version of the rx_pkt_hw functions are used to create two instances of very similar variations of these functions. The variations are specified by the "multi" parameter which significies that the rte_eth_rx_burst function should be called multiple times. The reason for this is that with the vector PMD, the maximum number of packets being returned is 32. If packets have been split in multiple mbufs then rte_eth_rx_burst might even receive less than 32 packets. Some algorithms (like QoS) only work correctly if more than 32 packets are received if the dequeue step involves finding 32 packets. */ #define MIN_PMD_RX 32 static uint16_t rx_pkt_hw_port_queue(struct port_queue *pq, struct rte_mbuf **mbufs, int multi) { uint16_t nb_rx, n; nb_rx = rte_eth_rx_burst(pq->port, pq->queue, mbufs, MAX_PKT_BURST); if (multi) { n = nb_rx; while (n != 0 && MAX_PKT_BURST - nb_rx >= MIN_PMD_RX) { n = rte_eth_rx_burst(pq->port, pq->queue, mbufs + nb_rx, MIN_PMD_RX); nb_rx += n; PROX_PANIC(nb_rx > 64, "Received %d packets while expecting maximum %d\n", n, MIN_PMD_RX); } } return nb_rx; } static void next_port(struct rx_params_hw *rx_params_hw) { ++rx_params_hw->last_read_portid; if (unlikely(rx_params_hw->last_read_portid == rx_params_hw->nb_rxports)) { rx_params_hw->last_read_portid = 0; } } static void next_port_pow2(struct rx_params_hw *rx_params_hw) { rx_params_hw->last_read_portid = (rx_params_hw->last_read_portid + 1) & rx_params_hw->rxport_mask; } static uint16_t rx_pkt_hw_param(struct task_base *tbase, struct rte_mbuf ***mbufs, int multi, void (*next)(struct rx_params_hw *rx_param_hw)) { uint8_t last_read_portid; uint16_t nb_rx; START_EMPTY_MEASSURE(); *mbufs = tbase->ws_mbuf->mbuf[0] + (RTE_ALIGN_CEIL(tbase->ws_mbuf->idx[0].prod, 2) & WS_MBUF_MASK); last_read_portid = tbase->rx_params_hw.last_read_portid; struct port_queue *pq = &tbase->rx_params_hw.rx_pq[last_read_portid]; nb_rx = rx_pkt_hw_port_queue(pq, *mbufs, multi); next(&tbase->rx_params_hw); if (likely(nb_rx > 0)) { TASK_STATS_ADD_RX(&tbase->aux->stats, nb_rx); return nb_rx; } TASK_STATS_ADD_IDLE(&tbase->aux->stats, rte_rdtsc() - cur_tsc); return 0; } static inline uint16_t rx_pkt_hw1_param(struct task_base *tbase, struct rte_mbuf ***mbufs, int multi) { uint16_t nb_rx, n; START_EMPTY_MEASSURE(); *mbufs = tbase->ws_mbuf->mbuf[0] + (RTE_ALIGN_CEIL(tbase->ws_mbuf->idx[0].prod, 2) & WS_MBUF_MASK); nb_rx = rte_eth_rx_burst(tbase->rx_params_hw1.rx_pq.port, tbase->rx_params_hw1.rx_pq.queue, *mbufs, MAX_PKT_BURST); if (multi) { n = nb_rx; while ((n != 0) && (MAX_PKT_BURST - nb_rx >= MIN_PMD_RX)) { n = rte_eth_rx_burst(tbase->rx_params_hw1.rx_pq.port, tbase->rx_params_hw1.rx_pq.queue, *mbufs + nb_rx, MIN_PMD_RX); nb_rx += n; PROX_PANIC(nb_rx > 64, "Received %d packets while expecting maximum %d\n", n, MIN_PMD_RX); } } if (likely(nb_rx > 0)) { TASK_STATS_ADD_RX(&tbase->aux->stats, nb_rx); return nb_rx; } TASK_STATS_ADD_IDLE(&tbase->aux->stats, rte_rdtsc() - cur_tsc); return 0; } uint16_t rx_pkt_hw(struct task_base *tbase, struct rte_mbuf ***mbufs) { return rx_pkt_hw_param(tbase, mbufs, 0, next_port); } uint16_t rx_pkt_hw_pow2(struct task_base *tbase, struct rte_mbuf ***mbufs) { return rx_pkt_hw_param(tbase, mbufs, 0, next_port_pow2); } uint16_t rx_pkt_hw1(struct task_base *tbase, struct rte_mbuf ***mbufs) { return rx_pkt_hw1_param(tbase, mbufs, 0); } uint16_t rx_pkt_hw_multi(struct task_base *tbase, struct rte_mbuf ***mbufs) { return rx_pkt_hw_param(tbase, mbufs, 1, next_port); } uint16_t rx_pkt_hw_pow2_multi(
/*
// Copyright (c) 2010-2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

#include <rte_malloc.h>

#include "prox_malloc.h"

#ifndef RTE_CACHE_LINE_SIZE
#define RTE_CACHE_LINE_SIZE CACHE_LINE_SIZE
#endif

void *prox_zmalloc(size_t size, int socket)
{
	return rte_zmalloc_socket(NULL, size, RTE_CACHE_LINE_SIZE, socket);
}

void prox_free(void *ptr)
{
	rte_free(ptr);
}