From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: USB list <linux-usb@vger.kernel.org>,
Sarah Sharp <sarah.a.sharp@linux.intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFCv2 01/10] xhci: Use command structures when calling xhci_configure_endpoint
Date: Wed, 05 Feb 2014 17:00:13 +0200 [thread overview]
Message-ID: <52F251FD.1080503@linux.intel.com> (raw)
In-Reply-To: <CAPcyv4gqcf2b8Yv-rqg0OiEeOeN4P4g-um+oYzMDXW6Y7N8qeQ@mail.gmail.com>
On 02/05/2014 04:21 AM, Dan Williams wrote:
> Hi Mathias, comments below:
>
> s/xhci_check_bandwith/xhci_check_bandwidth/
> s/strucure/structure/
> s/strucure/structure/
> s/requre/require/
> s/strucure/structure/
>
Thanks
I guess I need to start using a spell checker for commit messages.
>
> One cleanup we may want to consider in this series is making
> xhci_alloc_command() more readable. My brain hurts when I see "false,
> false" as I wonder what that means. I took a look and of the 4
> possible ways to call xhci_alloc_command, we only use 2:
>
> $ git grep xhci_alloc_command\(.*\) | grep -o
> xhci_alloc_command\(xhci,.*,.*, | sort -u
> xhci_alloc_command(xhci, false, true,
> xhci_alloc_command(xhci, true, true,
>
> So a first take is to just have a xhci_alloc_command() for "true,
> true" and a xhci_alloc_command_no_ctx() for "false, true".
>
> ...uh oh, this series adds a usage of:
> xhci_alloc_command(xhci, false, false,
>
> ...any reason we can't just use something like
> xhci_alloc_command_no_ctx() instead?
>
> Actually just make xhci_alloc_command() take an option in_ctx
> parameter, when it is NULL xhci_alloc_command will allocate one,
> otherwise it will use the passed in one.
>
This would make the code more readable.
The same thing needs to be done for the completion parameter as well then.
Do you think this change would fit in this patch series, or maybe as a
separate fix?
>> xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
>> "Queueing configure endpoint command");
>> xhci_queue_configure_endpoint(xhci,
>> xhci->devs[slot_id]->in_ctx->dma, slot_id,
>> false);
>> xhci_ring_cmd_db(xhci);
>> + kfree(command);
>
> It's not really acceptable to add dead code in a patch. Consider the
> case where some of the patches are reverted due to a regression. If,
> for example we revert patch 2, the unused infrastructure in patch1
> does not get deleted. Patch size minimization is good, but not when
> it separates new infrastructure from its first user.
This was a tradeoff I wasn't sure how to do. The first six patches make
sure there exists a command structure every time a command is submitted.
I added the kfrees because I didn't want to leak memory
up to the patch where the command can be freed in its right place (patch
9).
Actually, now looking at it, the command is still not properly freed
between patches 7 and 9.
Any suggestions? squashing first most of the commits together, or just
ignoring that memory is leaked mid-series?
>> -bandwidth_change:
>> - xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
>> - "Completed config ep cmd");
>> - virt_dev->cmd_status = cmd_comp_code;
>> - complete(&virt_dev->cmd_completion);
>> return;
>
> This change has no description in the change log. What's the reason
> for deleting the goto?
>
Previously xhci_configure_endpoint() could also be called without a
command parameter. In this case the completion was _not_ added to
device's own "command wait list". xhci_configure_endpoint() would wait
for completion on xhci->devs[udev->slot_id]->cmd_completion, and
the code after the bandwith_change goto was run.
Now this patch forces all xhci_configure_endpoint() callers to have a
command structure parameter, and now in all cases we're waiting for a
configure endpoint completion, the completion is added to the device's
own "command wait list". These completions are called in the beginning
of handle_cmd_completion_ep by handle_cmd_in_cmd_wait_list().
I probably should add some description about this in the changelog as well.
>
> Given that we are waiting for the command to finish within
> xhci_configure_endpoint() shouldn't we free the completion in
> xhci_configure_endpoint as well? In other words in what cases do we
> need an xhci_command to have a longer lifetime than the scope of the
> execution routine (xhci_stop_device, xhci_configure_endpoint,
> xhci_discover_or_reset_device, xhci_alloc_dev, xhci_setup_device).
Many of the functions that call xhci_configure_endpoint() handle their
command strucure and completion allocation/freeing in their own little
way. I didn't want to mess with these.
For example
xhci_free_streams() uses some pre-allocated command strucure
command = vdev->eps[ep_index].stream_info->free_streams_command;
while xhci_update_hub_device() allocates a new command with completion
before calling xhci_configure_endpoint(), and frees them both afterwards
>
> Taking things a step further it seems that all the locations where we
> asynchronously queue commands are in the completion handlers for other
> commands. I'm wondering if this would be cleaner if we simply queued
> all command submissions and completion events to a single threaded
> workqueue. I'll go through the rest of the series to see if that
> impression makes sense, but something to consider...
>
Handling the command completions in a workqueue could make sense, then
all the async-queued commands could be allocated outside interrupt
context. Not sure if this would expose or create some new races.
I'm not completely sure on what you have in mind when you say you want
to "queue all command submission and completion events to a single
threaded workqueue"
Thanks for taking a look at this
-Mathias
next prev parent reply other threads:[~2014-02-05 14:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-30 14:10 [RFCv2 00/10] xhci: re-work command queue management Mathias Nyman
2014-01-30 14:10 ` [RFCv2 01/10] xhci: Use command structures when calling xhci_configure_endpoint Mathias Nyman
2014-02-05 2:21 ` Dan Williams
2014-02-05 15:00 ` Mathias Nyman [this message]
2014-01-30 14:10 ` [RFCv2 02/10] xhci: use a command structure internally in xhci_address_device() Mathias Nyman
2014-01-30 14:10 ` [RFCv2 03/10] xhci: use command structures for xhci_queue_slot_control() Mathias Nyman
2014-01-30 14:10 ` [RFCv2 04/10] xhci: use command structures for xhci_queue_stop_endpoint() Mathias Nyman
2014-01-30 14:10 ` [RFCv2 05/10] xhci: use command structure for xhci_queue_new_dequeue_state() Mathias Nyman
2014-01-30 14:10 ` [RFCv2 06/10] xhci: use command structures for xhci_queue_reset_ep() Mathias Nyman
2014-01-30 14:10 ` [RFCv2 07/10] xhci: Use command structured when queuing commands Mathias Nyman
2014-01-30 14:10 ` [RFCv2 08/10] xhci: Add a global command queue Mathias Nyman
2014-02-05 6:57 ` Dan Williams
2014-02-05 22:23 ` Sarah Sharp
2014-01-30 14:10 ` [RFCv2 09/10] xhci: Use completion and status in " Mathias Nyman
2014-01-30 14:10 ` [RFCv2 10/10] xhci: rework command timeout and cancellation, Mathias Nyman
2014-01-30 14:25 ` [RFCv2 00/10] xhci: re-work command queue management David Laight
2014-01-30 22:39 ` Sarah Sharp
2014-02-05 2:35 ` Dan Williams
2014-02-05 9:22 ` David Laight
2014-02-05 16:48 ` Dan Williams
2014-02-05 17:05 ` David Laight
2014-02-05 17:27 ` Dan Williams
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=52F251FD.1080503@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=dan.j.williams@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sarah.a.sharp@linux.intel.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