1249268Sglebius/*- 2249268Sglebius * Copyright (c) 2012 Gleb Smirnoff <glebius@FreeBSD.org> 3249268Sglebius * All rights reserved. 4249268Sglebius * 5249268Sglebius * Redistribution and use in source and binary forms, with or without 6249268Sglebius * modification, are permitted provided that the following conditions 7249268Sglebius * are met: 8249268Sglebius * 1. Redistributions of source code must retain the above copyright 9249268Sglebius * notice, this list of conditions and the following disclaimer. 10249268Sglebius * 2. Redistributions in binary form must reproduce the above copyright 11249268Sglebius * notice, this list of conditions and the following disclaimer in the 12249268Sglebius * documentation and/or other materials provided with the distribution. 13249268Sglebius * 14249268Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15249268Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16249268Sglebius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17249268Sglebius * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18249268Sglebius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19249268Sglebius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20249268Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21249268Sglebius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22249268Sglebius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23249268Sglebius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24249268Sglebius * SUCH DAMAGE. 25249268Sglebius * 26249268Sglebius * $FreeBSD: stable/11/sys/sys/counter.h 349574 2019-07-01 10:09:19Z ae $ 27249268Sglebius */ 28249268Sglebius 29249268Sglebius#ifndef __SYS_COUNTER_H__ 30249268Sglebius#define __SYS_COUNTER_H__ 31249268Sglebius 32249268Sglebiustypedef uint64_t *counter_u64_t; 33249268Sglebius 34256514Sglebius#ifdef _KERNEL 35249268Sglebius#include <machine/counter.h> 36249268Sglebius 37249268Sglebiuscounter_u64_t counter_u64_alloc(int); 38249268Sglebiusvoid counter_u64_free(counter_u64_t); 39249268Sglebius 40249268Sglebiusvoid counter_u64_zero(counter_u64_t); 41249268Sglebiusuint64_t counter_u64_fetch(counter_u64_t); 42249268Sglebius 43253082Sae#define COUNTER_ARRAY_ALLOC(a, n, wait) do { \ 44349574Sae for (int _i = 0; _i < (n); _i++) \ 45349574Sae (a)[_i] = counter_u64_alloc(wait); \ 46253082Sae} while (0) 47253082Sae 48253082Sae#define COUNTER_ARRAY_FREE(a, n) do { \ 49349574Sae for (int _i = 0; _i < (n); _i++) \ 50349574Sae counter_u64_free((a)[_i]); \ 51253082Sae} while (0) 52253082Sae 53253082Sae#define COUNTER_ARRAY_COPY(a, dstp, n) do { \ 54349574Sae for (int _i = 0; _i < (n); _i++) \ 55349574Sae ((uint64_t *)(dstp))[_i] = counter_u64_fetch((a)[_i]);\ 56253082Sae} while (0) 57253082Sae 58253082Sae#define COUNTER_ARRAY_ZERO(a, n) do { \ 59349574Sae for (int _i = 0; _i < (n); _i++) \ 60349574Sae counter_u64_zero((a)[_i]); \ 61253082Sae} while (0) 62256514Sglebius#endif /* _KERNEL */ 63249268Sglebius#endif /* ! __SYS_COUNTER_H__ */ 64