Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
rsrv_impl.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// implementation of Reservations for Realm
19
20#ifndef REALM_RSRV_IMPL_H
21#define REALM_RSRV_IMPL_H
22
23#include "realm/reservation.h"
24
25#include "realm/id.h"
26#include "realm/network.h"
27#include "realm/nodeset.h"
28#include "realm/mutex.h"
29#include "realm/bgwork.h"
30#include "realm/event_impl.h"
31
32namespace Realm {
33
34#ifdef LOCK_TRACING
35 // For lock tracing
36 struct LockTraceItem {
37 public:
38 enum Action
39 {
40 ACT_LOCAL_REQUEST = 0, // request for a lock where the owner is local
41 ACT_REMOTE_REQUEST = 1, // request for a lock where the owner is not local
42 ACT_FORWARD_REQUEST = 2, // for forwarding of requests
43 ACT_LOCAL_GRANT = 3, // local grant of the lock
44 ACT_REMOTE_GRANT = 4, // remote grant of the lock (change owners)
45 ACT_REMOTE_RELEASE = 5, // remote release of a shared lock
46 };
47
48 public:
49 unsigned time_units, lock_id, owner, action;
50 };
51#endif
52
53 namespace Config {
55 };
56
58 public:
60
62
63 void init(ID _me, unsigned _init_owner);
64
65 static ID make_id(const ReservationImpl &dummy, int owner, ID::IDType index)
66 {
67 return ID::make_reservation(owner, index);
68 }
69
70 // protected:
72 NodeID owner; // which node owns the lock
73 unsigned count; // number of locks held by local threads
74 unsigned mode; // lock mode
75 bool in_use;
76
77 enum
78 {
80 ZERO_COUNT = 0x11223344
81 };
82
83 Mutex mutex; // controls which local thread has access to internal data (not
84 // runtime-visible lock)
85
86 // bitmasks of which remote nodes are waiting on a lock (or sharing it)
88 // std::list<LockWaiter *> local_waiters; // set of local threads that are waiting on
89 // lock
90
92
94
96 unsigned count;
98 };
99 std::map<unsigned, LocalSharedInfo> local_shared;
100
101 struct RetryInfo {
102 unsigned count;
104 };
105 std::map<unsigned, RetryInfo> retries;
106 bool requested; // do we have a request for the lock in flight?
107
111
113 {
114 // normal Reservation::acquire() - returns an event when the reservation is granted
116
117 // Reservation::try_acquire() - grants immediately or returns an event for when a
118 // retry should be performed
120
121 // a retried version of try_acquire()
123
124 // used when the try_acquire is preconditioned on something else first, so we never
125 // grant, but record a retry'er
127 };
128
129 // creates an Event if needed to describe when reservation is granted
130 Event acquire(unsigned new_mode, bool exclusive, AcquireType acquire_type,
131 Event after_lock = Event::NO_EVENT);
132
133 bool select_local_waiters(WaiterList &to_wake, Event &retry);
134
135 void release(TimeLimit work_until);
136
137 bool is_locked(unsigned check_mode, bool excl_ok);
138
140 };
141
142 // active messages
146 unsigned mode;
147
148 static void handle_message(NodeID sender, const LockRequestMessage &msg,
149 const void *data, size_t datalen);
150 };
151
155
156 static void handle_message(NodeID sender, const LockReleaseMessage &msg,
157 const void *data, size_t datalen);
158 };
159
162 unsigned mode;
163
164 static void handle_message(NodeID sender, const LockGrantMessage &msg,
165 const void *data, size_t datalen, TimeLimit work_until);
166 };
167
172
173 static void handle_message(NodeID sender, const DestroyLockMessage &msg,
174 const void *data, size_t datalen);
175 };
176
177}; // namespace Realm
178
179#endif // ifndef REALM_RSRV_IMPL_H
Definition event.h:50
static const Event NO_EVENT
The value should be usued to initialize an event handle. NO_EVENT is always in has triggered state .
Definition event.h:71
Definition id.h:30
ID_Types
Definition id.h:250
@ ID_LOCK
Definition id.h:255
static ID make_reservation(unsigned creator_node, unsigned rsrv_idx)
::realm_id_t IDType
Definition id.h:32
Definition nodeset.h:117
Definition rsrv_impl.h:57
static ReservationImpl * first_free
Definition rsrv_impl.h:109
Mutex mutex
Definition rsrv_impl.h:83
bool is_locked(unsigned check_mode, bool excl_ok)
std::map< unsigned, LocalSharedInfo > local_shared
Definition rsrv_impl.h:99
void init(ID _me, unsigned _init_owner)
void release(TimeLimit work_until)
unsigned count
Definition rsrv_impl.h:73
Event acquire(unsigned new_mode, bool exclusive, AcquireType acquire_type, Event after_lock=Event::NO_EVENT)
@ ZERO_COUNT
Definition rsrv_impl.h:80
@ MODE_EXCL
Definition rsrv_impl.h:79
bool in_use
Definition rsrv_impl.h:75
EventWaiter::EventWaiterList WaiterList
Definition rsrv_impl.h:91
NodeSet remote_waiter_mask
Definition rsrv_impl.h:87
static Mutex freelist_mutex
Definition rsrv_impl.h:108
void release_reservation(void)
bool select_local_waiters(WaiterList &to_wake, Event &retry)
WaiterList local_excl_waiters
Definition rsrv_impl.h:93
std::map< unsigned, RetryInfo > retries
Definition rsrv_impl.h:105
NodeID owner
Definition rsrv_impl.h:72
static const ID::ID_Types ID_TYPE
Definition rsrv_impl.h:61
unsigned mode
Definition rsrv_impl.h:74
Reservation me
Definition rsrv_impl.h:71
NodeSet remote_sharer_mask
Definition rsrv_impl.h:87
static ID make_id(const ReservationImpl &dummy, int owner, ID::IDType index)
Definition rsrv_impl.h:65
bool requested
Definition rsrv_impl.h:106
AcquireType
Definition rsrv_impl.h:113
@ ACQUIRE_BLOCKING
Definition rsrv_impl.h:115
@ ACQUIRE_NONBLOCKING_PLACEHOLDER
Definition rsrv_impl.h:126
@ ACQUIRE_NONBLOCKING
Definition rsrv_impl.h:119
@ ACQUIRE_NONBLOCKING_RETRY
Definition rsrv_impl.h:122
ReservationImpl * next_free
Definition rsrv_impl.h:110
Definition reservation.h:30
Definition timers.h:129
Definition mutex.h:223
bool use_fast_reservation_fallback
Definition activemsg.h:38
int NodeID
Definition nodeset.h:40
Definition rsrv_impl.h:168
Reservation actual
Definition rsrv_impl.h:169
Event wait_on
Definition rsrv_impl.h:171
Reservation dummy
Definition rsrv_impl.h:170
static void handle_message(NodeID sender, const DestroyLockMessage &msg, const void *data, size_t datalen)
Definition rsrv_impl.h:160
static void handle_message(NodeID sender, const LockGrantMessage &msg, const void *data, size_t datalen, TimeLimit work_until)
Reservation lock
Definition rsrv_impl.h:161
unsigned mode
Definition rsrv_impl.h:162
Definition rsrv_impl.h:152
Reservation lock
Definition rsrv_impl.h:154
static void handle_message(NodeID sender, const LockReleaseMessage &msg, const void *data, size_t datalen)
NodeID node
Definition rsrv_impl.h:153
Definition rsrv_impl.h:143
Reservation lock
Definition rsrv_impl.h:145
NodeID node
Definition rsrv_impl.h:144
unsigned mode
Definition rsrv_impl.h:146
static void handle_message(NodeID sender, const LockRequestMessage &msg, const void *data, size_t datalen)
unsigned count
Definition rsrv_impl.h:96
WaiterList waiters
Definition rsrv_impl.h:97
Definition rsrv_impl.h:101
unsigned count
Definition rsrv_impl.h:102
Event event
Definition rsrv_impl.h:103