EM-ODP  3.7.0
Event Machine on ODP
environment.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Nokia Solutions and Networks
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _ENVIRONMENT_H_
32 #define _ENVIRONMENT_H_
33 
34 #pragma GCC visibility push(default)
35 
36 /**
37  * @file
38  *
39  * Environment header file
40  */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #include <stdlib.h>
47 
48 #include <odp_api.h>
49 /* env generic macros */
50 #include <event_machine/platform/env/env_macros.h>
51 /* env configuration affecting other env files */
52 #include <event_machine/platform/env/env_conf.h>
53 
54 /**
55  * Thread local vars
56  */
57 #define ENV_LOCAL __thread
58 
59 /**
60  * Cache line size
61  */
62 #define ENV_CACHE_LINE_SIZE ODP_CACHE_LINE_SIZE
63 
64 /**
65  * Cache line size round up
66  */
67 #define ENV_CACHE_LINE_SIZE_ROUNDUP(x) \
68  ((((x) + ENV_CACHE_LINE_SIZE - 1) / ENV_CACHE_LINE_SIZE) \
69  * ENV_CACHE_LINE_SIZE)
70 
71 #define ENV_ALIGNED(x) ODP_ALIGNED(x)
72 
73 /**
74  * Cache line alignment
75  */
76 #define ENV_CACHE_LINE_ALIGNED ODP_ALIGNED_CACHE
77 
78 /*
79  * Cache Prefetch-macros
80  */
81 /** Prefetch into all cache levels */
82 #define ENV_PREFETCH(addr) odp_prefetch((addr))
83 
84 /*
85  * env helper include files - don't include these files directly,
86  * instead #include <environment.h>
87  */
88 #include <event_machine/platform/env/env_atomic.h>
90 #include <event_machine/platform/env/env_barrier.h>
91 #include <event_machine/platform/env/env_sharedmem.h>
92 #include <event_machine/platform/env/env_spinlock.h>
94 
95 /**
96  * Panic
97  */
98 #define env_panic(...) abort()
99 
100 static inline uint64_t env_get_cycle(void)
101 {
102  return odp_cpu_cycles();
103 }
104 
105 /**
106  * Returns difference of cpu cycles (cycles2 - cycles1).
107  *
108  * @param cycles2 Second cycle count
109  * @param cycles1 First cycle count
110  *
111  * @return Difference between given cpu cycles
112  */
113 static inline uint64_t env_cycles_diff(uint64_t cycles2, uint64_t cycles1)
114 {
115  return odp_cpu_cycles_diff(cycles2, cycles1);
116 }
117 
118 static inline void env_sync_mem(void)
119 {
120  odp_mb_full();
121 }
122 
123 static inline uint64_t env_core_hz(void)
124 {
125  return odp_cpu_hz();
126 }
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #pragma GCC visibility pop
133 #endif /* _ENVIRONMENT_H_ */
env_time.h
env_bitmask.h