hwpmc_logging.c (172836) | hwpmc_logging.c (174395) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2005 Joseph Koshy | 2 * Copyright (c) 2005-2007 Joseph Koshy 3 * Copyright (c) 2007 The FreeBSD Foundation |
3 * All rights reserved. 4 * | 4 * All rights reserved. 5 * |
6 * Portions of this software were developed by A. Joseph Koshy under 7 * sponsorship from the FreeBSD Foundation and Google, Inc. 8 * |
|
5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. --- 12 unchanged lines hidden (view full) --- 25 * 26 */ 27 28/* 29 * Logging code for hwpmc(4) 30 */ 31 32#include <sys/cdefs.h> | 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. --- 12 unchanged lines hidden (view full) --- 29 * 30 */ 31 32/* 33 * Logging code for hwpmc(4) 34 */ 35 36#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_logging.c 172836 2007-10-20 23:23:23Z julian $"); | 37__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_logging.c 174395 2007-12-07 08:20:17Z jkoshy $"); |
34 35#include <sys/param.h> 36#include <sys/file.h> 37#include <sys/kernel.h> 38#include <sys/kthread.h> 39#include <sys/lock.h> 40#include <sys/module.h> 41#include <sys/mutex.h> --- 17 unchanged lines hidden (view full) --- 59 * kern.hwpmc.logbuffersize -- size of the per-cpu owner buffers. 60 */ 61 62static int pmclog_buffer_size = PMC_LOG_BUFFER_SIZE; 63TUNABLE_INT(PMC_SYSCTL_NAME_PREFIX "logbuffersize", &pmclog_buffer_size); 64SYSCTL_INT(_kern_hwpmc, OID_AUTO, logbuffersize, CTLFLAG_TUN|CTLFLAG_RD, 65 &pmclog_buffer_size, 0, "size of log buffers in kilobytes"); 66 | 38 39#include <sys/param.h> 40#include <sys/file.h> 41#include <sys/kernel.h> 42#include <sys/kthread.h> 43#include <sys/lock.h> 44#include <sys/module.h> 45#include <sys/mutex.h> --- 17 unchanged lines hidden (view full) --- 63 * kern.hwpmc.logbuffersize -- size of the per-cpu owner buffers. 64 */ 65 66static int pmclog_buffer_size = PMC_LOG_BUFFER_SIZE; 67TUNABLE_INT(PMC_SYSCTL_NAME_PREFIX "logbuffersize", &pmclog_buffer_size); 68SYSCTL_INT(_kern_hwpmc, OID_AUTO, logbuffersize, CTLFLAG_TUN|CTLFLAG_RD, 69 &pmclog_buffer_size, 0, "size of log buffers in kilobytes"); 70 |
67 | |
68/* 69 * kern.hwpmc.nbuffer -- number of global log buffers 70 */ 71 72static int pmc_nlogbuffers = PMC_NLOGBUFFERS; 73TUNABLE_INT(PMC_SYSCTL_NAME_PREFIX "nbuffers", &pmc_nlogbuffers); 74SYSCTL_INT(_kern_hwpmc, OID_AUTO, nbuffers, CTLFLAG_TUN|CTLFLAG_RD, 75 &pmc_nlogbuffers, 0, "number of global log buffers"); --- 15 unchanged lines hidden (view full) --- 91 (D)->plb_base = (D)->plb_ptr = ((char *) (D)) + \ 92 __roundup; \ 93 } while (0) 94 95 96/* 97 * Log file record constructors. 98 */ | 71/* 72 * kern.hwpmc.nbuffer -- number of global log buffers 73 */ 74 75static int pmc_nlogbuffers = PMC_NLOGBUFFERS; 76TUNABLE_INT(PMC_SYSCTL_NAME_PREFIX "nbuffers", &pmc_nlogbuffers); 77SYSCTL_INT(_kern_hwpmc, OID_AUTO, nbuffers, CTLFLAG_TUN|CTLFLAG_RD, 78 &pmc_nlogbuffers, 0, "number of global log buffers"); --- 15 unchanged lines hidden (view full) --- 94 (D)->plb_base = (D)->plb_ptr = ((char *) (D)) + \ 95 __roundup; \ 96 } while (0) 97 98 99/* 100 * Log file record constructors. 101 */ |
99 | |
100#define _PMCLOG_TO_HEADER(T,L) \ 101 ((PMCLOG_HEADER_MAGIC << 24) | \ 102 (PMCLOG_TYPE_ ## T << 16) | \ 103 ((L) & 0xFFFF)) 104 105/* reserve LEN bytes of space and initialize the entry header */ 106#define _PMCLOG_RESERVE(PO,TYPE,LEN,ACTION) do { \ 107 uint32_t *_le; \ --- 22 unchanged lines hidden (view full) --- 130 pmclog_release((PO)); \ 131 } while (0) 132 133 134/* 135 * Assertions about the log file format. 136 */ 137 | 102#define _PMCLOG_TO_HEADER(T,L) \ 103 ((PMCLOG_HEADER_MAGIC << 24) | \ 104 (PMCLOG_TYPE_ ## T << 16) | \ 105 ((L) & 0xFFFF)) 106 107/* reserve LEN bytes of space and initialize the entry header */ 108#define _PMCLOG_RESERVE(PO,TYPE,LEN,ACTION) do { \ 109 uint32_t *_le; \ --- 22 unchanged lines hidden (view full) --- 132 pmclog_release((PO)); \ 133 } while (0) 134 135 136/* 137 * Assertions about the log file format. 138 */ 139 |
140CTASSERT(sizeof(struct pmclog_callchain) == 6*4 + 141 PMC_CALLCHAIN_DEPTH_MAX*sizeof(uintfptr_t)); |
|
138CTASSERT(sizeof(struct pmclog_closelog) == 3*4); 139CTASSERT(sizeof(struct pmclog_dropnotify) == 3*4); 140CTASSERT(sizeof(struct pmclog_map_in) == PATH_MAX + 141 4*4 + sizeof(uintfptr_t)); 142CTASSERT(offsetof(struct pmclog_map_in,pl_pathname) == 143 4*4 + sizeof(uintfptr_t)); 144CTASSERT(sizeof(struct pmclog_map_out) == 4*4 + 2*sizeof(uintfptr_t)); 145CTASSERT(sizeof(struct pmclog_pcsample) == 6*4 + sizeof(uintfptr_t)); --- 559 unchanged lines hidden (view full) --- 705 706 error: 707 mtx_unlock(&pmc_kthread_mtx); 708 709 return error; 710} 711 712 | 142CTASSERT(sizeof(struct pmclog_closelog) == 3*4); 143CTASSERT(sizeof(struct pmclog_dropnotify) == 3*4); 144CTASSERT(sizeof(struct pmclog_map_in) == PATH_MAX + 145 4*4 + sizeof(uintfptr_t)); 146CTASSERT(offsetof(struct pmclog_map_in,pl_pathname) == 147 4*4 + sizeof(uintfptr_t)); 148CTASSERT(sizeof(struct pmclog_map_out) == 4*4 + 2*sizeof(uintfptr_t)); 149CTASSERT(sizeof(struct pmclog_pcsample) == 6*4 + sizeof(uintfptr_t)); --- 559 unchanged lines hidden (view full) --- 709 710 error: 711 mtx_unlock(&pmc_kthread_mtx); 712 713 return error; 714} 715 716 |
713/* 714 * Send a 'close log' event to the log file. 715 */ | 717void 718pmclog_process_callchain(struct pmc *pm, struct pmc_sample *ps) 719{ 720 int n, recordlen; 721 uint32_t flags; 722 struct pmc_owner *po; |
716 | 723 |
724 PMCDBG(LOG,SAM,1,"pm=%p pid=%d n=%d", pm, ps->ps_pid, 725 ps->ps_nsamples); 726 727 recordlen = offsetof(struct pmclog_callchain, pl_pc) + 728 ps->ps_nsamples * sizeof(uintfptr_t); 729 po = pm->pm_owner; 730 flags = PMC_CALLCHAIN_TO_CPUFLAGS(ps->ps_cpu,ps->ps_flags); 731 PMCLOG_RESERVE(po, CALLCHAIN, recordlen); 732 PMCLOG_EMIT32(ps->ps_pid); 733 PMCLOG_EMIT32(pm->pm_id); 734 PMCLOG_EMIT32(flags); 735 for (n = 0; n < ps->ps_nsamples; n++) 736 PMCLOG_EMITADDR(ps->ps_pc[n]); 737 PMCLOG_DESPATCH(po); 738} 739 |
|
717void 718pmclog_process_closelog(struct pmc_owner *po) 719{ 720 PMCLOG_RESERVE(po,CLOSELOG,sizeof(struct pmclog_closelog)); 721 PMCLOG_DESPATCH(po); 722} 723 724void --- 31 unchanged lines hidden (view full) --- 756 PMCLOG_RESERVE(po, MAP_OUT, sizeof(struct pmclog_map_out)); 757 PMCLOG_EMIT32(pid); 758 PMCLOG_EMITADDR(start); 759 PMCLOG_EMITADDR(end); 760 PMCLOG_DESPATCH(po); 761} 762 763void | 740void 741pmclog_process_closelog(struct pmc_owner *po) 742{ 743 PMCLOG_RESERVE(po,CLOSELOG,sizeof(struct pmclog_closelog)); 744 PMCLOG_DESPATCH(po); 745} 746 747void --- 31 unchanged lines hidden (view full) --- 779 PMCLOG_RESERVE(po, MAP_OUT, sizeof(struct pmclog_map_out)); 780 PMCLOG_EMIT32(pid); 781 PMCLOG_EMITADDR(start); 782 PMCLOG_EMITADDR(end); 783 PMCLOG_DESPATCH(po); 784} 785 786void |
764pmclog_process_pcsample(struct pmc *pm, struct pmc_sample *ps) 765{ 766 struct pmc_owner *po; 767 768 PMCDBG(LOG,SAM,1,"pm=%p pid=%d pc=%p", pm, ps->ps_pid, 769 (void *) ps->ps_pc); 770 771 po = pm->pm_owner; 772 773 PMCLOG_RESERVE(po, PCSAMPLE, sizeof(struct pmclog_pcsample)); 774 PMCLOG_EMIT32(ps->ps_pid); 775 PMCLOG_EMITADDR(ps->ps_pc); 776 PMCLOG_EMIT32(pm->pm_id); 777 PMCLOG_EMIT32(ps->ps_usermode); 778 PMCLOG_DESPATCH(po); 779} 780 781void | |
782pmclog_process_pmcallocate(struct pmc *pm) 783{ 784 struct pmc_owner *po; 785 786 po = pm->pm_owner; 787 788 PMCDBG(LOG,ALL,1, "pm=%p", pm); 789 --- 210 unchanged lines hidden --- | 787pmclog_process_pmcallocate(struct pmc *pm) 788{ 789 struct pmc_owner *po; 790 791 po = pm->pm_owner; 792 793 PMCDBG(LOG,ALL,1, "pm=%p", pm); 794 --- 210 unchanged lines hidden --- |