@@ -258,6 +258,11 @@ std::string getPriorityGroupStatsKey(folly::StringPiece statKey, int pg) {
258
258
return folly::to<std::string>(statKey, " .pg" , pg);
259
259
}
260
260
261
+ MonotonicCounter getDefaultCounter (folly::StringPiece statKey) {
262
+ return MonotonicCounter (
263
+ statKey.str (), facebook::fb303::SUM, facebook::fb303::RATE);
264
+ }
265
+
261
266
} // namespace
262
267
263
268
namespace facebook ::fboss {
@@ -329,11 +334,9 @@ void BcmPort::reinitPortStat(
329
334
330
335
if (!stat) {
331
336
portCounters_.emplace (
332
- statKey.str (),
333
- MonotonicCounter (statName (statKey, portName), fb303::SUM, fb303::RATE));
337
+ statKey.str (), getDefaultCounter (statName (statKey, portName)));
334
338
} else if (stat->getName () != statName (statKey, portName)) {
335
- MonotonicCounter newStat{
336
- statName (statKey, portName), fb303::SUM, fb303::RATE};
339
+ MonotonicCounter newStat = getDefaultCounter (statName (statKey, portName));
337
340
stat->swap (newStat);
338
341
utility::deleteCounter (newStat.getName ());
339
342
}
@@ -772,6 +775,46 @@ void BcmPort::updatePortFlowletConfig(const std::shared_ptr<Port>& port) {
772
775
}
773
776
}
774
777
778
+ void BcmPort::clearSignalDetectAndLockStatusChangedStats () {
779
+ auto lastPmdStats = lastPhyInfo_.stats ()->line ()->pmd ();
780
+ for (auto & [laneId, laneStat] : *lastPmdStats->lanes ()) {
781
+ if (laneStat.signalDetectChangedCount ().has_value ()) {
782
+ laneStat.signalDetectChangedCount () = 0 ;
783
+ }
784
+ if (laneStat.cdrLockChangedCount ().has_value ()) {
785
+ laneStat.cdrLockChangedCount () = 0 ;
786
+ }
787
+ }
788
+ }
789
+
790
+ void BcmPort::clearInterfacePhyCounters () {
791
+ auto lockedPortStatsPtr = portStats_.wlock ();
792
+ if (!lockedPortStatsPtr->has_value ()) {
793
+ return ;
794
+ }
795
+
796
+ auto now = duration_cast<seconds>(system_clock::now ().time_since_epoch ());
797
+ HwPortStats curPortStats, lastPortStats;
798
+ curPortStats = (*lockedPortStatsPtr)->portStats ();
799
+
800
+ *curPortStats.fecCorrectableErrors () = 0 ;
801
+ *curPortStats.fecUncorrectableErrors () = 0 ;
802
+
803
+ auto portName = getPortName ();
804
+ auto resetPortStat = [&](folly::StringPiece statKey,
805
+ folly::StringPiece portName) {
806
+ auto stat = getPortCounterIf (statKey);
807
+ MonotonicCounter newStat = getDefaultCounter (statName (statKey, portName));
808
+ stat->swap (newStat);
809
+ };
810
+ resetPortStat (kFecCorrectable (), portName);
811
+ resetPortStat (kFecUncorrectable (), portName);
812
+
813
+ *lockedPortStatsPtr = BcmPortStats (std::move (curPortStats), now);
814
+
815
+ clearSignalDetectAndLockStatusChangedStats ();
816
+ }
817
+
775
818
void BcmPort::cacheFaultStatus (phy::LinkFaultStatus faultStatus) {
776
819
auto faultStatusPtr = cachedFaultStatus.wlock ();
777
820
*faultStatusPtr = faultStatus;
0 commit comments