def residency(residency_counters, residency_counter_msr, sleep_time=3): bsp_apicid = bits.bsp_apicid() sockets = dict( (skt_index, min(apic_list)) for skt_index, apic_list in bits.socket_apic_ids().iteritems()) rc = {} rc_start = {} delta = {} def read_rc(apic_id): return residency_counters(*(bits.rdmsr(apic_id, msr) for msr in residency_counter_msr)) tsc = bits.rdmsr(bsp_apicid, 0x10) for apic_id in sockets.itervalues(): rc_start[apic_id] = read_rc(apic_id) bits.blocking_sleep(sleep_time * 1000 * 1000) tsc = float(bits.rdmsr(bsp_apicid, 0x10) - tsc) for apic_id in sockets.itervalues(): rc[apic_id] = read_rc(apic_id) for apic_id in sockets.itervalues(): delta[apic_id] = residency_counters( *((end - start) / tsc for end, start in zip(rc[apic_id], rc_start[apic_id]))) return delta
def residency(residency_counters, residency_counter_msr, sleep_time=3): bsp_apicid = bits.bsp_apicid() sockets = dict((skt_index, min(apic_list)) for skt_index, apic_list in bits.socket_apic_ids().iteritems()) rc = {} rc_start = {} delta = {} def read_rc(apic_id): return residency_counters(*(bits.rdmsr(apic_id, msr) for msr in residency_counter_msr)) tsc = bits.rdmsr(bsp_apicid, 0x10) for apic_id in sockets.itervalues(): rc_start[apic_id] = read_rc(apic_id) bits.blocking_sleep(sleep_time*1000*1000) tsc = float(bits.rdmsr(bsp_apicid, 0x10) - tsc) for apic_id in sockets.itervalues(): rc[apic_id] = read_rc(apic_id) for apic_id in sockets.itervalues(): delta[apic_id] = residency_counters(*((end - start) / tsc for end, start in zip(rc[apic_id], rc_start[apic_id]))) return delta
def cmd_cpu_sleep(args): bits.blocking_sleep(args.usec)