diff options
Diffstat (limited to 'helper/include')
-rw-r--r-- | helper/include/odp/helper/debug.h (renamed from helper/include/odp/helper/odph_debug.h) | 0 | ||||
-rw-r--r-- | helper/include/odp/helper/odph_api.h | 9 | ||||
-rw-r--r-- | helper/include/odp/helper/odph_cuckootable.h | 146 | ||||
-rw-r--r-- | helper/include/odp/helper/odph_hashtable.h | 111 | ||||
-rw-r--r-- | helper/include/odp/helper/odph_iplookuptable.h | 125 | ||||
-rw-r--r-- | helper/include/odp/helper/odph_lineartable.h | 101 | ||||
-rw-r--r-- | helper/include/odp/helper/stress.h | 238 | ||||
-rw-r--r-- | helper/include/odp/helper/string.h | 62 | ||||
-rw-r--r-- | helper/include/odp/helper/table.h | 244 | ||||
-rw-r--r-- | helper/include/odp/helper/threads.h | 45 | ||||
-rw-r--r-- | helper/include/odph_list_internal.h | 88 |
11 files changed, 345 insertions, 824 deletions
diff --git a/helper/include/odp/helper/odph_debug.h b/helper/include/odp/helper/debug.h index 41b425ab2..41b425ab2 100644 --- a/helper/include/odp/helper/odph_debug.h +++ b/helper/include/odp/helper/debug.h diff --git a/helper/include/odp/helper/odph_api.h b/helper/include/odp/helper/odph_api.h index 94d43a61b..2541efa89 100644 --- a/helper/include/odp/helper/odph_api.h +++ b/helper/include/odp/helper/odph_api.h @@ -18,23 +18,20 @@ extern "C" { #include <odp/helper/autoheader_external.h> -#include <odp/helper/odph_debug.h> #include <odp/helper/chksum.h> -#include <odp/helper/odph_cuckootable.h> +#include <odp/helper/debug.h> #include <odp/helper/eth.h> #include <odp/helper/gtp.h> -#include <odp/helper/odph_hashtable.h> #include <odp/helper/icmp.h> #include <odp/helper/igmp.h> #include <odp/helper/ip.h> #include <odp/helper/ipsec.h> #include <odp/helper/macros.h> -#include <odp/helper/odph_lineartable.h> -#include <odp/helper/odph_iplookuptable.h> +#include <odp/helper/stress.h> #include <odp/helper/sctp.h> +#include <odp/helper/string.h> #include <odp/helper/strong_types.h> #include <odp/helper/tcp.h> -#include <odp/helper/table.h> #include <odp/helper/threads.h> #include <odp/helper/udp.h> #include <odp/helper/version.h> diff --git a/helper/include/odp/helper/odph_cuckootable.h b/helper/include/odp/helper/odph_cuckootable.h deleted file mode 100644 index 1c87a3d42..000000000 --- a/helper/include/odp/helper/odph_cuckootable.h +++ /dev/null @@ -1,146 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2016-2018 Linaro Limited - */ - -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ODPH_CUCKOO_TABLE_H_ -#define ODPH_CUCKOO_TABLE_H_ - -#include <odp/helper/table.h> - -/** - * @file - * - * ODP Cuckoo Hash Table - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup odph_cuckootable ODPH CUCKOO TABLE - * Cuckoo table - * - * @{ - */ - -/** - * Create a cuckoo table - * - * @param name Name of the cuckoo table to be created - * @param capacity Number of elements table may store - * @param key_size Size of the key for each element - * @param value_size Size of the value stored for each element - * - * @return Handle of created cuckoo table - * @retval NULL Create failed - */ -odph_table_t odph_cuckoo_table_create( - const char *name, - uint32_t capacity, - uint32_t key_size, - uint32_t value_size); - -/** - * Lookup a cuckoo table by name - * - * @param name Name of the table to be located - * - * @return Handle of the located cuckoo table - * @retval NULL No table matching supplied name found - */ -odph_table_t odph_cuckoo_table_lookup(const char *name); - -/** - * Destroy a cuckoo table - * - * @param table Handle of the cuckoo table to be destroyed - * - * @retval 0 Success - * @retval < 0 Failure - */ -int odph_cuckoo_table_destroy(odph_table_t table); - -/** - * Insert a key/value pair into a cuckoo table - * - * @param table Table into which value is to be stored - * @param key Address of an odph_table_t to be used as key - * @param value Value to be associated with specified key - * - * @retval >= 0 Success - * @retval < 0 Failure - */ -int odph_cuckoo_table_put_value(odph_table_t table, void *key, void *value); - -/** - * Retrieve a value from a cuckoo table - * - * @param table Table from which value is to be retrieved - * @param key Address of an odph_table_t to be used as key - * @param[out] buffer Address of buffer to receive resulting value - * @param buffer_size Size of supplied buffer - * - * @retval 0 Success - * @retval 1 Success - * @retval < 0 Failure - */ -int odph_cuckoo_table_get_value(odph_table_t table, - void *key, void *buffer, - uint32_t buffer_size); - -/** - * Remove a value from a cuckoo table - * - * @param table Table from which value is to be removed - * @param key Address of odph_table_t to be used as key - * - * @retval >= 0 Success - * @retval < 0 Failure - */ -int odph_cuckoo_table_remove_value(odph_table_t table, void *key); - -extern odph_table_ops_t odph_cuckoo_table_ops; /**< @internal */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ODPH_CUCKOO_TABLE_H_ */ diff --git a/helper/include/odp/helper/odph_hashtable.h b/helper/include/odp/helper/odph_hashtable.h deleted file mode 100644 index b2dd21920..000000000 --- a/helper/include/odp/helper/odph_hashtable.h +++ /dev/null @@ -1,111 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2018 Linaro Limited - */ - -/** - * @file - * - * ODP Hash Table - */ - -#ifndef ODPH_HASH_TABLE_H_ -#define ODPH_HASH_TABLE_H_ - -#include <odp/helper/table.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup odph_hash_table ODPH HASH TABLE - * Hash table - * - * @{ - */ - -/** - * Create a hash table - * - * @param name Name of the hash table to be created. - * @param capacity Number of elements table may store - * @param key_size Size of the key for each element - * @param value_size Size of the value stored for each element - * - * @return Handle of created hash table - * @retval NULL Create failed - */ -odph_table_t odph_hash_table_create(const char *name, - uint32_t capacity, - uint32_t key_size, - uint32_t value_size); - -/** - * Lookup a hash table by name - * - * @param name Name of the table to be located - * - * @return Handle of the located hash table - * @return NULL No table matching supplied name found - */ -odph_table_t odph_hash_table_lookup(const char *name); - -/** - * Destroy a hash table - * - * @param table Handle of the hash table to be destroyed - * - * @retval 0 Success - * @retval < 0 Failure - */ -int odph_hash_table_destroy(odph_table_t table); - -/** - * Insert a key/value pair into a hash table - * - * @param table Table into which value is to be stored - * @param key Address of an odph_table_t to be used as key - * @param value Value to be associated with specified key - * - * @retval >= 0 Success - * @retval < 0 Failure - */ -int odph_hash_put_value(odph_table_t table, void *key, void *value); - -/** - * Retrieve a value from a hash table - * - * @param table Table from which value is to be retrieved - * @param key Address of an odph_table_t to be used as key - * @param[out] buffer Address of buffer to receive resulting value - * @param buffer_size Size of supplied buffer - * - * @retval 0 Success - * @retval 1 Success - * @retval < 0 Failure - */ -int odph_hash_get_value(odph_table_t table, void *key, void *buffer, - uint32_t buffer_size); - -/** - * Remove a value from a hash table - * - * @param table Table from which value is to be removed - * @param key Address of odph_table_t to be used as key - * - * @retval >= 0 Success - * @retval < 0 Failure - */ -int odph_hash_remove_value(odph_table_t table, void *key); - -extern odph_table_ops_t odph_hash_table_ops; /**< @internal */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/helper/include/odp/helper/odph_iplookuptable.h b/helper/include/odp/helper/odph_iplookuptable.h deleted file mode 100644 index 41235ecc6..000000000 --- a/helper/include/odp/helper/odph_iplookuptable.h +++ /dev/null @@ -1,125 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2016-2018 Linaro Limited - */ - -/** - * @file - * - * ODP IP Lookup Table - */ - -#ifndef ODPH_IPLOOKUP_TABLE_H_ -#define ODPH_IPLOOKUP_TABLE_H_ - -#include <odp/helper/table.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup odph_iplookuptable ODPH IP LOOKUP TABLE - * IP lookup table - * - * @details - * This is an implementation of the IP lookup table. The key of this table is - * IPv4 address (32 bits), and the value can be defined by user. This table uses - * the 16,8,8 ip lookup (longest prefix matching) algorithm. - * - * @{ - */ - -/** - * IP Lookup Prefix - */ -typedef struct { - uint32_t ip; /**< IPv4 address */ - uint8_t cidr; /**< CIDR value for prefix matching */ -} odph_iplookup_prefix_t; - -/** - * Create an IP lookup table - * - * @param name Name of the table to be created - * @param ODP_IGNORED_1 Unused - * @param ODP_IGNORED_2 Unused - * @param value_size Byte size of each entry in the table - * - * @return Handle of the created ip lookup table - * @retval NULL If table create failed - */ -odph_table_t odph_iplookup_table_create(const char *name, - uint32_t ODP_IGNORED_1, - uint32_t ODP_IGNORED_2, - uint32_t value_size); - -/** - * Lookup an IP lookup table by name - * - * @param name Name of the table to be located - * - * @return Handle of the located ip lookup table - * @retval NULL No table matching supplied name found - */ -odph_table_t odph_iplookup_table_lookup(const char *name); - -/** - * Destroy an IP lookup table - * - * @param table Handle of the ip lookup table to be destroyed - * - * @retval 0 Success - * @retval < 0 Failure - */ -int odph_iplookup_table_destroy(odph_table_t table); - -/** - * Insert a key/value pair into an ip lookup table - * - * @param table Table into which value is to be stored - * @param key Address of an odph_iplookup_prefix_t to be used as key - * @param value Value to be associated with specified key - * - * @retval >= 0 Success - * @retval < 0 Failure - */ -int odph_iplookup_table_put_value(odph_table_t table, void *key, void *value); - -/** - * Retrieve a value from an iplookup table - * - * @param table Table from which value is to be retrieved - * @param key Address of an odph_iplookup_prefix_t to be used as key - * @param[out] buffer Address of buffer to receive resulting value - * @param buffer_size Size of supplied buffer - * - * @retval 0 Success - * @retval 1 Success - * @retval < 0 Failure - */ -int odph_iplookup_table_get_value(odph_table_t table, void *key, - void *buffer, uint32_t buffer_size); - -/** - * Remove a value from an iplookup table - * - * @param table Table from which value is to be removed - * @param key Address of odph_iplookup_prefix_t to be used as key - * - * @retval >= 0 Success - * @retval < 0 Failure - * - */ -int odph_iplookup_table_remove_value(odph_table_t table, void *key); - -extern odph_table_ops_t odph_iplookup_table_ops; /**< @internal */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ODPH_IPLOOKUP_TABLE_H_ */ diff --git a/helper/include/odp/helper/odph_lineartable.h b/helper/include/odp/helper/odph_lineartable.h deleted file mode 100644 index dc61113a5..000000000 --- a/helper/include/odp/helper/odph_lineartable.h +++ /dev/null @@ -1,101 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2018 Linaro Limited - */ - -/** - * @file - * - * ODP Linear Table - */ - -#ifndef ODPH_LINEAR_TABLE_H_ -#define ODPH_LINEAR_TABLE_H_ - -#include <stdint.h> -#include <odp/helper/table.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup odph_lineartable ODPH LINEAR TABLE - * Linear table - * - * @{ - */ - -/** - * Create a linear table - * - * @param name Name of the linear table to be created - * @param capacity Number of elements table may store - * @param ODP_IGNORED Ignored parameter - * @param value_size Size of the value stored for each element - * - * @return Handle of created linear table - * @return NULL Create failed - */ -odph_table_t odph_linear_table_create(const char *name, - uint32_t capacity, - uint32_t ODP_IGNORED, - uint32_t value_size); - -/** - * Lookup a linear table - * - * @param name Name of the table to be located - * - * @return Handle of the located linear table - * @retval NULL No table matching supplied name found - */ -odph_table_t odph_linear_table_lookup(const char *name); - -/** - * Destroy a linear table - * - * @param table Handle of linear table to be destroyed - * - * @retval 0 Success - * @retval < 0 Failure - */ -int odph_linear_table_destroy(odph_table_t table); - -/** - * Insert a value into a linear table - * - * @param table Table into which value is to be stored - * @param key Index value used as key - * @param value Value to be assoceiated with specified key index - * - * @retval >= 0 Success - * @retval < 0 Failure - */ -int odph_linear_put_value(odph_table_t table, void *key, void *value); - -/** - * Retrieve a value from a linear table - * - * @param table Table from which value is to be retrieved - * @param key Index value used as key - * @param[out] buffer Address of buffer to receive resulting value - * @param buffer_size Size of supplied buffer - * - * @retval 0 Success - * @retval 1 Success - * @retval < 0 Failure - */ -int odph_linear_get_value(odph_table_t table, void *key, void *buffer, - uint32_t buffer_size); - -extern odph_table_ops_t odph_linear_table_ops; /**< @internal */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/helper/include/odp/helper/stress.h b/helper/include/odp/helper/stress.h new file mode 100644 index 000000000..cfdc41033 --- /dev/null +++ b/helper/include/odp/helper/stress.h @@ -0,0 +1,238 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2024 Nokia + */ + +/** + * @file + * + * ODP helper stress + */ + +#ifndef ODPH_STRESS_H_ +#define ODPH_STRESS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup odph_stress ODPH STRESS + * Dummy CPU stress functions + * + * These functions may be used in test applications to create dummy CPU load. Functions are not + * highly optimized, as they try to utilize various parts of CPU instruction set (load/store, + * branch, integer/float arithmetics, vector, etc. instructions). + * + * @{ + */ + +/** + * Returns 'value' raised to the power of 2 + * + * @param value Base value + * + * @return The value raised to the power of 2 + */ +static inline uint32_t odph_stress_pow2_u32(uint32_t value) +{ + uint64_t v = (uint64_t)value; + uint64_t res = v * v; + + if (odp_unlikely(res > UINT32_MAX)) + return UINT32_MAX; + + return (uint32_t)res; +} + +/** + * Returns base 2 logarithm of 'value' + * + * @param value The value for which the logarithm is being calculated + * + * @return Base 2 logarithm of 'value' + */ +static inline uint32_t odph_stress_log2_u32(uint32_t value) +{ + uint32_t ret = 0; + + while ((value >>= 1) != 0) + ret++; + + return ret; +} + +/** + * Calculates square root of a 32-bit unsigned integer value + * + * @param value The value for which the square root is being calculated + * + * @return Square root of the value + */ +static inline uint32_t odph_stress_sqrt_u32(uint32_t value) +{ + uint64_t x; + uint64_t pow = 1; + + if (odp_unlikely(value == 0 || value == 1)) + return value; + + if (value & 0xffff0000) { + if (value & 0xff000000) { + if (value & 0xf0000000) { + x = 16384; + if (value & 0xe0000000) + x = 23170; + if (value & 0xc0000000) + x = 32768; + if (value & 0x80000000) + x = 46340; + } else { + /* value & 0x0f000000 */ + x = 4096; + if (value & 0x0e000000) + x = 5792; + if (value & 0x0c000000) + x = 8192; + if (value & 0x08000000) + x = 11585; + } + } else { + if (value & 0x00f00000) { + x = 1024; + if (value & 0x00e00000) + x = 1448; + if (value & 0x00c00000) + x = 2048; + if (value & 0x00800000) + x = 2896; + } else { + /* value & 0x000f0000 */ + x = 256; + if (value & 0x000e0000) + x = 362; + if (value & 0x000c0000) + x = 512; + if (value & 0x00080000) + x = 724; + } + } + } else { + /* value & 0xffff */ + x = 1; + + if (value >= 16384) { + x = 128; + if (value >= 25600) + x = 160; + if (value >= 36864) + x = 192; + if (value >= 50176) + x = 224; + } else { + if (value >= 1024) + x = 32; + if (value >= 4096) + x = 64; + if (value >= 9216) + x = 96; + } + } + + while (pow <= value) { + x++; + pow = x * x; + } + + return (uint32_t)(x - 1); +} + +/** + * Calculates square root of a floating point value + * + * @param value The value for which the square root is being calculated + * + * @return Square root of the value + */ +static inline float odph_stress_sqrt_f32(float value) +{ + double x; + double pow = 1; + + if (odp_unlikely(value == 0 || value == 1)) + return value; + + if (value >= 65536) { + if (value >= 16777215) { + if (value >= 268435456) { + x = 16384; + if (value >= 536870912) + x = 23170; + if (value >= 1073741824) + x = 32768; + if (value >= 2147483648) + x = 46340; + } else { + x = 4096; + if (value >= 33554432) + x = 5792; + if (value >= 67108864) + x = 8192; + if (value >= 134217728) + x = 11585; + } + } else { + if (value >= 1048576) { + x = 1024; + if (value >= 2097152) + x = 1448; + if (value >= 4194304) + x = 2048; + if (value >= 8388608) + x = 2896; + } else { + x = 256; + if (value >= 131072) + x = 362; + if (value >= 262144) + x = 512; + if (value >= 524288) + x = 724; + } + } + } else { + x = 1; + + if (value >= 16384) { + x = 128; + if (value >= 25600) + x = 160; + if (value >= 36864) + x = 192; + if (value >= 50176) + x = 224; + } else { + if (value >= 1024) + x = 32; + if (value >= 4096) + x = 64; + if (value >= 9216) + x = 96; + } + } + + while (pow <= value) { + x = x + 1; + pow = x * x; + } + + return (float)(x - 1); +} + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/helper/include/odp/helper/string.h b/helper/include/odp/helper/string.h new file mode 100644 index 000000000..da2d61a6b --- /dev/null +++ b/helper/include/odp/helper/string.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2024 Nokia + */ + +/** + * @file + * + * ODP string helper + */ + +#ifndef ODPH_STRING_H_ +#define ODPH_STRING_H_ + +#include <odp/api/hints.h> +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup odph_string ODPH STRING + * String helper + * + * @{ + */ + +/** + * Copy a string + * + * Like strncpy(), but additionally ensures that the destination string is null + * terminated, unless sz is zero in which case returns dst without doing + * anything else. + * + * @param[out] dst Pointer to destination string. + * @param src Pointer to source string. + * @param sz Destination size. + * @return Pointer to destination string. + */ +#ifdef __cplusplus +ODP_UNUSED static char *odph_strcpy(char *dst, const char *src, size_t sz) +#else +ODP_UNUSED static char *odph_strcpy(char *restrict dst, const char *restrict src, size_t sz) +#endif +{ + if (!sz) + return dst; + + strncpy(dst, src, sz - 1); + dst[sz - 1] = 0; + return dst; +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/helper/include/odp/helper/table.h b/helper/include/odp/helper/table.h deleted file mode 100644 index 6a24e742b..000000000 --- a/helper/include/odp/helper/table.h +++ /dev/null @@ -1,244 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2018 Linaro Limited - */ - -/** - * @file - * - * ODP table - */ - -#ifndef ODPH_TABLE_H_ -#define ODPH_TABLE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup odph_tables ODPH TABLES - * Table interface - * - * @details - * TCAM(Ternary Content Addressable Memory) is used widely in packet - * forwarding to speedup the table lookup. - * - * This file contains a simple interface for creating and using the table. - * Table here means a collection of related data held in a structured - * format. - * Some examples for table are ARP Table, Routing Table, etc.The table - * contains many entries, each consist of key and associated data - * (called key/value pair or rule/action pair in some paper.). - * Enclosed are some classical table examples, used publicly - * in data plane packet processing: - * - * <H3>Use Case: ARP table</H3> - * Once a route has been identified for an IP packet (so the output - * interface and the IP address of the next hop station are known), - * the MAC address of the next hop station is needed in order to - * send this packet onto the next leg of the journey - * towards its destination (as identified by its destination IP address). - * The MAC address of the next hop station becomes the destination - * MAC address of the outgoing Ethernet frame. - * <ol> - * <li>Key: The pair of (Output interface, Next Hop IP address) - * <li>Associated Data: MAC address of the next hop station - * <li>Algorithm: Hash - * </ol> - * - * <H3>Use Case: Routing Table</H3> - * When each router receives a packet, it searches its routing table - * to find the best match between the destination IP address of - * the packet and one of the network addresses in the routing table. - * <ol> - * <li>Key: destination IP address - * <li>Associated Data: The pair of (Output interface, Next Hop IP address) - * <li>Algorithm: LPM(Longest Prefix Match) - * </ol> - * - * <H3>Use Case: Flow Classification</H3> - * The flow classification is executed at least once for each - * input packet.This operation maps each incoming packet against - * one of the known traffic - * flows in the flow database that typically contains millions of flows. - * <ol> - * <li>Key:n-tuple of packet fields that uniquely identify a traffic flow. - * <li>Associated data: - * actions and action meta-data describing what processing to be - * applied for the packets of the current flow, such as whether - * encryption/decryption is required on this packet, what kind of cipher - * algorithm should be chosen. - * <li>Algorithm: Hash - * </ol> - * - * All these different types of lookup tables have the common operations: - * create a table, destroy a table, add (key,associated data), - * delete key and look up the associated data via the key. - * Usually these operations are software based, but also can be - * hardware accelerated such as using TCAM to implement ARP table - * or Routing Table. - * And specific alogithm can be used for specific lookup table. - * - * notes: key/value and key/associated data mean the same thing - * in this file unless otherwise mentioned. - * - * @{ - */ - -#include <stdint.h> - -/** - * @def ODPH_TABLE_NAME_LEN - * Max length of table name - */ -#define ODPH_TABLE_NAME_LEN 32 - -#include <odp/helper/strong_types.h> -/** @internal ODPH table handle @return */ -typedef ODPH_HANDLE_T(odph_table_t); - -/** -* create a table -* Generally, tables only support key-value pair both with fixed size -* -* @param name -* name of this table, max ODPH_TABLE_NAME_LEN - 1 -* May be specified as NULL for anonymous table -* @param capacity -* Max memory usage this table use, in MBytes -* @param key_size -* fixed size of the 'key' in bytes. -* @param value_size -* fixed size of the 'value' in bytes. -* @return -* Handle to table instance or NULL if failed -* @note -*/ -typedef odph_table_t (*odph_table_create)(const char *name, - uint32_t capacity, - uint32_t key_size, - uint32_t value_size); - -/** - * Find a table by name - * - * @param name Name of the table - * - * @return Handle of found table - * @retval NULL table could not be found - * - * @note This routine cannot be used to look up an anonymous - * table (one created with no name). - * This API supports Multiprocess - */ -typedef odph_table_t (*odph_table_lookup)(const char *name); - -/** - * Destroy a table previously created by odph_table_create() - * - * @param table Handle of the table to be destroyed - * - * @retval 0 Success - * @retval -1 Failure - * - * @note This routine destroys a previously created pool - * also should free any memory allocated at creation - * - */ -typedef int (*odph_table_destroy)(odph_table_t table); - -/** - * Add (key,associated data) pair into the specific table. - * When no associated data is currently associated with key, - * then the (key,assocatied data) association is created. - * When key is already associated with data0, then association (key, data0) - * will be removed and association (key, associated data) is created. - * - * @param table Handle of the table that the element be added - * - * @param key address of 'key' in key-value pair. - * User should make sure the address and 'key_size' - * bytes after are accessible - * @param value address of 'value' in key-value pair - * User should make sure the address and 'value_size' - * bytes after are accessible - * @retval 0 Success - * @retval -1 Failure - * @note Add a same key again with a new value, the older one will - * be covered. - */ -typedef int (*odph_table_put_value)(odph_table_t table, void *key, - void *value); - -/** - * Lookup the associated data via specific key. - * When no value is currently associated with key, then this operation - * restuns <0 to indicate the lookup miss. - * When key is associated with value, - * then this operation returns value. - * The (key,value) association won't change. - * - * @param table Handle of the table that the element be added - * - * @param key address of 'key' in key-value pair - * User should make sure the address and key_size bytes after - * are accessible - * - * @param buffer output The buffer address to the 'value' - * After successfully found, the content of 'value' will be - * copied to this address - * User should make sure the address and value_size bytes - * after are accessible - * @param buffer_size size of the buffer - * should be equal or bigger than value_size - * @retval 0 Success - * @retval -1 Failure - * - * @note - */ -typedef int (*odph_table_get_value)(odph_table_t table, void *key, - void *buffer, - uint32_t buffer_size); -/** - * Delete the association specified by key - * When no data is currently associated with key, this operation - * has no effect. When key is already associated data ad0, - * then (key,ad0) pair is deleted. - * - * @param table Handle of the table that the element will be removed from - * - * @param key address of 'key' in key-value pair - * User should make sure the address and key_size bytes after - * are accessible - * - * @retval 0 Success - * @retval -1 Failure - * - * @note - */ -typedef int (*odph_table_remove_value)(odph_table_t table, void *key); - -/** - * Table interface set. Defining the table operations. - */ -typedef struct odph_table_ops_t { - odph_table_create f_create; /**< Table Create */ - odph_table_lookup f_lookup; /**< Table Lookup */ - odph_table_destroy f_des; /**< Table Destroy */ - /** add (key,associated data) pair into the specific table */ - odph_table_put_value f_put; - /** lookup the associated data via specific key */ - odph_table_get_value f_get; - /** delete the association specified by key */ - odph_table_remove_value f_remove; -} odph_table_ops_t; - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/helper/include/odp/helper/threads.h b/helper/include/odp/helper/threads.h index c18a46e8a..ca420e80a 100644 --- a/helper/include/odp/helper/threads.h +++ b/helper/include/odp/helper/threads.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright (c) 2013-2018 Linaro Limited - * Copyright (c) 2019-2021 Nokia + * Copyright (c) 2019-2024 Nokia */ @@ -191,6 +191,20 @@ typedef struct { } odph_thread_common_param_t; +/** Thread join result */ +typedef struct { + /** Exit caused by signal */ + odp_bool_t is_sig; + + /** + * Exit status of the joined thread/process + * + * If 'is_sig' is true, then this is the signal number that caused + * process exit. Otherwise status of the exited thread/process. + */ + int ret; +} odph_thread_join_result_t; + /** * Initialize thread params * @@ -236,7 +250,8 @@ void odph_thread_common_param_init(odph_thread_common_param_t *param); * thread goes to the smallest CPU number of the mask, etc. * * Launched threads may be waited for exit with odph_thread_join(), or with - * direct Linux system calls. + * direct Linux system calls. If odph_thread_join() is used, the output thread + * table elements must not be modified during the life time of the threads. * * @param[out] thread Thread table for output * @param param Common parameters for all threads to be created @@ -261,10 +276,14 @@ int odph_thread_create(odph_thread_t thread[], * A function call may be used to wait any number of launched threads to exit. * A particular thread may be waited only once. * + * Threads are joined in the order they are in 'thread' table. Returns on the + * first non-zero exit status or other failure. + * * @param thread Table of threads to exit * @param num Number of threads to exit * - * @return Number of threads exited + * @return Number of threads successfully joined with zero exit status + * (0 ... num) * @retval -1 On failure * * @see odph_thread_create() @@ -272,6 +291,26 @@ int odph_thread_create(odph_thread_t thread[], int odph_thread_join(odph_thread_t thread[], int num); /** + * Wait previously launched threads to exit + * + * Similar to odph_thread_join() but outputs results of joined threads and + * stops only if the actual join operation fails for some thread. Threads are + * joined in the order they are in 'thread' table. Returns number of threads + * successfully joined and writes respective exit statuses into the 'res' + * table. + * + * @param thread Table of threads to exit + * @param[out] res Table for result output + * @param num Number of threads to exit and results to output + * + * @return Number of threads successfully joined (0 ... num) + * @retval -1 On failure + * + * @see odph_thread_create() + */ +int odph_thread_join_result(odph_thread_t thread[], odph_thread_join_result_t res[], int num); + +/** * Set CPU affinity of the current odp thread * * CPU affinity determines the CPU core on which the thread is diff --git a/helper/include/odph_list_internal.h b/helper/include/odph_list_internal.h deleted file mode 100644 index d90b07ebc..000000000 --- a/helper/include/odph_list_internal.h +++ /dev/null @@ -1,88 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2018 Linaro Limited - */ - -/** - * @file - * - * ODP list - * a simple implementation of Doubly linked list - */ - -#ifndef ODPH_LIST_INTER_H_ -#define ODPH_LIST_INTER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @cond _ODP_HIDE_FROM_DOXYGEN_ */ - -typedef struct odph_list_object { - struct odph_list_object *next; - - struct odph_list_object *prev; -} odph_list_object; - -typedef odph_list_object odph_list_head; - -static inline void ODPH_INIT_LIST_HEAD(odph_list_object *list) -{ - list->next = list; - list->prev = list; -} - -static inline void __odph_list_add(odph_list_object *new, - odph_list_object *prev, - odph_list_object *next) -{ - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; -} - -static inline void odph_list_add(odph_list_object *new, odph_list_object *head) -{ - __odph_list_add(new, head, head->next); -} - -static inline void odph_list_add_tail(struct odph_list_object *new, - odph_list_object *head) -{ - __odph_list_add(new, head->prev, head); -} - -static inline void __odph_list_del(struct odph_list_object *prev, - odph_list_object *next) -{ - next->prev = prev; - prev->next = next; -} - -static inline void odph_list_del(struct odph_list_object *entry) -{ - __odph_list_del(entry->prev, entry->next); - ODPH_INIT_LIST_HEAD(entry); -} - -static inline int odph_list_empty(const struct odph_list_object *head) -{ - return head->next == head; -} - -#define container_of(ptr, type, list_node) \ - ((type *)(void *)((char *)ptr - offsetof(type, list_node))) - -#define ODPH_LIST_FOR_EACH(pos, list_head, type, list_node) \ - for (pos = container_of((list_head)->next, type, list_node); \ - &pos->list_node != (list_head); \ - pos = container_of(pos->list_node.next, type, list_node)) - -/** @endcond */ - -#ifdef __cplusplus -} -#endif - -#endif |