Annotation of kernel/kern/xpr.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* 
        !            26:  * Mach Operating System
        !            27:  * Copyright (c) 1989 Carnegie-Mellon University
        !            28:  * Copyright (c) 1988 Carnegie-Mellon University
        !            29:  * Copyright (c) 1987 Carnegie-Mellon University
        !            30:  * All rights reserved.  The CMU software License Agreement specifies
        !            31:  * the terms and conditions for use and redistribution.
        !            32:  */
        !            33: /*
        !            34:  * xpr silent tracing circular buffer.
        !            35:  */
        !            36: 
        !            37: #if    NeXT
        !            38: #define NO_IPLMEAS     1
        !            39: #endif NeXT
        !            40: 
        !            41: #import <kern/xpr.h>
        !            42: #import <kern/lock.h>
        !            43: #import <bsd/machine/cpu.h>
        !            44: #import <machine/param.h>              /* for splhigh */
        !            45: #import <vm/vm_kern.h>
        !            46: #import <machine/spl.h>
        !            47: 
        !            48: decl_simple_lock_data(,xprlock)
        !            49: 
        !            50: #if    NeXT
        !            51: /* always allocate xpr buffers so xprs can be enabled anytime */
        !            52: int nxprbufs = 512;    /* Number of contiguous xprbufs allocated */
        !            53: #else  NeXT
        !            54: int nxprbufs = 0;      /* Number of contiguous xprbufs allocated */
        !            55: #endif NeXT
        !            56: unsigned int xprflags = 0;     /* Bit mask of xpr flags enabled */
        !            57: unsigned int xprwrap = TRUE;   /* xpr's wrap in buf or just stop at end */
        !            58: struct xprbuf *xprbase;        /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
        !            59: struct xprbuf *xprptr; /* Currently allocated xprbuf */
        !            60: struct xprbuf *xprlast;        /* Pointer to end of circular buffer */
        !            61: unsigned xprlocked = 0;        /* when TRUE, disables logging */
        !            62: 
        !            63: /*VARARGS1*/
        !            64: xpr(msg, arg1, arg2, arg3, arg4, arg5, arg6)
        !            65:        char *msg;
        !            66: {
        !            67:        register s;
        !            68:        register struct xprbuf *x;
        !            69: 
        !            70: #ifdef lint
        !            71:        arg6++;
        !            72: #endif lint
        !            73: 
        !            74:        /* If we aren't initialized, ignore trace request */
        !            75:        if (!nxprbufs || xprptr == 0 || xprlocked)
        !            76:                return;
        !            77:        /* Guard against all interrupts and allocate next buffer */
        !            78:        s = splhigh();
        !            79:        simple_lock(&xprlock);
        !            80:        x = xprptr++;
        !            81:        if (xprptr >= xprlast) {
        !            82:                /* wrap around */
        !            83:                xprptr = xprwrap ? xprbase : xprlast - 1;
        !            84:        }
        !            85:        x->timestamp = XPR_TIMESTAMP;
        !            86:        simple_unlock(&xprlock);
        !            87:        splx(s);
        !            88:        x->msg = msg;
        !            89:        x->arg1 = arg1;
        !            90:        x->arg2 = arg2;
        !            91:        x->arg3 = arg3;
        !            92:        x->arg4 = arg4;
        !            93:        x->arg5 = arg5;
        !            94:        x->cpuinfo = cpu_number();
        !            95: }
        !            96: 
        !            97: xprbootstrap()
        !            98: {
        !            99:        simple_lock_init(&xprlock);
        !           100:        if (nxprbufs == 0 && xprflags == 0)
        !           101:                return; /* assume XPR support not desired */
        !           102:        else if (nxprbufs == 0)
        !           103:                nxprbufs=512;   /* if flags are set must do something */
        !           104:        xprbase = (struct xprbuf *)kmem_alloc(kernel_map, 
        !           105:                        (vm_size_t)(nxprbufs * sizeof(struct xprbuf)));
        !           106:        xprlast = &xprbase[nxprbufs];
        !           107:        xprptr = xprbase;
        !           108: }
        !           109: 
        !           110: int            xprinitial = 0;
        !           111: 
        !           112: xprinit()
        !           113: {
        !           114:        xprflags |= xprinitial;
        !           115: }
        !           116: 
        !           117: /*
        !           118:  *     Save 'number' of xpr buffers to the area provided by buffer.
        !           119:  */
        !           120: 
        !           121: xpr_save(buffer,number)
        !           122: struct xprbuf *buffer;
        !           123: int number;
        !           124: {
        !           125:     int i,s;
        !           126:     struct xprbuf *x;
        !           127:     s = splhigh();
        !           128:     simple_lock(&xprlock);
        !           129:     if (number > nxprbufs) number = nxprbufs;
        !           130:     x = xprptr;
        !           131:     
        !           132:     for (i = number - 1; i >= 0 ; i-- ) {
        !           133:        if (--x < xprbase) {
        !           134:            /* wrap around */
        !           135:            x = xprlast - 1;
        !           136:        }
        !           137:        bcopy(x,&buffer[i],sizeof(struct xprbuf));
        !           138:     }
        !           139:     simple_unlock(&xprlock);
        !           140:     splx(s);
        !           141: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.