xref: /titanic_41/usr/src/man/man9f/drv_usectohz.9f (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
te
Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
Copyright 1989 AT&T
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 or http://www.opensolaris.org/os/licensing. 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]
DRV_USECTOHZ 9F "Apr 24, 2008"
NAME
drv_usectohz - convert microseconds to clock ticks
SYNOPSIS

#include <sys/types.h>
#include <sys/ddi.h>



clock_t drv_usectohz(clock_t microsecs);
INTERFACE LEVEL

Architecture independent level 1 (DDI/DKI).

PARAMETERS
microsecs

The number of microseconds to convert.

DESCRIPTION

The drv_usectohz() function converts a length of time expressed in microseconds to a number of system clock ticks. The time arguments to timeout(9F) and delay(9F) are expressed in clock ticks.

The drv_usectohz() function is a portable interface for drivers to make calls to timeout(9F) and delay(9F) and remain binary compatible should the driver object file be used on a system with a different clock speed (a different number of ticks in a second).

RETURN VALUES

The value returned is the number of system clock ticks equivalent to the microsecs argument. No error value is returned. If the clock tick equivalent to microsecs is too large to be represented as a clock_t, then the maximum clock_t value will be returned.

CONTEXT

The drv_usectohz() function can be called from user, interrupt, or kernel context.

SEE ALSO

delay(9F), drv_hztousec(9F), timeout(9F)

Writing Device Drivers

NOTES

If the microsecs argument to drv_usectohz() is less than drv_hztousec(9F), drv_usectohz() returns one tick. This, coupled with multiplication, can result in significantly longer durations than expected. For example, on a machine where hz is 100, calling drv_usectohz() with a microsecs value less than 10000 returns a result equivalent to 10000 (1 tick). This type of mistake causes code such as"5000 * drv_usectohz(1000)" to compute a duration of 50 seconds instead of the intended 5 seconds.