--- //depot/user/jhb/intr/amd64/amd64/intr_machdep.c +++ /home/jhb/work/p4/intr/amd64/amd64/intr_machdep.c @@ -476,6 +476,23 @@ return (intr_event_bind(isrc->is_event, cpu)); } +/* Add a description to an active interrupt handler. */ +int +intr_describe(u_int vector, void *ih, const char *descr) +{ + struct intsrc *isrc; + int error; + + isrc = intr_lookup_source(vector); + if (isrc == NULL) + return (EINVAL); + error = intr_event_describe_handler(isrc->is_event, ih, descr); + if (error) + return (error); + intrcnt_updatename(isrc); + return (0); +} + /* * Add a CPU to our mask of valid CPUs that can be destinations of * interrupts. --- //depot/user/jhb/intr/amd64/amd64/nexus.c +++ /home/jhb/work/p4/intr/amd64/amd64/nexus.c @@ -92,6 +92,9 @@ #endif static int nexus_config_intr(device_t, int, enum intr_trigger, enum intr_polarity); +static int nexus_describe_intr(device_t dev, device_t child, + struct resource *irq, void *cookie, + const char *descr); static int nexus_activate_resource(device_t, device_t, int, int, struct resource *); static int nexus_deactivate_resource(device_t, device_t, int, int, @@ -135,6 +138,7 @@ DEVMETHOD(bus_bind_intr, nexus_bind_intr), #endif DEVMETHOD(bus_config_intr, nexus_config_intr), + DEVMETHOD(bus_describe_intr, nexus_describe_intr), DEVMETHOD(bus_get_resource_list, nexus_get_reslist), DEVMETHOD(bus_set_resource, nexus_set_resource), DEVMETHOD(bus_get_resource, nexus_get_resource), @@ -479,6 +483,14 @@ return (intr_config_intr(irq, trig, pol)); } +static int +nexus_describe_intr(device_t dev, device_t child, struct resource *irq, + void *cookie, const char *descr) +{ + + return (intr_describe(rman_get_start(irq), cookie, descr)); +} + static struct resource_list * nexus_get_reslist(device_t dev, device_t child) { --- //depot/user/jhb/intr/amd64/include/intr_machdep.h +++ /home/jhb/work/p4/intr/amd64/include/intr_machdep.h @@ -151,6 +151,7 @@ #endif int intr_config_intr(int vector, enum intr_trigger trig, enum intr_polarity pol); +int intr_describe(u_int vector, void *ih, const char *descr); void intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame); u_int intr_next_cpu(void); struct intsrc *intr_lookup_source(int vector); --- //depot/user/jhb/intr/dev/e1000/if_igb.c +++ /home/jhb/work/p4/intr/dev/e1000/if_igb.c @@ -2181,9 +2181,10 @@ igb_msix_tx, txr, &txr->tag); if (error) { txr->res = NULL; - device_printf(dev, "Failed to register TX handler"); + device_printf(dev, "Failed to register TX handler\n"); return (error); } + bus_describe_intr(dev, txr->res, txr->tag, "tx %d", i); /* Make tasklet for deferred handling - one per queue */ TASK_INIT(&txr->tx_task, 0, igb_handle_tx, txr); txr->msix = vector; @@ -2215,9 +2216,10 @@ igb_msix_rx, rxr, &rxr->tag); if (error) { rxr->res = NULL; - device_printf(dev, "Failed to register RX handler"); + device_printf(dev, "Failed to register RX handler\n"); return (error); } + bus_describe_intr(dev, rxr->res, rxr->tag, "rx %d", i); /* Make tasklet for deferred handling - one per queue */ TASK_INIT(&rxr->rx_task, 0, igb_handle_rx, rxr); rxr->msix = vector; @@ -2251,9 +2253,10 @@ if ((error = bus_setup_intr(dev, adapter->res, INTR_TYPE_NET | INTR_MPSAFE, NULL, igb_msix_link, adapter, &adapter->tag)) != 0) { - device_printf(dev, "Failed to register Link handler"); + device_printf(dev, "Failed to register Link handler\n"); return (error); } + bus_describe_intr(dev, adapter->res, adapter->tag, "link"); adapter->linkvec = vector; adapter->tq = taskqueue_create_fast("igb_taskq", M_NOWAIT, taskqueue_thread_enqueue, &adapter->tq); --- //depot/user/jhb/intr/kern/bus_if.m +++ /home/jhb/work/p4/intr/kern/bus_if.m @@ -509,7 +509,6 @@ int _cpu; } DEFAULT bus_generic_bind_intr; - /** * @brief Allow (bus) drivers to specify the trigger mode and polarity * of the specified interrupt. @@ -527,6 +526,25 @@ } DEFAULT bus_generic_config_intr; /** + * @brief Allow drivers to associate a description with an active + * interrupt handler. + * + * @param _dev the parent device of @p _child + * @param _child the device which allocated the resource + * @param _irq the resource representing the interrupt + * @param _cookie the cookie value returned when the interrupt + * was originally registered + * @param _descr the description to associate with the interrupt + */ +METHOD int describe_intr { + device_t _dev; + device_t _child; + struct resource *_irq; + void *_cookie; + const char *_descr; +} DEFAULT bus_generic_describe_intr; + +/** * @brief Notify a (bus) driver about a child that the hints mechanism * believes it has discovered. * --- //depot/user/jhb/intr/kern/kern_intr.c +++ /home/jhb/work/p4/intr/kern/kern_intr.c @@ -524,7 +524,7 @@ ih->ih_filter = filter; ih->ih_handler = handler; ih->ih_argument = arg; - ih->ih_name = name; + strlcpy(ih->ih_name, name, sizeof(ih->ih_name)); ih->ih_event = ie; ih->ih_pri = pri; if (flags & INTR_EXCL) @@ -597,7 +597,7 @@ ih->ih_filter = filter; ih->ih_handler = handler; ih->ih_argument = arg; - ih->ih_name = name; + strlcpy(ih->ih_name, name, sizeof(ih->ih_name)); ih->ih_event = ie; ih->ih_pri = pri; if (flags & INTR_EXCL) @@ -665,6 +665,61 @@ #endif /* + * Append a description preceded by a ':' to the name of the specified + * interrupt handler. + */ +int +intr_event_describe_handler(struct intr_event *ie, void *cookie, + const char *descr) +{ + struct intr_handler *ih; + size_t space; + char *start; + + mtx_lock(&ie->ie_lock); +#ifdef INVARIANTS + TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) { + if (ih == cookie) + break; + } + if (ih == NULL) { + mtx_unlock(&ie->ie_lock); + panic("handler %p not find in interrupt event %p", cookie, ie); + } +#endif + ih = cookie; + + /* + * Look for an existing description by checking for an + * existing ":". This assumes device names do not include + * colons. If one is found, prepare to insert the new + * description at that point. If one is not found, find the + * end of the name to use as the insertion point. + */ + start = index(ih->ih_name, ':'); + if (start == NULL) + start = index(ih->ih_name, 0); + + /* + * See if there is enough remaining room in the string for the + * description + ":". The "- 1" leaves room for the trailing + * '\0'. The "+ 1" accounts for the colon. + */ + space = sizeof(ih->ih_name) - (start - ih->ih_name) - 1; + if (strlen(descr) + 1 > space) { + mtx_unlock(&ie->ie_lock); + return (ENOSPC); + } + + /* Append a colon followed by the description. */ + *start = ':'; + strcpy(start + 1, descr); + intr_event_update(ie); + mtx_unlock(&ie->ie_lock); + return (0); +} + +/* * Return the ie_source field from the intr_event an intr_handler is * associated with. */ --- //depot/user/jhb/intr/kern/subr_bus.c +++ /home/jhb/work/p4/intr/kern/subr_bus.c @@ -3536,6 +3536,24 @@ } /** + * @brief Helper function for implementing BUS_DESCRIBE_INTR(). + * + * This simple implementation of BUS_DESCRIBE_INTR() simply calls the + * BUS_DESCRIBE_INTR() method of the parent of @p dev. + */ +int +bus_generic_describe_intr(device_t dev, device_t child, struct resource *irq, + void *cookie, const char *descr) +{ + + /* Propagate up the bus hierarchy until someone handles it. */ + if (dev->parent) + return (BUS_DESCRIBE_INTR(dev->parent, child, irq, cookie, + descr)); + return (EINVAL); +} + +/** * @brief Helper function for implementing BUS_GET_DMA_TAG(). * * This simple implementation of BUS_GET_DMA_TAG() simply calls the @@ -3840,6 +3858,28 @@ } /** + * @brief Wrapper function for BUS_DESCRIBE_INTR(). + * + * This function first formats the requested description into a + * temporary buffer and then calls the BUS_DESCRIBE_INTR() method of + * the parent of @p dev. + */ +int +bus_describe_intr(device_t dev, struct resource *irq, void *cookie, + const char *fmt, ...) +{ + char descr[MAXCOMLEN]; + va_list ap; + + if (dev->parent == NULL) + return (EINVAL); + va_start(ap, fmt); + vsnprintf(descr, sizeof(descr), fmt, ap); + va_end(ap); + return (BUS_DESCRIBE_INTR(dev->parent, dev, irq, cookie, descr)); +} + +/** * @brief Wrapper function for BUS_SET_RESOURCE(). * * This function simply calls the BUS_SET_RESOURCE() method of the --- //depot/user/jhb/intr/sys/bus.h +++ /home/jhb/work/p4/intr/sys/bus.h @@ -295,6 +295,9 @@ int bus_generic_child_present(device_t dev, device_t child); int bus_generic_config_intr(device_t, int, enum intr_trigger, enum intr_polarity); +int bus_generic_describe_intr(device_t dev, device_t child, + struct resource *irq, void *cookie, + const char *descr); int bus_generic_deactivate_resource(device_t dev, device_t child, int type, int rid, struct resource *r); int bus_generic_detach(device_t dev); @@ -347,8 +350,10 @@ int flags; }; -int bus_alloc_resources(device_t dev, struct resource_spec *rs, struct resource **res); -void bus_release_resources(device_t dev, const struct resource_spec *rs, struct resource **res); +int bus_alloc_resources(device_t dev, struct resource_spec *rs, + struct resource **res); +void bus_release_resources(device_t dev, const struct resource_spec *rs, + struct resource **res); struct resource *bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end, u_long count, @@ -366,6 +371,8 @@ void *arg, void **cookiep); int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); int bus_bind_intr(device_t dev, struct resource *r, int cpu); +int bus_describe_intr(device_t dev, struct resource *irq, void *cookie, + const char *fmt, ...); int bus_set_resource(device_t dev, int type, int rid, u_long start, u_long count); int bus_get_resource(device_t dev, int type, int rid, --- //depot/user/jhb/intr/sys/interrupt.h +++ /home/jhb/work/p4/intr/sys/interrupt.h @@ -47,7 +47,7 @@ driver_intr_t *ih_handler; /* Threaded handler function. */ void *ih_argument; /* Argument to pass to handlers. */ int ih_flags; - const char *ih_name; /* Name of handler. */ + char ih_name[MAXCOMLEN]; /* Name of handler. */ struct intr_event *ih_event; /* Event we are connected to. */ int ih_need; /* Needs service. */ TAILQ_ENTRY(intr_handler) ih_next; /* Next handler for this event. */ @@ -172,6 +172,8 @@ void intr_event_execute_handlers(struct proc *p, struct intr_event *ie); int intr_event_handle(struct intr_event *ie, struct trapframe *frame); int intr_event_remove_handler(void *cookie); +int intr_event_describe_handler(struct intr_event *ie, void *cookie, + const char *descr); int intr_getaffinity(int irq, void *mask); void *intr_handler_source(void *cookie); int intr_setaffinity(int irq, void *mask);