DPDK patches and discussions
 help / color / mirror / Atom feed
From: "lihuisong (C)" <lihuisong@huawei.com>
To: "Morten Brørup" <mb@smartsharesystems.com>,
	maxime.coquelin@redhat.com, chenbox@nvidia.com
Cc: <stephen@networkplumber.org>, <dev@dpdk.org>
Subject: Re: [PATCH v5] virtio: optimize stats counters performance
Date: Mon, 5 Aug 2024 09:14:09 +0800	[thread overview]
Message-ID: <3f325714-bcde-2ad9-6aaf-6f70c1db0771@huawei.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F5F0@smartserver.smartshare.dk>


在 2024/8/2 19:27, Morten Brørup 写道:
>> From: lihuisong (C) [mailto:lihuisong@huawei.com]
>> Sent: Friday, 2 August 2024 04.23
>>
>> 在 2024/8/2 0:03, Morten Brørup 写道:
>>>    void
>>> -virtio_update_packet_stats(struct virtnet_stats *stats, struct
>> rte_mbuf *mbuf)
>>> +virtio_update_packet_stats(struct virtnet_stats *const stats,
>>> +		const struct rte_mbuf *const mbuf)
>> The two const is also for performace?  Is there gain?
> The "const struct rte_mbuf * mbuf" informs the optimizer that the function does not modify the mbuf.  This is for the benefit of callers of the function; they can rely on the mbuf being unchanged when the function returns.
> So, if the optimizer has cached some mbuf field before calling the function, it does not need to read the mbuf field again, but can continue using the cached value after the function call.
>
> The two "type *const ptr" probably make no performance difference with the compilers and function call conventions used by the CPU architectures supported by DPDK.
ok
>
>>> +	RTE_BUILD_BUG_ON(offsetof(struct virtnet_stats, broadcast) !=
>>> +			offsetof(struct virtnet_stats, multicast) +
>> sizeof(uint64_t));
>>> +	if (unlikely(rte_is_multicast_ether_addr(ea)))
>>> +		(&stats->multicast)[rte_is_broadcast_ether_addr(ea)]++;
>> The "rte_is_broadcast_ether_addr(ea) " will be calculated twice if
>> packet is mulitcast.
>> How about coding like:
>> -->
>> is_mulitcast = rte_is_multicast_ether_addr(ea);
>> if (unlikely(is_mulitcast))
>> (&stats->multicast)[rte_is_broadcast_ether_addr(ea)]++;
> I don't think "rte_is_broadcast_ether_addr(ea)" is calculated twice for multicast packets.
> My code essentially does this:
> 	if (mc(ea))
> 		stats[bc(ea)]++;
>
> Changing to this shouldn't make a difference:
> 	m = mc(ea);
> 	if (m)
> 		stats[bc(ea)]++;
Yeah,you are right.
>

  reply	other threads:[~2024-08-05  1:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31 13:17 [PATCH] " Morten Brørup
2024-07-31 14:04 ` [PATCH v2] " Morten Brørup
2024-07-31 15:13 ` [PATCH v3] " Morten Brørup
2024-07-31 22:58 ` [PATCH v4] " Morten Brørup
2024-07-31 23:45   ` Stephen Hemminger
2024-07-31 23:51     ` Morten Brørup
2024-08-01 16:03 ` [PATCH v5] " Morten Brørup
2024-08-01 16:17   ` Stephen Hemminger
2024-08-01 20:38     ` Morten Brørup
2024-08-02 14:49       ` Morten Brørup
2024-08-02  2:23   ` lihuisong (C)
2024-08-02  2:42     ` Stephen Hemminger
2024-08-02  3:17       ` lihuisong (C)
2024-08-02 11:27     ` Morten Brørup
2024-08-05  1:14       ` lihuisong (C) [this message]
2024-08-05  1:19   ` lihuisong (C)
2024-08-06  8:23   ` Chenbo Xia
2024-09-10 15:01   ` Maxime Coquelin
2024-09-19 12:04   ` Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f325714-bcde-2ad9-6aaf-6f70c1db0771@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=chenbox@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=mb@smartsharesystems.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).