diff options
author | Rodeo <[email protected]> | 2013-07-13 18:43:44 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2013-07-13 18:43:44 +0000 |
commit | 0c5cdc16d8c8cb336f052554c1489f2d5badde72 (patch) | |
tree | be2780f7cee80c8fbc611428d74e71ef26a78976 | |
parent | 8228a6411ed3c76d521dc398ddb5329154786f43 (diff) |
libhb: store and print additional CPU information
Printed in hb_scan(), so that it's present in all Activity Logs (both encode and scan).
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5648 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/hb.c | 13 | ||||
-rw-r--r-- | libhb/ports.c | 136 | ||||
-rw-r--r-- | libhb/ports.h | 18 |
3 files changed, 156 insertions, 11 deletions
diff --git a/libhb/hb.c b/libhb/hb.c index 0c475abd2..2a9ed1070 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -512,7 +512,7 @@ hb_handle_t * hb_init_dl( int verbose, int update_check ) h->main_thread = hb_thread_init( "libhb", thread_func, h, HB_NORMAL_PRIORITY ); - return h; + return h; } @@ -611,6 +611,17 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index, hb_title_close( &title ); } + /* Print CPU info here so that it's in all scan and encode logs */ + hb_log("hb_scan: CPU count: %i", hb_get_cpu_count()); + if (hb_get_cpu_name() != NULL) + { + hb_log("hb_scan: CPU name: %s", hb_get_cpu_name()); + } + if (hb_get_cpu_platform_name() != NULL) + { + hb_log("hb_scan: CPU type: %s", hb_get_cpu_platform_name()); + } + hb_log( "hb_scan: path=%s, title_index=%d", path, title_index ); h->scan_thread = hb_scan_init( h, &h->scan_die, path, title_index, &h->title_set, preview_count, diff --git a/libhb/ports.c b/libhb/ports.c index 64b68bcb4..9b9ab0200 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -74,6 +74,7 @@ #include <unistd.h> #include "hb.h" +#include "libavutil/cpu.h" /************************************************************************ * hb_get_date() @@ -161,21 +162,136 @@ void hb_snooze( int delay ) } /************************************************************************ - * hb_get_cpu_count() - ************************************************************************ - * Whenever possible, returns the number of CPUs on the current - * computer. Returns 1 otherwise. - * The detection is actually only performed on the first call. + * Get information about the CPU (number of cores, name, platform name) ************************************************************************/ +static void init_cpu_info(); +static int init_cpu_count(); +struct +{ + enum hb_cpu_platform platform; + const char *name; + char buf[48]; + int count; +} hb_cpu_info; + int hb_get_cpu_count() { - static int cpu_count = 0; + return hb_cpu_info.count; +} + +int hb_get_cpu_platform() +{ + return hb_cpu_info.platform; +} + +const char* hb_get_cpu_name() +{ + return hb_cpu_info.name; +} + +const char* hb_get_cpu_platform_name() +{ + switch (hb_cpu_info.platform) + { + // Intel 64 and IA-32 Architectures Software Developer's Manual, Vol. 3C + // Table 35-1: CPUID Signature Values of DisplayFamily_DisplayModel + case HB_CPU_PLATFORM_INTEL_SNB: + return "Intel microarchitecture Sandy Bridge"; + case HB_CPU_PLATFORM_INTEL_IVB: + return "Intel microarchitecture Ivy Bridge"; + case HB_CPU_PLATFORM_INTEL_HSW: + return "Intel microarchitecture Haswell"; + + default: + return NULL; + } +} + +static void init_cpu_info() +{ + hb_cpu_info.name = NULL; + hb_cpu_info.count = init_cpu_count(); + hb_cpu_info.platform = HB_CPU_PLATFORM_UNSPECIFIED; - if( cpu_count ) + if (av_get_cpu_flags() & AV_CPU_FLAG_SSE) { - return cpu_count; + int eax, ebx, ecx, edx, family, model; + + ff_cpu_cpuid(1, &eax, &ebx, &ecx, &edx); + family = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); + model = ((eax >> 4) & 0xf) + ((eax >> 12) & 0xf0); + + // Intel 64 and IA-32 Architectures Software Developer's Manual, Vol. 3C + // Table 35-1: CPUID Signature Values of DisplayFamily_DisplayModel + switch (family) + { + case 0x06: + { + switch (model) + { + case 0x2A: + case 0x2D: + hb_cpu_info.platform = HB_CPU_PLATFORM_INTEL_SNB; + break; + case 0x3A: + case 0x3E: + hb_cpu_info.platform = HB_CPU_PLATFORM_INTEL_IVB; + break; + case 0x3C: + case 0x45: + case 0x46: + hb_cpu_info.platform = HB_CPU_PLATFORM_INTEL_HSW; + break; + default: + break; + } + } break; + + default: + break; + } + + // Intel 64 and IA-32 Architectures Software Developer's Manual, Vol. 2A + // Figure 3-8: Determination of Support for the Processor Brand String + // Table 3-17: Information Returned by CPUID Instruction + ff_cpu_cpuid(0x80000000, &eax, &ebx, &ecx, &edx); + if ((eax & 0x80000004) < 0x80000004) + { + ff_cpu_cpuid(0x80000002, + (int*)&hb_cpu_info.buf[ 0], + (int*)&hb_cpu_info.buf[ 4], + (int*)&hb_cpu_info.buf[ 8], + (int*)&hb_cpu_info.buf[12]); + ff_cpu_cpuid(0x80000003, + (int*)&hb_cpu_info.buf[16], + (int*)&hb_cpu_info.buf[20], + (int*)&hb_cpu_info.buf[24], + (int*)&hb_cpu_info.buf[28]); + ff_cpu_cpuid(0x80000004, + (int*)&hb_cpu_info.buf[32], + (int*)&hb_cpu_info.buf[36], + (int*)&hb_cpu_info.buf[40], + (int*)&hb_cpu_info.buf[44]); + + hb_cpu_info.name = hb_cpu_info.buf; + hb_cpu_info.buf[47] = '\0'; // just in case + + while (isspace(*hb_cpu_info.name)) + { + // skip leading whitespace to prettify + hb_cpu_info.name++; + } + } } - cpu_count = 1; +} + +/* + * Whenever possible, returns the number of CPUs on the current computer. + * Returns 1 otherwise. + */ +static int init_cpu_count() +{ + int cpu_count = 1; #if defined(SYS_CYGWIN) || defined(SYS_MINGW) SYSTEM_INFO cpuinfo; @@ -263,6 +379,8 @@ int hb_platform_init() } #endif + init_cpu_info(); + return result; } diff --git a/libhb/ports.h b/libhb/ports.h index 10d01935b..38921300d 100644 --- a/libhb/ports.h +++ b/libhb/ports.h @@ -17,11 +17,27 @@ #endif /************************************************************************ + * CPU info utilities + ***********************************************************************/ +enum hb_cpu_platform +{ + // list of microarchitecture codenames + HB_CPU_PLATFORM_UNSPECIFIED = 0, + HB_CPU_PLATFORM_INTEL_SNB, + HB_CPU_PLATFORM_INTEL_IVB, + HB_CPU_PLATFORM_INTEL_HSW, +}; +int hb_get_cpu_count(); +int hb_get_cpu_platform(); +const char* hb_get_cpu_name(); +const char* hb_get_cpu_platform_name(); +extern void ff_cpu_cpuid(int index, int *eax, int *ebx, int *ecx, int *edx); + +/************************************************************************ * Utils ***********************************************************************/ uint64_t hb_get_date(); void hb_snooze( int delay ); -int hb_get_cpu_count(); int hb_platform_init(); #ifdef SYS_MINGW char *strtok_r(char *s, const char *delim, char **save_ptr); |