Kernel Newbies archive mirror
 help / color / mirror / Atom feed
From: Tony He <huangya90@gmail.com>
To: kernelnewbies@kernelnewbies.org
Subject: The method to alloc DMA ring buffer
Date: Wed, 7 Dec 2022 12:17:05 +0800	[thread overview]
Message-ID: <CAAUX2SWE5oKeJm7F1FYi3TfHaKLJbS4qOd9aF4RonpKoB7=Bng@mail.gmail.com> (raw)

Hi all,

This is my first question in the kernel newbies mailing list. Forgive
me if there is incorrect behavior.

I'm studying the NIC driver with the book <<Understanding the linux
network internals>>. This book uses 3com 3c59x NIC(3c59x.c) as an
example. The driver is very old and few people discuss it, but it's a
good place to start because it's simpler than many other drivers with
advanced offload features.

In the interrupt handler boomerang_rx(), I see it pre-allocate one new
skb and dma map before calling netif_rx.
boomerang_rx()
{
......
/* Pre-allocate the replacement skb.  If it or its
    * mapping fails then recycle the buffer thats already
    * in place
    */
    newskb = netdev_alloc_skb_ip_align(dev, PKT_BUF_SZ);
    if (!newskb) {
    dev->stats.rx_dropped++;
    goto clear_complete;
    }
    newdma = dma_map_single(vp->gendev, newskb->data,
    PKT_BUF_SZ, DMA_FROM_DEVICE);
    if (dma_mapping_error(vp->gendev, newdma)) {
    dev->stats.rx_dropped++;
    consume_skb(newskb);
    goto clear_complete;
    }

    /* Pass up the skbuff already on the Rx ring. */
    skb = vp->rx_skbuff[entry];
    vp->rx_skbuff[entry] = newskb;
    vp->rx_ring[entry].addr = cpu_to_le32(newdma);
    skb_put(skb, pkt_len);
    dma_unmap_single(vp->gendev, dma, PKT_BUF_SZ, DMA_FROM_DEVICE);
    vp->rx_nocopy++;
    ......
    netif_rx(skb);
    .......
}

However, I see intel e1000 driver optimizes this. Intel doesn't
pre-allocate one at a time.
e1000_clean_rx_irq()
{
......
    /* return some buffers to hardware, one at a time is too slow */
    if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
    adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
    cleaned_count = 0;
......
}

I just want to know why this is faster. For all scenarios or some
scenarios? Can someone analyse it rigorously?
My guess is this method reduces the delay when many packets come,
right? Thanks in advance!

Tony

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

             reply	other threads:[~2022-12-07  4:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07  4:17 Tony He [this message]
2022-12-07 19:55 ` The method to alloc DMA ring buffer Tom Mitchell
2022-12-08  2:17   ` Tony He

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='CAAUX2SWE5oKeJm7F1FYi3TfHaKLJbS4qOd9aF4RonpKoB7=Bng@mail.gmail.com' \
    --to=huangya90@gmail.com \
    --cc=kernelnewbies@kernelnewbies.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 read-only IMAP folder(s) and NNTP newsgroup(s).