def __init__(self, log_file, log_level):
        """Needs a logger and a logger level."""
        # set up logging to file
        logging.basicConfig(
            filename=log_file,
            filemode='w',
            level=log_level,
            format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
            datefmt='%H:%M:%S'
        )

        # set up logging to console
        if log_level == logging.DEBUG:
            console = logging.StreamHandler()
            console.setLevel(log_level)
            formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
            console.setFormatter(formatter)
            logging.getLogger('').addHandler(console)

        logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)

        self.thermal = ThermalUtil()
        self.fan = FanUtil()
    def manage_fans(self):
        max_duty = 100
        fan_policy_f2b = {
           0: [32, 0,      105000],
           1: [50, 105000, 120000],
           2: [63, 120000, 135000],
           3: [max_duty, 135000, sys.maxsize],
        }
        fan_policy_b2f = {
           0: [44, 0,      105000],
           1: [63, 105000, 120000],
           2: [75, 120000, 135000],
           3: [max_duty, 135000, sys.maxsize],
        }
        fan_policy_single = {
           0: 40000,
           1: 45000,
           2: 50000,
        }
  
        thermal = ThermalUtil()
        fan = FanUtil()
        for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1):
            fan_status = fan.get_fan_status(x)
            if fan_status is None:
                logging.debug('INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)', max_duty, x)
                return False
            if fan_status is False:             
                logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', max_duty, x)
                fan.set_fan_duty_cycle(max_duty)
                return True
            #logging.debug('INFO. fan_status is True (fan_num:%d)', x)
 
        fan_dir=fan.get_fan_dir(1)
        if fan_dir == 1:
            fan_policy = fan_policy_f2b
        else:
            fan_policy = fan_policy_b2f
       
        #Decide fan duty by if any of sensors > fan_policy_single. 
        new_duty_cycle = fan_policy[0][0]
        for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1):
            single_thm = thermal._get_thermal_node_val(x)
            for y in range(0, len(fan_policy_single)):
                if single_thm > fan_policy_single[y]:
                    if fan_policy[y+1][0] > new_duty_cycle:
                        new_duty_cycle = fan_policy[y+1][0]
                        logging.debug('INFO. Single thermal sensor %d with temp %d > %d , new_duty_cycle=%d', 
                                x, single_thm, fan_policy_single[y], new_duty_cycle)
	single_result = new_duty_cycle	


        #Find if current duty matched any of define duty. 
	#If not, set it to highest one.
        cur_duty_cycle = fan.get_fan_duty_cycle()       
        for x in range(0, len(fan_policy)):
            if cur_duty_cycle == fan_policy[x][0]:
                break
        if x == len(fan_policy) :
            fan.set_fan_duty_cycle(fan_policy[0][0])
            cur_duty_cycle = max_duty

        #Decide fan duty by if sum of sensors falls into any of fan_policy{}
        get_temp = thermal.get_thermal_temp()            
        new_duty_cycle = cur_duty_cycle
        for x in range(0, len(fan_policy)):
            y = len(fan_policy) - x -1 #checked from highest
            if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2] :
                new_duty_cycle= fan_policy[y][0]
                logging.debug('INFO. Sum of temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy[y][1], new_duty_cycle)

	sum_result = new_duty_cycle
	if (sum_result>single_result): 
		new_duty_cycle = sum_result;
	else:
		new_duty_cycle = single_result

        logging.debug('INFO. Final duty_cycle=%d', new_duty_cycle)
        if(new_duty_cycle != cur_duty_cycle):
            fan.set_fan_duty_cycle(new_duty_cycle)
        return True
Пример #3
0
    def manage_fans(self):
        max_duty = DUTY_MAX
        fan_policy_f2b = {
            0: [32, 0, 105000],
            1: [50, 105000, 120000],
            2: [63, 120000, 135000],
            3: [max_duty, 135000, sys.maxsize],
        }
        fan_policy_b2f = {
            0: [44, 0, 105000],
            1: [63, 105000, 120000],
            2: [75, 120000, 135000],
            3: [max_duty, 135000, sys.maxsize],
        }
        fan_policy_single = {
            0: 40000,
            1: 45000,
            2: 50000,
        }

        thermal = ThermalUtil()
        fan = FanUtil()
        for x in range(fan.get_idx_fan_start(), fan.get_num_fans() + 1):
            fan_status = fan.get_fan_status(x)
            if fan_status is None:
                logging.debug(
                    'INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)',
                    max_duty, x)
                return False
            if fan_status is False:
                logging.debug(
                    'INFO. SET new_perc to %d (FAN fault. fan_num:%d)',
                    max_duty, x)
                fan.set_fan_duty_cycle(max_duty)
                return True
            #logging.debug('INFO. fan_status is True (fan_num:%d)', x)

        fan_dir = fan.get_fan_dir(1)
        if fan_dir == 1:
            fan_policy = fan_policy_f2b
        else:
            fan_policy = fan_policy_b2f

        #Decide fan duty by if any of sensors > fan_policy_single.
        new_duty_cycle = fan_policy[0][0]
        for x in range(thermal.get_idx_thermal_start(),
                       thermal.get_num_thermals() + 1):
            single_thm = thermal._get_thermal_node_val(x)
            for y in range(0, len(fan_policy_single)):
                if single_thm > fan_policy_single[y]:
                    if fan_policy[y + 1][0] > new_duty_cycle:
                        new_duty_cycle = fan_policy[y + 1][0]
                        logging.debug(
                            'INFO. Single thermal sensor %d with temp %d > %d , new_duty_cycle=%d',
                            x, single_thm, fan_policy_single[y],
                            new_duty_cycle)
        single_result = new_duty_cycle

        #Find if current duty matched any of define duty.
        #If not, set it to highest one.
        cur_duty_cycle = fan.get_fan_duty_cycle()
        for x in range(0, len(fan_policy)):
            if cur_duty_cycle == fan_policy[x][0]:
                break
        if x == len(fan_policy):
            fan.set_fan_duty_cycle(fan_policy[0][0])
            cur_duty_cycle = max_duty

        #Decide fan duty by if sum of sensors falls into any of fan_policy{}
        get_temp = thermal.get_thermal_temp()
        new_duty_cycle = cur_duty_cycle
        for x in range(0, len(fan_policy)):
            y = len(fan_policy) - x - 1  #checked from highest
            if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2]:
                new_duty_cycle = fan_policy[y][0]
                logging.debug('INFO. Sum of temp %d > %d , new_duty_cycle=%d',
                              get_temp, fan_policy[y][1], new_duty_cycle)

        sum_result = new_duty_cycle
        if (sum_result > single_result):
            new_duty_cycle = sum_result
        else:
            new_duty_cycle = single_result

        logging.debug('INFO. Final duty_cycle=%d', new_duty_cycle)
        if (new_duty_cycle != cur_duty_cycle):
            fan.set_fan_duty_cycle(new_duty_cycle)
        return True
Пример #4
0
def handler(signum, frame):
    fan = FanUtil()
    logging.debug('INFO:Cause signal %d, set fan speed max.', signum)
    fan.set_fan_duty_cycle(DUTY_MAX)
    sys.exit(0)