xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/aggsum.h (revision 3a2d8a1b)
1*3a2d8a1bSPaul Dagnelie /*
2*3a2d8a1bSPaul Dagnelie  * CDDL HEADER START
3*3a2d8a1bSPaul Dagnelie  *
4*3a2d8a1bSPaul Dagnelie  * This file and its contents are supplied under the terms of the
5*3a2d8a1bSPaul Dagnelie  * Common Development and Distribution License ("CDDL"), version 1.0.
6*3a2d8a1bSPaul Dagnelie  * You may only use this file in accordance with the terms of version
7*3a2d8a1bSPaul Dagnelie  * 1.0 of the CDDL.
8*3a2d8a1bSPaul Dagnelie  *
9*3a2d8a1bSPaul Dagnelie  * A full copy of the text of the CDDL should have accompanied this
10*3a2d8a1bSPaul Dagnelie  * source.  A copy of the CDDL is also available via the Internet at
11*3a2d8a1bSPaul Dagnelie  * http://www.illumos.org/license/CDDL.
12*3a2d8a1bSPaul Dagnelie  *
13*3a2d8a1bSPaul Dagnelie  * CDDL HEADER END
14*3a2d8a1bSPaul Dagnelie  */
15*3a2d8a1bSPaul Dagnelie /*
16*3a2d8a1bSPaul Dagnelie  * Copyright (c) 2017 by Delphix. All rights reserved.
17*3a2d8a1bSPaul Dagnelie  */
18*3a2d8a1bSPaul Dagnelie 
19*3a2d8a1bSPaul Dagnelie #ifndef	_SYS_AGGSUM_H
20*3a2d8a1bSPaul Dagnelie #define	_SYS_AGGSUM_H
21*3a2d8a1bSPaul Dagnelie 
22*3a2d8a1bSPaul Dagnelie #include <sys/zfs_context.h>
23*3a2d8a1bSPaul Dagnelie 
24*3a2d8a1bSPaul Dagnelie #ifdef	__cplusplus
25*3a2d8a1bSPaul Dagnelie extern "C" {
26*3a2d8a1bSPaul Dagnelie #endif
27*3a2d8a1bSPaul Dagnelie 
28*3a2d8a1bSPaul Dagnelie #define	CACHE_LINE_SIZE	64
29*3a2d8a1bSPaul Dagnelie 
30*3a2d8a1bSPaul Dagnelie typedef struct aggsum_bucket {
31*3a2d8a1bSPaul Dagnelie 	kmutex_t asc_lock;
32*3a2d8a1bSPaul Dagnelie 	int64_t asc_delta;
33*3a2d8a1bSPaul Dagnelie 	uint64_t asc_borrowed;
34*3a2d8a1bSPaul Dagnelie 	uint64_t asc_pad[4]; /* pad out to cache line (64 bytes) */
35*3a2d8a1bSPaul Dagnelie } aggsum_bucket_t __aligned(CACHE_LINE_SIZE);
36*3a2d8a1bSPaul Dagnelie 
37*3a2d8a1bSPaul Dagnelie /*
38*3a2d8a1bSPaul Dagnelie  * Fan out over FANOUT cpus.
39*3a2d8a1bSPaul Dagnelie  */
40*3a2d8a1bSPaul Dagnelie typedef struct aggsum {
41*3a2d8a1bSPaul Dagnelie 	kmutex_t as_lock;
42*3a2d8a1bSPaul Dagnelie 	int64_t as_lower_bound;
43*3a2d8a1bSPaul Dagnelie 	int64_t as_upper_bound;
44*3a2d8a1bSPaul Dagnelie 	uint64_t as_numbuckets;
45*3a2d8a1bSPaul Dagnelie 	aggsum_bucket_t *as_buckets;
46*3a2d8a1bSPaul Dagnelie } aggsum_t;
47*3a2d8a1bSPaul Dagnelie 
48*3a2d8a1bSPaul Dagnelie void aggsum_init(aggsum_t *, uint64_t);
49*3a2d8a1bSPaul Dagnelie void aggsum_fini(aggsum_t *);
50*3a2d8a1bSPaul Dagnelie int64_t aggsum_lower_bound(aggsum_t *);
51*3a2d8a1bSPaul Dagnelie int64_t aggsum_upper_bound(aggsum_t *);
52*3a2d8a1bSPaul Dagnelie int aggsum_compare(aggsum_t *, uint64_t);
53*3a2d8a1bSPaul Dagnelie uint64_t aggsum_value(aggsum_t *);
54*3a2d8a1bSPaul Dagnelie void aggsum_add(aggsum_t *, int64_t);
55*3a2d8a1bSPaul Dagnelie 
56*3a2d8a1bSPaul Dagnelie #ifdef	__cplusplus
57*3a2d8a1bSPaul Dagnelie }
58*3a2d8a1bSPaul Dagnelie #endif
59*3a2d8a1bSPaul Dagnelie 
60*3a2d8a1bSPaul Dagnelie #endif /* _SYS_AGGSUM_H */