Skip to content

Commit 1909284

Browse files
lpbeliveau-silabspull[bot]
authored andcommitted
Replaced the Sync timestamp in the report scheduler with a CanBeSynced flag and combined it with the IsEngineRunScheduled flag. Modified the logic to preserve the same synching behaviour (#28733)
1 parent a4a8fe2 commit 1909284

4 files changed

+93
-73
lines changed

src/app/reporting/ReportScheduler.h

+21-19
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
6363
class ReadHandlerNode : public TimerContext
6464
{
6565
public:
66+
enum class ReadHandlerNodeFlags : uint8_t
67+
{
68+
// Flag to indicate if the engine run is already scheduled so the scheduler can ignore
69+
// it when calculating the next run time
70+
EngineRunScheduled = (1 << 0),
71+
// Flag to allow the read handler to be synced with other handlers that have an earlier max timestamp
72+
CanBeSynced = (1 << 1),
73+
};
74+
6675
ReadHandlerNode(ReadHandler * aReadHandler, ReportScheduler * aScheduler, const Timestamp & now) : mScheduler(aScheduler)
6776
{
6877
VerifyOrDie(aReadHandler != nullptr);
@@ -80,11 +89,16 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
8089
bool IsReportableNow(const Timestamp & now) const
8190
{
8291
return (mReadHandler->CanStartReporting() &&
83-
(now >= mMinTimestamp && (mReadHandler->IsDirty() || now >= mMaxTimestamp || now >= mSyncTimestamp)));
92+
(now >= mMinTimestamp && (mReadHandler->IsDirty() || now >= mMaxTimestamp || CanBeSynced())));
8493
}
8594

86-
bool IsEngineRunScheduled() const { return mEngineRunScheduled; }
87-
void SetEngineRunScheduled(bool aEngineRunScheduled) { mEngineRunScheduled = aEngineRunScheduled; }
95+
bool IsEngineRunScheduled() const { return mFlags.Has(ReadHandlerNodeFlags::EngineRunScheduled); }
96+
void SetEngineRunScheduled(bool aEngineRunScheduled)
97+
{
98+
mFlags.Set(ReadHandlerNodeFlags::EngineRunScheduled, aEngineRunScheduled);
99+
}
100+
bool CanBeSynced() const { return mFlags.Has(ReadHandlerNodeFlags::CanBeSynced); }
101+
void SetCanBeSynced(bool aCanBeSynced) { mFlags.Set(ReadHandlerNodeFlags::CanBeSynced, aCanBeSynced); }
88102

89103
/// @brief Set the interval timestamps for the node based on the read handler reporting intervals
90104
/// @param aReadHandler read handler to get the intervals from
@@ -94,9 +108,8 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
94108
{
95109
uint16_t minInterval, maxInterval;
96110
aReadHandler->GetReportingIntervals(minInterval, maxInterval);
97-
mMinTimestamp = now + System::Clock::Seconds16(minInterval);
98-
mMaxTimestamp = now + System::Clock::Seconds16(maxInterval);
99-
mSyncTimestamp = mMaxTimestamp;
111+
mMinTimestamp = now + System::Clock::Seconds16(minInterval);
112+
mMaxTimestamp = now + System::Clock::Seconds16(maxInterval);
100113
}
101114

102115
void TimerFired() override
@@ -105,27 +118,16 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
105118
SetEngineRunScheduled(true);
106119
}
107120

108-
void SetSyncTimestamp(System::Clock::Timestamp aSyncTimestamp)
109-
{
110-
// Prevents the sync timestamp being set to a value lower than the min timestamp to prevent it to appear as reportable
111-
// on the next timeout calculation and cause the scheduler to run the engine too early
112-
VerifyOrReturn(aSyncTimestamp >= mMinTimestamp);
113-
mSyncTimestamp = aSyncTimestamp;
114-
}
115-
116121
System::Clock::Timestamp GetMinTimestamp() const { return mMinTimestamp; }
117122
System::Clock::Timestamp GetMaxTimestamp() const { return mMaxTimestamp; }
118-
System::Clock::Timestamp GetSyncTimestamp() const { return mSyncTimestamp; }
119123

120124
private:
121125
ReadHandler * mReadHandler;
122126
ReportScheduler * mScheduler;
123127
Timestamp mMinTimestamp;
124128
Timestamp mMaxTimestamp;
125-
Timestamp mSyncTimestamp; // Timestamp at which the read handler will be allowed to emit a report so it can be synced with
126-
// other handlers that have an earlier max timestamp
127-
bool mEngineRunScheduled = false; // Flag to indicate if the engine run is already scheduled so the scheduler can ignore
128-
// it when calculating the next run time
129+
130+
BitFlags<ReadHandlerNodeFlags> mFlags;
129131
};
130132

131133
ReportScheduler(TimerDelegate * aTimerDelegate) : mTimerDelegate(aTimerDelegate) {}

src/app/reporting/ReportSchedulerImpl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void ReportSchedulerImpl::OnSubscriptionReportSent(ReadHandler * aReadHandler)
9595

9696
Timestamp now = mTimerDelegate->GetCurrentMonotonicTimestamp();
9797

98+
node->SetCanBeSynced(false);
9899
node->SetIntervalTimeStamps(aReadHandler, now);
99100
Milliseconds32 newTimeout;
100101
CalculateNextReportTimeout(newTimeout, node, now);

src/app/reporting/SynchronizedReportSchedulerImpl.cpp

+8-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CHIP_ERROR SynchronizedReportSchedulerImpl::ScheduleReport(Timeout timeout, Read
5050
mTimerDelegate->CancelTimer(this);
5151
if (timeout == Milliseconds32(0))
5252
{
53-
ReportTimerCallback();
53+
TimerFired();
5454
return CHIP_NO_ERROR;
5555
}
5656
ReturnErrorOnFailure(mTimerDelegate->StartTimer(this, timeout));
@@ -160,18 +160,6 @@ CHIP_ERROR SynchronizedReportSchedulerImpl::CalculateNextReportTimeout(Timeout &
160160
timeout = mNextMaxTimestamp - now;
161161
}
162162

163-
// Updates the synching time of each handler
164-
mNodesPool.ForEachActiveObject([now, timeout](ReadHandlerNode * node) {
165-
// Prevent modifying the sync if the handler is currently reportable, sync's purpose is to allow handler to become
166-
// reportable earlier than their max interval
167-
if (!node->IsReportableNow(now))
168-
{
169-
node->SetSyncTimestamp(Milliseconds64(now + timeout));
170-
}
171-
172-
return Loop::Continue;
173-
});
174-
175163
return CHIP_NO_ERROR;
176164
}
177165

@@ -184,11 +172,16 @@ void SynchronizedReportSchedulerImpl::TimerFired()
184172
InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun();
185173

186174
mNodesPool.ForEachActiveObject([now](ReadHandlerNode * node) {
175+
if (node->GetMinTimestamp() <= now)
176+
{
177+
node->SetCanBeSynced(true);
178+
}
179+
187180
if (node->IsReportableNow(now))
188181
{
189182
node->SetEngineRunScheduled(true);
190-
ChipLogProgress(DataManagement, "Handler: %p with min: %" PRIu64 " and max: %" PRIu64 " and sync: %" PRIu64, (node),
191-
node->GetMinTimestamp().count(), node->GetMaxTimestamp().count(), node->GetSyncTimestamp().count());
183+
ChipLogProgress(DataManagement, "Handler: %p with min: %" PRIu64 " and max: %" PRIu64 "", (node),
184+
node->GetMinTimestamp().count(), node->GetMaxTimestamp().count());
192185
}
193186

194187
return Loop::Continue;

0 commit comments

Comments
 (0)