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