xref: /freebsd/sys/contrib/openzfs/include/sys/aggsum.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  * Copyright (c) 2017 by Delphix. All rights reserved.
18  */
19 
20 #ifndef	_SYS_AGGSUM_H
21 #define	_SYS_AGGSUM_H
22 
23 #include <sys/zfs_context.h>
24 
25 #ifdef	__cplusplus
26 extern "C" {
27 #endif
28 
29 typedef struct aggsum_bucket aggsum_bucket_t;
30 
31 struct aggsum_bucket {
32 	kmutex_t asc_lock;
33 	int64_t asc_delta;
34 	uint64_t asc_borrowed;
35 } ____cacheline_aligned;
36 
37 /*
38  * Fan out over FANOUT cpus.
39  */
40 typedef struct aggsum {
41 	kmutex_t as_lock;
42 	int64_t as_lower_bound;
43 	uint64_t as_upper_bound;
44 	aggsum_bucket_t *as_buckets ____cacheline_aligned;
45 	uint_t as_numbuckets;
46 	uint_t as_bucketshift;
47 } aggsum_t;
48 
49 void aggsum_init(aggsum_t *, uint64_t);
50 void aggsum_fini(aggsum_t *);
51 int64_t aggsum_lower_bound(aggsum_t *);
52 uint64_t aggsum_upper_bound(aggsum_t *);
53 int aggsum_compare(aggsum_t *, uint64_t);
54 uint64_t aggsum_value(aggsum_t *);
55 void aggsum_add(aggsum_t *, int64_t);
56 
57 #ifdef	__cplusplus
58 }
59 #endif
60 
61 #endif /* _SYS_AGGSUM_H */
62