1a9643ea8Slogwang /*
2*2317ada5Sfengbojiang * Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
3a9643ea8Slogwang * All rights reserved.
4a9643ea8Slogwang *
5a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without
6a9643ea8Slogwang * modification, are permitted provided that the following conditions are met:
7a9643ea8Slogwang *
8a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright notice, this
9a9643ea8Slogwang * list of conditions and the following disclaimer.
10a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright notice,
11a9643ea8Slogwang * this list of conditions and the following disclaimer in the documentation
12a9643ea8Slogwang * and/or other materials provided with the distribution.
13a9643ea8Slogwang *
14a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16a9643ea8Slogwang * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17a9643ea8Slogwang * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18a9643ea8Slogwang * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19a9643ea8Slogwang * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20a9643ea8Slogwang * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21a9643ea8Slogwang * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22a9643ea8Slogwang * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23a9643ea8Slogwang * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24a9643ea8Slogwang *
25a9643ea8Slogwang */
26a9643ea8Slogwang
27a9643ea8Slogwang #ifndef __FSTACK_MACHINE_COUNTER_H__
28a9643ea8Slogwang #define __FSTACK_MACHINE_COUNTER_H__
29a9643ea8Slogwang
30a9643ea8Slogwang #include <sys/pcpu.h>
31a9643ea8Slogwang
32d9ca4c12Sfengbojiang #define EARLY_COUNTER &pcpup->pc_early_dummy_counter
33d9ca4c12Sfengbojiang
34d9ca4c12Sfengbojiang #define COUNTER_U64_DEFINE_EARLY(c) \
35d9ca4c12Sfengbojiang counter_u64_t __read_mostly c = (void *)__offsetof(struct pcpu, pc_early_dummy_counter); \
36d9ca4c12Sfengbojiang COUNTER_U64_SYSINIT(c)
3722ce4affSfengbojiang
38a9643ea8Slogwang #define counter_enter() do {} while (0)
39a9643ea8Slogwang #define counter_exit() do {} while (0)
40a9643ea8Slogwang
41a9643ea8Slogwang #ifdef IN_SUBR_COUNTER_C
42a9643ea8Slogwang
43a9643ea8Slogwang static inline uint64_t
counter_u64_fetch_inline(uint64_t * p)44a9643ea8Slogwang counter_u64_fetch_inline(uint64_t *p)
45a9643ea8Slogwang {
46a9643ea8Slogwang return (*p);
47a9643ea8Slogwang }
48a9643ea8Slogwang
49a9643ea8Slogwang static inline void
counter_u64_zero_inline(counter_u64_t c)50a9643ea8Slogwang counter_u64_zero_inline(counter_u64_t c)
51a9643ea8Slogwang {
52a9643ea8Slogwang *c = 0;
53a9643ea8Slogwang }
54a9643ea8Slogwang #endif
55a9643ea8Slogwang
56a9643ea8Slogwang #define counter_u64_add_protected(c, i) counter_u64_add(c, i)
57a9643ea8Slogwang
58a9643ea8Slogwang static inline void
counter_u64_add(counter_u64_t c,int64_t inc)59a9643ea8Slogwang counter_u64_add(counter_u64_t c, int64_t inc)
60a9643ea8Slogwang {
61a9643ea8Slogwang *c += inc;
62a9643ea8Slogwang }
63a9643ea8Slogwang
64a9643ea8Slogwang #endif /* ! __FSTACK_MACHINE_COUNTER_H__ */
65