From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ABCF343380; Mon, 20 Nov 2023 17:24:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98E6E42DDE; Mon, 20 Nov 2023 17:24:57 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 0733B42DD2 for ; Mon, 20 Nov 2023 17:24:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700497495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZxEHw4Nku61+iu42MEl7doQM7ZVPR3esNq1nfclmLPo=; b=Qx/XOREEFepLUEdRhHsDsKwc8Gym4gsl4/Ux016IePSM3zbPpTOVXAeL3etSgvTDVrVmMH CWe9hqnKWd9mz6lmSiFvLVjzCKHzoz6hFz4HGqcLGSat1N4M6hV1PnZlGL1wZCo4O1Lt1B 0Bcu0ROqW8h+Zy6wTG/U+amzkuPP9EU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-PwyH2kxkOdmBFsD5Ot2o0w-1; Mon, 20 Nov 2023 11:24:54 -0500 X-MC-Unique: PwyH2kxkOdmBFsD5Ot2o0w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFF1B185A784 for ; Mon, 20 Nov 2023 16:24:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47FAA2166B26 for ; Mon, 20 Nov 2023 16:24:53 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org Subject: [PATCH v2 1/3] usertools/rss: add driver abstractions Date: Mon, 20 Nov 2023 17:22:57 +0100 Message-ID: <20231120162256.74399-4-rjarry@redhat.com> In-Reply-To: <20231023080710.240402-3-rjarry@redhat.com> References: <20231023080710.240402-3-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The default RETA size is not the same for all drivers. In some drivers (mlx5), the RETA size may also be dependent on the number of RX queues. Introduce a new DriverInfo abstraction for known keys. Define a simple API to expose the RSS key and RETA size (based on the number of RX queues). Use that abstraction for all three known keys. Signed-off-by: Robin Jarry --- usertools/dpdk-rss-flows.py | 151 ++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 58 deletions(-) diff --git a/usertools/dpdk-rss-flows.py b/usertools/dpdk-rss-flows.py index 73821eb47125..241ee4fe28c6 100755 --- a/usertools/dpdk-rss-flows.py +++ b/usertools/dpdk-rss-flows.py @@ -154,60 +154,81 @@ def balanced_traffic( NO_PORT = (0,) -# fmt: off -# rss_intel_key, see drivers/net/ixgbe/ixgbe_rxtx.c -RSS_KEY_INTEL = bytes( - ( - 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, - 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, - 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, - 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, - 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, - ) -) -# rss_hash_default_key, see drivers/net/mlx5/mlx5_rxq.c -RSS_KEY_MLX = bytes( - ( - 0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7, - 0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94, - 0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1, - 0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59, - 0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a, - ) -) -# rss_key_default, see drivers/net/i40e/i40e_ethdev.c -# i40e is the only driver that takes 52 bytes keys -RSS_KEY_I40E = bytes( - ( - 0x44, 0x39, 0x79, 0x6b, 0xb5, 0x4c, 0x50, 0x23, - 0xb6, 0x75, 0xea, 0x5b, 0x12, 0x4f, 0x9f, 0x30, - 0xb8, 0xa2, 0xc0, 0x3d, 0xdf, 0xdc, 0x4d, 0x02, - 0xa0, 0x8c, 0x9b, 0x33, 0x4a, 0xf6, 0x4a, 0x4c, - 0x05, 0xc6, 0xfa, 0x34, 0x39, 0x58, 0xd8, 0x55, - 0x7d, 0x99, 0x58, 0x3a, 0xe1, 0x38, 0xc9, 0x2e, - 0x81, 0x15, 0x03, 0x66, - ) -) -# fmt: on -DEFAULT_DRIVER_KEYS = { - "intel": RSS_KEY_INTEL, - "mlx": RSS_KEY_MLX, - "i40e": RSS_KEY_I40E, + +class DriverInfo: + def __init__(self, key: bytes = None, reta_size: int = None): + self.__key = key + self.__reta_size = reta_size + + def rss_key(self) -> bytes: + return self.__key + + def reta_size(self, num_queues: int) -> int: + return self.__reta_size + + +class MlxDriverInfo(DriverInfo): + def rss_key(self) -> bytes: + return bytes( + ( + # fmt: off + # rss_hash_default_key, see drivers/net/mlx5/mlx5_rxq.c + 0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7, + 0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94, + 0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1, + 0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59, + 0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a, + # fmt: on + ) + ) + + def reta_size(self, num_queues: int) -> int: + if num_queues & (num_queues - 1) == 0: + # If the requested number of RX queues is power of two, + # use a table of this size. + return num_queues + # otherwise, use the maximum table size + return 512 + + +DEFAULT_DRIVERS = { + "intel": DriverInfo( + key=bytes( + ( + # fmt: off + # rss_intel_key, see drivers/net/ixgbe/ixgbe_rxtx.c + 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, + 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, + 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, + 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, + 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, + # fmt: on + ) + ), + reta_size=128, + ), + "mlx": MlxDriverInfo(), + "i40e": DriverInfo( + key=bytes( + ( + # fmt: off + # rss_key_default, see drivers/net/i40e/i40e_ethdev.c + # i40e is the only driver that takes 52 bytes keys + 0x44, 0x39, 0x79, 0x6b, 0xb5, 0x4c, 0x50, 0x23, + 0xb6, 0x75, 0xea, 0x5b, 0x12, 0x4f, 0x9f, 0x30, + 0xb8, 0xa2, 0xc0, 0x3d, 0xdf, 0xdc, 0x4d, 0x02, + 0xa0, 0x8c, 0x9b, 0x33, 0x4a, 0xf6, 0x4a, 0x4c, + 0x05, 0xc6, 0xfa, 0x34, 0x39, 0x58, 0xd8, 0x55, + 0x7d, 0x99, 0x58, 0x3a, 0xe1, 0x38, 0xc9, 0x2e, + 0x81, 0x15, 0x03, 0x66, + # fmt: on + ) + ), + reta_size=512, + ), } -def rss_key(value): - if value in DEFAULT_DRIVER_KEYS: - return DEFAULT_DRIVER_KEYS[value] - try: - key = binascii.unhexlify(value) - if len(key) not in (40, 52): - raise argparse.ArgumentTypeError("The key must be 40 or 52 bytes long") - return key - except (TypeError, ValueError) as e: - raise argparse.ArgumentTypeError(str(e)) from e - - def port_range(value): try: if "-" in value: @@ -296,21 +317,20 @@ def parse_args(): parser.add_argument( "-k", "--rss-key", - default=RSS_KEY_INTEL, - type=rss_key, - help=""" - The random 40-bytes key used to compute the RSS hash. This option + default="intel", + help=f""" + The random key used to compute the RSS hash. This option supports either a well-known name or the hex value of the key - (well-known names: "intel", "mlx", default: "intel"). + (well-known names: {', '.join(DEFAULT_DRIVERS)}, default: intel). """, ) parser.add_argument( "-t", "--reta-size", - default=128, type=power_of_two, help=""" - Size of the redirection table or "RETA" (default: 128). + Size of the redirection table or "RETA" (default: depends on driver if + using a well-known driver name, otherwise 128). """, ) parser.add_argument( @@ -339,9 +359,24 @@ def parse_args(): parser.error( f"{args.ip_src} and {args.ip_dst} don't have the same protocol version" ) + + if args.rss_key in DEFAULT_DRIVERS: + driver_info = DEFAULT_DRIVERS[args.rss_key] + else: + try: + key = binascii.unhexlify(args.rss_key) + except (TypeError, ValueError) as e: + parser.error(f"RSS_KEY: {e}") + driver_info = DriverInfo(key=key, reta_size=128) + + if args.reta_size is None: + args.reta_size = driver_info.reta_size(args.rx_queues) + if args.reta_size < args.rx_queues: parser.error("RETA_SIZE must be greater than or equal to RX_QUEUES") + args.rss_key = driver_info.rss_key() + return args -- 2.42.0