netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Jose E. Marchesi" <jose.marchesi@oracle.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Magnus Karlsson" <magnus.karlsson@intel.com>,
	"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
	"Przemek Kitszel" <przemyslaw.kitszel@intel.com>,
	"Jason Baron" <jbaron@akamai.com>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	bpf@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 6/7] xsk: add helper to get &xdp_desc's DMA and meta pointer in one go
Date: Mon, 23 Dec 2024 14:50:54 +0100	[thread overview]
Message-ID: <28af573f-2718-4d09-9dbd-0bb5764dc794@intel.com> (raw)
In-Reply-To: <20241220092647.63affabc@kernel.org>

From: Jakub Kicinski <kuba@kernel.org>
Date: Fri, 20 Dec 2024 09:26:47 -0800

> On Fri, 20 Dec 2024 16:58:57 +0100 Alexander Lobakin wrote:
>>> On Wed, 18 Dec 2024 18:44:34 +0100 Alexander Lobakin wrote:  
>>>> +	ret = (typeof(ret)){
>>>> +		/* Same logic as in xp_raw_get_dma() */
>>>> +		.dma	= (pool->dma_pages[addr >> PAGE_SHIFT] &
>>>> +			   ~XSK_NEXT_PG_CONTIG_MASK) + (addr & ~PAGE_MASK),
>>>> +	};  
>>>
>>> This is quite ugly IMHO  
>>
>> What exactly: that the logic is copied or how that code (>> & ~ + & ~)
>> looks like?
>>
>> If the former, I already thought of making a couple internal defs to
>> avoid copying.
>> If the latter, I also thought of this, just wanted to be clear that it's
>> the same as in xp_raw_get_dma(). But it can be refactored to look more
>> fancy anyway.
>>
>> Or the compound return looks ugly? Or the struct initialization?
> 
> Compound using typeof() and the fact it's multi line.
> 
> It's a two member struct, which you return by value,
> so unlikely to grow. Why not init the members manually?

BTW sometimes such compound initializations are faster than
member-by-member assignment. *Not* in this case, however, so sure,
done already.

> 
> And you could save the intermediate computations to a temp variable
> (addr >> PAGE_SHIFT, addr & ~PAGE_MASK) to make the line shorter.

I'll just derive it into a oneliner to not copy the same stuff again
between functions; also, page helpers like PHYS_PFN() and
offset_in_page() can be used here instead of open-coding.

Merry holidays!
Olek

  reply	other threads:[~2024-12-23 13:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-18 17:44 [PATCH net-next 0/7] xdp: a fistful of generic changes pt. III Alexander Lobakin
2024-12-18 17:44 ` [PATCH net-next 1/7] page_pool: add page_pool_dev_alloc_netmem() Alexander Lobakin
2024-12-18 17:44 ` [PATCH net-next 2/7] xdp: add generic xdp_buff_add_frag() Alexander Lobakin
2024-12-18 17:44 ` [PATCH net-next 3/7] xdp: add generic xdp_build_skb_from_buff() Alexander Lobakin
2024-12-18 17:44 ` [PATCH net-next 4/7] xsk: make xsk_buff_add_frag() really add the frag via __xdp_buff_add_frag() Alexander Lobakin
2024-12-18 17:44 ` [PATCH net-next 5/7] xsk: add generic XSk &xdp_buff -> skb conversion Alexander Lobakin
2024-12-18 17:44 ` [PATCH net-next 6/7] xsk: add helper to get &xdp_desc's DMA and meta pointer in one go Alexander Lobakin
2024-12-20  3:50   ` Jakub Kicinski
2024-12-20 15:58     ` Alexander Lobakin
2024-12-20 17:26       ` Jakub Kicinski
2024-12-23 13:50         ` Alexander Lobakin [this message]
2024-12-18 17:44 ` [PATCH net-next 7/7] unroll: add generic loop unroll helpers Alexander Lobakin
2024-12-20  4:00 ` [PATCH net-next 0/7] xdp: a fistful of generic changes pt. III patchwork-bot+netdevbpf

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=28af573f-2718-4d09-9dbd-0bb5764dc794@intel.com \
    --to=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jbaron@akamai.com \
    --cc=john.fastabend@gmail.com \
    --cc=jose.marchesi@oracle.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=nathan@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=toke@redhat.com \
    /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).