From nobody Mon Feb 9 17:37:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1612608625; cv=none; d=zohomail.com; s=zohoarc; b=C213OW+1jJbPQcTFoIyiZa+SMRmYj8evvzzy/PQkgGdYHt94/kd8nioSZ3lWE+OVRBpMhDboy8EUMCEGqk05wodUn59TRHoqL1j3+1464oNmFxyWph9slj15YfketjLHLrW0XauE4hYoQji2iT0GwnYenyTnb6UjJDPFYM5/M3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612608625; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+rhXTWkgbyXvV9gClvwDbgn20u/kYNFxY4GB9OVP82g=; b=dJ7l0f2Zp6hKjEg1ckoADllZ0SB7SY32IsdoSYe5DOWG4ICWmUgXsa7u3IztafF7RFot+MbP+O4YMslLBiPs8zUj1YDdK0iASTo5z3nSmP2ku9PV3RtFIHDBSCPQyWshLq2nCNAO7cLTY1OpDL+FgkgOdu4eywZQUk+JuKeRDq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612608625002916.978926851983; Sat, 6 Feb 2021 02:50:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.82127.151851 (Exim 4.92) (envelope-from ) id 1l8LAH-0006WC-Jg; Sat, 06 Feb 2021 10:50:09 +0000 Received: by outflank-mailman (output) from mailman id 82127.151851; Sat, 06 Feb 2021 10:50:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l8LAH-0006Vv-Ep; Sat, 06 Feb 2021 10:50:09 +0000 Received: by outflank-mailman (input) for mailman id 82127; Sat, 06 Feb 2021 10:50:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l8LAG-0005VY-J0 for xen-devel@lists.xenproject.org; Sat, 06 Feb 2021 10:50:08 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 379e30f7-dd5d-4dd4-ae1b-01c2cce109c6; Sat, 06 Feb 2021 10:49:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A8F2EAE55; Sat, 6 Feb 2021 10:49:47 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 379e30f7-dd5d-4dd4-ae1b-01c2cce109c6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612608587; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+rhXTWkgbyXvV9gClvwDbgn20u/kYNFxY4GB9OVP82g=; b=RGpZWqhB1MjUDVT7qV5Vbs65zV+xJItgY6MdTYnW6OU8SQSOPBnnf+yTZvjl+m/ff6/cm7 /sTtzQxlR3CrNaSip17pGUzElz0mgWAMvehJRNUMQ6YaeEXd2FgGbPTd9diut4ODNqVso9 3rFOpioQlUVEVE6RoWIRlOalao/MEgE= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH 5/7] xen/events: add per-xenbus device event statistics and settings Date: Sat, 6 Feb 2021 11:49:30 +0100 Message-Id: <20210206104932.29064-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210206104932.29064-1-jgross@suse.com> References: <20210206104932.29064-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add sysfs nodes for each xenbus device showing event statistics (number of events and spurious events, number of associated event channels) and for setting a spurious event threshold in case a frontend is sending too many events without being rogue on purpose. Signed-off-by: Juergen Gross --- drivers/xen/events/events_base.c | 27 ++++++++++++- drivers/xen/xenbus/xenbus_probe.c | 66 +++++++++++++++++++++++++++++++ include/xen/xenbus.h | 7 ++++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index 8c620c11e32a..d0c57c5664c0 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -327,6 +327,8 @@ static int xen_irq_info_evtchn_setup(unsigned irq, =20 ret =3D xen_irq_info_common_setup(info, irq, IRQT_EVTCHN, evtchn, 0); info->u.interdomain =3D dev; + if (dev) + atomic_inc(&dev->event_channels); =20 return ret; } @@ -572,18 +574,28 @@ static void xen_irq_lateeoi_locked(struct irq_info *i= nfo, bool spurious) return; =20 if (spurious) { + struct xenbus_device *dev =3D info->u.interdomain; + unsigned int threshold =3D 1; + + if (dev && dev->spurious_threshold) + threshold =3D dev->spurious_threshold; + if ((1 << info->spurious_cnt) < (HZ << 2)) { if (info->spurious_cnt !=3D 0xFF) info->spurious_cnt++; } - if (info->spurious_cnt > 1) { - delay =3D 1 << (info->spurious_cnt - 2); + if (info->spurious_cnt > threshold) { + delay =3D 1 << (info->spurious_cnt - 1 - threshold); if (delay > HZ) delay =3D HZ; if (!info->eoi_time) info->eoi_cpu =3D smp_processor_id(); info->eoi_time =3D get_jiffies_64() + delay; + if (dev) + atomic_add(delay, &dev->jiffies_eoi_delayed); } + if (dev) + atomic_inc(&dev->spurious_events); } else { info->spurious_cnt =3D 0; } @@ -920,6 +932,7 @@ static void __unbind_from_irq(unsigned int irq) =20 if (VALID_EVTCHN(evtchn)) { unsigned int cpu =3D cpu_from_irq(irq); + struct xenbus_device *dev; =20 xen_evtchn_close(evtchn); =20 @@ -930,6 +943,11 @@ static void __unbind_from_irq(unsigned int irq) case IRQT_IPI: per_cpu(ipi_to_irq, cpu)[ipi_from_irq(irq)] =3D -1; break; + case IRQT_EVTCHN: + dev =3D info->u.interdomain; + if (dev) + atomic_dec(&dev->event_channels); + break; default: break; } @@ -1593,6 +1611,7 @@ void handle_irq_for_port(evtchn_port_t port, struct e= vtchn_loop_ctrl *ctrl) { int irq; struct irq_info *info; + struct xenbus_device *dev; =20 irq =3D get_evtchn_to_irq(port); if (irq =3D=3D -1) @@ -1622,6 +1641,10 @@ void handle_irq_for_port(evtchn_port_t port, struct = evtchn_loop_ctrl *ctrl) =20 info =3D info_for_irq(irq); =20 + dev =3D (info->type =3D=3D IRQT_EVTCHN) ? info->u.interdomain : NULL; + if (dev) + atomic_inc(&dev->events); + if (ctrl->defer_eoi) { info->eoi_cpu =3D smp_processor_id(); info->irq_epoch =3D __this_cpu_read(irq_epoch); diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 18ffd0551b54..9494ecad3c92 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -206,6 +206,65 @@ void xenbus_otherend_changed(struct xenbus_watch *watc= h, } EXPORT_SYMBOL_GPL(xenbus_otherend_changed); =20 +#define XENBUS_SHOW_STAT(name) \ +static ssize_t show_##name(struct device *_dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct xenbus_device *dev =3D to_xenbus_device(_dev); \ + \ + return sprintf(buf, "%d\n", atomic_read(&dev->name)); \ +} \ +static DEVICE_ATTR(name, 0444, show_##name, NULL) + +XENBUS_SHOW_STAT(event_channels); +XENBUS_SHOW_STAT(events); +XENBUS_SHOW_STAT(spurious_events); +XENBUS_SHOW_STAT(jiffies_eoi_delayed); + +static ssize_t show_spurious_threshold(struct device *_dev, + struct device_attribute *attr, + char *buf) +{ + struct xenbus_device *dev =3D to_xenbus_device(_dev); + + return sprintf(buf, "%d\n", dev->spurious_threshold); +} + +static ssize_t set_spurious_threshold(struct device *_dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct xenbus_device *dev =3D to_xenbus_device(_dev); + unsigned int val; + ssize_t ret; + + ret =3D kstrtouint(buf, 0, &val); + if (ret) + return ret; + + dev->spurious_threshold =3D val; + + return count; +} + +static DEVICE_ATTR(spurious_threshold, 0644, show_spurious_threshold, + set_spurious_threshold); + +static struct attribute *xenbus_attrs[] =3D { + &dev_attr_event_channels.attr, + &dev_attr_events.attr, + &dev_attr_spurious_events.attr, + &dev_attr_jiffies_eoi_delayed.attr, + &dev_attr_spurious_threshold.attr, + NULL +}; + +static const struct attribute_group xenbus_group =3D { + .name =3D "xenbus", + .attrs =3D xenbus_attrs, +}; + int xenbus_dev_probe(struct device *_dev) { struct xenbus_device *dev =3D to_xenbus_device(_dev); @@ -253,6 +312,11 @@ int xenbus_dev_probe(struct device *_dev) return err; } =20 + dev->spurious_threshold =3D 1; + if (sysfs_create_group(&dev->dev.kobj, &xenbus_group)) + dev_warn(&dev->dev, "sysfs_create_group on %s failed.\n", + dev->nodename); + return 0; fail_put: module_put(drv->driver.owner); @@ -269,6 +333,8 @@ int xenbus_dev_remove(struct device *_dev) =20 DPRINTK("%s", dev->nodename); =20 + sysfs_remove_group(&dev->dev.kobj, &xenbus_group); + free_otherend_watch(dev); =20 if (drv->remove) { diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 2c43b0ef1e4d..13ee375a1f05 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -88,6 +88,13 @@ struct xenbus_device { struct completion down; struct work_struct work; struct semaphore reclaim_sem; + + /* Event channel based statistics and settings. */ + atomic_t event_channels; + atomic_t events; + atomic_t spurious_events; + atomic_t jiffies_eoi_delayed; + unsigned int spurious_threshold; }; =20 static inline struct xenbus_device *to_xenbus_device(struct device *dev) --=20 2.26.2