| 1036 | return cache_info |
| 1037 | |
| 1038 | def get_ticks(self): |
| 1039 | retval = None |
| 1040 | |
| 1041 | if DataSource.bits == '32bit': |
| 1042 | # Works on x86_32 |
| 1043 | restype = None |
| 1044 | argtypes = (ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint)) |
| 1045 | get_ticks_x86_32, address = self._asm_func(restype, argtypes, |
| 1046 | [ |
| 1047 | b"\x55", # push bp |
| 1048 | b"\x89\xE5", # mov bp,sp |
| 1049 | b"\x31\xC0", # xor ax,ax |
| 1050 | b"\x0F\xA2", # cpuid |
| 1051 | b"\x0F\x31", # rdtsc |
| 1052 | b"\x8B\x5D\x08", # mov bx,[di+0x8] |
| 1053 | b"\x8B\x4D\x0C", # mov cx,[di+0xc] |
| 1054 | b"\x89\x13", # mov [bp+di],dx |
| 1055 | b"\x89\x01", # mov [bx+di],ax |
| 1056 | b"\x5D", # pop bp |
| 1057 | b"\xC3" # ret |
| 1058 | ] |
| 1059 | ) |
| 1060 | |
| 1061 | high = ctypes.c_uint32(0) |
| 1062 | low = ctypes.c_uint32(0) |
| 1063 | |
| 1064 | get_ticks_x86_32(ctypes.byref(high), ctypes.byref(low)) |
| 1065 | retval = ((high.value << 32) & 0xFFFFFFFF00000000) | low.value |
| 1066 | elif DataSource.bits == '64bit': |
| 1067 | # Works on x86_64 |
| 1068 | restype = ctypes.c_uint64 |
| 1069 | argtypes = () |
| 1070 | get_ticks_x86_64, address = self._asm_func(restype, argtypes, |
| 1071 | [ |
| 1072 | b"\x48", # dec ax |
| 1073 | b"\x31\xC0", # xor ax,ax |
| 1074 | b"\x0F\xA2", # cpuid |
| 1075 | b"\x0F\x31", # rdtsc |
| 1076 | b"\x48", # dec ax |
| 1077 | b"\xC1\xE2\x20", # shl dx,byte 0x20 |
| 1078 | b"\x48", # dec ax |
| 1079 | b"\x09\xD0", # or ax,dx |
| 1080 | b"\xC3", # ret |
| 1081 | ] |
| 1082 | ) |
| 1083 | retval = get_ticks_x86_64() |
| 1084 | |
| 1085 | return retval |
| 1086 | |
| 1087 | def get_raw_hz(self): |
| 1088 | start = self.get_ticks() |