20 #include <odp/helper/odph_api.h>
23 #define MB (1024ull * 1024ull)
33 static options_t options;
34 static const options_t options_def = {
41 static void print_usage(
void)
44 "CRC performance test\n"
46 "Usage: odp_crc_perf [options]\n"
48 " -s, --size Size of buffer in KB (default %u)\n"
49 " -r, --rounds Number of test rounds (default %u)\n"
50 " Rounded down to nearest multiple of 8\n"
51 " -o, --offset Offset of data (default %u)\n"
52 " -t, --test Which API to test (default %u)\n"
54 " 1: odp_hash_crc32c\n"
55 " 2: odp_hash_crc32\n"
56 " -h, --help This help\n"
58 options_def.size, options_def.rounds, options_def.offset,
62 static int parse_options(
int argc,
char *argv[])
67 static const struct option longopts[] = {
68 {
"size", required_argument, NULL,
's' },
69 {
"rounds", required_argument, NULL,
'r' },
70 {
"offset", required_argument, NULL,
'o' },
71 {
"test", required_argument, NULL,
't' },
72 {
"help", no_argument, NULL,
'h' },
76 static const char *shortopts =
"+s:r:o:t:h";
78 options = options_def;
81 opt = getopt_long(argc, argv, shortopts, longopts, NULL);
88 options.size = atol(optarg);
91 options.rounds = atol(optarg);
94 options.offset = atol(optarg);
97 options.test = atol(optarg);
108 if (options.size < 1) {
109 ODPH_ERR(
"Invalid size: %" PRIu32
"\n", options.size);
113 if (options.offset > 4 * KB) {
114 ODPH_ERR(
"Invalid offset: %" PRIu32
"\n", options.offset);
118 if (options.test > 2) {
119 ODPH_ERR(
"Invalid API to test: %" PRIu32
"\n", options.test);
126 static void report(uint64_t nsec)
128 uint64_t size = (uint64_t)options.size * KB;
129 uint32_t rounds = options.rounds & ~7ul;
132 printf(
"size: %d KB rounds: %d offset: %d ",
133 options.size, rounds, options.offset);
134 mb = (double)(size * (uint64_t)rounds) / (
double)MB;
136 printf(
"MB: %.3f seconds: %.3f ", mb, seconds);
137 printf(
"MB/s: %.3f", mb / seconds);
141 static uint64_t measure_crc32c(uint8_t *data, uint32_t size)
143 void *p = data + options.offset;
148 for (uint32_t i = 0; i < options.rounds / 8; i++) {
169 static void test_odp_hash_crc32c(uint8_t *data)
171 uint64_t size = (uint64_t)options.size * KB;
175 measure_crc32c(data, size);
178 nsec = measure_crc32c(data, size);
183 static uint64_t measure_crc32(uint8_t *data, uint32_t size)
185 void *p = data + options.offset;
190 for (uint32_t i = 0; i < options.rounds / 8; i++) {
211 static void test_odp_hash_crc32(uint8_t *data)
213 uint64_t size = (uint64_t)options.size * KB;
217 measure_crc32(data, size);
220 nsec = measure_crc32(data, size);
225 int main(
int argc,
char **argv)
230 if (parse_options(argc, argv))
246 ODPH_ERR(
"Global init failed.\n");
252 ODPH_ERR(
"Local init failed.\n");
259 uint32_t size = options.size * KB;
261 const unsigned long page = 4 * KB;
264 buf = (uint8_t *)malloc(size + page * 2);
267 ODPH_ERR(
"Memory allocation failed.\n");
272 data = (uint8_t *)(((uintptr_t)buf + (page - 1)) & ~(page - 1));
275 ODPH_ERR(
"odp_random_test_data() failed.\n");
279 if (options.test == 0 || options.test == 1) {
280 printf(
"odp_hash_crc32c\n"
281 "---------------\n");
282 test_odp_hash_crc32c(data);
285 if (options.test == 0 || options.test == 2) {
286 printf(
"odp_hash_crc32\n"
288 test_odp_hash_crc32(data);
294 ODPH_ERR(
"Local terminate failed.\n");
299 ODPH_ERR(
"Global terminate failed.\n");
uint32_t odp_hash_crc32(const void *data, uint32_t data_len, uint32_t init_val)
Calculate CRC-32.
uint32_t odp_hash_crc32c(const void *data, uint32_t data_len, uint32_t init_val)
Calculate CRC-32C.
void odp_init_param_init(odp_init_t *param)
Initialize the odp_init_t to default values for all fields.
int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type)
Thread local ODP initialization.
int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params)
Global ODP initialization.
int odp_term_local(void)
Thread local ODP termination.
int odp_term_global(odp_instance_t instance)
Global ODP termination.
uint64_t odp_instance_t
ODP instance ID.
int32_t odp_random_test_data(uint8_t *buf, uint32_t len, uint64_t *seed)
Generate repeatable random data for testing purposes.
void odp_sys_info_print(void)
Print system info.
@ ODP_THREAD_CONTROL
Control thread.
#define ODP_TIME_SEC_IN_NS
A second in nanoseconds.
odp_time_t odp_time_local(void)
Current local time.
uint64_t odp_time_diff_ns(odp_time_t t2, odp_time_t t1)
Time difference in nanoseconds.
Global initialization parameters.
odp_feature_t not_used
Unused features.
uint32_t tm
Traffic Manager APIs, e.g., odp_tm_xxx()
uint32_t stash
Stash APIs, e.g., odp_stash_xxx()
uint32_t crypto
Crypto APIs, e.g., odp_crypto_xxx()
uint32_t ipsec
IPsec APIs, e.g., odp_ipsec_xxx()
uint32_t timer
Timer APIs, e.g., odp_timer_xxx(), odp_timeout_xxx()
uint32_t cls
Classifier APIs, e.g., odp_cls_xxx(), odp_cos_xxx()
uint32_t schedule
Scheduler APIs, e.g., odp_schedule_xxx()
struct odp_feature_t::@148 feat
Individual feature bits.
uint32_t compress
Compression APIs, e.g., odp_comp_xxx()