From: Andrei Borzenkov <arvidjaar@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: vasily.isaenko@oracle.com
Subject: Re: [PATCH V2 4/4] ofnet: implement the receive buffer
Date: Sat, 10 Dec 2016 21:29:08 +0300 [thread overview]
Message-ID: <75eb18bf-ccd0-d3a3-ec3a-28f484e82dbc@gmail.com> (raw)
In-Reply-To: <1480691405-15118-5-git-send-email-stanislav.kholmanskikh@oracle.com>
02.12.2016 18:10, Stanislav Kholmanskikh пишет:
> get_card_packet() from ofnet.c allocates a netbuff based on the device's MTU:
>
> nb = grub_netbuff_alloc (dev->mtu + 64 + 2);
>
> In the case when the MTU is large, and the received packet is
> relatively small, this leads to allocation of significantly more memory,
> than it's required. An example could be transmission of TFTP packets
> with 0x400 blksize via a network card with 0x10000 MTU.
>
> This patch implements a per-card receive buffer in a way similar to efinet.c,
> and makes get_card_packet() allocate a netbuff of the received data size.
>
> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
> ---
> grub-core/net/drivers/ieee1275/ofnet.c | 50 ++++++++++++++++++++++---------
> 1 files changed, 35 insertions(+), 15 deletions(-)
>
> diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c
> index 1f8ac9a..471b87b 100644
> --- a/grub-core/net/drivers/ieee1275/ofnet.c
> +++ b/grub-core/net/drivers/ieee1275/ofnet.c
> @@ -85,9 +85,18 @@ get_card_packet (struct grub_net_card *dev)
> grub_uint64_t start_time;
> struct grub_net_buff *nb;
>
> - nb = grub_netbuff_alloc (dev->mtu + 64 + 2);
> + start_time = grub_get_time_ms ();
> + do
> + rc = grub_ieee1275_read (data->handle, dev->rcvbuf, dev->rcvbufsize, &actual);
> + while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200));
> +
> + if (actual <= 0)
> + return NULL;
> +
> + nb = grub_netbuff_alloc (actual + 2);
> if (!nb)
> return NULL;
> +
> /* Reserve 2 bytes so that 2 + 14/18 bytes of ethernet header is divisible
> by 4. So that IP header is aligned on 4 bytes. */
> if (grub_netbuff_reserve (nb, 2))
> @@ -96,17 +105,15 @@ get_card_packet (struct grub_net_card *dev)
> return NULL;
> }
>
> - start_time = grub_get_time_ms ();
> - do
> - rc = grub_ieee1275_read (data->handle, nb->data, dev->mtu + 64, &actual);
> - while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200));
> - if (actual > 0)
> + grub_memcpy (nb->data, dev->rcvbuf, actual);
> +
> + if (grub_netbuff_put (nb, actual))
> {
> - grub_netbuff_put (nb, actual);
> - return nb;
> + grub_netbuff_free (nb);
> + return NULL;
> }
> - grub_netbuff_free (nb);
> - return NULL;
> +
> + return nb;
> }
>
> static struct grub_net_card_driver ofdriver =
> @@ -498,16 +505,21 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
> card->default_address = lla;
>
> card->txbufsize = ALIGN_UP (card->mtu, 64) + 256;
> + card->rcvbufsize = ALIGN_UP (card->mtu, 64) + 256;
>
> card->txbuf = ofnet_alloc_netbuf (card->txbufsize);
> if (!card->txbuf)
> + goto fail_netbuf;
> +
> + card->rcvbuf = ofnet_alloc_netbuf (card->rcvbufsize);
> + if (!card->rcvbuf)
> {
> - grub_free (ofdata->path);
> - grub_free (ofdata);
> - grub_free (card);
> - grub_print_error ();
> - return 1;
> + grub_error_push ();
> + ofnet_free_netbuf(card->txbuf, card->txbufsize);
> + grub_error_pop ();
> + goto fail_netbuf;
> }
> +
> card->driver = NULL;
> card->data = ofdata;
> card->flags = 0;
> @@ -519,6 +531,13 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
> card->driver = &ofdriver;
> grub_net_card_register (card);
> return 0;
> +
> +fail_netbuf:
> + grub_free (ofdata->path);
> + grub_free (ofdata);
> + grub_free (card);
> + grub_print_error ();
> + return 1;
> }
>
> static void
> @@ -553,6 +572,7 @@ GRUB_MOD_FINI(ofnet)
> grub_free (ofdata);
>
> ofnet_free_netbuf (card->txbuf, card->txbufsize);
> + ofnet_free_netbuf (card->rcvbuf, card->rcvbufsize);
>
> grub_free ((void *) card->name);
> grub_free (card);
>
See comment to 3/4. Otherwise OK from my side.
next prev parent reply other threads:[~2016-12-10 18:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-02 15:10 [V2] Implementing the receive buffer for ofnet Stanislav Kholmanskikh
2016-12-02 15:10 ` [PATCH V2 1/4] ofnet: add error check for grub_netbuff_reserve Stanislav Kholmanskikh
2016-12-05 15:49 ` Daniel Kiper
2016-12-10 18:08 ` Andrei Borzenkov
2016-12-12 10:34 ` Stanislav Kholmanskikh
2016-12-12 12:10 ` Andrei Borzenkov
2016-12-02 15:10 ` [PATCH V2 2/4] ofnet: move the allocation of the transmit buffer into a function Stanislav Kholmanskikh
2016-12-05 15:52 ` Daniel Kiper
2016-12-12 9:47 ` Stanislav Kholmanskikh
2016-12-12 10:27 ` Andrei Borzenkov
2016-12-12 10:38 ` Stanislav Kholmanskikh
2016-12-02 15:10 ` [PATCH V2 3/4] ofnet: free memory on module unload Stanislav Kholmanskikh
2016-12-05 16:02 ` Daniel Kiper
2016-12-10 18:18 ` Andrei Borzenkov
2016-12-12 9:56 ` Stanislav Kholmanskikh
2016-12-02 15:10 ` [PATCH V2 4/4] ofnet: implement the receive buffer Stanislav Kholmanskikh
2016-12-05 16:12 ` Daniel Kiper
2016-12-10 18:29 ` Andrei Borzenkov [this message]
2016-12-10 19:50 ` Mark Otto
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=75eb18bf-ccd0-d3a3-ec3a-28f484e82dbc@gmail.com \
--to=arvidjaar@gmail.com \
--cc=grub-devel@gnu.org \
--cc=vasily.isaenko@oracle.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).