From 58067a9909df61089e87551d9c026f343e011022 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Tue, 19 May 1998 08:58:53 +0000 Subject: [PATCH] Make the size of the msgbuf (dmesg) a "normal" option. --- sbin/dmesg/dmesg.c | 22 ++++++++++++++-------- sys/amd64/amd64/machdep.c | 22 ++++++++++++++++------ sys/amd64/amd64/pmap.c | 5 +++-- sys/conf/NOTES | 5 ++++- sys/conf/options | 5 ++++- sys/i386/conf/LINT | 5 ++++- sys/i386/conf/NOTES | 5 ++++- sys/i386/i386/machdep.c | 22 ++++++++++++++++------ sys/i386/i386/pmap.c | 5 +++-- sys/kern/subr_log.c | 13 +++++++------ sys/kern/subr_prf.c | 16 ++++++---------- sys/sys/msgbuf.h | 12 ++++++++---- 12 files changed, 89 insertions(+), 48 deletions(-) diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c index 2746e356bb03..cb7d5328f6d0 100644 --- a/sbin/dmesg/dmesg.c +++ b/sbin/dmesg/dmesg.c @@ -42,7 +42,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93"; #endif static const char rcsid[] = - "$Id: dmesg.c,v 1.6 1997/02/22 14:32:13 peter Exp $"; + "$Id: dmesg.c,v 1.7 1997/03/29 03:32:14 imp Exp $"; #endif /* not lint */ #include @@ -79,7 +79,7 @@ main(argc, argv) register int ch, newl, skip; register char *p, *ep; struct msgbuf *bufp, cur; - char *memf, *nlistf; + char *bp, *memf, *nlistf; kvm_t *kd; char buf[5]; @@ -116,11 +116,17 @@ main(argc, argv) errx(1, "%s: msgbufp not found", nlistf ? nlistf : "namelist"); if (KREAD(nl[X_MSGBUF].n_value, bufp) || KREAD((long)bufp, cur)) errx(1, "kvm_read: %s", kvm_geterr(kd)); - kvm_close(kd); if (cur.msg_magic != MSG_MAGIC) errx(1, "magic number incorrect"); - if (cur.msg_bufx >= MSG_BSIZE) + bp = malloc(cur.msg_size); + if (!bp) + errx(1, "malloc failed"); + if (kvm_read(kd, (long)cur.msg_ptr, bp, cur.msg_size) != + cur.msg_size) + errx(1, "kvm_read: %s", kvm_geterr(kd)); + if (cur.msg_bufx >= cur.msg_size) cur.msg_bufx = 0; + kvm_close(kd); /* * The message buffer is circular. If the buffer has wrapped, the @@ -129,12 +135,12 @@ main(argc, argv) * buffer starting at the write pointer and ignore nulls so that * we effectively start at the oldest data. */ - p = cur.msg_bufc + cur.msg_bufx; - ep = (cur.msg_bufx == 0 ? cur.msg_bufc + MSG_BSIZE : p); + p = bp + cur.msg_bufx; + ep = (cur.msg_bufx == 0 ? bp + cur.msg_size : p); newl = skip = 0; do { - if (p == cur.msg_bufc + MSG_BSIZE) - p = cur.msg_bufc; + if (p == bp + cur.msg_size) + p = bp; ch = *p; /* Skip "\n<.*>" syslog sequences. */ if (skip) { diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index fa851fa2a8e7..9ffd01789656 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.294 1998/04/06 15:46:17 peter Exp $ + * $Id: machdep.c,v 1.295 1998/05/19 00:00:09 tegge Exp $ */ #include "apm.h" @@ -44,6 +44,7 @@ #include "opt_cpu.h" #include "opt_ddb.h" #include "opt_maxmem.h" +#include "opt_msgbuf.h" #include "opt_perfmon.h" #include "opt_smp.h" #include "opt_sysvipc.h" @@ -146,7 +147,7 @@ int bouncepages = 0; #endif /* BOUNCE_BUFFERS */ int msgbufmapped = 0; /* set when safe to use msgbuf */ -int _udatasel, _ucodesel; +int _udatasel, _ucodesel; u_int atdevbase; #if defined(SWTCH_OPTIM_STATS) @@ -1090,6 +1091,7 @@ init386(first) unsigned biosbasemem, biosextmem; struct gate_descriptor *gdp; int gsel_tss; + char *cp; struct isa_device *idp; #ifndef SMP @@ -1503,7 +1505,7 @@ init386(first) * calculation, etc.). */ while (phys_avail[pa_indx - 1] + PAGE_SIZE + - round_page(sizeof(struct msgbuf)) >= phys_avail[pa_indx]) { + round_page(MSGBUF_SIZE) >= phys_avail[pa_indx]) { physmem -= atop(phys_avail[pa_indx] - phys_avail[pa_indx - 1]); phys_avail[pa_indx--] = 0; phys_avail[pa_indx--] = 0; @@ -1512,16 +1514,25 @@ init386(first) Maxmem = atop(phys_avail[pa_indx]); /* Trim off space for the message buffer. */ - phys_avail[pa_indx] -= round_page(sizeof(struct msgbuf)); + phys_avail[pa_indx] -= round_page(MSGBUF_SIZE); avail_end = phys_avail[pa_indx]; /* now running on new page tables, configured,and u/iom is accessible */ /* Map the message buffer. */ - for (off = 0; off < round_page(sizeof(struct msgbuf)); off += PAGE_SIZE) + for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) pmap_enter(kernel_pmap, (vm_offset_t)msgbufp + off, avail_end + off, VM_PROT_ALL, TRUE); + + cp = (char *)msgbufp; + msgbufp = (struct msgbuf *) (cp + MSGBUF_SIZE - sizeof(*msgbufp)); + if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_ptr != cp) { + bzero(cp, MSGBUF_SIZE); + msgbufp->msg_magic = MSG_MAGIC; + msgbufp->msg_size = (char *)msgbufp - cp; + msgbufp->msg_ptr = cp; + } msgbufmapped = 1; /* make a call gate to reenter kernel with */ @@ -1565,7 +1576,6 @@ f00f_hack(void *unused) { struct region_descriptor r_idt; #endif vm_offset_t tmp; - int i; if (!has_f00f_bug) return; diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 48c7baf5844e..5820a4e97001 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -39,7 +39,7 @@ * SUCH DAMAGE. * * from: @(#)pmap.c 7.7 (Berkeley) 5/12/91 - * $Id: pmap.c,v 1.199 1998/05/17 18:53:14 tegge Exp $ + * $Id: pmap.c,v 1.200 1998/05/19 00:06:35 tegge Exp $ */ /* @@ -70,6 +70,7 @@ #include "opt_disable_pse.h" #include "opt_pmap.h" +#include "opt_msgbuf.h" #include #include @@ -350,7 +351,7 @@ pmap_bootstrap(firstaddr, loadaddr) * XXX msgbufmap is not used. */ SYSMAP(struct msgbuf *, msgbufmap, msgbufp, - atop(round_page(sizeof(struct msgbuf)))) + atop(round_page(MSGBUF_SIZE))) #if !defined(SMP) /* diff --git a/sys/conf/NOTES b/sys/conf/NOTES index c6d59e476715..c8e0790f235c 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -2,7 +2,7 @@ # LINT -- config file for checking all the sources, tries to pull in # as much of the source tree as it can. # -# $Id: LINT,v 1.430 1998/05/16 14:08:31 des Exp $ +# $Id: LINT,v 1.431 1998/05/16 14:10:12 des Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -655,6 +655,9 @@ pseudo-device ccd 4 #Concatenated disk driver pseudo-device su #scsi user pseudo-device ssc #super scsi +# Size of the kernel message buffer. Should be N * pagesize. +options "MSGBUF_SIZE=40960" + ##################################################################### # HARDWARE DEVICE CONFIGURATION diff --git a/sys/conf/options b/sys/conf/options index a0b1403792dc..1a90af73728c 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -1,4 +1,4 @@ -# $Id: options,v 1.71 1998/04/20 03:57:21 julian Exp $ +# $Id: options,v 1.72 1998/04/20 04:30:41 julian Exp $ # # On the handling of kernel options # @@ -227,3 +227,6 @@ VM_KMEM_SIZE_MAX opt_vm.h # sys/netkey KEY KEY_DEBUG opt_key.h + +# Size of the kernel message buffer +MSGBUF_SIZE opt_msgbuf.h diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT index c6d59e476715..c8e0790f235c 100644 --- a/sys/i386/conf/LINT +++ b/sys/i386/conf/LINT @@ -2,7 +2,7 @@ # LINT -- config file for checking all the sources, tries to pull in # as much of the source tree as it can. # -# $Id: LINT,v 1.430 1998/05/16 14:08:31 des Exp $ +# $Id: LINT,v 1.431 1998/05/16 14:10:12 des Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -655,6 +655,9 @@ pseudo-device ccd 4 #Concatenated disk driver pseudo-device su #scsi user pseudo-device ssc #super scsi +# Size of the kernel message buffer. Should be N * pagesize. +options "MSGBUF_SIZE=40960" + ##################################################################### # HARDWARE DEVICE CONFIGURATION diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES index c6d59e476715..c8e0790f235c 100644 --- a/sys/i386/conf/NOTES +++ b/sys/i386/conf/NOTES @@ -2,7 +2,7 @@ # LINT -- config file for checking all the sources, tries to pull in # as much of the source tree as it can. # -# $Id: LINT,v 1.430 1998/05/16 14:08:31 des Exp $ +# $Id: LINT,v 1.431 1998/05/16 14:10:12 des Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -655,6 +655,9 @@ pseudo-device ccd 4 #Concatenated disk driver pseudo-device su #scsi user pseudo-device ssc #super scsi +# Size of the kernel message buffer. Should be N * pagesize. +options "MSGBUF_SIZE=40960" + ##################################################################### # HARDWARE DEVICE CONFIGURATION diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index fa851fa2a8e7..9ffd01789656 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.294 1998/04/06 15:46:17 peter Exp $ + * $Id: machdep.c,v 1.295 1998/05/19 00:00:09 tegge Exp $ */ #include "apm.h" @@ -44,6 +44,7 @@ #include "opt_cpu.h" #include "opt_ddb.h" #include "opt_maxmem.h" +#include "opt_msgbuf.h" #include "opt_perfmon.h" #include "opt_smp.h" #include "opt_sysvipc.h" @@ -146,7 +147,7 @@ int bouncepages = 0; #endif /* BOUNCE_BUFFERS */ int msgbufmapped = 0; /* set when safe to use msgbuf */ -int _udatasel, _ucodesel; +int _udatasel, _ucodesel; u_int atdevbase; #if defined(SWTCH_OPTIM_STATS) @@ -1090,6 +1091,7 @@ init386(first) unsigned biosbasemem, biosextmem; struct gate_descriptor *gdp; int gsel_tss; + char *cp; struct isa_device *idp; #ifndef SMP @@ -1503,7 +1505,7 @@ init386(first) * calculation, etc.). */ while (phys_avail[pa_indx - 1] + PAGE_SIZE + - round_page(sizeof(struct msgbuf)) >= phys_avail[pa_indx]) { + round_page(MSGBUF_SIZE) >= phys_avail[pa_indx]) { physmem -= atop(phys_avail[pa_indx] - phys_avail[pa_indx - 1]); phys_avail[pa_indx--] = 0; phys_avail[pa_indx--] = 0; @@ -1512,16 +1514,25 @@ init386(first) Maxmem = atop(phys_avail[pa_indx]); /* Trim off space for the message buffer. */ - phys_avail[pa_indx] -= round_page(sizeof(struct msgbuf)); + phys_avail[pa_indx] -= round_page(MSGBUF_SIZE); avail_end = phys_avail[pa_indx]; /* now running on new page tables, configured,and u/iom is accessible */ /* Map the message buffer. */ - for (off = 0; off < round_page(sizeof(struct msgbuf)); off += PAGE_SIZE) + for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) pmap_enter(kernel_pmap, (vm_offset_t)msgbufp + off, avail_end + off, VM_PROT_ALL, TRUE); + + cp = (char *)msgbufp; + msgbufp = (struct msgbuf *) (cp + MSGBUF_SIZE - sizeof(*msgbufp)); + if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_ptr != cp) { + bzero(cp, MSGBUF_SIZE); + msgbufp->msg_magic = MSG_MAGIC; + msgbufp->msg_size = (char *)msgbufp - cp; + msgbufp->msg_ptr = cp; + } msgbufmapped = 1; /* make a call gate to reenter kernel with */ @@ -1565,7 +1576,6 @@ f00f_hack(void *unused) { struct region_descriptor r_idt; #endif vm_offset_t tmp; - int i; if (!has_f00f_bug) return; diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index 48c7baf5844e..5820a4e97001 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -39,7 +39,7 @@ * SUCH DAMAGE. * * from: @(#)pmap.c 7.7 (Berkeley) 5/12/91 - * $Id: pmap.c,v 1.199 1998/05/17 18:53:14 tegge Exp $ + * $Id: pmap.c,v 1.200 1998/05/19 00:06:35 tegge Exp $ */ /* @@ -70,6 +70,7 @@ #include "opt_disable_pse.h" #include "opt_pmap.h" +#include "opt_msgbuf.h" #include #include @@ -350,7 +351,7 @@ pmap_bootstrap(firstaddr, loadaddr) * XXX msgbufmap is not used. */ SYSMAP(struct msgbuf *, msgbufmap, msgbufp, - atop(round_page(sizeof(struct msgbuf)))) + atop(round_page(MSGBUF_SIZE))) #if !defined(SMP) /* diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index f29d76cc853c..60b1c3e56b9d 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)subr_log.c 8.1 (Berkeley) 6/10/93 - * $Id: subr_log.c,v 1.26 1998/01/24 02:54:34 eivind Exp $ + * $Id: subr_log.c,v 1.27 1998/02/20 13:46:56 bde Exp $ */ /* @@ -39,6 +39,7 @@ */ #include "opt_devfs.h" +#include "opt_msgbuf.h" #include #include @@ -138,16 +139,16 @@ logread(dev, uio, flag) while (uio->uio_resid > 0) { l = mbp->msg_bufx - mbp->msg_bufr; if (l < 0) - l = MSG_BSIZE - mbp->msg_bufr; + l = mbp->msg_size - mbp->msg_bufr; l = min(l, uio->uio_resid); if (l == 0) break; - error = uiomove((caddr_t)&mbp->msg_bufc[mbp->msg_bufr], - (int)l, uio); + error = uiomove((caddr_t)msgbufp->msg_ptr + mbp->msg_bufr, + (int)l, uio); if (error) break; mbp->msg_bufr += l; - if (mbp->msg_bufr >= MSG_BSIZE) + if (mbp->msg_bufr >= mbp->msg_size) mbp->msg_bufr = 0; } return (error); @@ -215,7 +216,7 @@ logioctl(dev, com, data, flag, p) l = msgbufp->msg_bufx - msgbufp->msg_bufr; splx(s); if (l < 0) - l += MSG_BSIZE; + l += msgbufp->msg_size; *(int *)data = l; break; diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 34191afe4f1d..9124f673702c 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -36,9 +36,11 @@ * SUCH DAMAGE. * * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 - * $Id: subr_prf.c,v 1.43 1997/10/12 20:23:58 phk Exp $ + * $Id: subr_prf.c,v 1.44 1997/12/28 05:03:33 bde Exp $ */ +#include "opt_msgbuf.h" + #include #include #include @@ -586,18 +588,12 @@ msglogchar(int c, void *dummyarg) if (c != '\0' && c != '\r' && c != 0177 && msgbufmapped) { mbp = msgbufp; - if (mbp->msg_magic != MSG_MAGIC || - mbp->msg_bufx >= MSG_BSIZE || - mbp->msg_bufr >= MSG_BSIZE) { - bzero(mbp, sizeof(struct msgbuf)); - mbp->msg_magic = MSG_MAGIC; - } - mbp->msg_bufc[mbp->msg_bufx++] = c; - if (mbp->msg_bufx >= MSG_BSIZE) + mbp->msg_ptr[mbp->msg_bufx++] = c; + if (mbp->msg_bufx >= mbp->msg_size) mbp->msg_bufx = 0; /* If the buffer is full, keep the most recent data. */ if (mbp->msg_bufr == mbp->msg_bufx) { - if (++mbp->msg_bufr >= MSG_BSIZE) + if (++mbp->msg_bufr >= mbp->msg_size) mbp->msg_bufr = 0; } } diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h index 4491150eb181..2a153c88d34e 100644 --- a/sys/sys/msgbuf.h +++ b/sys/sys/msgbuf.h @@ -31,19 +31,23 @@ * SUCH DAMAGE. * * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93 - * $Id$ + * $Id: msgbuf.h,v 1.9 1997/02/22 09:45:37 peter Exp $ */ #ifndef _SYS_MSGBUF_H_ #define _SYS_MSGBUF_H_ -#define MSG_BSIZE (8192 - 3 * sizeof(unsigned int)) +#if defined(KERNEL) && !defined(MSGBUF_SIZE) +#define MSGBUF_SIZE 8192 +#endif + struct msgbuf { -#define MSG_MAGIC 0x063061 +#define MSG_MAGIC 0x063062 unsigned int msg_magic; + unsigned int msg_size; /* MSG_BSIZE */ unsigned int msg_bufx; /* write pointer */ unsigned int msg_bufr; /* read pointer */ - char msg_bufc[MSG_BSIZE]; /* buffer */ + char * msg_ptr; /* pointer to buffer */ }; #ifdef KERNEL extern int msgbufmapped;