/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2012 Konstantin Belousov <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifdef __i386__29#include <i386/counter.h>30#else /* !__i386__ */3132#ifndef __MACHINE_COUNTER_H__33#define __MACHINE_COUNTER_H__3435#include <sys/pcpu.h>36#include <sys/kassert.h>3738#define EARLY_COUNTER (void *)__offsetof(struct pcpu, pc_early_dummy_counter)3940#define counter_enter() do {} while (0)41#define counter_exit() do {} while (0)4243#ifdef IN_SUBR_COUNTER_C44static inline uint64_t45counter_u64_read_one(counter_u64_t c, int cpu)46{4748MPASS(c != EARLY_COUNTER);49return (*zpcpu_get_cpu(c, cpu));50}5152static inline uint64_t53counter_u64_fetch_inline(uint64_t *c)54{55uint64_t r;56int cpu;5758r = 0;59CPU_FOREACH(cpu)60r += counter_u64_read_one(c, cpu);6162return (r);63}6465static void66counter_u64_zero_one_cpu(void *arg)67{68counter_u64_t c;6970c = arg;71MPASS(c != EARLY_COUNTER);72*(zpcpu_get(c)) = 0;73}7475static inline void76counter_u64_zero_inline(counter_u64_t c)77{7879smp_rendezvous(smp_no_rendezvous_barrier, counter_u64_zero_one_cpu,80smp_no_rendezvous_barrier, c);81}82#endif8384#define counter_u64_add_protected(c, i) counter_u64_add(c, i)8586static inline void87counter_u64_add(counter_u64_t c, int64_t inc)88{8990KASSERT(IS_BSP() || c != EARLY_COUNTER, ("EARLY_COUNTER used on AP"));91zpcpu_add(c, inc);92}9394#endif /* ! __MACHINE_COUNTER_H__ */9596#endif /* __i386__ */979899