]> git.saurik.com Git - apple/xnu.git/blame - osfmk/arm/counter.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / arm / counter.c
CommitLineData
c3c9b80d 1/* * Copyright (c) 2020 Apple Inc. All rights reserved.
1c79356b 2 *
2d21ac55 3 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 4 *
2d21ac55
A
5 * This file contains Original Code and/or Modifications of Original Code
6 * as defined in and that are subject to the Apple Public Source License
7 * Version 2.0 (the 'License'). You may not use this file except in
8 * compliance with the License. The rights granted to you under the License
9 * may not be used to create, or enable the creation or redistribution of,
10 * unlawful or unlicensed copies of an Apple operating system, or to
11 * circumvent, violate, or enable the circumvention or violation of, any
12 * terms of an Apple operating system software license agreement.
0a7de745 13 *
2d21ac55
A
14 * Please obtain a copy of the License at
15 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 16 *
2d21ac55
A
17 * The Original Code and all software distributed under the License are
18 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
19 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
21 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
22 * Please see the License for the specific language governing rights and
23 * limitations under the License.
0a7de745 24 *
2d21ac55 25 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 26 */
1c79356b 27
1c79356b 28#include <kern/assert.h>
c3c9b80d
A
29#include <kern/cpu_data.h>
30#include <kern/counter.h>
31#include <kern/zalloc.h>
32#include <machine/atomic.h>
33#include <machine/machine_routines.h>
34#include <machine/cpu_number.h>
1c79356b 35
c3c9b80d
A
36OS_OVERLOADABLE
37void
38counter_add(scalable_counter_t *counter, uint64_t amount)
39{
40 os_atomic_add(zpercpu_get(*counter), amount, relaxed);
41}
42
43OS_OVERLOADABLE
44void
45counter_inc(scalable_counter_t *counter)
46{
47 os_atomic_inc(zpercpu_get(*counter), relaxed);
48}
49
50OS_OVERLOADABLE
51void
52counter_dec(scalable_counter_t *counter)
53{
54 os_atomic_dec(zpercpu_get(*counter), relaxed);
55}
1c79356b 56
1c79356b 57/*
c3c9b80d
A
58 * NB: On arm, the preemption disabled implementation is the same as
59 * the normal implementation. Otherwise we would need to enforce that
60 * callers never mix the interfaces for the same counter.
1c79356b 61 */
c3c9b80d
A
62OS_OVERLOADABLE
63void
64counter_add_preemption_disabled(scalable_counter_t *counter, uint64_t amount)
1c79356b 65{
c3c9b80d
A
66 counter_add(counter, amount);
67}
1c79356b 68
c3c9b80d
A
69OS_OVERLOADABLE
70void
71counter_inc_preemption_disabled(scalable_counter_t *counter)
72{
73 counter_inc(counter);
74}
1c79356b 75
c3c9b80d
A
76OS_OVERLOADABLE
77void
78counter_dec_preemption_disabled(scalable_counter_t *counter)
79{
80 counter_dec(counter);
1c79356b 81}