gem5  v21.1.0.2
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__
gem5::WaiterState::WaiterState
WaiterState(ThreadContext *_tc, int _bitmask)
this constructor is used if futex ops with bitset are used
Definition: futex_map.cc:43
gem5::FutexMap::suspend
void suspend(Addr addr, uint64_t tgid, ThreadContext *tc)
Inserts a futex into the map with one waiting TC.
Definition: futex_map.cc:53
gem5::FutexKey
FutexKey class defines an unique identifier for a particular futex in the system.
Definition: futex_map.hh:44
gem5::WaiterList
std::list< WaiterState > WaiterList
Definition: futex_map.hh:104
gem5::FutexKey::tgid
uint64_t tgid
Definition: futex_map.hh:48
gem5::WaiterState::bitmask
int bitmask
Definition: futex_map.hh:90
gem5::WaiterState::checkMask
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
gem5::FutexMap::requeue
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
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::FutexKey::FutexKey
FutexKey(uint64_t addr_in, uint64_t tgid_in)
Definition: futex_map.cc:34
gem5::FutexMap::waitingTcs
std::unordered_set< ThreadContext * > waitingTcs
Definition: futex_map.hh:143
gem5::FutexMap
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:109
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::X86ISA::count
count
Definition: misc.hh:709
gem5::FutexMap::suspend_bitset
void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc, int bitmask)
Definition: futex_map.cc:89
gem5::FutexKey::addr
uint64_t addr
Definition: futex_map.hh:47
gem5::FutexMap::wakeup
int wakeup(Addr addr, uint64_t tgid, int count)
Wakes up at most count waiting threads on a futex.
Definition: futex_map.cc:59
gem5::FutexMap::wakeup_bitset
int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask)
Definition: futex_map.cc:108
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::FutexMap::is_waiting
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
gem5::FutexKey::operator==
bool operator==(const FutexKey &in) const
Definition: futex_map.cc:38
std
Overload hash function for BasicBlockRange type.
Definition: types.hh:111
gem5::WaiterState
WaiterState defines internal state of a waiter thread.
Definition: futex_map.hh:86
std::hash< gem5::FutexKey >::operator()
size_t operator()(const gem5::FutexKey &in) const
Definition: futex_map.hh:67
std::list
STL list class.
Definition: stl.hh:51
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::WaiterState::tc
ThreadContext * tc
Definition: futex_map.hh:89
thread_context.hh
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:47 for gem5 by doxygen 1.8.17