[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4AC9941C.40708@jp.fujitsu.com>
Date: Mon, 05 Oct 2009 15:37:16 +0900
From: Hidetoshi Seto <seto.hidetoshi@...fujitsu.com>
To: Huang Ying <ying.huang@...el.com>
CC: Ingo Molnar <mingo@...e.hu>, "H. Peter Anvin" <hpa@...or.com>,
Andi Kleen <ak@...ux.intel.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH 05/10] x86, mce: make mce_log buffer to per-CPU, prep
Move core part of mce_read() into mce_read_buf(). Add mce_empty().
These changes are required to improve readability of next patch.
(This piece originates from Huang's patch, titled:
"x86, MCE: Fix bugs and issues of MCE log ring buffer")
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@...fujitsu.com>
---
arch/x86/kernel/cpu/mcheck/mce.c | 48 ++++++++++++++++++++++++++-----------
1 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 5f88ada..684b42e 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1452,20 +1452,12 @@ static int mce_release(struct inode *inode, struct file *file)
return 0;
}
-static DEFINE_MUTEX(mce_read_mutex);
-
-static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
- loff_t *off)
+static ssize_t mce_read_buf(char __user *inubuf, size_t usize)
{
- char __user *buf = ubuf;
+ char __user *ubuf = inubuf;
unsigned prev, next;
int i, err;
- /* Only supports full reads right now */
- if (*off != 0 || usize < sizeof(struct mce) * MCE_LOG_LEN)
- return -EINVAL;
-
- mutex_lock(&mce_read_mutex);
next = rcu_dereference(mcelog.next);
err = 0;
@@ -1485,9 +1477,9 @@ static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
ndelay(1);
}
smp_rmb();
- err |= copy_to_user(buf, mcelog.entry + i,
+ err |= copy_to_user(ubuf, mcelog.entry + i,
sizeof(struct mce));
- buf += sizeof(struct mce);
+ ubuf += sizeof(struct mce);
timeout:
;
}
@@ -1500,15 +1492,43 @@ timeout:
synchronize_sched();
+ return err ? -EFAULT : ubuf - inubuf;
+}
+
+static int mce_empty(void)
+{
+ return !rcu_dereference(mcelog.next);
+}
+
+static DEFINE_MUTEX(mce_read_mutex);
+
+static ssize_t mce_read(struct file *filp, char __user *inubuf, size_t usize,
+ loff_t *off)
+{
+ char __user *ubuf = inubuf;
+ int err;
+
+ /* Only supports full reads right now */
+ if (*off != 0 || usize < sizeof(struct mce) * MCE_LOG_LEN)
+ return -EINVAL;
+
+ mutex_lock(&mce_read_mutex);
+
+ err = mce_read_buf(ubuf, usize);
+ if (err > 0) {
+ ubuf += err;
+ err = 0;
+ }
+
mutex_unlock(&mce_read_mutex);
- return err ? -EFAULT : buf - ubuf;
+ return err ? err : ubuf - inubuf;
}
static unsigned int mce_poll(struct file *file, poll_table *wait)
{
poll_wait(file, &mce_wait, wait);
- if (rcu_dereference(mcelog.next))
+ if (!mce_empty())
return POLLIN | POLLRDNORM;
return 0;
}
--
1.6.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists