Changeset 5f0b366 in mainline


Ignore:
Timestamp:
2018-01-25T02:05:57Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b357377
Parents:
e8277c0
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-24 19:34:07)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-25 02:05:57)
Message:

usbhost: prepare bandwidth accounting privatization to usb2_bus

The endpoint does not account the bandwidth by default. The next step is
moving the count_bw callback to the usb2 bus.

Location:
uspace/lib/usbhost
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    re8277c0 r5f0b366  
    8787        fibril_condvar_t avail;
    8888
    89         /** Reserved bandwidth. Needed for USB2 bus. */
    90         size_t bandwidth;
    9189        /** Endpoint number */
    9290        usb_endpoint_t endpoint;
     
    121119extern void endpoint_deactivate_locked(endpoint_t *);
    122120
    123 /* Calculate bandwidth */
    124 ssize_t endpoint_count_bw(endpoint_t *, size_t);
    125 
    126121int endpoint_send_batch(endpoint_t *, usb_target_t, usb_direction_t,
    127122    char *, size_t, uint64_t, usbhc_iface_transfer_callback_t, void *,
  • uspace/lib/usbhost/src/endpoint.c

    re8277c0 r5f0b366  
    7474
    7575        ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe;
    76 
    77         ep->bandwidth = endpoint_count_bw(ep, ep->max_transfer_size);
    7876}
    7977
     
    201199        ep->active_batch = NULL;
    202200        fibril_condvar_signal(&ep->avail);
    203 }
    204 
    205 /**
    206  * Call the bus operation to count bandwidth.
    207  *
    208  * @param ep Endpoint on which the transfer will take place.
    209  * @param size The payload size.
    210  */
    211 ssize_t endpoint_count_bw(endpoint_t *ep, size_t size)
    212 {
    213         assert(ep);
    214 
    215         const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_count_bw);
    216         if (!ops)
    217                 return 0;
    218 
    219         return ops->endpoint_count_bw(ep, size);
    220201}
    221202
     
    262243        }
    263244
     245        /** Limit transfers with reserved bandwidth to the amount reserved */
     246        if ((ep->transfer_type == USB_TRANSFER_INTERRUPT
     247            || ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
     248            && size > ep->max_transfer_size)
     249                return ENOSPC;
     250
    264251        /* Offline devices don't schedule transfers other than on EP0. */
    265         if (!device->online && ep->endpoint > 0) {
     252        if (!device->online && ep->endpoint > 0)
    266253                return EAGAIN;
    267         }
    268 
    269         const size_t bw = endpoint_count_bw(ep, size);
    270         /* Check if we have enough bandwidth reserved */
    271         if (ep->bandwidth < bw) {
    272                 usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    273                     "but only %zu is reserved.\n",
    274                     device->address, ep->endpoint, name, bw, ep->bandwidth);
    275                 return ENOSPC;
    276         }
    277254
    278255        usb_transfer_batch_t *batch = usb_transfer_batch_create(ep);
  • uspace/lib/usbhost/src/usb2_bus.c

    re8277c0 r5f0b366  
    210210
    211211/**
     212 * Call the bus operation to count bandwidth.
     213 *
     214 * @param ep Endpoint on which the transfer will take place.
     215 * @param size The payload size.
     216 */
     217static ssize_t endpoint_count_bw(endpoint_t *ep)
     218{
     219        assert(ep);
     220
     221        bus_t *bus = ep->device->bus;
     222        const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, endpoint_count_bw);
     223        if (!ops)
     224                return 0;
     225
     226        return ops->endpoint_count_bw(ep, ep->max_transfer_size);
     227}
     228
     229/**
    212230 * Register an endpoint to the bus. Reserves bandwidth.
    213231 */
     
    218236        assert(ep);
    219237
     238        size_t bw = endpoint_count_bw(ep);
     239
    220240        /* Check for available bandwidth */
    221         if (ep->bandwidth > bus->free_bw)
     241        if (bw > bus->free_bw)
    222242                return ENOSPC;
    223243
    224         bus->free_bw -= ep->bandwidth;
     244        bus->free_bw -= bw;
    225245
    226246        return EOK;
     
    235255        assert(ep);
    236256
    237         bus->free_bw += ep->bandwidth;
     257        bus->free_bw += endpoint_count_bw(ep);
    238258}
    239259
Note: See TracChangeset for help on using the changeset viewer.