xaiefal
Loading...
Searching...
No Matches
xaiefal-groupevent.hpp
Go to the documentation of this file.
1// Copyright(C) 2020 - 2021 by Xilinx, Inc. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4#include <string.h>
5#include <vector>
6#include <xaiengine.h>
7
8#include <xaiefal/common/xaiefal-common.hpp>
9#include <xaiefal/rsc/xaiefal-rsc-base.hpp>
10#include <xaiefal/rsc/xaiefal-rscmgr.hpp>
11
12#pragma once
13
14namespace xaiefal {
20 public:
21 XAieGroupEvent() = delete;
22 XAieGroupEvent(std::shared_ptr<XAieDevHandle> DevHd,
23 XAie_LocType Loc, XAie_ModuleType Mod, XAie_Events gEvent):
25 GroupEvent(gEvent), GroupComposition(0) {
26 uint32_t GroupId;
27
28 if (getGroupId(DevHd, Mod, gEvent, GroupId) != XAIE_OK) {
29 throw std::invalid_argument("Invalid group Event");
30 }
31
32 State.Initialized = 1;
33 State.Configured = 1;
34 preferredId = static_cast<uint32_t>(GroupEvent);
35 }
36
42 XAie_Events getEvent() const {
43 return GroupEvent;
44 }
45
60 AieRC attachHandle(const XAieGroupEventHandle *Hid, uint32_t Comp) {
61 AieRC RC;
62
64
65 if (Hid == nullptr) {
66 Logger::log(LogLevel::FAL_ERROR) << "Group event " << __func__ << " (" <<
67 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
68 " Mod=" << Mod << ", empty handle." << std::endl;
69 return XAIE_INVALID_ARGS;
70 }
71 if (State.Reserved == 1) {
72 if (GroupComposition != Comp) {
73 Logger::log(LogLevel::FAL_ERROR) << "Group event " << __func__ << " (" <<
74 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
75 " Mod=" << Mod << " E=" << GroupEvent << " (" <<
76 XAie_EventGetString(GroupEvent) << ") is reserved with " <<
77 GroupComposition << ", request composition is " <<
78 Comp << "." << std::endl;
79 RC = XAIE_INVALID_ARGS;
80 } else {
81 Handles.emplace(Hid, false);
82 RC = XAIE_OK;
83 }
84 } else {
85 RC = reserve();
86 if (RC == XAIE_OK) {
87 GroupComposition = Comp;
88 Handles.emplace(Hid, false);
89 }
90 }
91
92 return RC;
93 }
94
106 AieRC RC = XAIE_OK;
107
108 auto H = Handles.find(Hid);
109 if (H == Handles.end()) {
110 Logger::log(LogLevel::FAL_ERROR) << "Group event " << __func__ << " (" <<
111 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
112 " Mod=" << Mod <<
113 " group event=" << GroupEvent <<
114 " (" << XAie_EventGetString(GroupEvent) <<
115 "), invalid handle." << std::endl;
116 RC = XAIE_INVALID_ARGS;
117 } else {
119
120 Handles[Hid] = true;
121 if (State.Running == 0) {
122 RC = start();
123 if (RC != XAIE_OK) {
124 Handles[Hid] = false;
125 }
126 }
127 }
128 return RC;
129 }
130
142 AieRC RC = XAIE_OK;
143
144 auto H = Handles.find(Hid);
145 if (H == Handles.end()) {
146 Logger::log(LogLevel::FAL_ERROR) << "Group event " << __func__ << " (" <<
147 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
148 " Mod=" << Mod <<
149 " group event=" << GroupEvent <<
150 " (" << XAie_EventGetString(GroupEvent) <<
151 "), invalid handle." << std::endl;
152 RC = XAIE_INVALID_ARGS;
153 } else {
155
156 Handles[Hid] = false;
157 // Have considered to use a StartCount to
158 // count how many handles are in use.
159 // However, considering every module needs
160 // such variable, even for loop which is
161 // less efficient then just a Starcount,
162 // use for loop to save memory, as this is
163 // not in performance critical path as it is
164 // used for profiling and debugging.
165 std::map<const XAieGroupEventHandle *, bool>::iterator it;
166 for (it = Handles.begin(); it != Handles.end();
167 it++) {
168 if (it->second) {
169 break;
170 }
171 }
172 if (it == Handles.end()) {
173 if (State.Running == 1) {
174 RC = stop();
175 if (RC != XAIE_OK) {
176 Handles[Hid] = true;
177 }
178 }
179 }
180 }
181 return RC;
182 }
183
195 AieRC RC = XAIE_OK;
196
197 auto H = Handles.find(Hid);
198 if (H == Handles.end()) {
199 Logger::log(LogLevel::FAL_ERROR) << "Group event " << __func__ << " (" <<
200 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
201 " Mod=" << Mod <<
202 " group event=" << GroupEvent <<
203 " (" << XAie_EventGetString(GroupEvent) <<
204 "), invalid handle." << std::endl;
205 RC = XAIE_INVALID_ARGS;
206 } else {
208
209 Handles.erase(Hid);
210 if (State.Reserved == 1 && Handles.empty()) {
211 RC = release();
212 }
213 }
214 return RC;
215 }
216
217 uint32_t getRscIdfromEvent(XAie_Events Event) {
218 uint8_t TileType;
219 const XAie_EvntMod *EvntMod;
220
221 TileType = XAie_GetTileTypefromLoc(AieHd->dev(), Loc);
222
223 if (Mod == XAIE_PL_MOD) {
224 EvntMod = &AieHd->dev()->DevProp.DevMod[TileType].EvntMod[0U];
225 } else {
226 EvntMod = &AieHd->dev()->DevProp.DevMod[TileType].EvntMod[Mod];
227 }
228
229 for (uint8_t i = 0; i < EvntMod->NumGroupEvents; i++) {
230 if (Event == EvntMod->Group[i].GroupEvent) {
231 return EvntMod->Group[i].GroupOff;
232 }
233 }
234 return XAIE_RSC_ID_ANY;
235 }
236 private:
237 XAie_Events GroupEvent;
238 uint32_t GroupComposition;
240 std::map<const XAieGroupEventHandle *, bool> Handles;
241
242 protected:
243 AieRC _reserve() {
244 AieRC RC;
245 XAieUserRsc Rsc;
246
247 Rsc.Loc = Loc;
248 Rsc.Mod = Mod;
249 Rsc.RscType = Type;
250 Rsc.RscId = getRscIdfromEvent(GroupEvent);
251 vRscs.push_back(Rsc);
252 RC = AieHd->rscMgr()->request(*this);
253 if (RC != XAIE_OK) {
254 Logger::log(LogLevel::FAL_WARN) << "groupevent " << __func__ << " (" <<
255 (uint32_t)Loc.Col << "," << (uint32_t)Loc.Row << ")" <<
256 " Mod=" << Mod << " resource not available.\n";
257 vRscs.clear();
258 } else {
259 reservedId = vRscs[0].RscId;
260 }
261 return RC;
262 }
263 AieRC _release() {
264 AieRC RC;
265
266 RC = AieHd->rscMgr()->free(*this);
267 vRscs.clear();
268 return RC;
269 }
270 AieRC _start() {
271 uint32_t lConfig = GroupComposition;
272
273 if (lConfig == 0) {
274 lConfig = 0xFFFFFFFFU;
275 }
276 return XAie_EventGroupControl(dev(), Loc, Mod, GroupEvent,
277 lConfig);
278 }
279 AieRC _stop() {
280 return XAie_EventGroupReset(dev(), Loc, Mod, GroupEvent);
281 }
282
283 private:
297 static AieRC getGroupId(std::shared_ptr<XAieDevHandle> DevHd,
298 XAie_ModuleType Module, XAie_Events Event, uint32_t &RscId) {
299 uint32_t i, *EIds;
300 uint32_t EIdsTotal;
301 AieRC RC;
302
303 if (Module == XAIE_CORE_MOD) {
304 EIds = DevHd->XAieGroupEventMapCore;
305 EIdsTotal = sizeof(DevHd->XAieGroupEventMapCore)/
306 sizeof(DevHd->XAieGroupEventMapCore[0]);
307 } else if (Module == XAIE_MEM_MOD) {
308 if (Event >= XAIE_EVENT_GROUP_0_MEM_TILE) {
309 EIds = DevHd->XAieGroupEventMapMemTile;
310 EIdsTotal = sizeof(DevHd->XAieGroupEventMapMemTile)/
311 sizeof(DevHd->XAieGroupEventMapMemTile[0]);
312 } else {
313 EIds = DevHd->XAieGroupEventMapMem;
314 EIdsTotal = sizeof(DevHd->XAieGroupEventMapMem)/
315 sizeof(DevHd->XAieGroupEventMapMem[0]);
316 }
317 } else {
318 EIds = DevHd->XAieGroupEventMapPl;
319 EIdsTotal = sizeof(DevHd->XAieGroupEventMapPl)/
320 sizeof(DevHd->XAieGroupEventMapPl[0]);
321 }
322 for (i = 0; i < EIdsTotal; i++) {
323 if (Event == EIds[i]) {
324 RscId = i;
325 break;
326 }
327 }
328 if (i >= EIdsTotal) {
329 RC = XAIE_INVALID_ARGS;
330 Logger::log(LogLevel::FAL_ERROR) << "Group event " << __func__ << " (" <<
331 " Mod=" << Module << " " << Event <<
332 " invalid." << std::endl;
333 } else {
334 RC = XAIE_OK;
335 }
336 return RC;
337 }
338 };
339
345 public:
347 XAieGroupEventHandle(std::shared_ptr<XAieDevHandle> DevHd,
348 std::shared_ptr<XAieGroupEvent> gEPtr):
349 XAieRsc(DevHd), GroupEventPtr(gEPtr), GroupComposition(0) {
350 State.Initialized = 1;
351 State.Configured = 1;
352 }
353
362 void setGroupEvents(uint32_t Comp) {
363 GroupComposition = Comp;
364 }
365
371 uint32_t getGroupEvents() const {
372 return GroupComposition;
373 }
374
379 XAie_Events getEvent() const {
380 return GroupEventPtr->getEvent();
381 }
382 protected:
383 AieRC _reserve() {
384 return GroupEventPtr->attachHandle(this, GroupComposition);
385 }
386 AieRC _release() {
387 return GroupEventPtr->removeHandle(this);
388 }
389 AieRC _start() {
390 return GroupEventPtr->startHandle(this);
391 }
392 AieRC _stop() {
393 return GroupEventPtr->stopHandle(this);
394 }
395 private:
396 std::shared_ptr<XAieGroupEvent> GroupEventPtr;
397 uint32_t GroupComposition;
398 };
399}
static std::ostream & log(LogLevel Lvl=LogLevel::FAL_MAX)
Definition xaiefal-log.hpp:50
class for group event resource reference
Definition xaiefal-groupevent.hpp:344
AieRC _stop()
Definition xaiefal-groupevent.hpp:392
void setGroupEvents(uint32_t Comp)
Definition xaiefal-groupevent.hpp:362
AieRC _start()
Definition xaiefal-groupevent.hpp:389
AieRC _reserve()
Definition xaiefal-groupevent.hpp:383
XAieGroupEventHandle(std::shared_ptr< XAieDevHandle > DevHd, std::shared_ptr< XAieGroupEvent > gEPtr)
Definition xaiefal-groupevent.hpp:347
AieRC _release()
Definition xaiefal-groupevent.hpp:386
XAie_Events getEvent() const
Definition xaiefal-groupevent.hpp:379
uint32_t getGroupEvents() const
Definition xaiefal-groupevent.hpp:371
AieRC stopHandle(const XAieGroupEventHandle *Hid)
Definition xaiefal-groupevent.hpp:141
AieRC removeHandle(const XAieGroupEventHandle *Hid)
Definition xaiefal-groupevent.hpp:194
AieRC _stop()
Definition xaiefal-groupevent.hpp:279
AieRC _release()
Definition xaiefal-groupevent.hpp:263
AieRC attachHandle(const XAieGroupEventHandle *Hid, uint32_t Comp)
Definition xaiefal-groupevent.hpp:60
AieRC _reserve()
Definition xaiefal-groupevent.hpp:243
AieRC _start()
Definition xaiefal-groupevent.hpp:270
XAieGroupEvent(std::shared_ptr< XAieDevHandle > DevHd, XAie_LocType Loc, XAie_ModuleType Mod, XAie_Events gEvent)
Definition xaiefal-groupevent.hpp:22
XAie_Events getEvent() const
Definition xaiefal-groupevent.hpp:42
uint32_t getRscIdfromEvent(XAie_Events Event)
Definition xaiefal-groupevent.hpp:217
AieRC startHandle(const XAieGroupEventHandle *Hid)
Definition xaiefal-groupevent.hpp:105
XAieRscType Type
Definition xaiefal-rsc-base.hpp:399
std::vector< XAieUserRsc > vRscs
Definition xaiefal-rsc-base.hpp:403
XAieRscState State
Definition xaiefal-rsc-base.hpp:398
XAie_DevInst * dev()
Definition xaiefal-rsc-base.hpp:373
AieRC release()
Definition xaiefal-rsc-base.hpp:188
AieRC reserve()
Definition xaiefal-rsc-base.hpp:161
AieRC start()
Definition xaiefal-rsc-base.hpp:239
uint32_t preferredId
Definition xaiefal-rsc-base.hpp:401
uint32_t reservedId
Definition xaiefal-rsc-base.hpp:402
std::shared_ptr< XAieDevHandle > AieHd
Definition xaiefal-rsc-base.hpp:400
AieRC stop()
Definition xaiefal-rsc-base.hpp:269
XAie_LocType Loc
Definition xaiefal-rsc-base.hpp:594
XAie_ModuleType Mod
Definition xaiefal-rsc-base.hpp:595
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition license.txt:89
Definition xaiefal-base.hpp:23
@ XAIE_GROUPEVENT
Definition xaiefal-rsc-group.hpp:35
@ FAL_ERROR
Definition xaiefal-log.hpp:14
@ FAL_WARN
Definition xaiefal-log.hpp:13
Data needed to make a resource request.
Definition xaiefal-rsc-base.hpp:27
uint32_t RscId
Definition xaiefal-rsc-base.hpp:41
XAieRscType RscType
Definition xaiefal-rsc-base.hpp:37
XAie_LocType Loc
Definition xaiefal-rsc-base.hpp:29
XAie_ModuleType Mod
Definition xaiefal-rsc-base.hpp:33
#define _XAIEFAL_MUTEX_ACQUIRE(...)
Definition xaiefal-common.hpp:27
#define _XAIEFAL_MUTEX_DECLARE(...)
Definition xaiefal-common.hpp:28
#define XAIE_RSC_ID_ANY
Definition xaiefal-common.hpp:7