gem5  v22.1.0.0
futex_map.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Advanced Micro Devices, Inc.
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 are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __FUTEX_MAP_HH__
30 #define __FUTEX_MAP_HH__
31 
32 #include <unordered_map>
33 #include <unordered_set>
34 
35 #include <cpu/thread_context.hh>
36 
37 namespace gem5
38 {
39 
44 class FutexKey
45 {
46  public:
47  uint64_t addr;
48  uint64_t tgid;
49 
50  FutexKey(uint64_t addr_in, uint64_t tgid_in);
51 
52  bool operator==(const FutexKey &in) const;
53 };
54 
55 } // namespace gem5
56 
57 namespace std
58 {
64  template <>
65  struct hash<gem5::FutexKey>
66  {
67  size_t operator()(const gem5::FutexKey& in) const
68  {
69  size_t hash = 65521;
70  for (int i = 0; i < sizeof(uint64_t) / sizeof(size_t); i++) {
71  hash ^= (size_t)(in.addr >> sizeof(size_t) * i) ^
72  (size_t)(in.tgid >> sizeof(size_t) * i);
73  }
74  return hash;
75  }
76  };
77 } // namespace std
78 
79 namespace gem5
80 {
81 
87 {
88  public:
90  int bitmask;
91 
95  WaiterState(ThreadContext* _tc, int _bitmask);
96 
101  bool checkMask(int wakeup_bitmask) const;
102 };
103 
105 
109 class FutexMap : public std::unordered_map<FutexKey, WaiterList>
110 {
111  public:
113  void suspend(Addr addr, uint64_t tgid, ThreadContext *tc);
114 
116  int wakeup(Addr addr, uint64_t tgid, int count);
117 
118  void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc,
119  int bitmask);
120 
121  int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask);
122 
133  int requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2);
134 
139  bool is_waiting(ThreadContext *tc);
140 
141  private:
142 
143  std::unordered_set<ThreadContext *> waitingTcs;
144 };
145 
146 } // namespace gem5
147 
148 #endif // __FUTEX_MAP_HH__
FutexKey class defines an unique identifier for a particular futex in the system.
Definition: futex_map.hh:45
FutexKey(uint64_t addr_in, uint64_t tgid_in)
Definition: futex_map.cc:34
uint64_t tgid
Definition: futex_map.hh:48
uint64_t addr
Definition: futex_map.hh:47
bool operator==(const FutexKey &in) const
Definition: futex_map.cc:38
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:110
void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc, int bitmask)
Definition: futex_map.cc:89
bool is_waiting(ThreadContext *tc)
Determine if the given thread context is currently waiting on a futex wait operation on any of the fu...
Definition: futex_map.cc:185
int requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2)
This operation wakes a given number (val) of waiters.
Definition: futex_map.cc:141
void suspend(Addr addr, uint64_t tgid, ThreadContext *tc)
Inserts a futex into the map with one waiting TC.
Definition: futex_map.cc:53
std::unordered_set< ThreadContext * > waitingTcs
Definition: futex_map.hh:143
int wakeup(Addr addr, uint64_t tgid, int count)
Wakes up at most count waiting threads on a futex.
Definition: futex_map.cc:59
int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask)
Definition: futex_map.cc:108
ThreadContext is the external interface to all thread state for anything outside of the CPU.
WaiterState defines internal state of a waiter thread.
Definition: futex_map.hh:87
bool checkMask(int wakeup_bitmask) const
return true if the bit-wise AND of the wakeup_bitmask given by a waking thread and this thread's inte...
Definition: futex_map.cc:47
ThreadContext * tc
Definition: futex_map.hh:89
WaiterState(ThreadContext *_tc, int _bitmask)
this constructor is used if futex ops with bitset are used
Definition: futex_map.cc:43
STL list class.
Definition: stl.hh:51
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
std::list< WaiterState > WaiterList
Definition: futex_map.hh:104
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2826
size_t operator()(const gem5::FutexKey &in) const
Definition: futex_map.hh:67

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1