[evlog-dev] [PATCH] save most recent event when the buffer overflows
"Zhu, Yi" <[email protected]> Wed, 30 Apr 2003 08:54:39 +0800
| Newsgroups | gmane.linux.kernel.event-logging |
|---|---|
| Message-ID | <3ACA40606221794F80A5670F0AF15F84277FF3@pdsmsx403.ccr.corp.intel.com> |
Hi,
I implemented the "saving most recent event when the buffer overflows" =
feature
(TODO list 16) for kernel 2.4.20 in below patch. Currently it is enabled =
by
selecting CONFIG_EVLOG_SAVE_RECENT when make menuconfig. I am also glad =
to know
if there is any requirement to export it as a proc interface to =
configure it at
run time.
diff -Nura evlog/kernel/v2.4.20/arch/i386/config.in =
evlog-saverecent/kernel/v2.4.20/arch/i386/config.in
--- evlog/kernel/v2.4.20/arch/i386/config.in 2003-04-14 =
10:56:21.000000000 +0800
+++ evlog-saverecent/kernel/v2.4.20/arch/i386/config.in 2003-04-25 =
19:00:11.000000000 +0800
@@ -237,6 +237,7 @@
if [ "$CONFIG_EVLOG" !=3D "n" ]; then
int 'Eventlog buffer size (in K bytes)' CONFIG_EVLOG_BUFSIZE 128
bool 'Forward printk messages to enterprise event log' =
CONFIG_EVLOG_FWPRINTK
+ bool 'Select kernel event buffer to save most recent event when the =
buffer overflows' CONFIG_EVLOG_SAVE_RECENT
fi
=20
# Visual Workstation support is utterly broken.
diff -Nura evlog/kernel/v2.4.20/Documentation/Configure.help =
evlog-saverecent/kernel/v2.4.20/Documentation/Configure.help
--- evlog/kernel/v2.4.20/Documentation/Configure.help 2003-04-14 =
10:56:21.000000000 +0800
+++ evlog-saverecent/kernel/v2.4.20/Documentation/Configure.help =
2003-04-25 19:07:29.000000000 +0800
@@ -128,6 +128,14 @@
=20
If you don't know what to do here, say N.
=20
+Select kernel event buffer to save most recent event when the buffer =
overflows
+CONFIG_EVLOG_SAVE_RECENT
+ This option configures kernel event buffer to save the most recent =
event
+ when the buffer overflows. However this requires more processing time =
in=20
+ the kernel. By default, event logging will keep the oldest event.
+
+ If you don't know what to do here, say N.
+
Symmetric Multi-Processing support
CONFIG_SMP
This enables support for systems with more than one CPU. If you have
diff -Nura evlog/kernel/v2.4.20/kernel/evl_buf.c =
evlog-saverecent/kernel/v2.4.20/kernel/evl_buf.c
--- evlog/kernel/v2.4.20/kernel/evl_buf.c 2003-04-14 10:56:21.000000000 =
+0800
+++ evlog-saverecent/kernel/v2.4.20/kernel/evl_buf.c 2003-04-29 =
16:09:57.000000000 +0800
@@ -107,6 +107,7 @@
const char * databuf);
extern int console_loglevel;
extern struct console *console_drivers;
+unsigned char * evl_getnext_rec(unsigned char *, size_t, unsigned char =
*);
=20
=20
/*
@@ -133,13 +134,38 @@
{
unsigned char *head, *end;
unsigned char *wrapbuf =3D bf_curr;
+#ifdef CONFIG_EVLOG_SAVE_RECENT
+ evl_buf_rec_t *p_rec;
+ size_t rec_size;
+# if defined(__ia64__)
+ evl_buf_rec_t record;
+# endif
+#endif
=20
end =3D bf_curr + len;
head =3D evl_ebuf.bf_head;
=20
if (bf_curr < head && end >=3D head) {
/* Insufficient free space in buffer; drop record. */
+
+#ifdef CONFIG_EVLOG_SAVE_RECENT
+ p_rec =3D (evl_buf_rec_t *) head;
+ rec_size =3D REC_HDR_SIZE + p_rec->rechdr.log_size;
+ while ( head + rec_size <=3D end ) {
+ head =3D evl_getnext_rec(head, rec_size, evl_ebuf.bf_tail);
+ p_rec =3D (evl_buf_rec_t *) head;
+# if defined(__ia64__)
+ memcpy(&record, rec, sizeof(evl_buf_rec_t));
+ rec_size =3D REC_HDR_SIZE + record.rechdr.log_size;
+# else
+ rec_size =3D REC_HDR_SIZE + p_rec->rechdr.log_size;
+# endif
+ };
+ evl_ebuf.bf_head =3D evl_getnext_rec(head, rec_size, =
evl_ebuf.bf_tail);
+ return wrapbuf;
+#else
return NULL;
+#endif
}
if (end > evl_ebuf.bf_end) {
/* end would be of end of buffer */
@@ -155,7 +181,23 @@
end =3D evl_ebuf.bf_buf + len;
if (end >=3D head) {
/* Insufficient free space in buffer; drop record. */
+#ifdef CONFIG_EVLOG_SAVE_RECENT
+ p_rec =3D (evl_buf_rec_t *) head;
+ rec_size =3D REC_HDR_SIZE + p_rec->rechdr.log_size;
+ while ( head + rec_size <=3D end ) {
+ head =3D evl_getnext_rec(head, rec_size, evl_ebuf.bf_tail);
+ p_rec =3D (evl_buf_rec_t *) head;
+# if defined(__ia64__)
+ memcpy(&record, rec, sizeof(evl_buf_rec_t));
+ rec_size =3D REC_HDR_SIZE + record.rechdr.log_size;
+# else
+ rec_size =3D REC_HDR_SIZE + p_rec->rechdr.log_size;
+# endif
+ };
+ evl_ebuf.bf_head =3D evl_getnext_rec(head, rec_size, =
evl_ebuf.bf_tail);
+#else
return NULL;
+#endif
}
}
return wrapbuf;
@@ -741,8 +783,10 @@
spin_lock_irqsave(&ebuf_lock, iflags);
if (evl_check_buf() < 0) {
evl_ebuf.bf_dropped++;
+#ifndef CONFIG_EVLOG_SAVE_RECENT
spin_unlock_irqrestore(&ebuf_lock, iflags);
return -ENOSPC;
+#endif
}
=20
if (args) {
Thanks,
--=20
-------------------------------------------------------------------------=
-----
Opinions expressed are those of the author and do not represent Intel =
Corp.
Zhu Yi (Chuyee)
Intel China Software Lab (ICSL)
22nd Floor, ShanghaiMart Tower No. 2299 Yan'an Road(West) Shanghai =
200336, PRC
Tel: 8621-52574545-1261 Fax: 8621-62366119
GnuPG v1.0.6 (GNU/Linux)
http://cn.geocities.com/chewie_chuyee/gpg.txt
1024D/71C34820 C939 2B0B FBCE 1D51 109A 55E5 8650 DB90 71C3 4820
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf