Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ratecheck(9) [netbsd man page]

RATECHECK(9)						   BSD Kernel Developer's Manual					      RATECHECK(9)

NAME
ratecheck -- function to help implement rate-limited actions SYNOPSIS
#include <sys/time.h> int ratecheck(struct timeval *lasttime, const struct timeval *mininterval); DESCRIPTION
The ratecheck() function provides a simple time interval check which can be used when implementing time-based rate-limited actions. If the difference between the current monotonically-increasing system time (mono_time) and lasttime is less than the value given by the mininterval argument, zero is returned. Otherwise, lasttime is set to the current time and a non-zero value is returned. The motivation for implementing ratecheck() was to provide a mechanism that could be used to add rate limiting to diagnostic message output. If printed too often, diagnostic messages can keep the system from doing useful work. If the repeated messages can be caused by deliberate user action or network events, they can be exploited to cause denial of system service. Note that using a very short time interval (less than a second) for mininterval defeats the purpose of this function. (It doesn't take much to flood a 9600 baud serial console with output, for instance.) EXAMPLES
Here is a simple example of use of the ratecheck() function: /* * The following variables could be global, in a device softc, etc., * depending on the exact usage. */ struct timeval drv_lasterr1time; /* time of last err1 message */ long drv_err1count; /* # of err1 errs since last msg */ struct timeval drv_lasterr2time; /* time of last err2 message */ long drv_err2count; /* # of err2 errs since last msg */ /* * The following variable will often be global or shared by all * instances of a driver. It should be initialized, so it can be * patched. Allowing it to be set via an option might be nice, * but could lead to an insane proliferation of options. */ struct timeval drv_errintvl = { 5, 0 }; /* 5 seconds */ /* error handling/reporting function */ void drv_errhandler(int err1, int err2) { /* * Note that you should NOT use the same last-event * time variable for dissimilar messages! */ if (err1) { /* handle err1 condition */ ... drv_err1count++; if (ratecheck(&drv_lasterr1notice, &drv_errinterval)) { printf("drv: %ld err1 errors occurred", drv_err1count); drv_err1count = 0; } } if (err2) { /* handle err2 condition */ ... drv_err2count++; if (ratecheck(&drv_lasterr2notice, &drv_errinterval)) { printf("drv: %ld err2 errors occurred", drv_err2count); drv_err2count = 0; } } } SEE ALSO
log(9), ppsratecheck(9), printf(9), time_second(9) HISTORY
The ratecheck() function appeared in NetBSD 1.5. BUGS
ratecheck() may not work as expected, if mininterval is less than the hardware clock interrupt interval (1/hz). BSD
February 2, 2000 BSD

Check Out this Related Man Page

IBQUERYERRORS(8)						OpenIB Diagnostics						  IBQUERYERRORS(8)

NAME
ibqueryerrors.pl - query and report non-zero IB port counters SYNOPSIS
ibqueryerrors.pl [-a -c -r -R -C <ca_name> -P <ca_port> -s <err1,err2,...> -S <switch_guid> -D <direct_route> -d] DESCRIPTION
ibqueryerrors.pl reports the port counters of switches. This is similar to ibcheckerrors with the additional ability to filter out selected errors, include the optional transmit and receive data counters, report actions to remedy a non-zero count, and report full link information for the link reported. OPTIONS
-a Report an action to take. Some of the counters are not errors in and of themselves. This reports some more information on what the counters mean and what actions can/should be taken if they are non-zero. -c Suppress some of the common "side effect" counters. These counters usually do not indicate an error condition and can be usually be safely ignored. -r Report the port information. This includes LID, port, external port (if applicable), link speed setting, remote GUID, remote port, remote external port (if applicable), and remote node description information. -R Recalculate the ibnetdiscover information, ie do not use the cached information. This option is slower but should be used if the diag tools have not been used for some time or if there are other reasons to believe that the fabric has changed. -s <err1,err2,...> Suppress the errors listed in the comma separated list provided. -S <switch_guid> Report results only for the switch specified. (hex format) -D <direct_route> Report results only for the switch specified by the direct route path. -d Include the optional transmit and receive data counters. -C <ca_name> use the specified ca_name for the search. -P <ca_port> use the specified ca_port for the search. AUTHOR
Ira Weiny <weiny2@llnl.gov> OpenIB Jan 24, 2008 IBQUERYERRORS(8)
Man Page