Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 1 | #include <analyzer/analyzer_main.hpp> |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 2 | #include <boost/interprocess/ipc/message_queue.hpp> |
Ben Tyner | 7212d21 | 2020-03-31 09:44:41 -0500 | [diff] [blame] | 3 | #include <cli.hpp> |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 4 | #include <listener.hpp> |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 5 | |
| 6 | /** |
| 7 | * @brief Attention handler application main() |
| 8 | * |
| 9 | * This is the main interface to the hardware diagnostics application. This |
| 10 | * application will either be loaded as a daemon for monitoring the attention |
| 11 | * gpio or it will be loaded as an application to analyze hardware and |
| 12 | * diagnose hadrware error conditions. |
| 13 | * |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 14 | * Usage: |
| 15 | * --analyze: Analyze the hardware |
| 16 | * --start: Start the attention handler |
| 17 | * --stop: Stop the attention handler |
| 18 | * --all <on|off>: All attention handling |
| 19 | * --vital <on|off>: Vital attention handling |
| 20 | * --checkstop <on|off>: Checkstop attention handling |
| 21 | * --terminate <on|off>: Terminate Immiediately attention handling |
| 22 | * --breakpoints <on|off>: Breakpoint attention handling |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 23 | * |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 24 | * Example: openpower-hw-diags --start --vital off |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 25 | * |
| 26 | * @return 0 = success |
| 27 | */ |
| 28 | int main(int argc, char* argv[]) |
| 29 | { |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 30 | int rc = 0; // assume success |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 31 | |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 32 | using namespace boost::interprocess; |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 33 | |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 34 | if (argc == 1) |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 35 | { |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 36 | printf("openpower-hw-diags <options>\n"); |
| 37 | printf("options:\n"); |
| 38 | printf(" --analyze: Analyze the hardware\n"); |
| 39 | printf(" --start: Start the attention handler\n"); |
| 40 | printf(" --stop: Stop the attention handler\n"); |
| 41 | printf(" --all <on|off>: All attention handling\n"); |
| 42 | printf(" --vital <on|off>: Vital attention handling\n"); |
| 43 | printf(" --checkstop <on|off>: Checkstop attention handling\n"); |
| 44 | printf(" --terminate <on|off>: Terminate Immediately attention " |
| 45 | "handling\n"); |
| 46 | printf(" --breakpoints <on|off>: Breakpoint attention handling\n"); |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 47 | } |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 48 | else |
| 49 | { |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 50 | // todo usage |
| 51 | |
| 52 | // Either analyze (application mode) or daemon mode |
| 53 | if (true == getCliOption(argv, argv + argc, "--analyze")) |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 54 | { |
| 55 | analyzer::analyzeHardware(); |
| 56 | } |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 57 | // daemon mode |
| 58 | else |
| 59 | { |
| 60 | // assume listener is not running |
| 61 | bool listenerStarted = false; |
| 62 | bool newListener = false; |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 63 | |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 64 | pthread_t ptidListener; // handle to listener thread |
| 65 | |
| 66 | // see if listener is already started |
| 67 | listenerStarted = listenerMqExists(); |
| 68 | |
| 69 | // listener is not running so start it |
| 70 | if (false == listenerStarted) |
| 71 | { |
| 72 | // create listener thread |
| 73 | if (0 == |
| 74 | pthread_create(&ptidListener, NULL, &threadListener, NULL)) |
| 75 | { |
| 76 | listenerStarted = true; |
| 77 | newListener = true; |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | rc = 1; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // listener was running or just started |
| 86 | if (true == listenerStarted) |
| 87 | { |
| 88 | // If we created a new listener this instance of |
| 89 | // openpower-hw-diags will become our daemon (it will not exit |
| 90 | // until stopped). |
| 91 | if (true == newListener) |
| 92 | { |
| 93 | bool listenerReady = false; |
| 94 | |
| 95 | // It may take some time for the listener to become ready, |
| 96 | // we will wait until the message queue has been created |
| 97 | // before starting to communicate with our daemon. |
| 98 | while (false == listenerReady) |
| 99 | { |
| 100 | usleep(500); |
| 101 | listenerReady = listenerMqExists(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // send cmd line to listener thread |
| 106 | if (argc != sendCmdLine(argc, argv)) |
| 107 | { |
| 108 | rc = 1; |
| 109 | } |
| 110 | |
| 111 | // if this is a new listener let it run until "stopped" |
| 112 | if (true == newListener) |
| 113 | { |
| 114 | pthread_join(ptidListener, NULL); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 119 | return rc; |
| 120 | } |