Skip to content

Commit

Permalink
Remove AccessMethod option from watchdog thrift interface
Browse files Browse the repository at this point in the history
Summary:
The BSP API specification is clear that watchdogs must be accessed via the chardev interface: https://www.internalfb.com/code/fbsource/[e4f6abca5b20ff588ff625c57d8425c2cb42d19f]/fbcode/fboss/docs/bsp_api_specification.md#2-2-7-fan-watchdog-watch

meaning all watchdogs will be accessed with sysfs paths. No need to have the `AccessMethod` for watchdog in the fan_service thrift interface.

Reviewed By: somasun

Differential Revision: D68866366

fbshipit-source-id: d37e1db5e4135f41ac0f54d874add72a84c8b16d
  • Loading branch information
Scott8440 authored and facebook-github-bot committed Jan 30, 2025
1 parent 3478aad commit fe56a12
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
5 changes: 1 addition & 4 deletions fboss/platform/configs/montblanc/fan_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"pwmLowerThreshold": 25,
"pwmUpperThreshold": 70,
"watchdog": {
"access": {
"accessType": "ACCESS_TYPE_SYSFS",
"path": "/run/devmap/watchdogs/FAN_WATCHDOG"
},
"sysfsPath": "/run/devmap/watchdogs/FAN_WATCHDOG",
"value": 0
},
"controlInterval": {
Expand Down
28 changes: 9 additions & 19 deletions fboss/platform/fan_service/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,20 @@ void Bsp::closeWatchdog() {
}

bool Bsp::writeToWatchdog(const std::string& value) {
int rc = true;
std::string cmdLine;
if (!config_.watchdog().has_value()) {
return rc;
return false;
}
AccessMethod access = *config_.watchdog()->access();
if (*access.accessType() == constants::ACCESS_TYPE_UTIL()) {
cmdLine = fmt::format("{} {}", *access.path(), value);
auto [exitStatus, standardOut] = PlatformUtils().execCommand(cmdLine);
rc = exitStatus;
} else if (*access.accessType() == constants::ACCESS_TYPE_SYSFS()) {
try {
if (!watchdogFd_.has_value()) {
watchdogFd_ = open(access.path()->c_str(), O_WRONLY);
}
rc = writeFd(watchdogFd_.value(), value);
} catch (std::exception& e) {
XLOG(ERR) << "Could not write to watchdog: " << e.what();
return false;
try {
auto sysfsPath = config_.watchdog()->sysfsPath()->c_str();
if (!watchdogFd_.has_value()) {
watchdogFd_ = open(sysfsPath, O_WRONLY);
}
} else {
throw facebook::fboss::FbossError("Invalid watchdog access type!");
return writeFd(watchdogFd_.value(), value);
} catch (std::exception& e) {
XLOG(ERR) << "Could not write to watchdog: " << e.what();
return false;
}
return rc;
}

std::vector<std::pair<std::string, float>> Bsp::processOpticEntries(
Expand Down
5 changes: 2 additions & 3 deletions fboss/platform/fan_service/ConfigValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ bool ConfigValidator::isValid(const FanServiceConfig& config) {
}

if (config.watchdog()) {
if (!accessMethodTypes.count(*config.watchdog()->access()->accessType())) {
XLOG(ERR) << "Invalid access method for watchdog config: "
<< *config.watchdog()->access()->accessType();
if (!config.watchdog()->sysfsPath()->c_str()) {
XLOG(ERR) << "Watchdog sysfs path must have a non-empty value";
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion fboss/platform/fan_service/if/fan_service_config.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct Fan {
}

struct Watchdog {
1: AccessMethod access;
1: string sysfsPath;
2: i32 value;
}

Expand Down

0 comments on commit fe56a12

Please sign in to comment.