int onlp_sysi_platform_manage_fans(void) { int rc; onlp_thermal_info_t ti1; onlp_thermal_info_t ti2; int mtemp=0; int new_rpm=0; if (chassis_fan_count() == 0) { return ONLP_STATUS_E_UNSUPPORTED; } /* Get temperature */ rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(1), &ti1); if (rc != ONLP_STATUS_OK) { return rc; } rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &ti2); if (rc != ONLP_STATUS_OK) { return rc; } mtemp=(ti1.mcelsius+ti2.mcelsius)/2; /* Bring fan speed according the temp */ if(mtemp<50000) new_rpm=FAN_IDLE_RPM; else if((mtemp>=55000)&&(mtemp<60000)) new_rpm=FAN_LEVEL1_RPM; else if((mtemp>=65000)&&(mtemp<70000)) new_rpm=FAN_LEVEL2_RPM; else if(mtemp>=75000) new_rpm=FAN_LEVEL3_RPM; else{ return ONLP_STATUS_OK; } onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(1),new_rpm); onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(2),new_rpm); return ONLP_STATUS_OK; }
static void temp_update_handler__(netsnmp_request_info *req, uint32_t index, onlp_snmp_sensor_t *ss) { uint64_t current = os_time_monotonic(); if (SENSOR_NEEDS_UPDATE(current, ss)) { onlp_thermal_info_t *ti = &ss->sensor_info.ti; onlp_oid_t oid = (onlp_oid_t) ss->sensor_id; int rv = onlp_thermal_info_get(oid, ti); SENSOR_SET_VALIDITY(rv, current, ss); } /* else use the last update info */ }
/************************************************************ * * Debug and Show Functions * ***********************************************************/ void onlp_thermal_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags) { int rv; iof_t iof; onlp_thermal_info_t info; VALIDATENR(id); onlp_oid_dump_iof_init_default(&iof, pvs); iof_push(&iof, "thermal @ %d", ONLP_OID_ID_GET(id)); rv = onlp_thermal_info_get(id, &info); if(rv < 0) { onlp_oid_info_get_error(&iof, rv); } else { onlp_oid_show_description(&iof, &info.hdr); if(info.status & 1) { /* Present */ iof_iprintf(&iof, "Status: %{onlp_thermal_status_flags}", info.status); iof_iprintf(&iof, "Caps: %{onlp_thermal_caps_flags}", info.caps); iof_iprintf(&iof, "Temperature: %d", info.mcelsius); iof_push(&iof, "thresholds"); { iof_iprintf(&iof, "Warning: %d", info.thresholds.warning); iof_iprintf(&iof, "Error: %d", info.thresholds.error); iof_iprintf(&iof, "Shutdown: %d", info.thresholds.shutdown); iof_pop(&iof); } } else { iof_iprintf(&iof, "Not present."); } } iof_pop(&iof); }
/* * For AC power Front to Back : * * If any fan fail, please fan speed register to 15 * * The max value of Fan speed register is 9 * [LM75(48) + LM75(49) + LM75(4A)] > 174 => set Fan speed value from 4 to 5 * [LM75(48) + LM75(49) + LM75(4A)] > 182 => set Fan speed value from 5 to 7 * [LM75(48) + LM75(49) + LM75(4A)] > 190 => set Fan speed value from 7 to 9 * * [LM75(48) + LM75(49) + LM75(4A)] < 170 => set Fan speed value from 5 to 4 * [LM75(48) + LM75(49) + LM75(4A)] < 178 => set Fan speed value from 7 to 5 * [LM75(48) + LM75(49) + LM75(4A)] < 186 => set Fan speed value from 9 to 7 * * * For AC power Back to Front : * * If any fan fail, please fan speed register to 15 * * The max value of Fan speed register is 10 * [LM75(48) + LM75(49) + LM75(4A)] > 140 => set Fan speed value from 4 to 5 * [LM75(48) + LM75(49) + LM75(4A)] > 150 => set Fan speed value from 5 to 7 * [LM75(48) + LM75(49) + LM75(4A)] > 160 => set Fan speed value from 7 to 10 * * [LM75(48) + LM75(49) + LM75(4A)] < 135 => set Fan speed value from 5 to 4 * [LM75(48) + LM75(49) + LM75(4A)] < 145 => set Fan speed value from 7 to 5 * [LM75(48) + LM75(49) + LM75(4A)] < 155 => set Fan speed value from 10 to 7 */ int onlp_sysi_platform_manage_fans(void) { int i = 0, arr_size, temp; fan_ctrl_policy_t *policy; int cur_duty_cycle, new_duty_cycle; onlp_thermal_info_t thermal_1, thermal_2, thermal_3; int fd, len; char buf[10] = {0}; /* Get each fan status */ for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++) { onlp_fan_info_t fan_info; if (onlp_fan_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to get fan(%d) status\r\n", i); return ONLP_STATUS_E_INTERNAL; } /* Decision 1: Set fan as full speed if any fan is failed. */ if (fan_info.status & ONLP_FAN_STATUS_FAILED) { AIM_LOG_ERROR("Fan(%d) is not working, set the other fans as full speed\r\n", i); return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX); } /* Decision 1.1: Set fan as full speed if any fan is not present. */ if (!(fan_info.status & ONLP_FAN_STATUS_PRESENT)) { AIM_LOG_ERROR("Fan(%d) is not present, set the other fans as full speed\r\n", i); return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX); } /* Get fan direction (Only get the first one since all fan direction are the same) */ if (i == 1) { if (fan_info.status & ONLP_FAN_STATUS_F2B) { policy = fan_ctrl_policy_f2b; arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_f2b); } else { policy = fan_ctrl_policy_b2f; arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_b2f); } } } /* Get current fan speed */ fd = open(FAN_SPEED_CTRL_PATH, O_RDONLY); if (fd == -1){ AIM_LOG_ERROR("Unable to open fan speed control node (%s)", FAN_SPEED_CTRL_PATH); return ONLP_STATUS_E_INTERNAL; } len = read(fd, buf, sizeof(buf)); close(fd); if (len <= 0) { AIM_LOG_ERROR("Unable to read fan speed from (%s)", FAN_SPEED_CTRL_PATH); return ONLP_STATUS_E_INTERNAL; } cur_duty_cycle = atoi(buf); /* Decision 2: If no matched fan speed is found from the policy, * use FAN_DUTY_CYCLE_MIN as default speed */ for (i = 0; i < arr_size; i++) { if (policy[i].duty_cycle != cur_duty_cycle) continue; break; } if (i == arr_size) { return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), policy[0].duty_cycle); } /* Get current temperature */ if (onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_1) != ONLP_STATUS_OK || onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(3), &thermal_2) != ONLP_STATUS_OK || onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(4), &thermal_3) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to read thermal status"); return ONLP_STATUS_E_INTERNAL; } temp = thermal_1.mcelsius + thermal_2.mcelsius + thermal_3.mcelsius; /* Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature */ new_duty_cycle = cur_duty_cycle; if ((temp >= policy[i].temp_up_adjust) && (i != (arr_size-1))) { new_duty_cycle = policy[i+1].duty_cycle; } else if ((temp <= policy[i].temp_down_adjust) && (i != 0)) { new_duty_cycle = policy[i-1].duty_cycle; } if (new_duty_cycle == cur_duty_cycle) { /* Duty cycle does not change, just return */ return ONLP_STATUS_OK; } return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), new_duty_cycle); }
void onlp_thermal_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags) { int rv; iof_t iof; onlp_thermal_info_t ti; VALIDATENR(id); int yaml; onlp_oid_show_iof_init_default(&iof, pvs, flags); rv = onlp_thermal_info_get(id, &ti); yaml = flags & ONLP_OID_SHOW_YAML; if(yaml) { iof_push(&iof, "- "); iof_iprintf(&iof, "Name: Thermal %d", ONLP_OID_ID_GET(id)); } else { iof_push(&iof, "Thermal %d", ONLP_OID_ID_GET(id)); } if(rv < 0) { if(yaml) { iof_iprintf(&iof, "State: Error"); iof_iprintf(&iof, "Error: %{onlp_status}", rv); } else { onlp_oid_info_get_error(&iof, rv); } } else { onlp_oid_show_description(&iof, &ti.hdr); if(ti.status & 0x1) { /* Present */ if(ti.status & ONLP_THERMAL_STATUS_FAILED) { iof_iprintf(&iof, "Status: Failed"); } else { iof_iprintf(&iof, "Status: Functional"); if(ti.caps & ONLP_THERMAL_CAPS_GET_TEMPERATURE) { iof_iprintf(&iof, "Temperature: %d.%d C", ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.mcelsius)); } #if ONLP_CONFIG_INCLUDE_THERMAL_THRESHOLDS == 1 if(ti.caps & ONLP_THERMAL_CAPS_GET_ANY_THRESHOLD) { iof_push(&iof, "Thresholds:"); if(ti.caps & ONLP_THERMAL_CAPS_GET_WARNING_THRESHOLD) { iof_iprintf(&iof, "Warning : %d.%d C", ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.thresholds.warning)); } if(ti.caps & ONLP_THERMAL_CAPS_GET_ERROR_THRESHOLD) { iof_iprintf(&iof, "Error : %d.%d C", ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.thresholds.error)); } if(ti.caps & ONLP_THERMAL_CAPS_GET_SHUTDOWN_THRESHOLD) { iof_iprintf(&iof, "Shutdown: %d.%d C", ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.thresholds.shutdown)); } iof_pop(&iof); } #endif } } else { /* Not present */ onlp_oid_show_state_missing(&iof); } } iof_pop(&iof); }
int onlp_sysi_platform_manage_fans(void) { int rc; onlp_thermal_info_t ti2, ti3, ti4; int mtemp=0; int new_rpm=0; if (chassis_fan_count() == 0) { return ONLP_STATUS_E_UNSUPPORTED; } /* Get temperature */ /*rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(1), &ti1); if (rc != ONLP_STATUS_OK) { return rc; }*/ rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &ti2); if (rc != ONLP_STATUS_OK) { return rc; } rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(3), &ti3); if (rc != ONLP_STATUS_OK) { return rc; } rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(4), &ti4); if (rc != ONLP_STATUS_OK) { return rc; } mtemp=(ti2.mcelsius+ti3.mcelsius + ti4.mcelsius) / 3; DEBUG_PRINT("mtemp %d\n", mtemp); /* Bring fan speed according the temp */ if(mtemp<25000) new_rpm=FAN_IDLE_RPM; else if((mtemp>=30000)&&(mtemp<40000)) new_rpm=FAN_LEVEL1_RPM; else if((mtemp>=45000)&&(mtemp<55000)) new_rpm=FAN_LEVEL2_RPM; else if((mtemp>=60000)&&(mtemp<75000)) new_rpm=FAN_LEVEL3_RPM; else if(mtemp>=80000) new_rpm=FAN_LEVEL4_RPM; else{ return ONLP_STATUS_OK; } onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(1),new_rpm); onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(2),new_rpm); onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(3),new_rpm); onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(4),new_rpm); onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(5),new_rpm); onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(6),new_rpm); return ONLP_STATUS_OK; }