Path: blob/main/sys/cddl/dev/dtrace/dtrace_vtime.c
48254 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2006 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526void27dtrace_vtime_enable(void)28{29dtrace_vtime_state_t state, nstate = 0;3031do {32state = dtrace_vtime_active;3334switch (state) {35case DTRACE_VTIME_INACTIVE:36nstate = DTRACE_VTIME_ACTIVE;37break;3839case DTRACE_VTIME_INACTIVE_TNF:40nstate = DTRACE_VTIME_ACTIVE_TNF;41break;4243case DTRACE_VTIME_ACTIVE:44case DTRACE_VTIME_ACTIVE_TNF:45panic("DTrace virtual time already enabled");46/*NOTREACHED*/47}4849} while (dtrace_cas32((uint32_t *)&dtrace_vtime_active,50state, nstate) != state);51}5253void54dtrace_vtime_disable(void)55{56dtrace_vtime_state_t state, nstate = 0;5758do {59state = dtrace_vtime_active;6061switch (state) {62case DTRACE_VTIME_ACTIVE:63nstate = DTRACE_VTIME_INACTIVE;64break;6566case DTRACE_VTIME_ACTIVE_TNF:67nstate = DTRACE_VTIME_INACTIVE_TNF;68break;6970case DTRACE_VTIME_INACTIVE:71case DTRACE_VTIME_INACTIVE_TNF:72panic("DTrace virtual time already disabled");73/*NOTREACHED*/74}7576} while (dtrace_cas32((uint32_t *)&dtrace_vtime_active,77state, nstate) != state);78}7980void81dtrace_vtime_switch(kthread_t *next)82{83dtrace_icookie_t cookie;84hrtime_t ts;8586cookie = dtrace_interrupt_disable();87ts = dtrace_gethrtime();8889if (curthread->t_dtrace_start != 0) {90curthread->t_dtrace_vtime += ts - curthread->t_dtrace_start;91curthread->t_dtrace_start = 0;92}9394if (next != NULL)95next->t_dtrace_start = ts;9697dtrace_interrupt_enable(cookie);98}99100101