From: Brice Goglin <brice@myri.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: netdev@vger.kernel.org, gallatin@myri.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] myri10ge - Driver core
Date: Sat, 20 May 2006 01:15:55 +0200 [thread overview]
Message-ID: <446E51AB.9080703@myri.com> (raw)
In-Reply-To: <200605180108.32949.arnd@arndb.de>
Arnd Bergmann wrote:
>> +static int myri10ge_open(struct net_device *dev)
>>
>
> This function is too long to read easily.
>
Ok we have split it a little bit.
>> + /* allocate the host shadow rings */
>> +
>> + bytes = 8 + (MYRI10GE_MCP_ETHER_MAX_SEND_DESC_TSO + 4)
>> + * sizeof(*mgp->tx.req_list);
>> + mgp->tx.req_bytes = kmalloc(bytes, GFP_KERNEL);
>> + if (mgp->tx.req_bytes == NULL)
>> + goto abort_with_nothing;
>> + memset(mgp->tx.req_bytes, 0, bytes);
>> +
>> + /* ensure req_list entries are aligned to 8 bytes */
>> + mgp->tx.req_list = (struct mcp_kreq_ether_send *)
>> + ALIGN((unsigned long)mgp->tx.req_bytes, 8);
>> +
>> + bytes = rx_ring_entries * sizeof(*mgp->rx_small.shadow);
>> + mgp->rx_small.shadow = kmalloc(bytes, GFP_KERNEL);
>> + if (mgp->rx_small.shadow == NULL)
>> + goto abort_with_tx_req_bytes;
>> + memset(mgp->rx_small.shadow, 0, bytes);
>> +
>> + bytes = rx_ring_entries * sizeof(*mgp->rx_big.shadow);
>> + mgp->rx_big.shadow = kmalloc(bytes, GFP_KERNEL);
>> + if (mgp->rx_big.shadow == NULL)
>> + goto abort_with_rx_small_shadow;
>> + memset(mgp->rx_big.shadow, 0, bytes);
>> +
>> + /* allocate the host info rings */
>> +
>> + bytes = tx_ring_entries * sizeof(*mgp->tx.info);
>> + mgp->tx.info = kmalloc(bytes, GFP_KERNEL);
>> + if (mgp->tx.info == NULL)
>> + goto abort_with_rx_big_shadow;
>> + memset(mgp->tx.info, 0, bytes);
>> +
>> + bytes = rx_ring_entries * sizeof(*mgp->rx_small.info);
>> + mgp->rx_small.info = kmalloc(bytes, GFP_KERNEL);
>> + if (mgp->rx_small.info == NULL)
>> + goto abort_with_tx_info;
>> + memset(mgp->rx_small.info, 0, bytes);
>> +
>> + bytes = rx_ring_entries * sizeof(*mgp->rx_big.info);
>> + mgp->rx_big.info = kmalloc(bytes, GFP_KERNEL);
>> + if (mgp->rx_big.info == NULL)
>> + goto abort_with_rx_small_info;
>> + memset(mgp->rx_big.info, 0, bytes);
>> +
>>
>
> Can you do all these allocations at once? Maybe you can even
> move them into the size passed to alloc_etherdev.
>
They are different things conceptually, so we prefer to allocate
them separately.
> If you need separate allocations, using kzalloc simplifies
> your code.
>
Right, will do.
>> + /* Break the SKB or Fragment up into pieces which
>> + * do not cross mgp->tx.boundary */
>> + low = MYRI10GE_LOWPART_TO_U32(bus);
>> + high_swapped = htonl(MYRI10GE_HIGHPART_TO_U32(bus));
>> + while (len) {
>> + u8 flags_next;
>> + int cum_len_next;
>> +
>> + if (unlikely(count == max_segments))
>> + goto abort_linearize;
>> +
>> + boundary = (low + tx->boundary) & ~(tx->boundary - 1);
>> + seglen = boundary - low;
>> + if (seglen > len)
>> + seglen = len;
>> + flags_next = flags & ~MYRI10GE_MCP_ETHER_FLAGS_FIRST;
>> + cum_len_next = cum_len + seglen;
>> +#ifdef NETIF_F_TSO
>> + if (mss) { /* TSO */
>> + (req - rdma_count)->rdma_count = rdma_count + 1;
>> +
>> + if (likely(cum_len >= 0)) { /* payload */
>> + int next_is_first, chop;
>> +
>> + chop = (cum_len_next > mss);
>> + cum_len_next = cum_len_next % mss;
>> + next_is_first = (cum_len_next == 0);
>> + flags |= chop *
>> + MYRI10GE_MCP_ETHER_FLAGS_TSO_CHOP;
>> + flags_next |= next_is_first *
>> + MYRI10GE_MCP_ETHER_FLAGS_FIRST;
>> + rdma_count |= -(chop | next_is_first);
>> + rdma_count += chop & !next_is_first;
>> + } else if (likely(cum_len_next >= 0)) { /* header ends */
>> + int small;
>> +
>> + rdma_count = -1;
>> + cum_len_next = 0;
>> + seglen = -cum_len;
>> + small =
>> + (mss <=
>> + MYRI10GE_MCP_ETHER_SEND_SMALL_SIZE);
>> + flags_next =
>> + MYRI10GE_MCP_ETHER_FLAGS_TSO_PLD |
>> + MYRI10GE_MCP_ETHER_FLAGS_FIRST |
>> + (small *
>> + MYRI10GE_MCP_ETHER_FLAGS_SMALL);
>> + }
>> + }
>>
>
> 100 characters per line are too much, as are six levels of intentation,
> or the number of lines in this function.
> You should try to split into into smaller ones.
>
We have tried :) But there is no nice way to split this code. So I guess
we will have to keep it like this.
Thanks,
Brice
next prev parent reply other threads:[~2006-05-19 23:16 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-17 22:02 [PATCH 0/4] myri10ge - Myri-10G Ethernet driver - v2 Brice Goglin
2006-05-17 22:03 ` [PATCH 1/4] myri10ge - Revive pci_find_ext_capability Brice Goglin
2006-05-17 22:04 ` [PATCH 2/4] myri10ge - Driver header files Brice Goglin
2006-05-17 22:28 ` Randy.Dunlap
2006-05-18 23:36 ` Brice Goglin
2006-05-17 22:06 ` [PATCH 3/4] myri10ge - Driver core Brice Goglin
2006-05-17 22:36 ` Roland Dreier
2006-05-18 23:38 ` Brice Goglin
2006-05-17 23:08 ` Arnd Bergmann
2006-05-18 23:56 ` Brice Goglin
2006-05-19 1:55 ` Arnd Bergmann
2006-05-19 2:25 ` Brice Goglin
2006-05-19 10:00 ` Arnd Bergmann
2006-05-19 11:09 ` Andi Kleen
2006-05-19 15:48 ` Brice Goglin
2006-05-20 7:58 ` Brice Goglin
2006-05-19 14:39 ` Brice Goglin
2006-05-19 23:15 ` Brice Goglin [this message]
2006-05-20 0:01 ` Andi Kleen
2006-05-23 15:39 ` Anton Blanchard
2006-05-24 8:04 ` Brice Goglin
2006-05-24 21:21 ` Anton Blanchard
2006-05-25 7:59 ` Benjamin Herrenschmidt
2006-05-25 9:07 ` Brice Goglin
2006-05-25 7:56 ` Benjamin Herrenschmidt
2006-05-26 9:49 ` Ingo Oeser
2006-05-26 10:02 ` Benjamin Herrenschmidt
2006-05-26 10:30 ` Jeff Garzik
2006-05-26 10:56 ` Benjamin Herrenschmidt
2006-05-17 22:07 ` [PATCH 4/4] myri10ge - Kconfig and Makefile Brice Goglin
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=446E51AB.9080703@myri.com \
--to=brice@myri.com \
--cc=arnd@arndb.de \
--cc=gallatin@myri.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.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).