pkg: ship usr/lib/security/amd64/*.so links
[unleashed.git] / include / sys / cpu_uarray.h
blob9cad7725976f55a62d0d1a7aca64d766a79fbc51
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2018, Joyent, Inc.
17 * Use a cpu_uarray_t for an array of uint64_t values that are written on a
18 * per-CPU basis. We align each CPU on a 128-byte boundary (so two cachelines).
19 * It's not clear why, but this can have a significant effect in multi-socket
20 * systems running certain benchmarks on a relatively current Intel system.
22 * So the layout is like this, for example:
24 * 0: STAT1 for CPU 0
25 * 8: STAT2 for CPU 0
26 * 16: STAT3 for CPU 0
27 * 24: padding
28 * 128: STAT1 for CPU 1
29 * 136: STAT2 for CPU 1
30 * ...
32 * At collection time, cpu_uarray_sum() can be used to sum the given value index
33 * across all CPUs, or cpu_uarray_sum_all() sums all stats across all CPUs.
34 * The summation is done such that it saturates at UINT64_MAX.
37 #ifndef _SYS_CPU_UARRAY_H
38 #define _SYS_CPU_UARRAY_H
40 #include <sys/types.h>
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 #ifdef _KERNEL
49 * Trying to include sysmacros.h for P2ROUNDUP() here is just too painful.
51 #define CUA_ROUNDUP(x, align) (-(-(x) & -(align)))
52 #define CUA_ALIGN (128)
53 #define CUA_CPU_STRIDE(nr_items) \
54 CUA_ROUNDUP((nr_items), CUA_ALIGN / sizeof (uint64_t))
55 #define CUA_INDEX(nr_items, c, i) (((c) * CUA_CPU_STRIDE(nr_items)) + (i))
57 #define CPU_UARRAY_VAL(cua, cpu_index, stat_index) \
58 ((cua)->cu_vals[CUA_INDEX((cua)->cu_nr_items, cpu_index, stat_index)])
60 typedef struct {
61 uint64_t cu_nr_items;
62 char cu_pad[CUA_ALIGN - sizeof (uint64_t)];
63 #ifdef __lint
64 volatile uint64_t cu_vals[1];
65 #else
66 volatile uint64_t cu_vals[];
67 #endif
68 } cpu_uarray_t __aligned(CUA_ALIGN);
70 extern cpu_uarray_t *cpu_uarray_zalloc(size_t, int);
71 extern void cpu_uarray_free(cpu_uarray_t *);
72 extern uint64_t cpu_uarray_sum(cpu_uarray_t *, size_t);
73 extern uint64_t cpu_uarray_sum_all(cpu_uarray_t *);
75 #endif /* _KERNEL */
77 #ifdef __cplusplus
79 #endif
81 #endif /* _SYS_CPU_UARRAY_H */