Removed unused PollingState enum and GlobalPollingStateManager class

This commit eliminates the `PollingState` enum and the
`GlobalPollingStateManager` class, as they are no longer needed
in the current implementation. Additionally, references to
polling state management have been removed from the `NsmDevice`
and `SensorManagerImpl` classes.

Fixes JIRA https://jirasw.nvidia.com/browse/DGXOPENBMC-17810
Signed-off-by: Paweł Iwaneczko <piwaneczko@nvidia.com>
diff --git a/common/types.hpp b/common/types.hpp
index ce10d78..9e2c662 100644
--- a/common/types.hpp
+++ b/common/types.hpp
@@ -52,12 +52,6 @@
 using InventoryProperties =
     std::map<InventoryPropertyId, InventoryPropertyData>;
 
-enum PollingState
-{
-    POLL_PRIORITY,
-    POLL_NON_PRIORITY,
-};
-
 } // namespace nsm
 
 namespace dbus
diff --git a/nsmd/globalPollingStateManager.hpp b/nsmd/globalPollingStateManager.hpp
deleted file mode 100644
index 89c4e46..0000000
--- a/nsmd/globalPollingStateManager.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION &
- * AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0
- *
- * 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.
- */
-
-#include <common/types.hpp>
-#include <nsmd/nsmDevice.hpp>
-
-namespace nsm
-{
-
-/**
- * @brief The GlobalPollingStateManager class provides access to the global
- * state of devices.
- *
- * This class acts as a centralized interface for retrieving and managing
- * device state.
- */
-class GlobalPollingStateManager
-{
-  public:
-    GlobalPollingStateManager(const NsmDeviceTable& nsmDevices) :
-        nsmDevices(nsmDevices)
-    {}
-    inline PollingState getState()
-    {
-        for (const auto& device : nsmDevices)
-        {
-            // only active devices are considered for priority polling
-            // if inactive devices are stuck with priority polling state
-            // then it will impact round robin sensor refresh
-            if (device->isDeviceActive &&
-                device->getPollingState() == POLL_PRIORITY)
-            {
-                return POLL_PRIORITY;
-            }
-        }
-        return POLL_NON_PRIORITY;
-    }
-
-  private:
-    const NsmDeviceTable& nsmDevices;
-};
-
-} // namespace nsm
diff --git a/nsmd/nsmDevice.hpp b/nsmd/nsmDevice.hpp
index 119ce25..b59b042 100644
--- a/nsmd/nsmDevice.hpp
+++ b/nsmd/nsmDevice.hpp
@@ -333,16 +333,6 @@
         return longRunningSemaphore;
     }
 
-    inline PollingState getPollingState()
-    {
-        return devicePollingState;
-    }
-
-    inline void setPollingState(const PollingState s)
-    {
-        devicePollingState = s;
-    }
-
     // Track if NSM message types were successfully retrieved
     bool areMessageTypesRetrieved{false};
 
@@ -394,7 +384,6 @@
         longRunningSemaphore; // Semaphore for synchronizing long running
                               // commands
     std::optional<ActiveLongRunningHandlerInfo> longRunningHandler;
-    PollingState devicePollingState = POLL_NON_PRIORITY;
 
     void initMsgTypesSensor();
 
diff --git a/nsmd/sensorManager.cpp b/nsmd/sensorManager.cpp
index 0f438f5..337e697 100644
--- a/nsmd/sensorManager.cpp
+++ b/nsmd/sensorManager.cpp
@@ -55,8 +55,7 @@
     mctp_socket::Manager& sockManager, bool verbose) :
     SensorManager(nsmDevices, localEid), bus(bus), event(event),
     handler(handler), instanceIdDb(instanceIdDb), objServer(objServer),
-    eidTable(eidTable), sockManager(sockManager), verbose(verbose),
-    globalPollingStateManager(nsmDevices)
+    eidTable(eidTable), sockManager(sockManager), verbose(verbose)
 {
     deferScanInventory = std::make_unique<sdeventplus::source::Defer>(
         event, std::bind(&SensorManagerImpl::scanInventory, this));
@@ -574,14 +573,6 @@
 
         while (sensorIndex < sensors.size())
         {
-            if (globalPollingStateManager.getState() != POLL_NON_PRIORITY)
-            {
-                // Sleep for 20ms and then check again if we have time.
-                co_await common::Sleep(event.get(), 20000, common::Priority);
-                sd_event_now(event.get(), CLOCK_MONOTONIC, &t1);
-                continue;
-            }
-
             auto sensor = sensors[sensorIndex];
 
             if (!sensor->needsUpdate(t1))
@@ -642,6 +633,7 @@
     uint64_t inActiveSleepTimeInUsec = INACTIVE_SLEEP_TIME_IN_MS * 1000;
     uint64_t pollingTimeInUsec = SENSOR_POLLING_TIME * 1000;
     bool hasFailedToSearchEID = false;
+    DeviceManager& deviceManager = DeviceManager::getInstance();
 
     do
     {
@@ -652,7 +644,6 @@
         if (!nsmDevice->isDeviceActive)
         {
             // search EID
-            DeviceManager& deviceManager = DeviceManager::getInstance();
             auto foundEID = deviceManager.searchEID(
                 nsmDevice->getDeviceType(), nsmDevice->getInstanceNumber(),
                 nsmDevice->getDeviceRole());
@@ -665,9 +656,8 @@
                     nsmDevice->getDeviceRole());
 
                 nsmDevice->eid = *foundEID;
-                nsmDevice->isDeviceActive = true;
-                co_await deviceManager.updateNsmDevice(nsmDevice, *foundEID);
                 co_await nsmDevice->setOnline();
+                co_await deviceManager.updateNsmDevice(nsmDevice, *foundEID);
                 co_await common::Sleep(event.get(), 20000, common::NonPriority);
                 continue;
             }
@@ -700,7 +690,6 @@
             co_await pollEvents(eid);
         }
 #endif
-        DeviceManager& deviceManager = DeviceManager::getInstance();
         // Refresh command matrix
         auto rc = co_await deviceManager.refreshCommandMatrix(nsmDevice, eid);
         if (rc != NSM_SW_SUCCESS)
@@ -708,8 +697,6 @@
             lg2::error("Failed to refresh command matrix, rc={RC}, eid={EID}",
                        "RC", rc, "EID", eid);
         }
-        // update all priority sensors
-        nsmDevice->setPollingState(POLL_PRIORITY);
 
         auto& sensors = nsmDevice->prioritySensors;
         const size_t prioritySensorCount = sensors.size();
@@ -734,16 +721,13 @@
         lttng_ust_tracepoint(nsmd, priority_polling_ended, eid);
 #endif
 
-        // update roundRobin sensors for rest of polling time interval
-        nsmDevice->setPollingState(POLL_NON_PRIORITY);
-
         auto toBeUpdated = nsmDevice->roundRobinSensors.size();
 
         // Make sure the first round-robin sensor is not compared
         // to an uninitialised timestamp
         sd_event_now(event.get(), CLOCK_MONOTONIC, &t1);
 
-        while ((t1 - t0) < pollingTimeInUsec)
+        while ((t1 - t0) < (pollingTimeInUsec - allowedBufferInUsec))
         {
             if (!toBeUpdated)
             {
@@ -758,18 +742,6 @@
                 break;
             }
 
-            if (globalPollingStateManager.getState() != POLL_NON_PRIORITY &&
-                nsmDevice
-                    ->isDeviceReady) // Throttling logic shouldn't affect HMC
-                                     // Ready. Check if the device is ready and
-                                     // only then implement the throttling logic
-            {
-                // Sleep for 20ms and then check again if we have time.
-                co_await common::Sleep(event.get(), 20000, common::Priority);
-                sd_event_now(event.get(), CLOCK_MONOTONIC, &t1);
-                continue;
-            }
-
             auto sensor = nsmDevice->roundRobinSensors.front();
 
             nsmDevice->roundRobinSensors.pop_front();
@@ -819,25 +791,17 @@
             timerEventPriority = common::NonPriority;
         }
 
-        uint64_t diff = t1 - t0;
-        if (diff > pollingTimeInUsec)
+        auto sleepTime = (t1 - t0) < pollingTimeInUsec
+                             ? pollingTimeInUsec - (t1 - t0)
+                             : allowedBufferInUsec; // sleep for at least
+                                                    // allowedBufferInUsec to
+                                                    // ensure minimal delay and
+                                                    // CPU usage
+        if (sleepTime > 0)
         {
-            // We have already crossed the polling interval. Complete mandatory
-            // sleep of 20ms then continue polling for yield some CPU
-            co_await common::Sleep(event, 20000, timerEventPriority);
-            continue;
+            co_await common::Sleep(event, sleepTime, timerEventPriority);
         }
 
-        uint64_t sleepDeltaInUsec = pollingTimeInUsec - diff;
-        if (sleepDeltaInUsec < allowedBufferInUsec)
-        {
-            // If the delta is within the allowed buffer, complete mandatory
-            // sleep of 20ms and continue then polling.
-            co_await common::Sleep(event, 20000, timerEventPriority);
-            continue;
-        }
-        co_await common::Sleep(event, sleepDeltaInUsec, timerEventPriority);
-
     } while (true);
 
     // coverity[missing_return]
diff --git a/nsmd/sensorManager.hpp b/nsmd/sensorManager.hpp
index 64fc329..59f49cc 100644
--- a/nsmd/sensorManager.hpp
+++ b/nsmd/sensorManager.hpp
@@ -23,7 +23,6 @@
 #include "nsmDevice.hpp"
 #include "nsmObject.hpp"
 #include "nsmServiceReadyInterface.hpp"
-#include "nsmd/globalPollingStateManager.hpp"
 #include "nsmd/nsmNumericSensor/nsmNumericSensorComposite.hpp"
 #include "requester/handler.hpp"
 #include "stateChangeLogger.hpp"
@@ -223,7 +222,6 @@
         queuedAddedInterfaces;
     std::coroutine_handle<> interfaceAddedTaskHandle;
     requester::Coroutine interfaceAddedTask();
-    GlobalPollingStateManager globalPollingStateManager;
     std::map<eid_t, StateChangeLogger> stateChangeLoggers;
     StateChangeLogger uuidLogger;
 };