[PATCH v2] node: lookup with RISC-V vector extension

Stephen Hemminger stephen at networkplumber.org
Sun Feb 1 20:04:05 CET 2026


On Mon,  2 Feb 2026 00:09:31 +0800
Sun Yuechi <sunyuechi at iscas.ac.cn> wrote:

> +static uint16_t
> +ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
> +			void **objs, uint16_t nb_objs)
> +{
> +	struct rte_mbuf **pkts;
> +	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
> +	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
> +	rte_edge_t next_index;
> +	void **to_next, **from;
> +	uint16_t last_spec = 0;
> +	uint16_t n_left_from;
> +	uint16_t held = 0;
> +	uint32_t drop_nh;
> +
> +	/* Temporary arrays for batch processing */
> +	uint32_t ips[RVV_MAX_BURST];
> +	uint32_t res[RVV_MAX_BURST];
> +	rte_edge_t next_hops[RVV_MAX_BURST];
> +
> +	/* Speculative next */
> +	next_index = RTE_NODE_IP4_LOOKUP_NEXT_REWRITE;
> +	/* Drop node */
> +	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
> +
> +	pkts = (struct rte_mbuf **)objs;
> +	from = objs;
> +	n_left_from = nb_objs;
> +
> +	/* Get stream for the speculated next node */
> +	to_next = rte_node_next_stream_get(graph, node, next_index, nb_objs);
> +
> +	while (n_left_from > 0) {
> +		rte_edge_t fix_spec = 0;
> +
> +		size_t vl = __riscv_vsetvl_e32m8(RTE_MIN(n_left_from, RVV_MAX_BURST));
> +
> +		/* Extract IP addresses and metadata from current batch */
> +		for (size_t i = 0; i < vl; i++) {
> +			struct rte_ipv4_hdr *ipv4_hdr =
> +				rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv4_hdr *,
> +						sizeof(struct rte_ether_hdr));
> +			ips[i] = ipv4_hdr->dst_addr;
> +			node_mbuf_priv1(pkts[i], dyn)->cksum = ipv4_hdr->hdr_checksum;
> +			node_mbuf_priv1(pkts[i], dyn)->ttl = ipv4_hdr->time_to_live;
> +		}
> +
> +		/* Perform LPM lookup */
> +		rte_lpm_lookup_vec(lpm, ips, res, vl, drop_nh);
> +
> +		for (size_t i = 0; i < vl; i++) {
> +			/* Update statistics */
> +			if ((res[i] >> 16) == (drop_nh >> 16))
> +				NODE_INCREMENT_XSTAT_ID(node, 0, 1, 1);
> +
> +			/* Extract next hop and next node */
> +			node_mbuf_priv1(pkts[i], dyn)->nh = res[i] & 0xFFFF;
> +			next_hops[i] = res[i] >> 16;
> +
> +			/* Check speculation */
> +			fix_spec |= (next_index ^ next_hops[i]);
> +		}
> +
> +		if (unlikely(fix_spec)) {
> +			/* Copy successfully speculated packets before this batch */
> +			rte_memcpy(to_next, from, last_spec * sizeof(from[0]));

Please use memcpy for this small copy

> +			from += last_spec;
> +			to_next += last_spec;
> +			held += last_spec;
> +			last_spec = 0;
> +
> +			/* Process each packet in current batch individually */
> +			for (size_t i = 0; i < vl; i++) {
> +				if (next_index == next_hops[i]) {
> +					*to_next++ = from[i];
> +					held++;
> +				} else {
> +					rte_node_enqueue_x1(graph, node, next_hops[i], from[i]);
> +				}
> +			}
> +
> +			from += vl;
> +		} else {
> +			last_spec += vl;
> +		}
> +
> +		pkts += vl;
> +		n_left_from -= vl;
> +	}
> +
> +	/* Handle successfully speculated packets */
> +	if (likely(last_spec == nb_objs)) {
> +		rte_node_next_stream_move(graph, node, next_index);
> +		return nb_objs;
> +	}
> +
> +	held += last_spec;
> +	rte_memcpy(to_next, from, last_spec * sizeof(from[0]));

Since compiler doesn't bounds check rte_memcpy() use memcpy here please


More information about the dev mailing list