Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Removed fwerrorcnt from default show sensor list
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel K Osawa <[email protected]>
  • Loading branch information
dkosawa authored and Juston Li committed Oct 18, 2017
1 parent 66fa361 commit 8d20148
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 12 deletions.
42 changes: 40 additions & 2 deletions src/cli/features/core/SensorFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void cli::nvmcli::SensorFeature::getPaths(cli::framework::CommandSpecList &list)
showSensor.addOption(framework::OPTION_ALL);
showSensor.addTarget(TARGET_SENSOR_R)
.valueText("MediaTemperature|ControllerTemperature|SpareCapacity|WearLevel|UnsafeShutdowns|"
"PowerOnTime|UpTime|PowerCycles|FWErrorCount|PowerLimited|Health")
"PowerOnTime|UpTime|PowerCycles|PowerLimited|Health")
.helpText(TR("Restrict output to a specific sensor type by supplying the name. "
"The default is to display all sensors."));
showSensor.addTarget(TARGET_DIMM)
Expand Down Expand Up @@ -156,6 +156,27 @@ cli::framework::ResultBase * cli::nvmcli::SensorFeature::run(
return pResult;
}

sensor_category cli::nvmcli::SensorFeature::sensorNameToCategory(std::string sensorName)
{
transform(sensorName.begin(), sensorName.end(), sensorName.begin(), ::tolower);
std::string pwrLimited = core::device::sensor::PROPERTY_SENSOR_TYPE_POWERLIMITED;
transform(pwrLimited.begin(), pwrLimited.end(), pwrLimited.begin(), ::tolower);
std::string fwErrCnt = core::device::sensor::PROPERTY_SENSOR_TYPE_FWERRORLOGCOUNT;
transform(fwErrCnt.begin(), fwErrCnt.end(), fwErrCnt.begin(), ::tolower);

if (0 == sensorName.compare(pwrLimited))
{
return SENSOR_CAT_POWER;
}
else if (0 == sensorName.compare(fwErrCnt))
{
return SENSOR_CAT_FW_ERROR;
}
else
{
return SENSOR_CAT_SMART_HEALTH;
}
}

/*
* Show sensors provided by the NVDIMMSensorFactory::getInstances function. If
Expand Down Expand Up @@ -269,16 +290,33 @@ cli::framework::ResultBase* cli::nvmcli::SensorFeature::showSensor(
if (!dev.isManageable())
continue;

if(NVM_SUCCESS != (rc = nvm_get_sensors(dev.getUid().c_str(), sensors, NVM_MAX_DEVICE_SENSORS)))
NVM_SENSOR_CATEGORY_BITMASK sensor_categories = 0;
NVM_SENSOR_CATEGORY_BITMASK sensor_thresholds = 0;
if (singleSensorTarget)
{
sensor_categories = sensorNameToCategory(sensorTargetName);
sensor_thresholds = sensor_categories;
}
else
{
sensor_categories = SENSOR_CAT_SMART_HEALTH | SENSOR_CAT_POWER;
sensor_thresholds = sensor_categories;
}

if(NVM_SUCCESS != (rc = nvm_get_sensors_by_category(dev.getUid().c_str(), sensors, NVM_MAX_DEVICE_SENSORS, sensor_categories, sensor_thresholds)))
{
free(pResults);
throw wbem::exception::NvmExceptionLibError(rc);
}

for (int i = 0; i < NVM_MAX_DEVICE_SENSORS; ++i)
{
if (SENSOR_NOT_INITIALIZED == sensors[i].current_state)
continue;

framework::PropertyListResult* pResultDimmProps = new framework::PropertyListResult();
core::device::sensor::Sensor *sensor = core::device::sensor::SensorFactory::CreateSensor(sensors[i]);

if (singleSensorTarget)
{
std::string sensorName = sensor->GetName();
Expand Down
3 changes: 2 additions & 1 deletion src/cli/features/core/SensorFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class NVM_API SensorFeature : public cli::nvmcli::VerboseFeatureBase
bool tryParseVal (const std::string& str, NVM_REAL32 *p_value) const;
void roundToNearestSixteenth(NVM_REAL32 &val);
void updateResultsWithPropertyList(core::device::Device dev, framework::ObjectListResult *pResults);

sensor_category sensorNameToCategory(std::string sensorName);

/*
* Helper for modify sensor.
* Fetches the properties from the parsed command, performs validation, and converts to WBEM
Expand Down
1 change: 0 additions & 1 deletion src/lib/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ int populate_devices(struct device_discovery *p_devices,
{
rc = fw_rc;
}

calculate_capabilities_for_populated_devices(p_devices,
populated_count);
calculate_uids_for_populated_devices(p_devices, populated_count);
Expand Down
52 changes: 52 additions & 0 deletions src/lib/nvm_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ enum sensor_type
SENSOR_HEALTH = 10, // Apache Pass DIMM health as reported in the SMART log.
};

typedef NVM_UINT64 NVM_SENSOR_CATEGORY_BITMASK;

/*
* The bitmask for sensor type.
*/
enum sensor_category
{
SENSOR_CAT_SMART_HEALTH = 0x1,
SENSOR_CAT_POWER = 0x2,
SENSOR_CAT_FW_ERROR = 0x4,
};

/*
* The units of measurement for a sensor.
*/
Expand All @@ -240,6 +252,7 @@ enum sensor_units
*/
enum sensor_status
{
SENSOR_NOT_INITIALIZED = -1, //no attempt to read sensor value yet.
SENSOR_UNKNOWN = 0, // Sensor status cannot be determined.
SENSOR_NORMAL = 1, // Current value of the sensor is in the normal range.
SENSOR_NONCRITICAL = 2, // Current value of the sensor is in non critical range.
Expand Down Expand Up @@ -1931,6 +1944,45 @@ extern NVM_API int nvm_get_security_permission(struct device_discovery *p_discov
extern NVM_API int nvm_get_sensors(const NVM_UID device_uid, struct sensor *p_sensors,
const NVM_UINT16 count);

/*
* Retrieve sensors that are associated with certain sensor categories.
* @param[in] device_uid
* The device identifier.
* @param[in,out] p_sensors
* An array of #sensor structures allocated by the caller.
* @param[in] count
* The size of the array. Should be #NVM_MAX_DEVICE_SENSORS.
* @param[in] categories
* A bitmask that specifies which sensor categories to retrieve.
* @param[in] thresholds
* A bitmask that specifies which sensor categories should include
* threshold information.
* @pre The caller has administrative privileges.
* @pre The device is manageable.
* @remarks Sensors are used to monitor a particular aspect of a device by
* settings thresholds against a current value.
* @remarks The number of sensors for a device is defined as #NVM_MAX_DEVICE_SENSORS.
* @remarks Sensor information is returned as part of the #device_details structure.
* @return Returns one of the following @link #return_code return_codes: @endlink @n
* #NVM_SUCCESS @n
* #NVM_ERR_NOTSUPPORTED @n
* #NVM_ERR_INVALIDPERMISSIONS @n
* #NVM_ERR_INVALIDPARAMETER @n
* #NVM_ERR_DRIVERFAILED @n
* #NVM_ERR_ARRAYTOOSMALL @n
* #NVM_ERR_BADDEVICE @n
* #NVM_ERR_NOMEMORY @n
* #NVM_ERR_NOTMANAGEABLE @n
* #NVM_ERR_DATATRANSFERERROR @n
* #NVM_ERR_DEVICEERROR @n
* #NVM_ERR_DEVICEBUSY @n
* #NVM_ERR_UNKNOWN @n
* #NVM_ERR_BADDRIVER @n
* #NVM_ERR_NOSIMULATOR (Simulated builds only)
*/
extern NVM_API int nvm_get_sensors_by_category(const NVM_UID device_uid, struct sensor *p_sensors, const NVM_UINT16 count,
NVM_SENSOR_CATEGORY_BITMASK categories, NVM_SENSOR_CATEGORY_BITMASK thresholds);

/*
* Retrieve a specific health sensor from the specified AEP DIMM.
* @param[in] device_uid
Expand Down
114 changes: 106 additions & 8 deletions src/lib/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int get_sensor_thresholds(int device_handle, struct sensor_thresholds *p_thresho
}

int get_smart_log_sensors(const NVM_UID device_uid,
const NVM_UINT32 dev_handle, struct sensor *p_sensors)
const NVM_UINT32 dev_handle, struct sensor *p_sensors, NVM_BOOL include_thresholds)
{
COMMON_LOG_ENTRY();

Expand All @@ -116,8 +116,11 @@ int get_smart_log_sensors(const NVM_UID device_uid,
* the smart health log ... if it's successful. So if thresholds fail, just continue.
*/
struct sensor_thresholds thresholds;
int threshold_rc = get_sensor_thresholds(dev_handle, &thresholds);
KEEP_ERROR(rc, threshold_rc);
if (include_thresholds)
{
int threshold_rc = get_sensor_thresholds(dev_handle, &thresholds);
KEEP_ERROR(rc, threshold_rc);
}

struct sensor *p_sensor = NULL;
// Media Temperature
Expand All @@ -129,6 +132,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
media_temp_celsius = fw_convert_fw_celsius_to_float(dimm_smart.media_temperature);
p_sensor->reading = nvm_encode_temperature(media_temp_celsius);
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
p_sensor->upper_noncritical_settable = 1;
p_sensor->upper_noncritical_support = 1;
p_sensor->upper_critical_support = 1;
Expand Down Expand Up @@ -174,6 +181,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
{
p_sensor->reading = (NVM_UINT64) dimm_smart.spare;
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
p_sensor->lower_noncritical_settable = 1;
p_sensor->lower_noncritical_support = 1;
p_sensor->settings.enabled = thresholds.is_spare_alarm_threshold_enabled;
Expand Down Expand Up @@ -203,6 +214,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
{
p_sensor->reading = (NVM_UINT64) dimm_smart.percentage_used;
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
if (!dimm_smart.validation_flags.parts.percentage_used_field)
{
p_sensor->current_state = SENSOR_UNKNOWN;
Expand All @@ -225,6 +240,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
p_sensor->reading = dimm_smart.vendor_data.power_cycles;
p_sensor->current_state = SENSOR_NORMAL;
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
}

// Power On Time
Expand All @@ -235,6 +254,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
p_sensor->reading = dimm_smart.vendor_data.power_on_seconds;
p_sensor->current_state = SENSOR_NORMAL;
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
}

// Up Time
Expand All @@ -245,6 +268,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
p_sensor->reading = dimm_smart.vendor_data.uptime;
p_sensor->current_state = SENSOR_NORMAL;
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
}

// Unsafe Shutdowns
Expand All @@ -255,6 +282,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
p_sensor->reading = dimm_smart.vendor_data.unsafe_shutdowns;
p_sensor->current_state = SENSOR_NORMAL;
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
}

// Controller Temperature
Expand All @@ -267,6 +298,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
fw_convert_fw_celsius_to_float(dimm_smart.controller_temperature);
p_sensor->reading = nvm_encode_temperature(controller_temp_celsius);
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
p_sensor->upper_noncritical_settable = 1;
p_sensor->upper_noncritical_support = 1;
p_sensor->upper_critical_support = 1;
Expand Down Expand Up @@ -323,6 +358,10 @@ int get_smart_log_sensors(const NVM_UID device_uid,
break;
}
}
else
{
p_sensor->current_state = SENSOR_UNKNOWN;
}
}
}

Expand Down Expand Up @@ -395,6 +434,7 @@ void initialize_sensors(const NVM_UID device_uid,
{
memmove(sensors[i].device_uid, device_uid, NVM_MAX_UID_LEN);
sensors[i].type = i;
sensors[i].current_state = SENSOR_NOT_INITIALIZED;
}
sensors[SENSOR_MEDIA_TEMPERATURE].units = UNIT_CELSIUS;
sensors[SENSOR_SPARECAPACITY].units = UNIT_PERCENT;
Expand All @@ -415,14 +455,76 @@ int get_all_sensors(const NVM_UID device_uid,
COMMON_LOG_ENTRY();

initialize_sensors(device_uid, sensors);
int rc = get_smart_log_sensors(device_uid, dev_handle, sensors);
int rc = get_smart_log_sensors(device_uid, dev_handle, sensors, 1);
KEEP_ERROR(rc, get_fw_error_log_sensors(device_uid, dev_handle, sensors));
KEEP_ERROR(rc, get_power_limited_sensor(device_uid, dev_handle, sensors));

COMMON_LOG_EXIT_RETURN_I(rc);
return rc;
}

int nvm_get_sensors_by_category(const NVM_UID device_uid, struct sensor *p_sensors, const NVM_UINT16 count,
NVM_SENSOR_CATEGORY_BITMASK categories, NVM_SENSOR_CATEGORY_BITMASK thresholds)
{
COMMON_LOG_ENTRY();
int rc = NVM_SUCCESS;

struct device_discovery discovery;
if (check_caller_permissions() != COMMON_SUCCESS)
{
rc = NVM_ERR_INVALIDPERMISSIONS;
}
if (device_uid == NULL)
{
COMMON_LOG_ERROR("Invalid parameter, device_uid is NULL");
rc = NVM_ERR_INVALIDPARAMETER;
}
else if (p_sensors == NULL)
{
COMMON_LOG_ERROR("Invalid parameter, p_status is NULL");
rc = NVM_ERR_INVALIDPARAMETER;
}
else if ((rc = exists_and_manageable(device_uid, &discovery, 1)) == NVM_SUCCESS)
{
struct sensor sensors[NVM_MAX_DEVICE_SENSORS];
memset(sensors, 0, sizeof(sensors));
const NVM_UINT32 dev_handle = discovery.device_handle.handle;
int rc;
initialize_sensors(device_uid, sensors);
if (categories & SENSOR_CAT_SMART_HEALTH)
{
NVM_BOOL get_thresh = thresholds & SENSOR_CAT_SMART_HEALTH;
KEEP_ERROR(rc, get_smart_log_sensors(device_uid, dev_handle, sensors, get_thresh));
}

if (categories & SENSOR_CAT_POWER)
{
KEEP_ERROR(rc, get_power_limited_sensor(device_uid, dev_handle, sensors));
}

if (categories & SENSOR_CAT_FW_ERROR)
{
KEEP_ERROR(rc, get_fw_error_log_sensors(device_uid, dev_handle, sensors));
}

// even if the array is too small, we still want to fill in as many as possible.
// Just return the error code
if (count < NVM_MAX_DEVICE_SENSORS)
{
rc = NVM_ERR_ARRAYTOOSMALL;
}

// fill in the user provided sensor array
memset(p_sensors, 0, sizeof(struct sensor) * count);
for (int i = 0; i < count; i++)
{
memmove(&p_sensors[i], &sensors[i], sizeof(struct sensor));
}
}
COMMON_LOG_EXIT_RETURN_I(rc);
return rc;
}

/*
* This function populates sensor information for the specified device.
* Sensors are used to monitor a particular aspect of a device by settings
Expand All @@ -445,10 +547,6 @@ int nvm_get_sensors(const NVM_UID device_uid, struct sensor *p_sensors,
{
rc = NVM_ERR_BADDRIVER;
}
else if ((rc = IS_NVM_FEATURE_SUPPORTED(get_sensors)) != NVM_SUCCESS)
{
COMMON_LOG_ERROR("Retrieving " NVM_DIMM_NAME " sensors is not supported.");
}
else if (device_uid == NULL)
{
COMMON_LOG_ERROR("Invalid parameter, device_uid is NULL");
Expand Down

0 comments on commit 8d20148

Please sign in to comment.