blob: 000022c872a7aceabf5e3e392255b9a25399610f [file] [log] [blame]
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -05001#pragma once
2
3extern "C"
4{
5#include <libpdbg.h>
6#include <libpdbg_sbe.h>
7}
8
9#include <cstdint>
10#include <filesystem>
11#include <future>
12#include <vector>
13
14namespace openpower::dump::sbe_chipop
15{
16
17/**
18 * @class SbeDumpCollector
19 * @brief Manages the collection of dumps from SBEs on failure.
20 *
21 * This class provides functionalities to orchestrate the collection of
22 * diagnostic dumps from Self Boot Engines across multiple processors
23 * in response to failures or for diagnostic purposes.
24 */
25class SbeDumpCollector
26{
27 public:
28 /**
29 * @brief Constructs a new SbeDumpCollector object.
30 */
31 SbeDumpCollector() = default;
32
33 /**
34 * @brief Destroys the SbeDumpCollector object.
35 */
36 ~SbeDumpCollector() = default;
37
38 /**
39 * @brief Orchestrates the collection of dumps from all available SBEs.
40 *
41 * Initiates the process of collecting diagnostic dumps from SBEs. This
42 * involves identifying available processors, initiating the dump
43 * collection process, and managing the collected dump files.
44 *
45 * @param type The type of dump to collect.
46 * @param id A unique identifier for the dump collection operation.
47 * @param failingUnit The identifier of the failing unit prompting the dump
48 * collection.
49 * @param path The filesystem path where collected dumps should be stored.
50 */
51 void collectDump(uint8_t type, uint32_t id, uint64_t failingUnit,
52 const std::filesystem::path& path);
53
54 private:
55 /**
56 * @brief Collects a dump from a single SBE.
57 *
58 * Executes the low-level operations required to collect a diagnostic
59 * dump from the specified SBE.
60 *
61 * @param chip A pointer to the pdbg_target structure representing the SBE.
62 * @param path The filesystem path where the dump should be stored.
63 * @param id The unique identifier for this dump collection operation.
64 * @param type The type of dump to collect.
65 * @param clockState The clock state of the SBE during dump collection.
66 * @param failingUnit The identifier of the failing unit.
67 */
68 void collectDumpFromSBE(struct pdbg_target* chip,
69 const std::filesystem::path& path, uint32_t id,
70 uint8_t type, uint8_t clockState,
71 uint64_t failingUnit);
72
73 /**
74 * @brief Initializes the PDBG library.
75 *
76 * Prepares the PDBG library for interacting with processor targets. This
77 * must be called before any PDBG-related operations are performed.
78 */
79 void initializePdbg();
80
81 /**
82 * @brief Launches asynchronous dump collection tasks for a set of targets.
83 *
84 * This method initiates the dump collection process asynchronously for each
85 * target provided in the `targets` vector. It launches a separate
86 * asynchronous task for each target, where each task calls
87 * `collectDumpFromSBE` with the specified parameters, including the clock
88 * state.
89 *
90 * @param type The type of the dump to collect. This could be a hardware
91 * dump, software dump, etc., as defined by the SBE dump type enumeration.
92 * @param id A unique identifier for the dump collection operation. This ID
93 * is used to tag the collected dump for identification.
94 * @param path The filesystem path where the collected dumps should be
95 * stored. Each dump file will be stored under this directory.
96 * @param failingUnit The identifier of the unit or component that is
97 * failing or suspected to be the cause of the issue prompting the dump
98 * collection. This is used for diagnostic purposes.
99 * @param cstate The clock state during the dump collection. This parameter
100 * dictates whether the dump should be collected with the
101 * clocks running (SBE_CLOCK_ON) or with the clocks stopped (SBE_CLOCK_OFF).
102 * @param targets A vector of `pdbg_target*` representing the targets from
103 * which dumps should be collected. Each target corresponds to a physical or
104 * logical component in the system, such as a processor or an SBE.
105 *
106 * @return A vector of `std::future<void>` objects. Each future represents
107 * the completion state of an asynchronous dump collection task. The caller
108 * can wait on these futures to determine when all dump collection
109 * tasks have completed. Exceptions thrown by the asynchronous tasks are
110 * captured by the futures and can be rethrown when the futures are
111 * accessed.
112 */
113 std::vector<std::future<void>> spawnDumpCollectionProcesses(
114 uint8_t type, uint32_t id, const std::filesystem::path& path,
115 uint64_t failingUnit, uint8_t cstate,
116 const std::vector<struct pdbg_target*>& targets);
117};
118
119} // namespace openpower::dump::sbe_chipop