callo.h revision f635d46a9872dc5a02bbbd736f2bf18685c2c221
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_CALLO_H
#define _SYS_CALLO_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
typedef long callout_id_t; /* internal form of timeout_id_t */
/*
* The callout mechanism provides general-purpose event scheduling:
* an arbitrary function is called in a specified amount of time.
*/
typedef struct callout {
void (*c_func)(void *); /* function to call */
void *c_arg; /* argument to function */
} callout_t;
/*
* The extended callout ID consists of the callout ID (as returned by
* timeout()) plus a bit indicating whether the callout is executing.
*
* The callout ID uniquely identifies a callout. It contains a table ID,
* indicating which callout table the callout belongs to, a bit indicating
* whether this is a short-term or long-term callout, and a running counter.
* The highest bit of the running counter is always set; this ensures that
* the callout ID is always non-zero, thus eliminating the need for an
* explicit wrap-around test during ID generation.
*
* The long-term bit exists to address the problem of callout ID collision.
* This is an issue because the system typically generates a large number of
* timeout() requests, which means that callout IDs eventually get recycled.
* Most timeouts are very short-lived, so that ID recycling isn't a problem;
* but there are a handful of timeouts which are sufficiently long-lived to
* see their own IDs reused. We use the long-term bit to partition the
* ID namespace into pieces; the short-term space gets all the heavy traffic
* and can wrap frequently (i.e., on the order of a day) with no ill effects;
* the long-term space gets very little traffic and thus never wraps.
*/
#define CALLOUT_FANOUT_BITS 3
#define CALLOUT_TYPE_BITS 1
#define CALLOUT_TABLES CALLOUT_COUNTER_LOW
#define CALLOUT_TABLE(t, f) \
(((t) << CALLOUT_FANOUT_BITS) + ((f) & CALLOUT_FANOUT_MASK))
/*
* We assume that during any period of CALLOUT_LONGTERM_TICKS ticks, at most
* (CALLOUT_COUNTER_HIGH / CALLOUT_COUNTER_LOW) callouts will be generated.
*/
#define CALLOUT_LONGTERM_TICKS 0x4000
#define CALLOUT_HASH(x) ((x) & CALLOUT_BUCKET_MASK)
#define CALLOUT_LBHASH(x) CALLOUT_HASH(x)
#define CALLOUT_REALTIME 0 /* realtime callout type */
/*
* All of the state information associated with a callout table.
* The fields are ordered with cache performance in mind.
*/
typedef struct callout_table {
#ifdef _KERNEL
extern void callout_init(void);
extern void callout_schedule(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_CALLO_H */