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 E91BB42CA9; Tue, 13 Jun 2023 15:24:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C216640A8A; Tue, 13 Jun 2023 15:24:56 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2081E40698 for ; Tue, 13 Jun 2023 15:24:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686662694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TOjgWxmWbnDUjDvX6xTndGF9e88jbZEuHBblGGRtBk0=; b=KDZ5KqO87cwkLtWRCopjqlNPuUEVIIenZzd3H608w6daADP+bnRCdb2atp+zSpA14lx277 WtUnXIHpNWsmSUFSa55DAlznvZj7GcSvMmKB3LYRuWKYVgz6VoLbeJmks7DNaKO+3q4rEx nFKRCD9qMPL6oPSyuuICJeU1gr3UWEs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-308-9MwgRfqUP7Gfpfb7MNxUeQ-1; Tue, 13 Jun 2023 09:24:51 -0400 X-MC-Unique: 9MwgRfqUP7Gfpfb7MNxUeQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28D1C1C0A584; Tue, 13 Jun 2023 13:24:51 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.225.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id E810040C20F5; Tue, 13 Jun 2023 13:24:49 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Subject: [PATCH v2] ethdev: prefer offload names in logs Date: Tue, 13 Jun 2023 15:24:31 +0200 Message-Id: <20230613132431.781883-1-david.marchand@redhat.com> In-Reply-To: <20230309081633.780438-1-david.marchand@redhat.com> References: <20230309081633.780438-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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 Displaying a bitmask is terrible for users. Prefer offload names when refusing some offloads in rte_eth_dev_configure. Before: Ethdev port_id=0 requested Rx offloads 0x621 doesn't match Rx offloads capabilities 0x0 in rte_eth_dev_configure() After: Ethdev port_id=0 does not support Rx offloads VLAN_STRIP,QINQ_STRIP,VLAN_FILTER,VLAN_EXTEND Ethdev port_id=0 was requested Rx offloads VLAN_STRIP,QINQ_STRIP,VLAN_FILTER,VLAN_EXTEND Ethdev port_id=0 supports Rx offloads none Signed-off-by: David Marchand --- Changes since v1: - reworked string formatter to avoid dynamic allocations, - split log message in three, with the most important part logged as ERR, and the rest being logged as DEBUG, --- lib/ethdev/rte_ethdev.c | 80 ++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 7317015895..731423ef03 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -1047,6 +1047,49 @@ rte_eth_dev_tx_offload_name(uint64_t offload) return name; } +static char * +eth_dev_offload_names(uint64_t bitmask, char *buf, size_t size, + const char *(*offload_name)(uint64_t)) +{ + unsigned int pos = 0; + int ret; + + /* There should be at least enough space to handle those cases */ + RTE_ASSERT(size >= sizeof("none") && size >= sizeof("...")); + + if (bitmask == 0) { + ret = snprintf(&buf[pos], size - pos, "none"); + if (ret < 0 || pos + ret >= size) + ret = 0; + pos += ret; + goto out; + } + + while (bitmask != 0) { + uint64_t offload = RTE_BIT64(__builtin_ctzll(bitmask)); + const char *name = offload_name(offload); + + ret = snprintf(&buf[pos], size - pos, "%s,", name); + if (ret < 0 || pos + ret >= size) { + if (pos + sizeof("...") >= size) + pos = size - sizeof("..."); + ret = snprintf(&buf[pos], size - pos, "..."); + if (ret > 0 && pos + ret < size) + pos += ret; + goto out; + } + + pos += ret; + bitmask &= ~offload; + } + + /* Eliminate trailing comma */ + pos--; +out: + buf[pos] = '\0'; + return buf; +} + const char * rte_eth_dev_capability_name(uint64_t capability) { @@ -1353,23 +1396,36 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, /* Any requested offloading must be within its device capabilities */ if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) != dev_conf->rxmode.offloads) { - RTE_ETHDEV_LOG(ERR, - "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads " - "capabilities 0x%"PRIx64" in %s()\n", - port_id, dev_conf->rxmode.offloads, - dev_info.rx_offload_capa, - __func__); + char buffer[512]; + + RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u does not support Rx offloads %s\n", + port_id, eth_dev_offload_names( + dev_conf->rxmode.offloads & ~dev_info.rx_offload_capa, + buffer, sizeof(buffer), rte_eth_dev_rx_offload_name)); + RTE_ETHDEV_LOG(DEBUG, "Ethdev port_id=%u was requested Rx offloads %s\n", + port_id, eth_dev_offload_names(dev_conf->rxmode.offloads, + buffer, sizeof(buffer), rte_eth_dev_rx_offload_name)); + RTE_ETHDEV_LOG(DEBUG, "Ethdev port_id=%u supports Rx offloads %s\n", + port_id, eth_dev_offload_names(dev_info.rx_offload_capa, + buffer, sizeof(buffer), rte_eth_dev_rx_offload_name)); + ret = -EINVAL; goto rollback; } if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) != dev_conf->txmode.offloads) { - RTE_ETHDEV_LOG(ERR, - "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads " - "capabilities 0x%"PRIx64" in %s()\n", - port_id, dev_conf->txmode.offloads, - dev_info.tx_offload_capa, - __func__); + char buffer[512]; + + RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u does not support Tx offloads %s\n", + port_id, eth_dev_offload_names( + dev_conf->txmode.offloads & ~dev_info.tx_offload_capa, + buffer, sizeof(buffer), rte_eth_dev_tx_offload_name)); + RTE_ETHDEV_LOG(DEBUG, "Ethdev port_id=%u was requested Tx offloads %s\n", + port_id, eth_dev_offload_names(dev_conf->txmode.offloads, + buffer, sizeof(buffer), rte_eth_dev_tx_offload_name)); + RTE_ETHDEV_LOG(DEBUG, "Ethdev port_id=%u supports Tx offloads %s\n", + port_id, eth_dev_offload_names(dev_info.tx_offload_capa, + buffer, sizeof(buffer), rte_eth_dev_tx_offload_name)); ret = -EINVAL; goto rollback; } -- 2.40.1