xref: /spdk/scripts/perf/nvmf/set_xps_rxqs (revision a6dbe3721eb3b5990707fc3e378c95e505dd8ab5)
1c0fc19f3SKarol Latecki#!/bin/bash
2c0fc19f3SKarol Latecki# SPDX-License-Identifier: BSD-3-Clause
3*a6dbe372Spaul luse# Copyright (C) 2021 Intel Corporation.
4c0fc19f3SKarol Latecki#
5c0fc19f3SKarol Latecki# Script to setup mechanism for Tx queue selection based on Rx queue(s) map.
6c0fc19f3SKarol Latecki# This is done by configuring Rx queue(s) map per Tx queue via sysfs. This
7c0fc19f3SKarol Latecki# Rx queue(s) map is used during selection of Tx queue in
8c0fc19f3SKarol Latecki# data path (net/core/dev.c:get_xps_queue).
9c0fc19f3SKarol Latecki#
10c0fc19f3SKarol Latecki# typical usage is (as root):
11c0fc19f3SKarol Latecki# set_xps_rxqs <ethX>
12c0fc19f3SKarol Latecki#
13c0fc19f3SKarol Latecki# to get help:
14c0fc19f3SKarol Latecki# set_xps_rxqs
15c0fc19f3SKarol Latecki
16c0fc19f3SKarol Lateckiiface=$1
17c0fc19f3SKarol Latecki
18c0fc19f3SKarol Lateckiif [ -z "$iface" ]; then
19c0fc19f3SKarol Latecki	echo "Usage: $0 <interface>"
20c0fc19f3SKarol Latecki	exit 1
21c0fc19f3SKarol Lateckifi
22c0fc19f3SKarol Latecki
23c0fc19f3SKarol LateckiCHECK() {
24c0fc19f3SKarol Latecki	if ! "$@"; then
25c0fc19f3SKarol Latecki		echo "Error in command ${1}, execution aborted, but some changes may have already been made!" >&2
26c0fc19f3SKarol Latecki		exit 1
27c0fc19f3SKarol Latecki	fi
28c0fc19f3SKarol Latecki}
29c0fc19f3SKarol Latecki
30c0fc19f3SKarol LateckiCPUMASK() {
31c0fc19f3SKarol Latecki	cpu=$1
32c0fc19f3SKarol Latecki	if [ $cpu -ge 32 ]; then
33c0fc19f3SKarol Latecki		mask_fill=""
34c0fc19f3SKarol Latecki		mask_zero="00000000"
35c0fc19f3SKarol Latecki		pow=$((cpu / 32))
36c0fc19f3SKarol Latecki		for ((i = 1; i <= pow; i++)); do
37c0fc19f3SKarol Latecki			mask_fill="${mask_fill},${mask_zero}"
38c0fc19f3SKarol Latecki		done
39c0fc19f3SKarol Latecki
40c0fc19f3SKarol Latecki		cpu=$((cpu - 32 * pow))
41c0fc19f3SKarol Latecki		mask_tmp=$((1 << cpu))
42c0fc19f3SKarol Latecki		mask=$(printf "%X%s" $mask_tmp $mask_fill)
43c0fc19f3SKarol Latecki	else
44c0fc19f3SKarol Latecki		mask_tmp=$((1 << cpu))
45c0fc19f3SKarol Latecki		mask=$(printf "%X" $mask_tmp)
46c0fc19f3SKarol Latecki	fi
47c0fc19f3SKarol Latecki	echo $mask
48c0fc19f3SKarol Latecki}
49c0fc19f3SKarol Latecki
50c0fc19f3SKarol Lateckifor i in /sys/class/net/"$iface"/queues/tx-*/xps_rxqs; do
51c0fc19f3SKarol Latecki	j=$(echo $i | cut -d'/' -f7 | cut -d'-' -f2)
52c0fc19f3SKarol Latecki	mask=$(CPUMASK $j)
53c0fc19f3SKarol Latecki	echo ${mask} > $i
54c0fc19f3SKarol Latecki	CHECK echo ${mask} > $i
55c0fc19f3SKarol Lateckidone
56