Add CPU missing event
Beep code (1-5-2-1) needs to trigger, if the CPU1 (Base CPU) is not present.
Added an error monitor for CPU Presence to check the beep signal needs to be raise,
if the CPU1 is not present in the socket.
User needs to hear the beep sound if the system boots without CPU1 (Base CPU) presence.
Tested:
1. Beep sound is raised if the CPU1 is not present.
Signed-off-by: Vasu V <vasu.v@intel.com>
Change-Id: I1bd94fe8bdf2fed0a48c46139a1c7afd195f9d0c
diff --git a/include/error_monitors/cpu_presence_monitor.hpp b/include/error_monitors/cpu_presence_monitor.hpp
new file mode 100644
index 0000000..beaf92c
--- /dev/null
+++ b/include/error_monitors/cpu_presence_monitor.hpp
@@ -0,0 +1,108 @@
+/*
+// Copyright (c) 2022 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#pragma once
+
+#include <systemd/sd-journal.h>
+
+#include <error_monitors/base_monitor.hpp>
+#include <gpiod.hpp>
+#include <host_error_monitor.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+namespace host_error_monitor::cpu_presence_monitor
+{
+class CPUPresenceMonitor : public host_error_monitor::base_monitor::BaseMonitor
+{
+ int cpuPresent;
+ size_t cpuNum;
+ const static constexpr uint8_t beepCPUMIssing = 3;
+
+ void logEvent()
+ {
+ std::string msg = "CPU " + std::to_string(cpuNum) + " missing";
+
+ sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
+ LOG_INFO, "REDFISH_MESSAGE_ID=%s",
+ "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s",
+ msg.c_str(), NULL);
+ }
+
+ void CPUPresenceAssertHandler(
+ std::shared_ptr<sdbusplus::asio::connection> conn)
+ {
+ std::cerr << signalName << " asserted\n";
+ // raising beep alert for base cpu missing
+ beep(conn, beepCPUMIssing);
+ logEvent();
+ }
+
+ bool getCPUPresence(const std::string& cpuPresenceName)
+ {
+ // Find the GPIO line
+ gpiod::line cpuPresenceLine = gpiod::find_line(cpuPresenceName);
+ if (!cpuPresenceLine)
+ {
+ std::cerr << "Failed to find the " << cpuPresenceName << " line.\n";
+ return false;
+ }
+
+ // Request GPIO input
+ try
+ {
+ cpuPresenceLine.request(
+ {"host-error-monitor", gpiod::line_request::DIRECTION_INPUT});
+ }
+ catch (const std::exception&)
+ {
+ std::cerr << "Failed to request " << cpuPresenceName << " input\n";
+ return false;
+ }
+
+ // CPU presence is low-assert
+ cpuPresent = !cpuPresenceLine.get_value();
+
+ return true;
+ }
+
+ void checkCPUPresence(std::shared_ptr<sdbusplus::asio::connection> conn)
+ {
+ // Ignore this if the CPU present
+ if (!cpuPresent)
+ {
+ CPUPresenceAssertHandler(conn);
+ }
+ }
+
+ public:
+ CPUPresenceMonitor(boost::asio::io_service& io,
+ std::shared_ptr<sdbusplus::asio::connection> conn,
+ const std::string& signalName, const size_t cpuNum) :
+ BaseMonitor(io, conn, signalName),
+ cpuNum(cpuNum)
+ {
+ if (!getCPUPresence(signalName))
+ {
+ return;
+ }
+ checkCPUPresence(conn);
+ valid = true;
+ }
+ void hostOn() override
+ {
+ checkCPUPresence(conn);
+ }
+};
+} // namespace host_error_monitor::cpu_presence_monitor