MULTI2のベンチマークテストを追加
This commit is contained in:
parent
b34bf17209
commit
d258f82043
@ -9,6 +9,16 @@
|
||||
#include "ts_common_types.h"
|
||||
#include "ts_section_parser.h"
|
||||
|
||||
#ifdef USE_BENCHMARK
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
inner structures
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
@ -428,6 +438,8 @@ static void extract_emm_fixed_part(EMM_FIXED_PART *dst, uint8_t *src);
|
||||
static uint8_t *resync(uint8_t *head, uint8_t *tail, int32_t unit);
|
||||
static uint8_t *resync_force(uint8_t *head, uint8_t *tail, int32_t unit);
|
||||
|
||||
static void fill_random_bytes(uint8_t *data, size_t size);
|
||||
|
||||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
interface method implementation
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
@ -2918,3 +2930,79 @@ static uint8_t *resync_force(uint8_t *head, uint8_t *tail, int32_t unit_size)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void fill_random_bytes(uint8_t *data, size_t size)
|
||||
{
|
||||
uint8_t mask = 0xFF;
|
||||
|
||||
srand(1234);
|
||||
for(size_t i=0;i<size;i++){
|
||||
data[i] = (uint8_t)(rand() & mask);
|
||||
}
|
||||
}
|
||||
|
||||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
test function implementation
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#ifdef USE_BENCHMARK
|
||||
#define PACKETS_PER_SEC 10000
|
||||
int test_multi2_decryption(void *std_b25, int64_t *time, int32_t instruction, int32_t round)
|
||||
{
|
||||
uint8_t system_key[32];
|
||||
uint8_t init_cbc[8];
|
||||
uint8_t scramble_key[4][16];
|
||||
uint8_t test_data[192];
|
||||
#if defined(_WIN32)
|
||||
int32_t start_time = 0;
|
||||
#else
|
||||
struct timeval start_time,end_time;
|
||||
#endif
|
||||
int32_t type = 2;
|
||||
|
||||
MULTI2 *m2;
|
||||
ARIB_STD_B25_PRIVATE_DATA *prv;
|
||||
|
||||
prv = private_data(std_b25);
|
||||
if(prv == NULL){
|
||||
return ARIB_STD_B25_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
m2 = create_multi2();
|
||||
if(m2 == NULL){
|
||||
return ARIB_STD_B25_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fill_random_bytes(system_key, sizeof(system_key));
|
||||
fill_random_bytes(init_cbc, sizeof(init_cbc));
|
||||
fill_random_bytes(&scramble_key[0][0], sizeof(scramble_key));
|
||||
fill_random_bytes(test_data, sizeof(test_data));
|
||||
|
||||
m2->set_simd(m2, (enum INSTRUCTION_TYPE)instruction);
|
||||
m2->set_system_key(m2, system_key);
|
||||
m2->set_init_cbc(m2, init_cbc);
|
||||
m2->set_round(m2, prv->multi2_round);
|
||||
|
||||
#if defined(_WIN32)
|
||||
start_time = timeGetTime();
|
||||
#else
|
||||
gettimeofday(&start_time, NULL);
|
||||
#endif
|
||||
for(int32_t i=0;i<round;i++){
|
||||
if(i % PACKETS_PER_SEC == 0){
|
||||
m2->set_scramble_key(m2, scramble_key[(i/PACKETS_PER_SEC) % (sizeof(scramble_key)/sizeof(scramble_key[0]))]);
|
||||
type = type == 2 ? 3 : 2;
|
||||
}
|
||||
m2->decrypt(m2, type, test_data, 184);
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
*time += timeGetTime() - start_time;
|
||||
#else
|
||||
gettimeofday(&end_time, NULL);
|
||||
*time = (int64_t)(start_time.tv_sec - end_time.tv_sec) * 1000;
|
||||
*time += (int64_t)(start_time.tv_usec - end_time.tv_usec) / 1000;
|
||||
#endif
|
||||
|
||||
m2->release(m2);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -58,6 +58,10 @@ extern "C" {
|
||||
|
||||
extern ARIB_STD_B25 *create_arib_std_b25(void);
|
||||
|
||||
#ifdef USE_BENCHMARK
|
||||
extern int test_multi2_decryption(void *std_b25, int64_t *time, int32_t instructin, int32_t round);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -91,7 +91,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -111,7 +111,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>USE_BENCHMARK;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
@ -128,7 +128,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader />
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@ -155,7 +155,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>USE_BENCHMARK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
|
119
aribb25/td.c
119
aribb25/td.c
@ -8,6 +8,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
@ -40,12 +41,15 @@ typedef struct {
|
||||
int32_t emm;
|
||||
int32_t verbose;
|
||||
int32_t power_ctrl;
|
||||
int32_t simd_instruction;
|
||||
int32_t benchmark;
|
||||
} OPTION;
|
||||
|
||||
static void show_usage();
|
||||
static int parse_arg(OPTION *dst, int argc, TCHAR **argv);
|
||||
static void test_arib_std_b25(const TCHAR *src, const TCHAR *dst, OPTION *opt);
|
||||
static void show_bcas_power_on_control_info(B_CAS_CARD *bcas);
|
||||
static void run_multi2_benchmark_test(OPTION *opt);
|
||||
|
||||
int _tmain(int argc, TCHAR **argv)
|
||||
{
|
||||
@ -63,10 +67,14 @@ int _tmain(int argc, TCHAR **argv)
|
||||
#endif
|
||||
|
||||
n = parse_arg(&opt, argc, argv);
|
||||
if(n+2 > argc){
|
||||
if(n+2 > argc && opt.benchmark == 0){
|
||||
show_usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(opt.benchmark == 1){
|
||||
run_multi2_benchmark_test(&opt);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for(;n<=(argc-2);n+=2){
|
||||
test_arib_std_b25(argv[n+0], argv[n+1], &opt);
|
||||
@ -97,6 +105,12 @@ static void show_usage()
|
||||
_ftprintf(stderr, _T(" -v verbose\n"));
|
||||
_ftprintf(stderr, _T(" 0: silent\n"));
|
||||
_ftprintf(stderr, _T(" 1: show processing status (default)\n"));
|
||||
_ftprintf(stderr, _T(" -i instruction\n"));
|
||||
_ftprintf(stderr, _T(" 0: use no SIMD instruction\n"));
|
||||
_ftprintf(stderr, _T(" 1: use SSE2 instruction if available\n"));
|
||||
_ftprintf(stderr, _T(" 2: use SSSE3 instruction if available\n"));
|
||||
_ftprintf(stderr, _T(" 3: use AVX2 instruction if available (default)\n"));
|
||||
_ftprintf(stderr, _T(" -b MULTI2 benchmark test for SIMD\n"));
|
||||
_ftprintf(stderr, _T("\n"));
|
||||
}
|
||||
|
||||
@ -109,6 +123,8 @@ static int parse_arg(OPTION *dst, int argc, TCHAR **argv)
|
||||
dst->emm = 0;
|
||||
dst->power_ctrl = 1;
|
||||
dst->verbose = 1;
|
||||
dst->simd_instruction = 3;
|
||||
dst->benchmark = 0;
|
||||
|
||||
for(i=1;i<argc;i++){
|
||||
if(argv[i][0] != '-'){
|
||||
@ -155,6 +171,17 @@ static int parse_arg(OPTION *dst, int argc, TCHAR **argv)
|
||||
i += 1;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
if(argv[i][2]){
|
||||
dst->simd_instruction = _ttoi(argv[i]+2);
|
||||
}else{
|
||||
dst->simd_instruction = _ttoi(argv[i+1]);
|
||||
i += 1;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
dst->benchmark = 1;
|
||||
break;
|
||||
default:
|
||||
_ftprintf(stderr, _T("error - unknown option '-%c'\n"), argv[i][1]);
|
||||
return argc;
|
||||
@ -230,6 +257,12 @@ static void test_arib_std_b25(const TCHAR *src, const TCHAR *dst, OPTION *opt)
|
||||
goto LAST;
|
||||
}
|
||||
|
||||
code = b25->set_simd_mode(b25, opt->simd_instruction);
|
||||
if(code < 0){
|
||||
_ftprintf(stderr, _T("error - failed on ARIB_STD_B25::set_simd_mode() : code=%d\n"), code);
|
||||
goto LAST;
|
||||
}
|
||||
|
||||
bcas = create_b_cas_card();
|
||||
if(bcas == NULL){
|
||||
_ftprintf(stderr, _T("error - failed on create_b_cas_card()\n"));
|
||||
@ -464,3 +497,87 @@ static void show_bcas_power_on_control_info(B_CAS_CARD *bcas)
|
||||
_ftprintf(stdout, _T("least %d hours\n"), pwc.data[i].hold_time);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_BENCHMARK
|
||||
#define BENCHMARK_ROUND 200000
|
||||
#define MAX_INSTRUCTION 4
|
||||
static void run_multi2_benchmark_test(OPTION *opt)
|
||||
{
|
||||
int code;
|
||||
|
||||
const TCHAR *INSTRUCTION_NAMES[MAX_INSTRUCTION] = {_T("normal"), _T("SSE2"), _T("SSSE3"), _T("AVX2")};
|
||||
int64_t totals[MAX_INSTRUCTION];
|
||||
int64_t base_time;
|
||||
int64_t max_time;
|
||||
int32_t time_percentage;
|
||||
int32_t supported_mode;
|
||||
uint32_t test_count;
|
||||
|
||||
ARIB_STD_B25 *b25;
|
||||
|
||||
b25 = create_arib_std_b25();
|
||||
if(b25 == NULL){
|
||||
_ftprintf(stderr, _T("error - failed on create_arib_std_b25()\n"));
|
||||
goto LAST;
|
||||
}
|
||||
supported_mode = b25->get_simd_mode(b25);
|
||||
|
||||
code = b25->set_multi2_round(b25, opt->round);
|
||||
if(code < 0){
|
||||
_ftprintf(stderr, _T("error - failed on ARIB_STD_B25::set_multi2_round() : code=%d\n"), code);
|
||||
goto LAST;
|
||||
}
|
||||
|
||||
code = b25->set_strip(b25, opt->strip);
|
||||
if(code < 0){
|
||||
_ftprintf(stderr, _T("error - failed on ARIB_STD_B25::set_strip() : code=%d\n"), code);
|
||||
goto LAST;
|
||||
}
|
||||
|
||||
_ftprintf(stdout, _T("running - MULTI2 benchmark test\n"));
|
||||
|
||||
memset(totals, 0, sizeof(totals));
|
||||
max_time = INT64_MIN;
|
||||
test_count = 0;
|
||||
do{
|
||||
for(int32_t i=0;i<MAX_INSTRUCTION;i++){
|
||||
code = test_multi2_decryption(b25, &totals[i], i, BENCHMARK_ROUND);
|
||||
if(code >= 0){
|
||||
if(totals[i] > max_time){
|
||||
max_time = totals[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
test_count += BENCHMARK_ROUND;
|
||||
}while(max_time < 1500);
|
||||
|
||||
_ftprintf(stdout, _T("complete - MULTI2 benchmark test (count=%u)\n"), test_count);
|
||||
base_time = totals[0];
|
||||
for(int32_t i=0;i<MAX_INSTRUCTION;i++){
|
||||
_ftprintf(stdout, _T(" %-6s: %5" PRId64 " ms [%8d packets/s]"), INSTRUCTION_NAMES[i], totals[i], (int32_t)round(test_count*1000LL/(double)totals[i]));
|
||||
if(i == 0){
|
||||
_ftprintf(stdout, _T("\n"));
|
||||
continue;
|
||||
}
|
||||
if(totals[i] < base_time){
|
||||
time_percentage = (int32_t)(base_time*100/totals[i]) - 100;
|
||||
}else{
|
||||
time_percentage = -(int32_t)(totals[i]*100/base_time) - 100;
|
||||
}
|
||||
|
||||
_ftprintf(stdout, _T(" (%3d%% faster)\n"), time_percentage);
|
||||
}
|
||||
|
||||
LAST:
|
||||
|
||||
if(b25 != NULL){
|
||||
b25->release(b25);
|
||||
b25 = NULL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void run_multi2_benchmark_test(OPTION *opt)
|
||||
{
|
||||
_ftprintf(stdout, _T("MULTI2 benchmark test is disabled\n"));
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user