xref: /freebsd/sys/contrib/openzfs/include/sys/zfs_ratelimit.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * This file and its contents are supplied under the terms of the
6  * Common Development and Distribution License ("CDDL"), version 1.0.
7  * You may only use this file in accordance with the terms of version
8  * 1.0 of the CDDL.
9  *
10  * A full copy of the text of the CDDL should have accompanied this
11  * source.  A copy of the CDDL is also available via the Internet at
12  * http://www.illumos.org/license/CDDL.
13  *
14  * CDDL HEADER END
15  */
16 
17 /*
18  * Copyright (c) 2016, Lawrence Livermore National Security, LLC.
19  */
20 
21 #ifndef _SYS_ZFS_RATELIMIT_H
22 #define	_SYS_ZFS_RATELIMIT_H
23 
24 #include <sys/zfs_context.h>
25 
26 typedef struct {
27 	hrtime_t start;
28 	unsigned int count;
29 
30 	/*
31 	 * Pointer to number of events per interval.  We do this to
32 	 * allow the burst to be a (changeable) module parameter.
33 	 */
34 	unsigned int *burst;
35 
36 	unsigned int interval;	/* Interval length in seconds */
37 	kmutex_t lock;
38 } zfs_ratelimit_t;
39 
40 int zfs_ratelimit(zfs_ratelimit_t *rl);
41 void zfs_ratelimit_init(zfs_ratelimit_t *rl, unsigned int *burst,
42     unsigned int interval);
43 void zfs_ratelimit_fini(zfs_ratelimit_t *rl);
44 
45 #endif	/* _SYS_ZFS_RATELIMIT_H */
46