2010-07-07 05:08:51 +04:00
|
|
|
/* $NetBSD: uvm_stat.h,v 1.47 2010/07/07 01:08:51 chs Exp $ */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 Charles D. Cranor and Washington University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles D. Cranor and
|
|
|
|
* Washington University.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1998-02-07 14:07:38 +03:00
|
|
|
*
|
|
|
|
* from: Id: uvm_stat.h,v 1.1.2.4 1998/02/07 01:16:56 chs Exp
|
1998-02-05 09:25:08 +03:00
|
|
|
*/
|
1998-02-10 05:34:17 +03:00
|
|
|
|
|
|
|
#ifndef _UVM_UVM_STAT_H_
|
|
|
|
#define _UVM_UVM_STAT_H_
|
|
|
|
|
2001-05-30 15:57:16 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-02-10 17:08:44 +03:00
|
|
|
#include "opt_uvmhist.h"
|
1998-02-13 07:55:14 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
2008-05-25 20:02:08 +04:00
|
|
|
#ifdef UVMHIST
|
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#endif
|
1998-02-10 17:08:44 +03:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
|
|
|
* uvm_stat: monitor what is going on with uvm (or whatever)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* history/tracing
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct uvm_history_ent {
|
1998-02-13 08:33:55 +03:00
|
|
|
struct timeval tv; /* time stamp */
|
2003-02-10 01:33:18 +03:00
|
|
|
int cpunum;
|
2004-11-23 07:57:17 +03:00
|
|
|
const char *fmt; /* printf format */
|
1998-02-13 08:33:55 +03:00
|
|
|
size_t fmtlen; /* length of printf format */
|
2004-11-23 07:57:17 +03:00
|
|
|
const char *fn; /* function name */
|
1998-02-13 08:33:55 +03:00
|
|
|
size_t fnlen; /* length of function name */
|
|
|
|
u_long call; /* function call number */
|
|
|
|
u_long v[4]; /* values */
|
1998-02-05 09:25:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct uvm_history {
|
2004-04-23 06:48:12 +04:00
|
|
|
const char *name; /* name of this history */
|
1998-02-13 08:33:55 +03:00
|
|
|
size_t namelen; /* length of name, not including null */
|
|
|
|
LIST_ENTRY(uvm_history) list; /* link on list of all histories */
|
2010-07-07 05:08:51 +04:00
|
|
|
unsigned int n; /* number of entries */
|
|
|
|
unsigned int f; /* next free one */
|
1998-02-13 08:33:55 +03:00
|
|
|
struct uvm_history_ent *e; /* the malloc'd entries */
|
1998-02-05 09:25:08 +03:00
|
|
|
};
|
|
|
|
|
1998-02-13 07:55:14 +03:00
|
|
|
LIST_HEAD(uvm_history_head, uvm_history);
|
|
|
|
|
1998-06-20 17:19:00 +04:00
|
|
|
/*
|
|
|
|
* grovelling lists all at once. we currently do not allow more than
|
|
|
|
* 32 histories to exist, as the way to dump a number of them at once
|
|
|
|
* is by calling uvm_hist() with a bitmask.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* this is used to set the size of some arrays */
|
|
|
|
#define MAXHISTS 32 /* do not change this! */
|
|
|
|
|
|
|
|
/* and these are the bit values of each history */
|
|
|
|
#define UVMHIST_MAPHIST 0x00000001 /* maphist */
|
|
|
|
#define UVMHIST_PDHIST 0x00000002 /* pdhist */
|
2001-02-04 13:55:58 +03:00
|
|
|
#define UVMHIST_UBCHIST 0x00000004 /* ubchist */
|
2004-11-23 07:51:56 +03:00
|
|
|
#define UVMHIST_LOANHIST 0x00000008 /* loanhist */
|
1998-06-20 17:19:00 +04:00
|
|
|
|
1999-06-21 21:25:11 +04:00
|
|
|
#ifdef _KERNEL
|
|
|
|
|
1998-06-20 17:19:00 +04:00
|
|
|
/*
|
|
|
|
* macros to use the history/tracing code. note that UVMHIST_LOG
|
|
|
|
* must take 4 arguments (even if they are ignored by the format).
|
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
#ifndef UVMHIST
|
|
|
|
#define UVMHIST_DECL(NAME)
|
|
|
|
#define UVMHIST_INIT(NAME,N)
|
|
|
|
#define UVMHIST_INIT_STATIC(NAME,BUF)
|
|
|
|
#define UVMHIST_LOG(NAME,FMT,A,B,C,D)
|
|
|
|
#define UVMHIST_CALLED(NAME)
|
|
|
|
#define UVMHIST_FUNC(FNAME)
|
|
|
|
#define uvmhist_dump(NAME)
|
|
|
|
#else
|
2002-03-05 08:45:54 +03:00
|
|
|
#include <sys/kernel.h> /* for "cold" variable */
|
2010-07-07 05:08:51 +04:00
|
|
|
#include <sys/atomic.h>
|
2002-03-05 08:45:54 +03:00
|
|
|
|
1998-02-13 07:55:14 +03:00
|
|
|
extern struct uvm_history_head uvm_histories;
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
#define UVMHIST_DECL(NAME) struct uvm_history NAME
|
|
|
|
|
1998-02-13 08:33:55 +03:00
|
|
|
#define UVMHIST_INIT(NAME,N) \
|
|
|
|
do { \
|
1998-02-13 07:55:14 +03:00
|
|
|
(NAME).name = __STRING(NAME); \
|
2004-04-30 03:13:35 +04:00
|
|
|
(NAME).namelen = strlen(__STRING(NAME)); \
|
1998-02-05 09:25:08 +03:00
|
|
|
(NAME).n = (N); \
|
|
|
|
(NAME).f = 0; \
|
|
|
|
(NAME).e = (struct uvm_history_ent *) \
|
|
|
|
malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
|
1998-02-13 08:33:55 +03:00
|
|
|
M_WAITOK); \
|
1998-08-10 02:36:37 +04:00
|
|
|
memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
|
1998-02-13 07:55:14 +03:00
|
|
|
LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
|
2002-11-02 10:40:47 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-02-13 08:33:55 +03:00
|
|
|
#define UVMHIST_INIT_STATIC(NAME,BUF) \
|
|
|
|
do { \
|
1998-02-13 07:55:14 +03:00
|
|
|
(NAME).name = __STRING(NAME); \
|
2004-04-30 03:13:35 +04:00
|
|
|
(NAME).namelen = strlen(__STRING(NAME)); \
|
1998-02-05 09:25:08 +03:00
|
|
|
(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
|
|
|
|
(NAME).f = 0; \
|
|
|
|
(NAME).e = (struct uvm_history_ent *) (BUF); \
|
1998-08-10 02:36:37 +04:00
|
|
|
memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
|
1998-02-13 07:55:14 +03:00
|
|
|
LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
|
2002-11-02 10:40:47 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
#if defined(UVMHIST_PRINT)
|
1998-02-12 23:10:15 +03:00
|
|
|
extern int uvmhist_print_enabled;
|
|
|
|
#define UVMHIST_PRINTNOW(E) \
|
1998-02-13 08:33:55 +03:00
|
|
|
do { \
|
1998-02-12 23:10:15 +03:00
|
|
|
if (uvmhist_print_enabled) { \
|
2008-08-08 21:09:28 +04:00
|
|
|
uvmhist_entry_print(E); \
|
1998-02-12 23:10:15 +03:00
|
|
|
DELAY(100000); \
|
|
|
|
} \
|
2002-11-02 10:40:47 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1998-02-05 09:25:08 +03:00
|
|
|
#else
|
|
|
|
#define UVMHIST_PRINTNOW(E) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
1998-02-13 08:33:55 +03:00
|
|
|
#define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
|
|
|
|
do { \
|
2010-07-07 05:08:51 +04:00
|
|
|
unsigned int _i_, _j_; \
|
|
|
|
do { \
|
|
|
|
_i_ = (NAME).f; \
|
|
|
|
_j_ = (_i_ + 1 < (NAME).n) ? _i_ + 1 : 0; \
|
|
|
|
} while (atomic_cas_uint(&(NAME).f, _i_, _j_) != _i_); \
|
1998-02-13 08:33:55 +03:00
|
|
|
if (!cold) \
|
2000-04-11 06:34:19 +04:00
|
|
|
microtime(&(NAME).e[_i_].tv); \
|
2003-03-08 18:17:23 +03:00
|
|
|
(NAME).e[_i_].cpunum = cpu_number(); \
|
2000-04-11 06:34:19 +04:00
|
|
|
(NAME).e[_i_].fmt = (FMT); \
|
2004-04-30 03:13:35 +04:00
|
|
|
(NAME).e[_i_].fmtlen = strlen(FMT); \
|
2000-04-11 06:34:19 +04:00
|
|
|
(NAME).e[_i_].fn = _uvmhist_name; \
|
2004-04-30 03:13:35 +04:00
|
|
|
(NAME).e[_i_].fnlen = strlen(_uvmhist_name); \
|
2000-04-11 06:34:19 +04:00
|
|
|
(NAME).e[_i_].call = _uvmhist_call; \
|
|
|
|
(NAME).e[_i_].v[0] = (u_long)(A); \
|
|
|
|
(NAME).e[_i_].v[1] = (u_long)(B); \
|
|
|
|
(NAME).e[_i_].v[2] = (u_long)(C); \
|
|
|
|
(NAME).e[_i_].v[3] = (u_long)(D); \
|
|
|
|
UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
|
2002-11-02 10:40:47 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
#define UVMHIST_CALLED(NAME) \
|
1998-02-13 08:33:55 +03:00
|
|
|
do { \
|
2010-07-07 05:08:51 +04:00
|
|
|
_uvmhist_call = atomic_inc_uint_nv(&_uvmhist_cnt); \
|
1998-02-13 08:33:55 +03:00
|
|
|
UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
|
2002-11-02 10:40:47 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
#define UVMHIST_FUNC(FNAME) \
|
2010-07-07 05:08:51 +04:00
|
|
|
static unsigned int _uvmhist_cnt = 0; \
|
2004-11-23 07:57:17 +03:00
|
|
|
static const char *const _uvmhist_name = FNAME; \
|
2001-05-25 08:06:11 +04:00
|
|
|
int _uvmhist_call;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2010-02-06 15:10:59 +03:00
|
|
|
static inline void uvmhist_entry_print(struct uvm_history_ent *);
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2010-02-06 15:10:59 +03:00
|
|
|
static inline void
|
2008-08-08 21:09:28 +04:00
|
|
|
uvmhist_entry_print(e)
|
1998-02-13 08:33:55 +03:00
|
|
|
struct uvm_history_ent *e;
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2009-02-01 17:25:11 +03:00
|
|
|
printf("%06" PRIu64 ".%06d ", e->tv.tv_sec, e->tv.tv_usec);
|
2003-02-10 01:33:18 +03:00
|
|
|
printf("%s#%ld@%d: ", e->fn, e->call, e->cpunum);
|
1998-02-13 08:33:55 +03:00
|
|
|
printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
|
|
|
|
printf("\n");
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
#endif /* UVMHIST */
|
1998-02-10 05:34:17 +03:00
|
|
|
|
1999-06-21 21:25:11 +04:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
1998-02-10 05:34:17 +03:00
|
|
|
#endif /* _UVM_UVM_STAT_H_ */
|