17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 534709573Sraf * Common Development and Distribution License (the "License"). 634709573Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2134709573Sraf 227c478bd9Sstevel@tonic-gate /* 23*e0cf54a5SRoger A. Faulkner * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_TIMER_H 287c478bd9Sstevel@tonic-gate #define _SYS_TIMER_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <sys/proc.h> 327c478bd9Sstevel@tonic-gate #include <sys/thread.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef _KERNEL 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #define _TIMER_MAX 32 4134709573Sraf extern int timer_max; /* patchable via /etc/system */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Bit values for the it_lock field. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate #define ITLK_LOCKED 0x01 477c478bd9Sstevel@tonic-gate #define ITLK_WANTED 0x02 487c478bd9Sstevel@tonic-gate #define ITLK_REMOVE 0x04 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Bit values for the it_flags field. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate #define IT_SIGNAL 0x01 547c478bd9Sstevel@tonic-gate #define IT_PORT 0x02 /* use event port notification */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate struct clock_backend; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate typedef struct itimer { 597c478bd9Sstevel@tonic-gate itimerspec_t it_itime; 607c478bd9Sstevel@tonic-gate hrtime_t it_hrtime; 617c478bd9Sstevel@tonic-gate ushort_t it_flags; 627c478bd9Sstevel@tonic-gate ushort_t it_lock; 637c478bd9Sstevel@tonic-gate void *it_arg; 647c478bd9Sstevel@tonic-gate sigqueue_t *it_sigq; 657c478bd9Sstevel@tonic-gate klwp_t *it_lwp; 667c478bd9Sstevel@tonic-gate struct proc *it_proc; 677c478bd9Sstevel@tonic-gate kcondvar_t it_cv; 687c478bd9Sstevel@tonic-gate int it_blockers; 697c478bd9Sstevel@tonic-gate int it_pending; 707c478bd9Sstevel@tonic-gate int it_overrun; 717c478bd9Sstevel@tonic-gate struct clock_backend *it_backend; 727c478bd9Sstevel@tonic-gate kmutex_t it_mutex; 737c478bd9Sstevel@tonic-gate void *it_portev; /* port_kevent_t pointer */ 747c478bd9Sstevel@tonic-gate void *it_portsrc; /* port_source_t pointer */ 757c478bd9Sstevel@tonic-gate int it_portfd; /* port file descriptor */ 767c478bd9Sstevel@tonic-gate } itimer_t; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate typedef struct clock_backend { 797c478bd9Sstevel@tonic-gate struct sigevent clk_default; 807c478bd9Sstevel@tonic-gate int (*clk_clock_settime)(timespec_t *); 817c478bd9Sstevel@tonic-gate int (*clk_clock_gettime)(timespec_t *); 827c478bd9Sstevel@tonic-gate int (*clk_clock_getres)(timespec_t *); 837c478bd9Sstevel@tonic-gate int (*clk_timer_create)(itimer_t *, struct sigevent *); 847c478bd9Sstevel@tonic-gate int (*clk_timer_settime)(itimer_t *, int, const struct itimerspec *); 857c478bd9Sstevel@tonic-gate int (*clk_timer_gettime)(itimer_t *, struct itimerspec *); 867c478bd9Sstevel@tonic-gate int (*clk_timer_delete)(itimer_t *); 877c478bd9Sstevel@tonic-gate void (*clk_timer_lwpbind)(itimer_t *); 887c478bd9Sstevel@tonic-gate } clock_backend_t; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate extern void clock_add_backend(clockid_t clock, clock_backend_t *backend); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate extern void timer_fire(itimer_t *); 937c478bd9Sstevel@tonic-gate extern void timer_lwpbind(); 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate extern void timer_func(sigqueue_t *); 967c478bd9Sstevel@tonic-gate extern void timer_exit(void); 977c478bd9Sstevel@tonic-gate extern void timer_lwpexit(void); 987c478bd9Sstevel@tonic-gate extern clock_t hzto(struct timeval *); 997c478bd9Sstevel@tonic-gate extern clock_t timespectohz(timespec_t *, timespec_t); 100f635d46aSqiao extern int64_t timespectohz64(timespec_t *); 1017c478bd9Sstevel@tonic-gate extern int itimerspecfix(timespec_t *); 1027c478bd9Sstevel@tonic-gate extern void timespecadd(timespec_t *, timespec_t *); 1037c478bd9Sstevel@tonic-gate extern void timespecsub(timespec_t *, timespec_t *); 1047c478bd9Sstevel@tonic-gate extern void timespecfix(timespec_t *); 1057c478bd9Sstevel@tonic-gate extern int xgetitimer(uint_t, struct itimerval *, int); 1067c478bd9Sstevel@tonic-gate extern int xsetitimer(uint_t, struct itimerval *, int); 107*e0cf54a5SRoger A. Faulkner extern void delete_itimer_realprof(void); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #define timerspecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) 1107c478bd9Sstevel@tonic-gate #define timerspeccmp(tvp, uvp) (((tvp)->tv_sec - (uvp)->tv_sec) ? \ 1117c478bd9Sstevel@tonic-gate ((tvp)->tv_sec - (uvp)->tv_sec):((tvp)->tv_nsec - (uvp)->tv_nsec)) 1127c478bd9Sstevel@tonic-gate #define timerspecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate struct oldsigevent { 1157c478bd9Sstevel@tonic-gate /* structure definition prior to notification attributes member */ 1167c478bd9Sstevel@tonic-gate int _notify; 1177c478bd9Sstevel@tonic-gate union { 1187c478bd9Sstevel@tonic-gate int _signo; 1197c478bd9Sstevel@tonic-gate void (*_notify_function)(union sigval); 1207c478bd9Sstevel@tonic-gate } _un; 1217c478bd9Sstevel@tonic-gate union sigval _value; 1227c478bd9Sstevel@tonic-gate }; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate struct oldsigevent32 { 1277c478bd9Sstevel@tonic-gate int32_t _notify; 1287c478bd9Sstevel@tonic-gate union { 1297c478bd9Sstevel@tonic-gate int32_t _signo; 1307c478bd9Sstevel@tonic-gate caddr32_t _notify_function; 1317c478bd9Sstevel@tonic-gate } _un; 1327c478bd9Sstevel@tonic-gate union sigval32 _value; 1337c478bd9Sstevel@tonic-gate }; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1367c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate #endif 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif /* _SYS_TIMER_H */ 143