10a041f3bSBjoern A. Zeeb /*- 20a041f3bSBjoern A. Zeeb * Copyright (c) 2014 Bjoern A. Zeeb 30a041f3bSBjoern A. Zeeb * All rights reserved. 40a041f3bSBjoern A. Zeeb * 50a041f3bSBjoern A. Zeeb * This software was developed by SRI International and the University of 60a041f3bSBjoern A. Zeeb * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 70a041f3bSBjoern A. Zeeb * ("MRC2"), as part of the DARPA MRC research programme. 80a041f3bSBjoern A. Zeeb * 90a041f3bSBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 100a041f3bSBjoern A. Zeeb * modification, are permitted provided that the following conditions 110a041f3bSBjoern A. Zeeb * are met: 120a041f3bSBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 130a041f3bSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 140a041f3bSBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 150a041f3bSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 160a041f3bSBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 170a041f3bSBjoern A. Zeeb * 180a041f3bSBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 190a041f3bSBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 200a041f3bSBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 210a041f3bSBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 220a041f3bSBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 230a041f3bSBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 240a041f3bSBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 250a041f3bSBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 260a041f3bSBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 270a041f3bSBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 280a041f3bSBjoern A. Zeeb * SUCH DAMAGE. 290a041f3bSBjoern A. Zeeb * 300a041f3bSBjoern A. Zeeb * $FreeBSD$ 310a041f3bSBjoern A. Zeeb */ 320a041f3bSBjoern A. Zeeb 330a041f3bSBjoern A. Zeeb #ifndef _LINUX_TIMER_H 340a041f3bSBjoern A. Zeeb #define _LINUX_TIMER_H 350a041f3bSBjoern A. Zeeb 360a041f3bSBjoern A. Zeeb #ifndef __LINUX_ARCH_SIGEV_PREAMBLE_SIZE 370a041f3bSBjoern A. Zeeb #define __LINUX_ARCH_SIGEV_PREAMBLE_SIZE \ 380a041f3bSBjoern A. Zeeb (sizeof(l_int) * 2 + sizeof(l_sigval_t)) 390a041f3bSBjoern A. Zeeb #endif 400a041f3bSBjoern A. Zeeb 410a041f3bSBjoern A. Zeeb #define LINUX_SIGEV_MAX_SIZE 64 420a041f3bSBjoern A. Zeeb #define LINUX_SIGEV_PAD_SIZE \ 430a041f3bSBjoern A. Zeeb ((LINUX_SIGEV_MAX_SIZE - __LINUX_ARCH_SIGEV_PREAMBLE_SIZE) / \ 440a041f3bSBjoern A. Zeeb sizeof(l_int)) 450a041f3bSBjoern A. Zeeb 460a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_REALTIME 0 470a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_MONOTONIC 1 480a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_PROCESS_CPUTIME_ID 2 490a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_THREAD_CPUTIME_ID 3 500a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_MONOTONIC_RAW 4 510a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_REALTIME_COARSE 5 520a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_MONOTONIC_COARSE 6 530a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_BOOTTIME 7 540a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_REALTIME_ALARM 8 550a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_BOOTTIME_ALARM 9 560a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_SGI_CYCLE 10 570a041f3bSBjoern A. Zeeb #define LINUX_CLOCK_TAI 11 580a041f3bSBjoern A. Zeeb 592711aba9SDmitry Chagin #define LINUX_CPUCLOCK_PERTHREAD_MASK 4 602711aba9SDmitry Chagin #define LINUX_CPUCLOCK_MASK 3 612711aba9SDmitry Chagin #define LINUX_CPUCLOCK_WHICH(clock) \ 622711aba9SDmitry Chagin ((clock) & (clockid_t) LINUX_CPUCLOCK_MASK) 632711aba9SDmitry Chagin #define LINUX_CPUCLOCK_PROF 0 642711aba9SDmitry Chagin #define LINUX_CPUCLOCK_VIRT 1 652711aba9SDmitry Chagin #define LINUX_CPUCLOCK_SCHED 2 662711aba9SDmitry Chagin #define LINUX_CPUCLOCK_MAX 3 672711aba9SDmitry Chagin #define LINUX_CLOCKFD LINUX_CPUCLOCK_MAX 682711aba9SDmitry Chagin #define LINUX_CLOCKFD_MASK \ 692711aba9SDmitry Chagin (LINUX_CPUCLOCK_PERTHREAD_MASK|LINUX_CPUCLOCK_MASK) 702711aba9SDmitry Chagin 712711aba9SDmitry Chagin #define LINUX_CPUCLOCK_ID(clock) ((pid_t) ~((clock) >> 3)) 722711aba9SDmitry Chagin #define LINUX_CPUCLOCK_PERTHREAD(clock) \ 732711aba9SDmitry Chagin (((clock) & (clockid_t) LINUX_CPUCLOCK_PERTHREAD_MASK) != 0) 742711aba9SDmitry Chagin 75*f0f58384SDmitry Chagin #define LINUX_TIMER_ABSTIME 0x01 762711aba9SDmitry Chagin 770a041f3bSBjoern A. Zeeb #define L_SIGEV_SIGNAL 0 780a041f3bSBjoern A. Zeeb #define L_SIGEV_NONE 1 790a041f3bSBjoern A. Zeeb #define L_SIGEV_THREAD 2 800a041f3bSBjoern A. Zeeb #define L_SIGEV_THREAD_ID 4 810a041f3bSBjoern A. Zeeb 820a041f3bSBjoern A. Zeeb #define TS_CP(src,dst,fld) do { \ 830a041f3bSBjoern A. Zeeb CP((src).fld,(dst).fld,tv_sec); \ 840a041f3bSBjoern A. Zeeb CP((src).fld,(dst).fld,tv_nsec); \ 850a041f3bSBjoern A. Zeeb } while (0) 860a041f3bSBjoern A. Zeeb 870a041f3bSBjoern A. Zeeb #define ITS_CP(src, dst) do { \ 880a041f3bSBjoern A. Zeeb TS_CP((src), (dst), it_interval); \ 890a041f3bSBjoern A. Zeeb TS_CP((src), (dst), it_value); \ 900a041f3bSBjoern A. Zeeb } while (0) 910a041f3bSBjoern A. Zeeb 920a041f3bSBjoern A. Zeeb struct l_sigevent { 930a041f3bSBjoern A. Zeeb l_sigval_t sigev_value; 940a041f3bSBjoern A. Zeeb l_int sigev_signo; 950a041f3bSBjoern A. Zeeb l_int sigev_notify; 960a041f3bSBjoern A. Zeeb union { 970a041f3bSBjoern A. Zeeb l_int _pad[LINUX_SIGEV_PAD_SIZE]; 980a041f3bSBjoern A. Zeeb l_int _tid; 990a041f3bSBjoern A. Zeeb struct { 1000a041f3bSBjoern A. Zeeb l_uintptr_t _function; 1010a041f3bSBjoern A. Zeeb l_uintptr_t _attribute; 1020a041f3bSBjoern A. Zeeb } _l_sigev_thread; 1030a041f3bSBjoern A. Zeeb } _l_sigev_un; 1040a041f3bSBjoern A. Zeeb } 1050a041f3bSBjoern A. Zeeb #if defined(__amd64__) && defined(COMPAT_LINUX32) 1060a041f3bSBjoern A. Zeeb __packed 1070a041f3bSBjoern A. Zeeb #endif 1080a041f3bSBjoern A. Zeeb ; 1090a041f3bSBjoern A. Zeeb 1100a041f3bSBjoern A. Zeeb struct l_itimerspec { 1110a041f3bSBjoern A. Zeeb struct l_timespec it_interval; 1120a041f3bSBjoern A. Zeeb struct l_timespec it_value; 1130a041f3bSBjoern A. Zeeb }; 1140a041f3bSBjoern A. Zeeb 1150670e972SDmitry Chagin int native_to_linux_timespec(struct l_timespec *, 11668098228SDmitry Chagin struct timespec *); 11768098228SDmitry Chagin int linux_to_native_timespec(struct timespec *, 11868098228SDmitry Chagin struct l_timespec *); 11916ac71bcSDmitry Chagin int linux_to_native_clockid(clockid_t *, clockid_t); 120dd93b628SDmitry Chagin int native_to_linux_itimerspec(struct l_itimerspec *, 121dd93b628SDmitry Chagin struct itimerspec *); 122dd93b628SDmitry Chagin int linux_to_native_itimerspec(struct itimerspec *, 123dd93b628SDmitry Chagin struct l_itimerspec *); 124*f0f58384SDmitry Chagin int linux_to_native_timerflags(int *, int); 12568098228SDmitry Chagin 1260a041f3bSBjoern A. Zeeb #endif /* _LINUX_TIMER_H */ 127