[BACK]Return to uvm_stat.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / uvm

Annotation of src/sys/uvm/uvm_stat.h, Revision 1.18

1.18    ! pk          1: /*     $NetBSD: uvm_stat.h,v 1.17 2000/04/11 02:34:19 chs Exp $        */
1.1       mrg         2:
                      3: /*
                      4:  *
                      5:  * Copyright (c) 1997 Charles D. Cranor and Washington University.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *      This product includes software developed by Charles D. Cranor and
                     19:  *      Washington University.
                     20:  * 4. The name of the author may not be used to endorse or promote products
                     21:  *    derived from this software without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     24:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     25:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     26:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     27:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     28:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     29:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     30:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     31:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     32:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.4       mrg        33:  *
                     34:  * from: Id: uvm_stat.h,v 1.1.2.4 1998/02/07 01:16:56 chs Exp
1.1       mrg        35:  */
1.6       perry      36:
                     37: #ifndef _UVM_UVM_STAT_H_
                     38: #define _UVM_UVM_STAT_H_
1.7       mrg        39:
1.9       thorpej    40: #if defined(_KERNEL) && !defined(_LKM)
1.7       mrg        41: #include "opt_uvmhist.h"
1.9       thorpej    42: #endif
                     43:
                     44: #include <sys/queue.h>
1.6       perry      45:
1.1       mrg        46: /*
                     47:  * uvm_stat: monitor what is going on with uvm (or whatever)
                     48:  */
                     49:
                     50: /*
                     51:  * counters  [XXX: maybe replace event counters with this]
                     52:  */
                     53:
                     54: #define UVMCNT_MASK    0xf                     /* rest are private */
                     55: #define UVMCNT_CNT     0                       /* normal counter */
                     56: #define UVMCNT_DEV     1                       /* device event counter */
                     57:
                     58: struct uvm_cnt {
                     59:        int c;                                  /* the value */
                     60:        int t;                                  /* type */
                     61:        struct uvm_cnt *next;                   /* global list of cnts */
                     62:        char *name;                             /* counter name */
                     63:        void *p;                                /* private data */
                     64: };
                     65:
1.15      thorpej    66: #ifdef _KERNEL
                     67:
1.1       mrg        68: extern struct uvm_cnt *uvm_cnt_head;
                     69:
                     70: /*
1.3       chs        71:  * counter operations.  assume spl is set ok.
1.1       mrg        72:  */
                     73:
1.10      thorpej    74: #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) \
                     75: do { \
1.1       mrg        76:        CNT.c = VAL; \
                     77:        CNT.t = TYP; \
                     78:        CNT.next = uvm_cnt_head; \
                     79:        uvm_cnt_head = &CNT; \
                     80:        CNT.name = NAM; \
                     81:        CNT.p = PRIV; \
1.10      thorpej    82: } while (0)
1.1       mrg        83:
1.10      thorpej    84: #define UVMCNT_SET(C,V) \
                     85: do { \
1.1       mrg        86:        (C).c = (V); \
1.10      thorpej    87: } while (0)
1.1       mrg        88:
1.10      thorpej    89: #define UVMCNT_ADD(C,V) \
                     90: do { \
1.1       mrg        91:        (C).c += (V); \
1.10      thorpej    92: } while (0)
1.1       mrg        93:
                     94: #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
                     95: #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
                     96:
1.15      thorpej    97: #endif /* _KERNEL */
1.1       mrg        98:
                     99: /*
                    100:  * history/tracing
                    101:  */
                    102:
                    103: struct uvm_history_ent {
1.10      thorpej   104:        struct timeval tv;              /* time stamp */
                    105:        char *fmt;                      /* printf format */
                    106:        size_t fmtlen;                  /* length of printf format */
                    107:        char *fn;                       /* function name */
                    108:        size_t fnlen;                   /* length of function name */
                    109:        u_long call;                    /* function call number */
                    110:        u_long v[4];                    /* values */
1.1       mrg       111: };
                    112:
                    113: struct uvm_history {
1.10      thorpej   114:        const char *name;               /* name of this this history */
                    115:        size_t namelen;                 /* length of name, not including null */
                    116:        LIST_ENTRY(uvm_history) list;   /* link on list of all histories */
                    117:        int n;                          /* number of entries */
                    118:        int f;                          /* next free one */
                    119:        simple_lock_data_t l;           /* lock on this history */
                    120:        struct uvm_history_ent *e;      /* the malloc'd entries */
1.1       mrg       121: };
                    122:
1.9       thorpej   123: LIST_HEAD(uvm_history_head, uvm_history);
                    124:
1.12      mrg       125: /*
                    126:  * grovelling lists all at once.  we currently do not allow more than
                    127:  * 32 histories to exist, as the way to dump a number of them at once
                    128:  * is by calling uvm_hist() with a bitmask.
                    129:  */
                    130:
                    131: /* this is used to set the size of some arrays */
                    132: #define        MAXHISTS                32      /* do not change this! */
                    133:
                    134: /* and these are the bit values of each history */
                    135: #define        UVMHIST_MAPHIST         0x00000001      /* maphist */
                    136: #define        UVMHIST_PDHIST          0x00000002      /* pdhist */
                    137:
1.15      thorpej   138: #ifdef _KERNEL
                    139:
1.12      mrg       140: /*
                    141:  * macros to use the history/tracing code.  note that UVMHIST_LOG
                    142:  * must take 4 arguments (even if they are ignored by the format).
                    143:  */
1.1       mrg       144: #ifndef UVMHIST
                    145: #define UVMHIST_DECL(NAME)
                    146: #define UVMHIST_INIT(NAME,N)
                    147: #define UVMHIST_INIT_STATIC(NAME,BUF)
                    148: #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
                    149: #define UVMHIST_CALLED(NAME)
                    150: #define UVMHIST_FUNC(FNAME)
                    151: #define uvmhist_dump(NAME)
                    152: #else
1.9       thorpej   153: extern struct uvm_history_head uvm_histories;
                    154:
1.1       mrg       155: #define UVMHIST_DECL(NAME) struct uvm_history NAME
                    156:
1.10      thorpej   157: #define UVMHIST_INIT(NAME,N) \
                    158: do { \
1.9       thorpej   159:        (NAME).name = __STRING(NAME); \
                    160:        (NAME).namelen = strlen((NAME).name); \
1.1       mrg       161:        (NAME).n = (N); \
                    162:        (NAME).f = 0; \
                    163:        simple_lock_init(&(NAME).l); \
                    164:        (NAME).e = (struct uvm_history_ent *) \
                    165:                malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
1.10      thorpej   166:                    M_WAITOK); \
1.13      perry     167:        memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
1.9       thorpej   168:        LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
1.10      thorpej   169: } while (0)
1.1       mrg       170:
1.10      thorpej   171: #define UVMHIST_INIT_STATIC(NAME,BUF) \
                    172: do { \
1.9       thorpej   173:        (NAME).name = __STRING(NAME); \
                    174:        (NAME).namelen = strlen((NAME).name); \
1.1       mrg       175:        (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
                    176:        (NAME).f = 0; \
                    177:        simple_lock_init(&(NAME).l); \
                    178:        (NAME).e = (struct uvm_history_ent *) (BUF); \
1.13      perry     179:        memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
1.9       thorpej   180:        LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
1.10      thorpej   181: } while (0)
1.1       mrg       182:
                    183: extern int cold;
                    184:
                    185: #if defined(UVMHIST_PRINT)
1.8       thorpej   186: extern int uvmhist_print_enabled;
                    187: #define UVMHIST_PRINTNOW(E) \
1.10      thorpej   188: do { \
1.8       thorpej   189:                if (uvmhist_print_enabled) { \
                    190:                        uvmhist_print(E); \
                    191:                        DELAY(100000); \
                    192:                } \
1.10      thorpej   193: } while (0)
1.1       mrg       194: #else
                    195: #define UVMHIST_PRINTNOW(E) /* nothing */
                    196: #endif
                    197:
1.10      thorpej   198: #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
                    199: do { \
1.18    ! pk        200:        int _i_, _s_ = splhigh(); \
1.1       mrg       201:        simple_lock(&(NAME).l); \
1.17      chs       202:        _i_ = (NAME).f; \
                    203:        (NAME).f = (_i_ + 1) % (NAME).n; \
1.1       mrg       204:        simple_unlock(&(NAME).l); \
1.17      chs       205:        splx(_s_); \
1.10      thorpej   206:        if (!cold) \
1.17      chs       207:                microtime(&(NAME).e[_i_].tv); \
                    208:        (NAME).e[_i_].fmt = (FMT); \
                    209:        (NAME).e[_i_].fmtlen = strlen((NAME).e[_i_].fmt); \
                    210:        (NAME).e[_i_].fn = _uvmhist_name; \
                    211:        (NAME).e[_i_].fnlen = strlen((NAME).e[_i_].fn); \
                    212:        (NAME).e[_i_].call = _uvmhist_call; \
                    213:        (NAME).e[_i_].v[0] = (u_long)(A); \
                    214:        (NAME).e[_i_].v[1] = (u_long)(B); \
                    215:        (NAME).e[_i_].v[2] = (u_long)(C); \
                    216:        (NAME).e[_i_].v[3] = (u_long)(D); \
                    217:        UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
1.10      thorpej   218: } while (0)
1.1       mrg       219:
                    220: #define UVMHIST_CALLED(NAME) \
1.10      thorpej   221: do { \
                    222:        { \
                    223:                int s = splhigh(); \
                    224:                simple_lock(&(NAME).l); \
                    225:                _uvmhist_call = _uvmhist_cnt++; \
                    226:                simple_unlock(&(NAME).l); \
                    227:                splx(s); \
                    228:        } \
                    229:        UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
                    230: } while (0)
1.1       mrg       231:
                    232: #define UVMHIST_FUNC(FNAME) \
                    233:        static int _uvmhist_cnt = 0; \
                    234:        static char *_uvmhist_name = FNAME; \
                    235:        int _uvmhist_call;
                    236:
                    237: static __inline void uvmhist_print __P((struct uvm_history_ent *));
                    238:
1.10      thorpej   239: static __inline void
                    240: uvmhist_print(e)
                    241:        struct uvm_history_ent *e;
1.1       mrg       242: {
1.10      thorpej   243:        printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
                    244:        printf("%s#%ld: ", e->fn, e->call);
                    245:        printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
                    246:        printf("\n");
1.1       mrg       247: }
                    248: #endif /* UVMHIST */
1.15      thorpej   249:
                    250: #endif /* _KERNEL */
1.6       perry     251:
                    252: #endif /* _UVM_UVM_STAT_H_ */

CVSweb <webmaster@jp.NetBSD.org>