[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] xen/mce: add .poll method for mcelog device driver



Liu, Jinsong wrote:
>>> So another bug which is that mcelog is spinning at 100% CPU (and
>>> only under Xen). 
>>> 
>>> It seems to be doing:
>>> 
>>> ppoll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}], 2, NULL, [],
>>> 8) = 1 ([{fd=3, revents=POLLIN}]) read(3, "", 2816)
>>> = 0
>>> ppoll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}], 2, NULL, [],
>>> 8) = 1 ([{fd=3, revents=POLLIN}]) read(3, "", 2816)
>>> 
>>> constantly.
>> 
>> I will debug it. I have try at my platform, but fail to reproduce it.
>> (You still use the config you send me last time, right?) Would you
>> tell me your step? 
>> 
>> Thanks,
>> Jinsong
> 
> Have a look at it, it caused by NULL .poll method.
> Attached is the patch to fix this bug, but I cannot reproduce the bug
> at my platform, so would you please help me to test it at your side? 
> 

Ah I know how you trigger the bug - you run mcelog as daemon ... then spinning 
at CPU.
I update my patch as attached, and test at my platform OK now.

Thanks,
Jinsong

========================
>From 771bf5835a1ed9e439c7da289cb3a72ee8c9bd02 Mon Sep 17 00:00:00 2001
From: Liu, Jinsong <jinsong.liu@xxxxxxxxx>
Date: Fri, 15 Jun 2012 09:03:39 +0800
Subject: [PATCH] xen/mce: add .poll method for mcelog device driver

If a driver leaves its poll method NULL, the device is assumed to
be both readable and writable without blocking.

This patch add .poll method to xen mcelog device driver, so that
when mcelog use system calls like ppoll or select, it would be
blocked when no data available, and avoid spinning at CPU.

Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Signed-off-by: Liu, Jinsong <jinsong.liu@xxxxxxxxx>
---
 drivers/xen/mcelog.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/xen/mcelog.c b/drivers/xen/mcelog.c
index 804aa3c..8feee08 100644
--- a/drivers/xen/mcelog.c
+++ b/drivers/xen/mcelog.c
@@ -41,6 +41,8 @@
 #include <linux/miscdevice.h>
 #include <linux/uaccess.h>
 #include <linux/capability.h>
+#include <linux/poll.h>
+#include <linux/sched.h>
 
 #include <xen/interface/xen.h>
 #include <xen/events.h>
@@ -67,6 +69,8 @@ static DEFINE_SPINLOCK(xen_mce_chrdev_state_lock);
 static int xen_mce_chrdev_open_count;  /* #times opened */
 static int xen_mce_chrdev_open_exclu;  /* already open exclusive? */
 
+static DECLARE_WAIT_QUEUE_HEAD(xen_mce_chrdev_wait);
+
 static int xen_mce_chrdev_open(struct inode *inode, struct file *file)
 {
        spin_lock(&xen_mce_chrdev_state_lock);
@@ -135,6 +139,16 @@ out:
        return err ? err : buf - ubuf;
 }
 
+static unsigned int xen_mce_chrdev_poll(struct file *file, poll_table *wait)
+{
+       poll_wait(file, &xen_mce_chrdev_wait, wait);
+
+       if (xen_mcelog.next)
+               return POLLIN | POLLRDNORM;
+
+       return 0;
+}
+
 static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd,
                                unsigned long arg)
 {
@@ -166,6 +180,7 @@ static const struct file_operations xen_mce_chrdev_ops = {
        .open                   = xen_mce_chrdev_open,
        .release                = xen_mce_chrdev_release,
        .read                   = xen_mce_chrdev_read,
+       .poll                   = xen_mce_chrdev_poll,
        .unlocked_ioctl         = xen_mce_chrdev_ioctl,
        .llseek                 = no_llseek,
 };
@@ -329,6 +344,9 @@ static void xen_mce_work_fn(struct work_struct *work)
                pr_err(XEN_MCELOG
                       "Failed to handle nonurgent mc_info queue.\n");
 
+       /* wake processes polling /dev/mcelog */
+       wake_up_interruptible(&xen_mce_chrdev_wait);
+
        mutex_unlock(&mcelog_lock);
 }
 static DECLARE_WORK(xen_mce_work, xen_mce_work_fn);
-- 
1.7.1

Attachment: 0001-xen-mce-add-.poll-method-for-mcelog-device-driver.patch
Description: 0001-xen-mce-add-.poll-method-for-mcelog-device-driver.patch

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.