gem5  v20.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 
41 class FutexKey {
42  public:
43  uint64_t addr;
44  uint64_t tgid;
45 
46  FutexKey(uint64_t addr_in, uint64_t tgid_in);
47 
48  bool operator==(const FutexKey &in) const;
49 };
50 
51 namespace std {
57  template <>
58  struct hash<FutexKey>
59  {
60  size_t operator()(const FutexKey& in) const;
61  };
62 }
63 
68 class WaiterState {
69  public:
71  int bitmask;
72 
76  WaiterState(ThreadContext* _tc, int _bitmask);
77 
82  bool checkMask(int wakeup_bitmask) const;
83 };
84 
86 
90 class FutexMap : public std::unordered_map<FutexKey, WaiterList>
91 {
92  public:
94  void suspend(Addr addr, uint64_t tgid, ThreadContext *tc);
95 
97  int wakeup(Addr addr, uint64_t tgid, int count);
98 
99  void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc,
100  int bitmask);
101 
102  int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask);
103 
114  int requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2);
115 
120  bool is_waiting(ThreadContext *tc);
121 
122  private:
123 
124  std::unordered_set<ThreadContext *> waitingTcs;
125 };
126 
127 #endif // __FUTEX_MAP_HH__
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:62
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:68
FutexMap::waitingTcs
std::unordered_set< ThreadContext * > waitingTcs
Definition: futex_map.hh:124
FutexKey::operator==
bool operator==(const FutexKey &in) const
Definition: futex_map.cc:35
FutexKey::addr
uint64_t addr
Definition: futex_map.hh:43
FutexMap::suspend_bitset
void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc, int bitmask)
Definition: futex_map.cc:98
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:56
FutexMap
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:90
X86ISA::count
count
Definition: misc.hh:703
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:194
FutexKey
FutexKey class defines an unique identifier for a particular futex in the system.
Definition: futex_map.hh:41
WaiterState::bitmask
int bitmask
Definition: futex_map.hh:71
FutexKey::tgid
uint64_t tgid
Definition: futex_map.hh:44
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
WaiterState::WaiterState
WaiterState(ThreadContext *_tc, int _bitmask)
this constructor is used if futex ops with bitset are used
Definition: futex_map.cc:52
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
FutexKey::FutexKey
FutexKey(uint64_t addr_in, uint64_t tgid_in)
Definition: futex_map.cc:31
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:150
WaiterState
WaiterState defines internal state of a waiter thread.
Definition: futex_map.hh:68
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
FutexMap::wakeup_bitset
int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask)
Definition: futex_map.cc:117
addr
ip6_addr_t addr
Definition: inet.hh:423
WaiterList
std::list< WaiterState > WaiterList
Definition: futex_map.hh:85
std::list
STL list class.
Definition: stl.hh:51
WaiterState::tc
ThreadContext * tc
Definition: futex_map.hh:70
thread_context.hh

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17