Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/dev/tprof/tprof.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/dev/tprof/tprof.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.6.4.2 retrieving revision 1.7 diff -u -p -r1.6.4.2 -r1.7 --- src/sys/dev/tprof/tprof.c 2011/04/21 01:42:02 1.6.4.2 +++ src/sys/dev/tprof/tprof.c 2010/08/11 11:36:02 1.7 @@ -1,7 +1,7 @@ -/* $NetBSD: tprof.c,v 1.6.4.2 2011/04/21 01:42:02 rmind Exp $ */ +/* $NetBSD: tprof.c,v 1.7 2010/08/11 11:36:02 pgoyette Exp $ */ /*- - * Copyright (c)2008,2009,2010 YAMAMOTO Takashi, + * Copyright (c)2008,2009 YAMAMOTO Takashi, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.6.4.2 2011/04/21 01:42:02 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.7 2010/08/11 11:36:02 pgoyette Exp $"); #include #include @@ -38,7 +38,6 @@ __KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1. #include #include #include -#include #include #include @@ -56,10 +55,12 @@ __KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1. * L: tprof_lock * R: tprof_reader_lock * S: tprof_startstop_lock - * s: writer should hold tprof_startstop_lock and tprof_lock - * reader should hold tprof_startstop_lock or tprof_lock */ +typedef struct { + uintptr_t s_pc; /* program counter */ +} tprof_sample_t; + typedef struct tprof_buf { u_int b_used; u_int b_size; @@ -76,7 +77,6 @@ typedef struct tprof_buf { typedef struct { tprof_buf_t *c_buf; - uint32_t c_cpuid; struct work c_work; callout_t c_callout; } __aligned(CACHE_LINE_SIZE) tprof_cpu_t; @@ -89,7 +89,7 @@ typedef struct tprof_backend { } tprof_backend_t; static kmutex_t tprof_lock; -static bool tprof_running; /* s: */ +static bool tprof_running; static u_int tprof_nworker; /* L: # of running worker LWPs */ static lwp_t *tprof_owner; static STAILQ_HEAD(, tprof_buf) tprof_list; /* L: global buffer list */ @@ -296,8 +296,6 @@ tprof_start(const struct tprof_param *pa error = tb->tb_ops->tbo_start(NULL); if (error != 0) { - KASSERT(tb->tb_usecount > 0); - tb->tb_usecount--; tprof_stop1(); goto done; } @@ -320,6 +318,8 @@ done: static void tprof_stop(void) { + CPU_INFO_ITERATOR cii; + struct cpu_info *ci; tprof_backend_t *tb; KASSERT(mutex_owned(&tprof_startstop_lock)); @@ -335,11 +335,16 @@ tprof_stop(void) mutex_enter(&tprof_lock); tprof_running = false; cv_broadcast(&tprof_reader_cv); - while (tprof_nworker > 0) { - cv_wait(&tprof_cv, &tprof_lock); - } mutex_exit(&tprof_lock); + for (CPU_INFO_FOREACH(cii, ci)) { + mutex_enter(&tprof_lock); + while (tprof_nworker > 0) { + cv_wait(&tprof_cv, &tprof_lock); + } + mutex_exit(&tprof_lock); + } + tprof_stop1(); done: ; @@ -395,10 +400,7 @@ tprof_backend_lookup(const char *name) * tprof_sample: record a sample on the per-cpu buffer. * * be careful; can be called in NMI context. - * we are bluntly assuming the followings are safe. - * curcpu() - * curlwp->l_lid - * curlwp->l_proc->p_pid + * we are assuming that curcpu() is safe. */ void @@ -406,9 +408,7 @@ tprof_sample(tprof_backend_cookie_t *coo { tprof_cpu_t * const c = tprof_curcpu(); tprof_buf_t * const buf = c->c_buf; - tprof_sample_t *sp; const uintptr_t pc = tfi->tfi_pc; - const lwp_t * const l = curlwp; u_int idx; idx = buf->b_used; @@ -416,12 +416,7 @@ tprof_sample(tprof_backend_cookie_t *coo buf->b_overflow++; return; } - sp = &buf->b_data[idx]; - sp->s_pid = l->l_proc->p_pid; - sp->s_lwpid = l->l_lid; - sp->s_cpuid = c->c_cpuid; - sp->s_flags = (tfi->tfi_inkernel) ? TPROF_SAMPLE_INKERNEL : 0; - sp->s_pc = pc; + buf->b_data[idx].s_pc = pc; buf->b_used = idx + 1; } @@ -667,7 +662,6 @@ MODULE(MODULE_CLASS_DRIVER, tprof, NULL) static void tprof_driver_init(void) { - unsigned int i; mutex_init(&tprof_lock, MUTEX_DEFAULT, IPL_NONE); mutex_init(&tprof_reader_lock, MUTEX_DEFAULT, IPL_NONE); @@ -675,12 +669,6 @@ tprof_driver_init(void) cv_init(&tprof_cv, "tprof"); cv_init(&tprof_reader_cv, "tprof_rd"); STAILQ_INIT(&tprof_list); - for (i = 0; i < __arraycount(tprof_cpus); i++) { - tprof_cpu_t * const c = &tprof_cpus[i]; - - c->c_buf = NULL; - c->c_cpuid = i; - } } static void