diff options
author | Matias Elo <matias.elo@nokia.com> | 2022-03-01 13:56:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-01 13:56:00 +0200 |
commit | 6c96e7253082bdc5b3a6a6f39a1ced8200a39ee0 (patch) | |
tree | 908bd33aff383744a8cc18e4f8374c22ed61c46c /example | |
parent | 09a1f287c7956b36db8b3320a45e10a22058c269 (diff) | |
parent | 4c9bd497c64a8dada64e205c57c6db7dddacb1ec (diff) |
Merge ODP v1.34.0.0v1.34.0.0_DPDK_19.11
Merge ODP linux-generic v1.34.0.0 into linux-dpdk.
Diffstat (limited to 'example')
-rw-r--r-- | example/classifier/odp_classifier.c | 35 | ||||
-rw-r--r-- | example/ipfragreass/Makefile.am | 2 | ||||
-rw-r--r-- | example/ipfragreass/odp_ipfragreass.c | 10 | ||||
-rw-r--r-- | example/ipfragreass/odp_ipfragreass_atomics.h | 55 | ||||
-rw-r--r-- | example/ipfragreass/odp_ipfragreass_atomics_arm.h | 130 | ||||
-rw-r--r-- | example/ipfragreass/odp_ipfragreass_helpers.h | 6 | ||||
-rw-r--r-- | example/ipfragreass/odp_ipfragreass_reassemble.c | 38 | ||||
-rw-r--r-- | example/ipfragreass/odp_ipfragreass_reassemble.h | 40 | ||||
-rw-r--r-- | example/ipsec_crypto/odp_ipsec.c | 30 | ||||
-rw-r--r-- | example/ipsec_crypto/odp_ipsec_cache.c | 18 | ||||
-rw-r--r-- | example/ipsec_crypto/odp_ipsec_cache.h | 1 | ||||
-rw-r--r-- | example/ipsec_crypto/odp_ipsec_misc.h | 1 | ||||
-rw-r--r-- | example/timer/odp_timer_accuracy.c | 25 | ||||
-rw-r--r-- | example/traffic_mgmt/odp_traffic_mgmt.c | 95 |
14 files changed, 175 insertions, 311 deletions
diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 2c36fce0e..d22c9a7df 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -1,6 +1,6 @@ /* Copyright (c) 2015-2018, Linaro Limited - * Copyright (c) 2019-2020, Nokia - * Copyright (C) 2020, Marvell + * Copyright (c) 2019-2021, Nokia + * Copyright (c) 2020, Marvell * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -892,6 +892,10 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) len = strlen(optarg); len++; pmr_str = malloc(len); + if (pmr_str == NULL) { + ODPH_ERR("Memory allocation failed\n"); + return -1; + } strcpy(pmr_str, optarg); /* PMR TERM */ @@ -899,7 +903,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) token = strtok(pmr_str, ":"); if (convert_str_to_pmr_enum(token, &term)) { ODPH_ERR("Invalid ODP_PMR_TERM string\n"); - exit(EXIT_FAILURE); + goto error; } stats[policy_count].rule.term = term; stats[policy_count].rule.offset = 0; @@ -952,7 +956,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) if (odph_ipv4_addr_parse(&ip_addr, token)) { ODPH_ERR("Bad IP address\n"); - exit(EXIT_FAILURE); + goto error; } u32 = odp_cpu_to_be_32(ip_addr); @@ -982,7 +986,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) if (odph_eth_addr_parse(&mac, token)) { ODPH_ERR("Invalid MAC address. Use format 11-22-33-44-55-66.\n"); - exit(EXIT_FAILURE); + goto error; } memcpy(stats[policy_count].rule.value_be, mac.addr, ODPH_ETHADDR_LEN); @@ -993,7 +997,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) mask_sz = parse_custom(token, stats[policy_count].rule.mask_be, ODPH_ETHADDR_LEN); if (mask_sz != ODPH_ETHADDR_LEN) { ODPH_ERR("Invalid mask. Provide mask without 0x prefix.\n"); - return -1; + goto error; } break; case ODP_PMR_CUSTOM_FRAME: @@ -1005,7 +1009,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) offset = strtoul(token, NULL, 0); stats[policy_count].rule.offset = offset; if (errno) - return -1; + goto error; token = strtok(NULL, ":"); strncpy(stats[policy_count].value, token, @@ -1015,7 +1019,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) MAX_VAL_SIZE); stats[policy_count].rule.val_sz = val_sz; if (val_sz <= 0) - return -1; + goto error; token = strtok(NULL, ":"); strncpy(stats[policy_count].mask, token, @@ -1024,11 +1028,10 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) stats[policy_count].rule.mask_be, MAX_VAL_SIZE); if (mask_sz != val_sz) - return -1; + goto error; break; default: - usage(); - exit(EXIT_FAILURE); + goto error; } /* Optional source CoS name and name of this CoS @@ -1036,7 +1039,7 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) cos0 = strtok(NULL, ":"); cos1 = strtok(NULL, ":"); if (cos0 == NULL) - return -1; + goto error; if (cos1) { stats[policy_count].has_src_cos = 1; @@ -1052,6 +1055,10 @@ static int parse_pmr_policy(appl_args_t *appl_args, char *optarg) appl_args->policy_count++; free(pmr_str); return 0; + +error: + free(pmr_str); + return -1; } static int parse_policy_ci_pass_count(appl_args_t *appl_args, char *optarg) @@ -1075,6 +1082,10 @@ static int parse_policy_ci_pass_count(appl_args_t *appl_args, char *optarg) len = strlen(optarg); len++; count_str = malloc(len); + if (count_str == NULL) { + ODPH_ERR("Memory allocation failed\n"); + return -1; + } strcpy(count_str, optarg); token = strtok(count_str, ":"); diff --git a/example/ipfragreass/Makefile.am b/example/ipfragreass/Makefile.am index 2cd61a39e..f9180ea93 100644 --- a/example/ipfragreass/Makefile.am +++ b/example/ipfragreass/Makefile.am @@ -8,8 +8,6 @@ odp_ipfragreass_SOURCES = odp_ipfragreass.c \ odp_ipfragreass_fragment.c \ odp_ipfragreass_helpers.c \ odp_ipfragreass_reassemble.c \ - odp_ipfragreass_atomics.h \ - odp_ipfragreass_atomics_arm.h \ odp_ipfragreass_fragment.h \ odp_ipfragreass_helpers.h \ odp_ipfragreass_ip.h \ diff --git a/example/ipfragreass/odp_ipfragreass.c b/example/ipfragreass/odp_ipfragreass.c index 828f11002..db5779915 100644 --- a/example/ipfragreass/odp_ipfragreass.c +++ b/example/ipfragreass/odp_ipfragreass.c @@ -51,7 +51,7 @@ static struct ODP_ALIGNED_CACHE { } thread_stats[MAX_WORKERS]; /** Shared hash map structure for reassembly */ -static union fraglist *fraglists; +static odp_atomic_u128_t *fraglists; /** Barrier for synchronising reassembly worker threads */ static odp_barrier_t barrier; @@ -74,6 +74,7 @@ static void init(odp_instance_t *instance, odp_pool_t *fragment_pool, odp_queue_param_t frag_queue_params; odp_queue_param_t reass_queue_params; char cpumask_str[ODP_CPUMASK_STR_SIZE]; + union fraglist init_data; srand(seed); printf("= Seed: %d\n", seed); @@ -103,7 +104,8 @@ static void init(odp_instance_t *instance, odp_pool_t *fragment_pool, } /* Reserve (and initialise) shared memory for reassembly fraglists */ - *shm = odp_shm_reserve("fraglists", FRAGLISTS * sizeof(union fraglist), + *shm = odp_shm_reserve("fraglists", + FRAGLISTS * sizeof(odp_atomic_u128_t), ODP_CACHE_LINE_SIZE, 0); if (*shm == ODP_SHM_INVALID) { fprintf(stderr, "ERROR: odp_shm_reserve\n"); @@ -114,8 +116,10 @@ static void init(odp_instance_t *instance, odp_pool_t *fragment_pool, fprintf(stderr, "ERROR: odp_shm_addr\n"); exit(1); } + + init_fraglist(&init_data); for (i = 0; i < FRAGLISTS; ++i) - init_fraglist(&fraglists[i]); + odp_atomic_init_u128(&fraglists[i], init_data.raw); /* Create a queue for holding fragments */ odp_queue_param_init(&frag_queue_params); diff --git a/example/ipfragreass/odp_ipfragreass_atomics.h b/example/ipfragreass/odp_ipfragreass_atomics.h deleted file mode 100644 index 743a004e2..000000000 --- a/example/ipfragreass/odp_ipfragreass_atomics.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (c) 2017-2018, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef ODP_FRAGREASS_PP_ATOMICS_H_ -#define ODP_FRAGREASS_PP_ATOMICS_H_ - -#if __SIZEOF_POINTER__ == 4 -/** - * A wrapper function to perform a 64-bit "strong" atomic compare and swap - * (CAS) operation. This generic version of the function is used if an - * architecture-specific (e.g. lockless) variant is not specified. - * - * @param var The location at which the CAS should take place - * @param exp A pointer to the expected value - * @param neu A pointer to the new value to be written on success - * @param mo_success The memory order on success - * @param mo_failure The memory order on failure - * - * @return Whether the operation succeeded - */ -static inline bool atomic_strong_cas_dblptr(uint64_t *var, uint64_t *exp, - uint64_t neu, int mo_success, - int mo_failure) -{ - return __atomic_compare_exchange_n(var, exp, neu, 0, mo_success, - mo_failure); -} -#elif __SIZEOF_POINTER__ == 8 -/** - * A wrapper function to perform a 128-bit "strong" atomic compare and swap - * (CAS) operation. This generic version of the function is used if an - * architecture-specific (e.g. lockless) variant is not specified. - * - * @param var The location at which the CAS should take place - * @param exp A pointer to the expected value - * @param neu A pointer to the new value to be written on success - * @param mo_success The memory order on success - * @param mo_failure The memory order on failure - * - * @return Whether the operation succeeded - */ -__extension__ static inline bool atomic_strong_cas_dblptr(__int128 *var, - __int128 *exp, - __int128 neu, - int mo_success, - int mo_failure) -{ - return __atomic_compare_exchange_n(var, exp, neu, 0, mo_success, - mo_failure); -} -#endif -#endif diff --git a/example/ipfragreass/odp_ipfragreass_atomics_arm.h b/example/ipfragreass/odp_ipfragreass_atomics_arm.h deleted file mode 100644 index 4bea45f9e..000000000 --- a/example/ipfragreass/odp_ipfragreass_atomics_arm.h +++ /dev/null @@ -1,130 +0,0 @@ -/* Copyright (c) 2017-2018, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef ODP_FRAGREASS_PP_ATOMICS_ARM_H_ -#define ODP_FRAGREASS_PP_ATOMICS_ARM_H_ - -#include <odp_api.h> - -#if __SIZEOF_POINTER__ == 8 && defined(__aarch64__) - -__extension__ typedef __int128 _int128_t; - -static inline _int128_t lld(_int128_t *var, int mo) -{ - _int128_t old; - uint64_t lo, hi; - - if (mo == __ATOMIC_ACQUIRE) - __asm__ volatile("ldaxp %0, %1, [%2]" : "=&r" (lo), "=&r" (hi) - : "r" (var) : "memory"); - else /* mo == __ATOMIC_RELAXED */ - __asm__ volatile("ldxp %0, %1, [%2]" : "=&r" (lo), "=&r" (hi) - : "r" (var) : ); - old = hi; - old <<= 64; - old |= lo; - - return old; - -} - -static inline uint32_t scd(_int128_t *var, _int128_t neu, int mo) -{ - uint32_t ret; - uint64_t lo = neu, hi = neu >> 64; - - if (mo == __ATOMIC_RELEASE) - __asm__ volatile("stlxp %w0, %1, %2, [%3]" : "=&r" (ret) - : "r" (lo), "r" (hi), "r" (var) : "memory"); - else /* mo == __ATOMIC_RELAXED */ - __asm__ volatile("stxp %w0, %1, %2, [%3]" : "=&r" (ret) - : "r" (lo), "r" (hi), "r" (var) : "memory"); - return ret; -} - -static inline bool atomic_strong_cas_dblptr(_int128_t *var, _int128_t *exp, - _int128_t neu, int mo_success, - int mo_failure ODP_UNUSED) -{ - register _int128_t old; - register _int128_t expected = *exp; - int ll_mo, sc_mo; - - ll_mo = (mo_success != __ATOMIC_RELAXED && - mo_success != __ATOMIC_RELEASE) ? __ATOMIC_ACQUIRE - : __ATOMIC_RELAXED; - sc_mo = (mo_success == __ATOMIC_RELEASE || - mo_success == __ATOMIC_ACQ_REL || - mo_success == __ATOMIC_SEQ_CST) ? __ATOMIC_RELEASE - : __ATOMIC_RELAXED; - - /* - * To prevent spurious failures and ensure atomicity, we must write some - * value back -- whether it's the value we wanted to write, or the value - * that is currently there. Repeat until we perform a successful write. - */ - do { - old = lld(var, ll_mo); - } while (scd(var, old == expected ? neu : old, sc_mo)); - - *exp = old; - return (old == expected); -} -#elif __SIZEOF_POINTER__ == 4 && defined(__ARM_ARCH) && __ARM_ARCH == 7 -static inline uint64_t lld(uint64_t *var, int mo) -{ - uint64_t old; - - __asm__ volatile("ldrexd %0, %H0, [%1]" : "=&r" (old) : "r" (var) : ); - if (mo == __ATOMIC_ACQUIRE) - __asm__ volatile("dmb ish" ::: "memory"); - return old; -} - -static inline uint32_t scd(uint64_t *var, uint64_t neu, int mo) -{ - uint32_t ret; - - if (mo == __ATOMIC_RELEASE) - __asm__ volatile("dmb ish" ::: "memory"); - __asm__ volatile("strexd %0, %1, %H1, [%2]" : "=&r" (ret) - : "r" (neu), "r" (var) : ); - return ret; -} - -static inline bool atomic_strong_cas_dblptr(uint64_t *var, uint64_t *exp, - uint64_t neu, int mo_success, - int mo_failure ODP_UNUSED) -{ - register uint64_t old; - register uint64_t expected = *exp; - int ll_mo, sc_mo; - - ll_mo = (mo_success != __ATOMIC_RELAXED && - mo_success != __ATOMIC_RELEASE) ? __ATOMIC_ACQUIRE - : __ATOMIC_RELAXED; - sc_mo = (mo_success == __ATOMIC_RELEASE || - mo_success == __ATOMIC_ACQ_REL || - mo_success == __ATOMIC_SEQ_CST) ? __ATOMIC_RELEASE - : __ATOMIC_RELAXED; - - /* - * To prevent spurious failures and ensure atomicity, we must write some - * value back -- whether it's the value we wanted to write, or the value - * that is currently there. Repeat until we perform a successful write. - */ - do { - old = lld(var, ll_mo); - } while (scd(var, old == expected ? neu : old, sc_mo)); - - *exp = old; - return (old == expected); -} -#else -#include "odp_ipfragreass_atomics.h" -#endif -#endif diff --git a/example/ipfragreass/odp_ipfragreass_helpers.h b/example/ipfragreass/odp_ipfragreass_helpers.h index 3678b7db6..af47e326c 100644 --- a/example/ipfragreass/odp_ipfragreass_helpers.h +++ b/example/ipfragreass/odp_ipfragreass_helpers.h @@ -9,12 +9,6 @@ #include <odp/helper/ip.h> -#if defined(__ARM_ARCH) -#include "odp_ipfragreass_atomics_arm.h" -#else -#include "odp_ipfragreass_atomics.h" -#endif - /** * Generate a random IPv4 UDP packet from the specified parameters * diff --git a/example/ipfragreass/odp_ipfragreass_reassemble.c b/example/ipfragreass/odp_ipfragreass_reassemble.c index fba900f7a..57e0f375a 100644 --- a/example/ipfragreass/odp_ipfragreass_reassemble.c +++ b/example/ipfragreass/odp_ipfragreass_reassemble.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include <odp_api.h> + #include <stdio.h> #include <stdlib.h> #include <assert.h> @@ -382,7 +384,7 @@ static void sort_fraglist(union fraglist *fl, struct flts now) * * @return The number of packets reassembled and sent to the output queue */ -static int add_fraglist_to_fraglist(union fraglist *fl, union fraglist frags, +static int add_fraglist_to_fraglist(odp_atomic_u128_t *fl, union fraglist frags, struct packet *frags_head, struct flts now, odp_queue_t out, odp_bool_t dont_assemble) { @@ -401,8 +403,7 @@ redo:; struct flts oldfl_earliest; struct flts frags_earliest; - __atomic_load(&fl->half[0], &oldfl.half[0], __ATOMIC_RELAXED); - __atomic_load(&fl->half[1], &oldfl.half[1], __ATOMIC_RELAXED); + oldfl.raw = odp_atomic_load_u128(fl); /* * If we're updating a non-empty fraglist, we should always attempt @@ -435,9 +436,7 @@ redo:; * yet. If not, just write out our changes and move on. */ if (newfl.part_len < newfl.whole_len || dont_assemble) { - if (!atomic_strong_cas_dblptr(&fl->raw, &oldfl.raw, newfl.raw, - __ATOMIC_RELEASE, - __ATOMIC_RELAXED)) { + if (!odp_atomic_cas_rel_u128(fl, &oldfl.raw, newfl.raw)) { /* Failed to add this fragment? Try again. */ set_prev_packet(frags_head, NULL); goto redo; @@ -456,8 +455,7 @@ redo:; * otherwise we'll update the slot with our changes later. */ init_fraglist(&nullfl); - if (!atomic_strong_cas_dblptr(&fl->raw, &oldfl.raw, nullfl.raw, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!odp_atomic_cas_acq_u128(fl, &oldfl.raw, nullfl.raw)) { /* Failed to take this fraglist? Try again. */ set_prev_packet(frags_head, NULL); goto redo; @@ -560,7 +558,7 @@ redo:; * * @return The number of packets reassembled and sent to the output */ -static int add_frag_to_fraglist(union fraglist *fl, struct packet *frag, +static int add_frag_to_fraglist(odp_atomic_u128_t *fl, struct packet *frag, uint16_t frag_payload_len, uint16_t frag_reass_payload_len, odp_queue_t out) @@ -586,7 +584,7 @@ static int add_frag_to_fraglist(union fraglist *fl, struct packet *frag, * @param out The queue to which reassembled packets should be written * @param force Whether all flows in the fraglist should be considered stale */ -static void remove_stale_flows(union fraglist *fl, union fraglist oldfl, +static void remove_stale_flows(odp_atomic_u128_t *fl, union fraglist oldfl, struct flts timestamp_now, odp_queue_t out, odp_bool_t force) { @@ -685,7 +683,7 @@ static void remove_stale_flows(union fraglist *fl, union fraglist oldfl, * @param out The queue to which reassembled packets should be written * @param force Whether all flows in the fraglist should be considered stale */ -static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out, +static void garbage_collect_fraglist(odp_atomic_u128_t *fl, odp_queue_t out, odp_bool_t force) { uint64_t time_now; @@ -698,8 +696,9 @@ static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out, do { time_now = odp_time_to_ns(odp_time_global()); timestamp_now.t = time_now / TS_RES_NS; - __atomic_load(&fl->half[0], &oldfl.half[0], __ATOMIC_RELAXED); - __atomic_load(&fl->half[1], &oldfl.half[1], __ATOMIC_RELAXED); + + oldfl.raw = odp_atomic_load_u128(fl); + elapsed.t = timestamp_now.t - oldfl.earliest; if (oldfl.tail == NULL || @@ -712,11 +711,8 @@ static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out, union fraglist nullfl; init_fraglist(&nullfl); - success = atomic_strong_cas_dblptr(&fl->raw, &oldfl.raw, - nullfl.raw, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); - + success = odp_atomic_cas_acq_u128(fl, &oldfl.raw, + nullfl.raw); if (success) remove_stale_flows(fl, oldfl, timestamp_now, out, force); @@ -724,7 +720,7 @@ static void garbage_collect_fraglist(union fraglist *fl, odp_queue_t out, } while (!success); } -int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists, +int reassemble_ipv4_packets(odp_atomic_u128_t *fraglists, int num_fraglists, struct packet *fragments, int num_fragments, odp_queue_t out) { @@ -737,7 +733,7 @@ int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists, uint16_t frag_payload_len; uint16_t frag_reass_payload_len; uint32_t key; - union fraglist *fl; + odp_atomic_u128_t *fl; int status; frag = fragments[i]; @@ -767,7 +763,7 @@ int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists, return packets_reassembled; } -void garbage_collect_fraglists(union fraglist *fraglists, int num_fraglists, +void garbage_collect_fraglists(odp_atomic_u128_t *fraglists, int num_fraglists, odp_queue_t out, odp_bool_t destroy_all) { int i; diff --git a/example/ipfragreass/odp_ipfragreass_reassemble.h b/example/ipfragreass/odp_ipfragreass_reassemble.h index e0e132b6c..1fb71284e 100644 --- a/example/ipfragreass/odp_ipfragreass_reassemble.h +++ b/example/ipfragreass/odp_ipfragreass_reassemble.h @@ -7,13 +7,13 @@ #ifndef ODP_FRAGREASS_PP_REASSEMBLE_H_ #define ODP_FRAGREASS_PP_REASSEMBLE_H_ +#include <odp_api.h> #include <odp/helper/ip.h> #include "odp_ipfragreass_ip.h" #include "odp_ipfragreass_helpers.h" -ODP_STATIC_ASSERT((__SIZEOF_POINTER__ == 4 || __SIZEOF_POINTER__ == 8), - "ODPREASS_PTR__SIZE_ERROR"); +ODP_STATIC_ASSERT(__SIZEOF_POINTER__ <= 8, "ODP_REASS_PTR__SIZE_ERROR"); /** * The time in nanoseconds after reception of the earliest fragment that a @@ -22,41 +22,25 @@ ODP_STATIC_ASSERT((__SIZEOF_POINTER__ == 4 || __SIZEOF_POINTER__ == 8), #define FLOW_TIMEOUT_NS 15000000000ULL /** Convert nanoseconds into a unit for packet.arrival */ -#if __SIZEOF_POINTER__ == 4 -#define TS_RES_NS ((uint64_t)5000000000) /**< ns -> 5s */ -#elif __SIZEOF_POINTER__ == 8 #define TS_RES_NS ((uint64_t)1000000) /**< ns -> 1ms */ -#endif /** * The maximum value of the packet.arrival field. */ -#if __SIZEOF_POINTER__ == 4 -#define EARLIEST_MAX 15 -#elif __SIZEOF_POINTER__ == 8 #define EARLIEST_MAX UINT32_MAX -#endif /** * The time in packet.arrival ticks that indications of the time "now" are * permitted to be off by. */ -#if __SIZEOF_POINTER__ == 4 -#define TS_NOW_TOLERANCE 1 -#elif __SIZEOF_POINTER__ == 8 #define TS_NOW_TOLERANCE 5000 -#endif /** * The timestamp format used for fragments. Sadly, this has to be a structure * as we may need a bit field. */ struct flts { -#if __SIZEOF_POINTER__ == 4 - uint8_t t:4; -#elif __SIZEOF_POINTER__ == 8 uint32_t t; -#endif }; /** @@ -81,11 +65,7 @@ union fraglist { * The timestamp of the earliest arriving fragment in this * fraglist */ -#if __SIZEOF_POINTER__ == 4 - uint32_t earliest:4; -#elif __SIZEOF_POINTER__ == 8 uint32_t earliest; -#endif /** * The sum of the payloads of the fragments in this list @@ -116,17 +96,7 @@ union fraglist { struct packet *tail; }; -#if __SIZEOF_POINTER__ == 4 - struct { - uint32_t half[2]; - }; - uint64_t raw; -#elif __SIZEOF_POINTER__ == 8 - struct { - uint64_t half[2]; - }; - __extension__ __int128 raw; -#endif + odp_u128_t raw; }; /** @@ -193,7 +163,7 @@ static inline void set_prev_packet(struct packet *packet, struct packet *prev) * * @return The number of packets successfully reassembled and written to "out" */ -int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists, +int reassemble_ipv4_packets(odp_atomic_u128_t *fraglists, int num_fraglists, struct packet *fragments, int num_fragments, odp_queue_t out); @@ -205,7 +175,7 @@ int reassemble_ipv4_packets(union fraglist *fraglists, int num_fraglists, * @param out The queue to which reassembled packets should be written * @param destroy_all Whether all encountered flows should be cleaned up */ -void garbage_collect_fraglists(union fraglist *fraglists, int num_fraglists, +void garbage_collect_fraglists(odp_atomic_u128_t *fraglists, int num_fraglists, odp_queue_t out, odp_bool_t destroy_all); #endif diff --git a/example/ipsec_crypto/odp_ipsec.c b/example/ipsec_crypto/odp_ipsec.c index 9fec94620..c6a64399f 100644 --- a/example/ipsec_crypto/odp_ipsec.c +++ b/example/ipsec_crypto/odp_ipsec.c @@ -1,4 +1,5 @@ /* Copyright (c) 2013-2018, Linaro Limited + * Copyright (c) 2021, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -772,6 +773,20 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt, return PKT_CONTINUE; } +static int generate_iv(uint8_t *buf, uint32_t size) +{ + uint32_t n = 0; + int32_t ret; + + while (n < size) { + ret = odp_random_data(buf + n, size - n, ODP_RANDOM_CRYPTO); + if (ret < 0) + return 1; + n += ret; + } + return 0; +} + /** * Packet Processing - Output IPsec packet classification * @@ -859,7 +874,9 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt, trl_len = encrypt_len - ip_data_len; esp->spi = odp_cpu_to_be_32(entry->esp.spi); - memcpy(esp + 1, entry->state.iv, entry->esp.iv_len); + if (generate_iv(esp->iv, entry->esp.iv_len)) + return PKT_DROP; + params.cipher_iv_ptr = esp->iv; esp_t = (odph_esptrl_t *)(ip_data + encrypt_len) - 1; esp_t->pad_len = trl_len - sizeof(*esp_t); @@ -957,20 +974,9 @@ pkt_disposition_e do_ipsec_out_seq(odp_packet_t *pkt, } if (ctx->ipsec.tun_hdr_offset) { odph_ipv4hdr_t *ip; - int ret; ip = (odph_ipv4hdr_t *)(ctx->ipsec.tun_hdr_offset + buf); ip->id = odp_cpu_to_be_16((*ctx->ipsec.tun_hdr_id)++); - if (!ip->id) { - /* re-init tunnel hdr id */ - ret = odp_random_data((uint8_t *)ctx->ipsec.tun_hdr_id, - sizeof(*ctx->ipsec.tun_hdr_id), - 1); - if (ret != sizeof(*ctx->ipsec.tun_hdr_id)) { - ODPH_ERR("Error: Not enough random data\n"); - exit(EXIT_FAILURE); - } - } } out_pkt = entry->in_place ? *pkt : ODP_PACKET_INVALID; diff --git a/example/ipsec_crypto/odp_ipsec_cache.c b/example/ipsec_crypto/odp_ipsec_cache.c index 044538c59..e4cd5142a 100644 --- a/example/ipsec_crypto/odp_ipsec_cache.c +++ b/example/ipsec_crypto/odp_ipsec_cache.c @@ -95,13 +95,11 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, params.cipher_alg = cipher_sa->alg.u.cipher; params.cipher_key.data = cipher_sa->key.data; params.cipher_key.length = cipher_sa->key.length; - params.cipher_iv.data = entry->state.iv; - params.cipher_iv.length = cipher_sa->iv_len; + params.cipher_iv_len = cipher_sa->iv_len; mode = cipher_sa->mode; } else { params.cipher_alg = ODP_CIPHER_ALG_NULL; - params.cipher_iv.data = NULL; - params.cipher_iv.length = 0; + params.cipher_iv_len = 0; } /* Auth */ @@ -111,23 +109,15 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, params.auth_key.length = auth_sa->key.length; params.auth_digest_len = auth_sa->icv_len; mode = auth_sa->mode; + params.hash_result_in_auth_range = true; } else { params.auth_alg = ODP_AUTH_ALG_NULL; } - /* Generate an IV */ - if (params.cipher_iv.length) { - int32_t size = params.cipher_iv.length; - - int32_t ret = odp_random_data(params.cipher_iv.data, size, 1); - if (ret != size) - return -1; - } - /* Synchronous session create for now */ if (odp_crypto_session_create(¶ms, &session, &ses_create_rc)) return -1; - if (ODP_CRYPTO_SES_CREATE_ERR_NONE != ses_create_rc) + if (ODP_CRYPTO_SES_ERR_NONE != ses_create_rc) return -1; /* Copy remainder */ diff --git a/example/ipsec_crypto/odp_ipsec_cache.h b/example/ipsec_crypto/odp_ipsec_cache.h index 1523778ff..be31ca72c 100644 --- a/example/ipsec_crypto/odp_ipsec_cache.h +++ b/example/ipsec_crypto/odp_ipsec_cache.h @@ -57,7 +57,6 @@ typedef struct ipsec_cache_entry_s { odp_crypto_session_t session; /**< Crypto session handle */ uint32_t esp_seq; /**< ESP TX sequence number */ uint32_t ah_seq; /**< AH TX sequence number */ - uint8_t iv[MAX_IV_LEN]; /**< ESP IV storage */ odp_u16be_t tun_hdr_id; /**< Tunnel header IP ID */ } state; } ipsec_cache_entry_t; diff --git a/example/ipsec_crypto/odp_ipsec_misc.h b/example/ipsec_crypto/odp_ipsec_misc.h index 4f50f27ec..6186a2369 100644 --- a/example/ipsec_crypto/odp_ipsec_misc.h +++ b/example/ipsec_crypto/odp_ipsec_misc.h @@ -24,7 +24,6 @@ extern "C" { #define MAX_DB 32 /**< maximum number of data base entries */ #define MAX_LOOPBACK 10 /**< maximum number of loop back interfaces */ #define MAX_STRING 32 /**< maximum string length */ -#define MAX_IV_LEN 32 /**< Maximum IV length in bytes */ #define KEY_BITS_3DES 192 /**< 3DES cipher key length in bits */ #define KEY_BITS_MD5_96 128 /**< MD5_96 auth key length in bits */ diff --git a/example/timer/odp_timer_accuracy.c b/example/timer/odp_timer_accuracy.c index 9318e1090..b9a0cf585 100644 --- a/example/timer/odp_timer_accuracy.c +++ b/example/timer/odp_timer_accuracy.c @@ -1,10 +1,11 @@ /* Copyright (c) 2018, Linaro Limited - * Copyright (c) 2019-2021, Nokia + * Copyright (c) 2019-2022, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ +#include <errno.h> #include <stdio.h> #include <string.h> #include <inttypes.h> @@ -717,15 +718,6 @@ int main(int argc, char *argv[]) if (parse_options(argc, argv, &test_global)) return -1; - if (test_global.opt.output) { - test_global.file = fopen(test_global.filename, "w"); - if (test_global.file == NULL) { - printf("Failed to open file: %s\n", - test_global.filename); - return -1; - } - } - /* List features not to be used (may optimize performance) */ odp_init_param_init(&init); init.not_used.feat.cls = 1; @@ -759,6 +751,7 @@ int main(int argc, char *argv[]) if (test_global.timer_ctx == NULL) { printf("Timer context table calloc failed.\n"); + ret = -1; goto quit; } @@ -767,11 +760,20 @@ int main(int argc, char *argv[]) void *addr; uint64_t size = test_global.tot_timers * sizeof(test_log_t); + test_global.file = fopen(test_global.filename, "w"); + if (test_global.file == NULL) { + printf("Failed to open output file %s: %s\n", + test_global.filename, strerror(errno)); + ret = -1; + goto quit; + } + shm = odp_shm_reserve("timer_accuracy_log", size, sizeof(test_log_t), 0); if (shm == ODP_SHM_INVALID) { printf("Test log alloc failed.\n"); + ret = -1; goto quit; } @@ -781,7 +783,8 @@ int main(int argc, char *argv[]) test_global.log_shm = shm; } - if (start_timers(&test_global)) + ret = start_timers(&test_global); + if (ret) goto quit; run_test(&test_global); diff --git a/example/traffic_mgmt/odp_traffic_mgmt.c b/example/traffic_mgmt/odp_traffic_mgmt.c index c82c1d5b2..689cac2ae 100644 --- a/example/traffic_mgmt/odp_traffic_mgmt.c +++ b/example/traffic_mgmt/odp_traffic_mgmt.c @@ -1,6 +1,7 @@ /* Copyright 2015 EZchip Semiconductor Ltd. All Rights Reserved. * * Copyright (c) 2015-2018, Linaro Limited + * Copyright (c) 2022, Marvell * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -106,7 +107,7 @@ static profile_params_set_t COS0_PROFILE_PARAMS = { .shaper_params = { .commit_rate = 1 * MBPS, .commit_burst = 100000, .peak_rate = 4 * MBPS, .peak_burst = 200000, - .dual_rate = FALSE, .shaper_len_adjust = 20 + .dual_rate = TRUE, .shaper_len_adjust = 20 }, .threshold_params = { @@ -148,7 +149,7 @@ static profile_params_set_t COS1_PROFILE_PARAMS = { .shaper_params = { .commit_rate = 500 * KBPS, .commit_burst = 50000, .peak_rate = 1500 * KBPS, .peak_burst = 150000, - .dual_rate = FALSE, .shaper_len_adjust = 20 + .dual_rate = TRUE, .shaper_len_adjust = 20 }, .threshold_params = { @@ -190,7 +191,7 @@ static profile_params_set_t COS2_PROFILE_PARAMS = { .shaper_params = { .commit_rate = 200 * KBPS, .commit_burst = 20000, .peak_rate = 400 * KBPS, .peak_burst = 40000, - .dual_rate = FALSE, .shaper_len_adjust = 20 + .dual_rate = TRUE, .shaper_len_adjust = 20 }, .threshold_params = { @@ -293,6 +294,39 @@ static uint8_t g_print_tm_stats = TRUE; static void tester_egress_fcn(odp_packet_t odp_pkt); +static uint64_t tm_shaper_min_rate; +static uint64_t tm_shaper_max_rate; +static uint32_t tm_shaper_min_burst; +static uint32_t tm_shaper_max_burst; + +static uint64_t +clamp_rate(uint64_t rate) +{ + uint64_t val = MIN(MAX(rate, tm_shaper_min_rate), tm_shaper_max_rate); + + if (!rate) + return 0; + + if (val != rate) + printf("INFO: Clamped shaper rate from %" PRIu64 " bps" + " to %" PRIu64 " bps\n", rate, val); + return val; +} + +static uint32_t +clamp_burst(uint32_t burst) +{ + uint32_t val = MIN(MAX(burst, tm_shaper_min_burst), tm_shaper_max_burst); + + if (!burst) + return 0; + + if (val != burst) + printf("INFO: Clamped shaper burst from %" PRIu32 "bits to %" PRIu32 "bits\n", + burst, val); + return val; +} + /* Returns the number of errors encountered. */ static uint32_t create_profile_set(profile_params_set_t *profile_params_set, @@ -317,10 +351,14 @@ static uint32_t create_profile_set(profile_params_set_t *profile_params_set, odp_tm_shaper_params_init(&shaper_params); shaper = &profile_params_set->shaper_params; - shaper_params.commit_rate = shaper->commit_rate * shaper_scale; - shaper_params.peak_rate = shaper->peak_rate * shaper_scale; - shaper_params.commit_burst = shaper->commit_burst * shaper_scale; - shaper_params.peak_burst = shaper->peak_burst * shaper_scale; + shaper_params.commit_rate = clamp_rate(shaper->commit_rate * + shaper_scale); + shaper_params.peak_rate = clamp_rate(shaper->peak_rate * + shaper_scale); + shaper_params.commit_burst = clamp_burst(shaper->commit_burst * + shaper_scale); + shaper_params.peak_burst = clamp_burst(shaper->peak_burst * + shaper_scale); shaper_params.dual_rate = shaper->dual_rate; shaper_params.shaper_len_adjust = shaper->shaper_len_adjust; profile_set->shaper_profile = odp_tm_shaper_create(name, @@ -550,6 +588,7 @@ static int create_and_config_tm(void) { odp_tm_level_requirements_t *per_level; odp_tm_requirements_t requirements; + odp_tm_capabilities_t tm_capa; odp_tm_egress_t egress; uint32_t level, err_cnt; @@ -579,6 +618,44 @@ static int create_and_config_tm(void) egress.egress_fcn = tester_egress_fcn; odp_tm_test = odp_tm_create("TM test", &requirements, &egress); + if (odp_tm_test == ODP_TM_INVALID) { + printf("Error: failed to create TM\n"); + return -1; + } + + if (odp_tm_capability(odp_tm_test, &tm_capa) != 0) { + printf("Error: failed to get tm capability"); + return -1; + } + + tm_shaper_min_rate = tm_capa.per_level[0].min_rate; + tm_shaper_max_rate = tm_capa.per_level[0].max_rate; + tm_shaper_min_burst = tm_capa.per_level[0].min_burst; + tm_shaper_max_burst = tm_capa.per_level[0].max_burst; + + for (level = 1; level < tm_capa.max_levels; level++) { + odp_tm_level_capabilities_t *per_level = + &tm_capa.per_level[level]; + + if (per_level->min_rate > tm_shaper_min_rate) + tm_shaper_min_rate = per_level->min_rate; + + if (per_level->min_burst > tm_shaper_min_burst) + tm_shaper_min_burst = per_level->min_burst; + + if (per_level->max_rate < tm_shaper_max_rate) + tm_shaper_max_rate = per_level->max_rate; + + if (per_level->max_burst < tm_shaper_max_burst) + tm_shaper_max_burst = per_level->max_burst; + } + + if (tm_shaper_min_rate > tm_shaper_max_rate || + tm_shaper_min_burst > tm_shaper_max_burst) { + printf("Error: No shaper rate supported by all TM levels"); + return -1; + } + err_cnt = init_profile_sets(); if (err_cnt != 0) printf("%s init_profile_sets encountered %" PRIu32 " errors\n", @@ -873,7 +950,9 @@ int main(int argc, char *argv[]) if (process_cmd_line_options(argc, argv) < 0) return -1; - create_and_config_tm(); + rc = create_and_config_tm(); + if (rc != 0) + return rc; /* Start TM */ rc = odp_tm_start(odp_tm_test); |