callout.h revision 283291
11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1990, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * (c) UNIX System Laboratories, Inc. 51541Srgrimes * All or some portions of this file are derived from material licensed 61541Srgrimes * to the University of California by American Telephone and Telegraph 71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81541Srgrimes * the permission of UNIX System Laboratories, Inc. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 4. Neither the name of the University nor the names of its contributors 191541Srgrimes * may be used to endorse or promote products derived from this software 201541Srgrimes * without specific prior written permission. 211541Srgrimes * 221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321541Srgrimes * SUCH DAMAGE. 331541Srgrimes * 341541Srgrimes * @(#)callout.h 8.2 (Berkeley) 1/21/94 3550477Speter * $FreeBSD: head/sys/sys/callout.h 283291 2015-05-22 17:05:21Z jkim $ 361541Srgrimes */ 371541Srgrimes 382165Spaul#ifndef _SYS_CALLOUT_H_ 392165Spaul#define _SYS_CALLOUT_H_ 402165Spaul 41221059Skib#include <sys/_callout.h> 4229683Sgibbs 4344510Swollman#define CALLOUT_LOCAL_ALLOC 0x0001 /* was allocated from callfree */ 4450673Sjlemon#define CALLOUT_ACTIVE 0x0002 /* callout is currently active */ 4550673Sjlemon#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */ 46283291Sjkim#define CALLOUT_MPSAFE 0x0008 /* deprecated */ 47141428Siedowse#define CALLOUT_RETURNUNLOCKED 0x0010 /* handler returns with mtx unlocked */ 48277528Shselasky#define CALLOUT_SHAREDLOCK 0x0020 /* callout lock held in shared mode */ 49277528Shselasky#define CALLOUT_DFRMIGRATION 0x0040 /* callout in deferred migration mode */ 50247777Sdavide#define CALLOUT_PROCESSED 0x0080 /* callout in wheel or processing list? */ 51247777Sdavide#define CALLOUT_DIRECT 0x0100 /* allow exec from hw int context */ 5244510Swollman 53247777Sdavide#define C_DIRECT_EXEC 0x0001 /* direct execution of callout */ 54247777Sdavide#define C_PRELBITS 7 55247777Sdavide#define C_PRELRANGE ((1 << C_PRELBITS) - 1) 56247777Sdavide#define C_PREL(x) (((x) + 1) << 1) 57247777Sdavide#define C_PRELGET(x) (int)((((x) >> 1) & C_PRELRANGE) - 1) 58247777Sdavide#define C_HARDCLOCK 0x0100 /* align to hardclock() calls */ 59247777Sdavide#define C_ABSOLUTE 0x0200 /* event time is absolute. */ 60247777Sdavide 6183045Sobrienstruct callout_handle { 6229683Sgibbs struct callout *callout; 6329683Sgibbs}; 6429683Sgibbs 6555205Speter#ifdef _KERNEL 66280785Srrs/* 67280785Srrs * Note the flags field is actually *two* fields. The c_flags 68280785Srrs * field is the one that caller operations that may, or may not have 69280785Srrs * a lock touches i.e. callout_deactivate(). The other, the c_iflags, 70280785Srrs * is the internal flags that *must* be kept correct on which the 71280872Srrs * callout system depend on e.g. callout_pending(). 72280872Srrs * The c_iflag is used internally by the callout system to determine which 73280872Srrs * list the callout is on and track internal state. Callers *should not* 74280872Srrs * use the c_flags field directly but should use the macros provided. 75280785Srrs * 76280872Srrs * The c_iflags field holds internal flags that are protected by internal 77280872Srrs * locks of the callout subsystem. The c_flags field holds external flags. 78280872Srrs * The caller must hold its own lock while manipulating or reading external 79280872Srrs * flags via callout_active(), callout_deactivate(), callout_reset*(), or 80280872Srrs * callout_stop() to avoid races. 81280785Srrs */ 8250673Sjlemon#define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE) 8350673Sjlemon#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE) 84277528Shselasky#define callout_drain(c) _callout_stop_safe(c, 1) 8592719Salfredvoid callout_init(struct callout *, int); 86173760Sattiliovoid _callout_init_lock(struct callout *, struct lock_object *, int); 87173760Sattilio#define callout_init_mtx(c, mtx, flags) \ 88173760Sattilio _callout_init_lock((c), ((mtx) != NULL) ? &(mtx)->lock_object : \ 89173760Sattilio NULL, (flags)) 90254712Sdavide#define callout_init_rm(c, rm, flags) \ 91270259Sgavin _callout_init_lock((c), ((rm) != NULL) ? &(rm)->lock_object : \ 92254703Sdavide NULL, (flags)) 93173760Sattilio#define callout_init_rw(c, rw, flags) \ 94173760Sattilio _callout_init_lock((c), ((rw) != NULL) ? &(rw)->lock_object : \ 95173760Sattilio NULL, (flags)) 96280785Srrs#define callout_pending(c) ((c)->c_iflags & CALLOUT_PENDING) 97247777Sdavideint callout_reset_sbt_on(struct callout *, sbintime_t, sbintime_t, 98277528Shselasky void (*)(void *), void *, int, int); 99247777Sdavide#define callout_reset_sbt(c, sbt, pr, fn, arg, flags) \ 100280785Srrs callout_reset_sbt_on((c), (sbt), (pr), (fn), (arg), -1, (flags)) 101247777Sdavide#define callout_reset_sbt_curcpu(c, sbt, pr, fn, arg, flags) \ 102275046Savg callout_reset_sbt_on((c), (sbt), (pr), (fn), (arg), PCPU_GET(cpuid),\ 103275046Savg (flags)) 104247777Sdavide#define callout_reset_on(c, to_ticks, fn, arg, cpu) \ 105275046Savg callout_reset_sbt_on((c), tick_sbt * (to_ticks), 0, (fn), (arg), \ 106247777Sdavide (cpu), C_HARDCLOCK) 107177859Sjeff#define callout_reset(c, on_tick, fn, arg) \ 108280785Srrs callout_reset_on((c), (on_tick), (fn), (arg), -1) 109177859Sjeff#define callout_reset_curcpu(c, on_tick, fn, arg) \ 110177859Sjeff callout_reset_on((c), (on_tick), (fn), (arg), PCPU_GET(cpuid)) 111275045Savg#define callout_schedule_sbt_on(c, sbt, pr, cpu, flags) \ 112275045Savg callout_reset_sbt_on((c), (sbt), (pr), (c)->c_func, (c)->c_arg, \ 113275045Savg (cpu), (flags)) 114275045Savg#define callout_schedule_sbt(c, sbt, pr, flags) \ 115280785Srrs callout_schedule_sbt_on((c), (sbt), (pr), -1, (flags)) 116275045Savg#define callout_schedule_sbt_curcpu(c, sbt, pr, flags) \ 117275045Savg callout_schedule_sbt_on((c), (sbt), (pr), PCPU_GET(cpuid), (flags)) 118181191Ssamint callout_schedule(struct callout *, int); 119181191Ssamint callout_schedule_on(struct callout *, int, int); 120181191Ssam#define callout_schedule_curcpu(c, on_tick) \ 121181191Ssam callout_schedule_on((c), (on_tick), PCPU_GET(cpuid)) 122277528Shselasky#define callout_stop(c) _callout_stop_safe(c, 0) 123277528Shselaskyint _callout_stop_safe(struct callout *, int); 124247777Sdavidevoid callout_process(sbintime_t now); 12544510Swollman 12655205Speter#endif 1272165Spaul 12829683Sgibbs#endif /* _SYS_CALLOUT_H_ */ 129