greybus: loopback: provide interface to read all latency data-points
The current loopback code provides the minimum, maximum and average latency
values for a given test set. It would be highly useful for user-space to
have access to each one of the latency metrics in order to graph outliers.
This patch adds a simple character device interface implmenting a read()
interface that allows user-space to read out the saved latency metrics
which have been stored in a kfifo for this purpose.
A module parameter is provided to allow varying the depth of the kfifo in
order to allow a user to capture potentially large data sets. This version
sets the default depth for the kfifo at 8192 dwords.
Current code allows a sysfs callback and a kernel worker thread to write
all over and act upon data that could be in the process of being updated by
the other. This patch adds a reasonably coarse mutex to enscure sync
between the two.
It is of more interest to graphing system performance to base our
timestamps on the time it takes a greybus_operation_sync() to complete.
Higher level timestamping code is less accurate and not relevant to
throughput and latency characterization.
greybus: initialize svc connection while creating hd
Its really part of initializing the host device and is required for
every 'hd' that is created. Lets move the call to do basic
initialization of svc connection to greybus_create_hd().
Also add a comment to specify why we need to do it that early.
greybus: core: clean up ida memory for host controller
We forgot to free any ida internal structures that were used by this
host controller structure when we free the memory for the controller.
So fix that up by doing so in the release function.
Perry Hung [Fri, 24 Jul 2015 23:02:34 +0000 (19:02 -0400)]
greybus: svc: add flags and traffic class parameter to connection create op
The AP needs to be able to specify L4 CPort flags and traffic class
parameters on a connection-by-connection basis. Extend the connection
create operation to accept these. Since there's no policy to decide
these, fix them at TC0 with end-to-end-flow control, controlled segment
dropping, and CPort safety valve enabled.
Perry Hung [Fri, 24 Jul 2015 23:02:32 +0000 (19:02 -0400)]
greybus: svc: create bidirectional routes on hotplug request
Upon receiving a hotplug request, we need to prepare the routing table
to allow packets to flow between the AP interface and the newly detected
interface.
We have switched over to use the "new" svc messages, no more need to
have a special USB endpoint to handle them, they come through the normal
CPort messages.
We have switched over to use the "new" svc messages, no more need to
have a special USB endpoint to handle them, they come through the normal
CPort messages.
Perry Hung [Fri, 24 Jul 2015 23:02:30 +0000 (19:02 -0400)]
greybus: connection: silence warning on unbound protocols
If a protocol was not successfully created, we can't drop the refcount
on it. This might happen for example if the connection fails to bind a
protocol.
Silences a warning on cleanup.
Signed-off-by: Perry Hung <perry@leaflabs.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
We no longer create a fresh connection on receiving svc-hello message,
but rather update the initial one.
Update 'initial_svc_connection' after the connection is fully
initialized. Look for the partially initialized connection while
removing hd, as hd might be removed before getting svc-hello requests
from svc.
Also update gb_svc_connection_init() to initialize id_map on the first
(and the only) call to connection-init function.
We also can't update connection->bundle->intf->svc, as its a bundle-less
connection. Lets stop updating intf->svc as its not really used.
greybus: svc: fully initialize the partially initialized connection
SVC hello message is received now and we should fully initialize the
partially initialized connection. This can be done by removing and
re-adding the device corresponding to the connection.
greybus: loopback: convert loopback wake/sleep to a waitqueue
Current code will incrementally poll for gb->type == 0 and sleep.
This type of polling strategy wastes cycles.
This patch changes the sleep strategy by introducing a wait-queue which
waits for gb->type != 0 or kthread_should_stop() to wake-up and work or
to wake-up and terminate.
greybus: loopback: add poll support to the iteration_count sysfs file
This adds the ability to poll on "iteration_count" in sysfs and be woken
up when it changes, saving some cycles constantly hammering on the file
waiting for it to change.
Johan Hovold [Thu, 23 Jul 2015 08:50:03 +0000 (10:50 +0200)]
greybus: operation: add completion work queue
Add dedicated bound work queue for operation completions and use the
connection work queues for incoming requests only.
There is no need to keep responses ordered internally or with respect to
requests. Instead allow operations to complete as soon as possible when
a response arrives (or the operation is cancelled).
Note that this also allows synchronous requests to be submitted from
request handlers as responses will no longer be blocked on the same
single-threaded work queue. Similarly, operations can now also be
cancelled from a request handler.
Tested-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fix below warnings that only generate for a 64 bit system:
greybus/svc.c:202:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
dev_err(dev, "%s: Illegal size of hello request (%d %d)\n",
^
greybus/svc.c:202:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘long unsigned int’ [-Wformat=]
Johan Hovold [Wed, 22 Jul 2015 15:49:17 +0000 (17:49 +0200)]
greybus: operation: fix operation ordering
Make the operation work queue single threaded.
The operation work queue was meant to be single threaded, but due to a
missing flag instead allowed one active task per CPU, something which
could lead to requests being processed out of order on SMP systems.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Tested-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The name frequency does not adequately describe the data-point tracking the
number of greybus operations performed in a second by the loopback code.
Firmware team is moving towards calling this variable requests-per-second
or similar. This patch renames to keep the namespace consistent.
greybus: loopback: add commentary to sysfs variables
Add some missing comments.
Add a TODO to look at doing iteration_count with KOBJ_CHANGE event instead
of having user-space poll the value reported in iteration_count to
determine when a test set is complete.
greybus: loopback: run operations a set number of times
In order to extract a meaningful set of data out of loopback metrics it
makes sense to have the ability to specify how many times a loopback
operation should run and then to stop when the threshold is hit.
This will allow exactly the same loopback data pattern to be run again and
again, which is a fundamental prerequisite to instrumenting and
characterizing the loopback interface over time.
This patch introduces a simple sysfs controlled variable iteration_max.
iteration_max is the maximum number of iterations to run for a given set.
iteration_count is used internally to count from zero to iteration_max
if-and-only-if iteration_max is non zero. If iteration_max is zero then the
original behaviour of running the test command ad infinitum is maintained.
User-space should incrementally poll the iteration_count to determine when
the sequence is finished.
To accomplish this we move away from running as many commands as possible
in a one second window and instead run a fixed number of commands and log
the time it takes for those commands to complete in aggregate. Since we are
no longer resetting counters every one second, the tracker variables have
been moved from u32 to u64 to allow for reasonably long tests to gather
reasonably large amounts of data, without fear of over-flowing the
data-points.
greybus: loopback: timestamp seeding should not drop metrics
In the current code if the ts variable is not initialized then any data
already gathered in a previous loopback command is dropped instead of
logged. Also the timestamping of ts is done after the greybus operation.
This delayed time-stamping means that the delta between the before and
after timestamps is incorrect and if a delay in-between loopback operations
has been specified by the user, the ts timestamp will be very skewed
indeed.
- Move the ts initialization directly before the greybus operation.
- Remove the continue statement on first initialization of the ts variable.
This patch converts a dangling pr_err in the manifest parsing error path to
a dev_err in order to remain consistent with similar error messages
elsewhere.
greybus: manifest: reserve control connection cport/bundle ids
5ae6906e ('interface: Get manifest using Control protocol') in
gb_create_control_connection introduces the concept that the Control
Protocol is at cport_id 2 and bundle_id 0. Currently the manifest parsing
code does not enforce that concept and as a result it is possible for a
manifest to declare the Control Protocol at a different address.
Based on that change 6a6945c9684e ('greybus-spec/control: Formally define
Control Protocol reserved addresses') makes the above coding convention a
formal requirement of the greybus specification. This patch implements the
change introduced in the specification @ 6a6945c9684e.
This patch will reject a manifest if it doesn't match the critiera laid
down in the spec.
This patch makes three changes:
- Changes gb_manifest_parse_cports so that only GB_CONTROL_CPORT_ID may
have a protocol_id of GREYBUS_PROTOCOL_CONTROL, otherwise the manifest
will be rejected.
- Changes gb_manifest_parse_bundles so that only GB_CONTROL_BUNDLE_ID may
have a class of GREYBUS_CLASS_CONTROL, otherwise the manifest will be
rejected.
- gb_connection_exit() and gb_connection_destroy() are removed from
gb_manifest_parse_cports on error - since gb_manifest_parse_bundles()
already has a call into gb_bundle_destroy() which will again call
gb_connection_exit() and gb_connection_destroy() leading to an oops.
greybus: svc: Add helpers to create AP<->SVC connection
SVC connection is required before the AP knows its position on the endo
and type of endo. To enable message processing between the AP and SVC at
this time, we need a partially initialized connection which can handle
these messages.
Once the AP receives more information from the SVC, it can discard this
partially initialized connection and create a proper one, tied to a
bundle and interface.
Destroying the partially initialized connection is a bit tricky, as it
is required to send a response to svc-hello. That part will be properly
fixed separately.
greybus: interface: Update gb_create_control_connection() to support SVC protocol
We need to create bundle/connection for svc cport after the endo layout
and interface id is known to the AP. gb_create_control_connection() can
be reused for this, but it should be renamed to something more
appropriate, as its not about control-connection anymore.
greybus: connection: Allow a bundle-less connection
We need a bundle-less connection for AP's SVC protocol, as that will be
used much before the endo layout and interface-id of the AP is known to
greybus core.
This updates gb_connection_create_range() to take few more arguments,
which were earlier fetched from the 'bundle' pointer.
greybus: connection: Create gb_connection_create_range() to specify hd-cport-id range
We need to allocate specific hd-cport-id for AP's control/svc protocols.
Support that by splitting functionality of gb_connection_create() into a
new routine, which takes range of hd_cport_id's to allocate from.
For now, the plan is to use a single cport for both control and svc
protocol. Defining separate macros for control and svc protocol's
cport/bundle would make the code more flexible, in case we need two
separate cports in future.
Lets define cport/bundle for svc protocol as well.
Johan Hovold [Tue, 14 Jul 2015 13:43:36 +0000 (15:43 +0200)]
greybus: operation: allow drivers to define custom timeouts
Add new interface gb_operation_request_send_sync_timeout, which allows
drivers to define a custom operation timeout instead of the default
one-second timeout.
The timeout is expected to depend on protocol and operation and
therefore needs to be configurable.
Note that that a timeout of zero is used to wait indefinitely.
Make sure the request handler has submitted the response before
cancelling it during operation cancellation.
This prevents cancelling not-yet-submitted messages. It currently also
avoids us ending up with an active message on a stalled connection (e.g.
due to E2EFC).
Note that the call to gb_operation_result_set() is now redundant but is
kept as a precaution to guarantee that a response has indeed been
allocated as part of response submission.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Johan Hovold [Tue, 14 Jul 2015 13:43:33 +0000 (15:43 +0200)]
greybus: operation: fix operation look-up race
Make sure to fully initialise the operation before adding it to the
active list when sending a request.
The operation should be fully initialised before adding it to the active
list to avoid racing with operation look up when receiving a response,
something which could potentially lead to a match against some earlier
(or intermediate) value of the id field.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Johan Hovold [Tue, 14 Jul 2015 13:43:32 +0000 (15:43 +0200)]
greybus: connection: fix protocol tear-down race
Make sure to cancel all active operations before calling protocol
connection_exit to prevent use-after-free issues when the protocol state
is being deallocated (e.g. late processing of already-queued requests or
completions).
Note that already-queued requests or completions will be processed as
part of cancellation.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Johan Hovold [Tue, 14 Jul 2015 13:43:31 +0000 (15:43 +0200)]
greybus: operation: fix connection tear down
Fix connection tear down, which was done in an unsafe way that could
result in use-after-free as the per-connection list of operations was
iterated without any locking or refcounting.
Specifically, the operations list was iterated without holding any locks or
operation refcounts even though operations were being both removed from
the list and deallocated during per-operation cancellation. Any
operation completing during tear down could also cause corruption.
Change the per-connection operation list to only contain active
operations and use the recently introduced active counter to maintain
the list.
Add new helper that is called on connection tear down to cancel all
outstanding operations in a safe way by using proper locks and making
sure to hold a reference to any operation being cancelled.
Note that by verifying the connection state before incrementing the
active count we can make sure that all active operations have been
cancelled and that no new ones have been started when the helper
returns.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Johan Hovold [Tue, 14 Jul 2015 13:43:27 +0000 (15:43 +0200)]
greybus: operation: complete operations on cancellation
Make sure to call the operation completion callback also when the
operation is being cancelled.
The completion callback may need to release resources allocated at
submission and the driver should be informed that the operation has
failed due to cancellation.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fixing needless redefinition of operation types in gbsim reveals this typo
GB_UART_TYPE_SET_BREAK -> GB_UART_TYPE_SEND_BREAK. This patch should be
applied in lock-step to the patch to gbsim 'gbsim/uart: remove unnecessary
redefinition of operation types' since gbsim does not contain the typo.
greybus: loopback: update throughput metrics to improve granularity
Throughput capture should account for the entire size of the data going out
on the wire. In addition throughput should be captured for each supported
loopback operation.
greybus: loopback: truncate maximum loop data to link size
Get maximum payload by way of gb_operation_get_payload_size_max() and
truncate any requested loopback size greater than this value. RX of data
from firmware over the specified size will not be accepted.
Loopback sink command will operate as an amalgam of the ping and tranfer
operations. Sink will send an ACK'd variable size operation over greybus.
Unlike the transfer type which transmits the received data back, the sink
type will simply ACK without sending the received data back.
This patch adds the kernel side of the sink command.
greybus: loopback: make loopback type input equivalent to protocol type
Sepcifying loopback operation type with a type value that is internal to
the loopback driver is non-intunitive and requires reading code to
understand. Remove confusing duplicate definitions and update code to
accept the greybus-specification function identity defintiions as the
appropriate type values for initiating loopback operations.
See greybus-spec section 10.16.1 'Greybus Loopback Message Types' for a
full list of valid messages to set this type field to.
This wouldn't happen normally, but in a buggy corner case it is possible
that all the connections aren't removed properly and they are still
present after the interfaces and endo are removed.
Warn in such a case and cleanup connections, so that /sys/bus/greybus/
can be removed while removing greybus modules.
greybus: properly cleanup ida and idr structures when shutting down
idr and ida structures have internal memory allocated that needs to be
freed when modules are removed. So call the proper idr_destroy() or
ida_destroy() functions on the module exit path to free the memory.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Reviewed-by: Alex Elder <elder@linaro.org>
greybus: svc: save pointer to struct gb_svc in struct gb_interface
Its another special protocol (just like control protocol) and is
required to be accessed from other files, lets save a pointer to it in
interface structure.
greybus: connection: Exit connection before destroying it
gb_connection_create() can initialize a connection if bundle->device id
is valid. And so the connection must be destroyed by calling
gb_connection_exit() before gb_connection_destroy(). This wasn't done in
the code that is parsing the manifest.
greybus: sdio: fix transfer buffer handling and blocks counting
Fix copy to/from scatterlist destination buffer offset, fix
calculation of blocks to be transfer and make a more verbose out of
error when the blocks receive/send do not match.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
As we do not have, yet, a event callback to notify core about changes
we add the MMC_CAP_NEEDS_POLL capability to the rest of the caps
received from the module.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>