Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <hei_isolation_data.hpp> |
| 4 | #include <isolator/hei_isolation_node.hpp> |
| 5 | |
| 6 | namespace libhei |
| 7 | { |
| 8 | |
| 9 | /** |
| 10 | * @brief This class contains all information required to isolate attentions on |
| 11 | * a specific chip type. |
| 12 | * |
| 13 | * The primary function of this class is analyze(), which will do a depth-first |
| 14 | * search of the hardware attention reporting tree structure (characterized by |
| 15 | * IsolationNode objects) to find all active attentions on a chip. |
| 16 | * |
| 17 | * The data for each chip type is built from information in the Chip Data Files. |
| 18 | * |
| 19 | * IMPORTANT: |
| 20 | * Most of the objects created and referenced by this class are stored in the |
| 21 | * flyweight factories, which are used as a space saving mechanism by |
| 22 | * preventing duplicate object creation. For example, a large set of the |
| 23 | * registers for a specific chip model will likely be common between each of |
| 24 | * chip level of that model. It is not necessary to create new objects for |
| 25 | * each level when the attributes are all the same. Because the flyweights are |
| 26 | * used, it is not possible to remove all of the data for a specific chip |
| 27 | * model/level be deleting an IsolationChip object. Instead, you must call the |
| 28 | * main uninitialize() function and clear all data for all objects. |
| 29 | */ |
| 30 | class IsolationChip |
| 31 | { |
| 32 | public: // Constructors, destructor, assignment |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 33 | /** @brief Constructor. */ |
| 34 | explicit IsolationChip(ChipType_t i_chipType) : iv_chipType(i_chipType) {} |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 35 | |
| 36 | /** @brief Destructor. */ |
| 37 | ~IsolationChip() = default; |
| 38 | |
| 39 | /** @brief Copy constructor. */ |
| 40 | IsolationChip(const IsolationChip&) = delete; |
| 41 | |
| 42 | /** @brief Assignment operator. */ |
| 43 | IsolationChip& operator=(const IsolationChip&) = delete; |
| 44 | |
| 45 | private: // Instance variables |
| 46 | /** This chip's type. */ |
| 47 | const ChipType_t iv_chipType; |
| 48 | |
| 49 | /** Root nodes for this chip type. */ |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 50 | RootNodeMap iv_rootNodes; |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 51 | |
| 52 | public: // Member functions |
| 53 | /** |
| 54 | * @brief Finds all active attentions on this chip. |
| 55 | * @param i_chip The target chip for isolation. Will assert the given |
| 56 | * chip type matches iv_chipType. |
| 57 | * @param io_isoData The isolation data returned back to the user |
| 58 | * application. |
| 59 | * @return True, if any active attentions found on this chip. |
| 60 | * False, otherwise. |
| 61 | */ |
| 62 | bool analyze(const Chip& i_chip, IsolationData& io_isoData) const; |
| 63 | |
| 64 | /** @brief Chip type accessor. */ |
| 65 | ChipType_t getChipType() const |
| 66 | { |
| 67 | return iv_chipType; |
| 68 | } |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * @brief Adds a root node to this chip. |
| 72 | * @param i_attnType The target attention type. Will assert this type does |
| 73 | * not already exist in iv_rootNodes. |
| 74 | * @param i_node The target isolation node for this attention type. |
| 75 | */ |
| 76 | void addRootNode(AttentionType_t i_attnType, IsolationNodePtr i_node) |
| 77 | { |
| 78 | auto ret = iv_rootNodes.emplace(i_attnType, i_node); |
| 79 | HEI_ASSERT(ret.second); // Should have not already existed. |
| 80 | } |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 81 | }; |
| 82 | |
Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 83 | /** A simple map to ensure only one IsolationChip exists per chip type. */ |
| 84 | using IsolationChipMap = |
| 85 | std::map<ChipType_t, const std::unique_ptr<const IsolationChip>>; |
| 86 | |
Zane Shelley | 508ce58 | 2020-05-05 13:47:19 -0500 | [diff] [blame] | 87 | } // end namespace libhei |