[PATCH 6/6] app/testpmd: factorize fwd engine Tx

Ferruh Yigit ferruh.yigit at amd.com
Thu Feb 16 11:07:30 CET 2023


On 2/16/2023 8:01 AM, Singh, Aman Deep wrote:
> 
> On 2/14/2023 11:47 PM, Ferruh Yigit wrote:
>> On 2/14/2023 11:03 AM, Singh, Aman Deep wrote:
>>> On 1/24/2023 4:17 PM, David Marchand wrote:
>>>> Reduce code duplication by introducing a helper that takes care of
>>>> transmitting, retrying if enabled and incrementing tx counter.
>>>>
>>>> Signed-off-by: David Marchand <david.marchand at redhat.com>
>> <...>
>>
>>>> diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
>>>> index b80ab6f5df..7144b3d5eb 100644
>>>> --- a/app/test-pmd/txonly.c
>>>> +++ b/app/test-pmd/txonly.c
>>>> @@ -331,10 +331,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>>>        struct rte_mbuf *pkt;
>>>>        struct rte_mempool *mbp;
>>>>        struct rte_ether_hdr eth_hdr;
>>>> -    uint16_t nb_tx;
>>>> +    uint16_t nb_dropped;
>>>>        uint16_t nb_pkt;
>>>>        uint16_t vlan_tci, vlan_tci_outer;
>>>> -    uint32_t retry;
>>>>        uint64_t ol_flags = 0;
>>>>        uint64_t tx_offloads;
>>>>    @@ -391,34 +390,18 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>>>        if (nb_pkt == 0)
>>>>            return false;
>>>>    -    nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
>>>> nb_pkt);
>>>> -
>>>> -    /*
>>>> -     * Retry if necessary
>>>> -     */
>>>> -    if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
>>>> -        retry = 0;
>>>> -        while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
>>>> -            rte_delay_us(burst_tx_delay_time);
>>>> -            nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
>>>> -                    &pkts_burst[nb_tx], nb_pkt - nb_tx);
>>>> -        }
>>>> -    }
>>>> -    fs->tx_packets += nb_tx;
>>>> +    nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
>>>>          if (txonly_multi_flow)
>>>> -        RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
>>>> +        RTE_PER_LCORE(_ip_var) -= nb_dropped;
>>>>    -    inc_tx_burst_stats(fs, nb_tx);
>>>> -    if (unlikely(nb_tx < nb_pkt)) {
>>>> +    if (unlikely(nb_dropped > 0)) {
>>>>            if (verbose_level > 0 && fs->fwd_dropped == 0)
>>>>                printf("port %d tx_queue %d - drop "
>>>> -                   "(nb_pkt:%u - nb_tx:%u)=%u packets\n",
>>>> -                   fs->tx_port, fs->tx_queue,
>>>> -                   (unsigned) nb_pkt, (unsigned) nb_tx,
>>>> -                   (unsigned) (nb_pkt - nb_tx));
>>>> -        fs->fwd_dropped += (nb_pkt - nb_tx);
>>>> -        rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
>>>> +                "(nb_pkt:%"PRIu16" - nb_tx:%"PRIu16")="
>>>> +                "%"PRIu16" packets\n",
>>>> +                fs->tx_port, fs->tx_queue, nb_pkt,
>>>> +                nb_pkt - nb_dropped, nb_dropped);
>>> Build error reported in this file here-
>>> ../app/test-pmd/txonly.c:404:5: error: format specifies type 'unsigned
>>> short' but the argument has type 'int' [-Werror,-Wformat]
>>>
>> both 'nb_pkt' & 'nb_dropped' are 'uint16_t' (unsigned short), I wonder
>> which argument is causing this warning?
> 
> I think, subtraction of two unsigned numbers promotes the result to int.
> As 'nb_pkt > nb_dropped', we may explicitly typecast it-
> '(unsigned)(nb_pkt - nb_dropped)'
> 

You are right, subtraction promoted to int.
May be better to cast to 'uint16_t', since warning is not just sign but
also type related.



More information about the dev mailing list