net: pkt: Refactor because of timeout overhaul

Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2020-04-03 14:03:03 +03:00
commit b9cbf8a5ed
2 changed files with 104 additions and 85 deletions

View file

@ -1034,27 +1034,27 @@ static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
*/ */
struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool, struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_get_reserve_data(pool, timeout) \ #define net_pkt_get_reserve_data(pool, timeout) \
net_pkt_get_reserve_data_debug(pool, timeout, __func__, __LINE__) net_pkt_get_reserve_data_debug(pool, timeout, __func__, __LINE__)
struct net_buf *net_pkt_get_reserve_rx_data_debug(s32_t timeout, struct net_buf *net_pkt_get_reserve_rx_data_debug(k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_get_reserve_rx_data(timeout) \ #define net_pkt_get_reserve_rx_data(timeout) \
net_pkt_get_reserve_rx_data_debug(timeout, __func__, __LINE__) net_pkt_get_reserve_rx_data_debug(timeout, __func__, __LINE__)
struct net_buf *net_pkt_get_reserve_tx_data_debug(s32_t timeout, struct net_buf *net_pkt_get_reserve_tx_data_debug(k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_get_reserve_tx_data(timeout) \ #define net_pkt_get_reserve_tx_data(timeout) \
net_pkt_get_reserve_tx_data_debug(timeout, __func__, __LINE__) net_pkt_get_reserve_tx_data_debug(timeout, __func__, __LINE__)
struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt,
s32_t timeout, k_timeout_t timeout,
const char *caller, int line); const char *caller, int line);
#define net_pkt_get_frag(pkt, timeout) \ #define net_pkt_get_frag(pkt, timeout) \
net_pkt_get_frag_debug(pkt, timeout, __func__, __LINE__) net_pkt_get_frag_debug(pkt, timeout, __func__, __LINE__)
@ -1118,13 +1118,12 @@ void net_pkt_print_frags(struct net_pkt *pkt);
* *
* @param timeout Affects the action taken should the net buf pool be empty. * @param timeout Affects the action taken should the net buf pool be empty.
* If K_NO_WAIT, then return immediately. If K_FOREVER, then * If K_NO_WAIT, then return immediately. If K_FOREVER, then
* wait as long as necessary. Otherwise, wait up to the specified * wait as long as necessary. Otherwise, wait up to the specified time.
* number of milliseconds before timing out.
* *
* @return Network buffer if successful, NULL otherwise. * @return Network buffer if successful, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_buf *net_pkt_get_reserve_rx_data(s32_t timeout); struct net_buf *net_pkt_get_reserve_rx_data(k_timeout_t timeout);
#endif #endif
/** /**
@ -1136,13 +1135,12 @@ struct net_buf *net_pkt_get_reserve_rx_data(s32_t timeout);
* *
* @param timeout Affects the action taken should the net buf pool be empty. * @param timeout Affects the action taken should the net buf pool be empty.
* If K_NO_WAIT, then return immediately. If K_FOREVER, then * If K_NO_WAIT, then return immediately. If K_FOREVER, then
* wait as long as necessary. Otherwise, wait up to the specified * wait as long as necessary. Otherwise, wait up to the specified time.
* number of milliseconds before timing out.
* *
* @return Network buffer if successful, NULL otherwise. * @return Network buffer if successful, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_buf *net_pkt_get_reserve_tx_data(s32_t timeout); struct net_buf *net_pkt_get_reserve_tx_data(k_timeout_t timeout);
#endif #endif
/** /**
@ -1152,13 +1150,12 @@ struct net_buf *net_pkt_get_reserve_tx_data(s32_t timeout);
* @param pkt Network packet. * @param pkt Network packet.
* @param timeout Affects the action taken should the net buf pool be empty. * @param timeout Affects the action taken should the net buf pool be empty.
* If K_NO_WAIT, then return immediately. If K_FOREVER, then * If K_NO_WAIT, then return immediately. If K_FOREVER, then
* wait as long as necessary. Otherwise, wait up to the specified * wait as long as necessary. Otherwise, wait up to the specified time.
* number of milliseconds before timing out.
* *
* @return Network buffer if successful, NULL otherwise. * @return Network buffer if successful, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, s32_t timeout); struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, k_timeout_t timeout);
#endif #endif
/** /**
@ -1299,31 +1296,31 @@ const char *net_pkt_pool2str(struct net_buf_pool *pool);
*/ */
#if defined(NET_PKT_DEBUG_ENABLED) #if defined(NET_PKT_DEBUG_ENABLED)
struct net_pkt *net_pkt_alloc_debug(s32_t timeout, struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
const char *caller, int line); const char *caller, int line);
#define net_pkt_alloc(_timeout) \ #define net_pkt_alloc(_timeout) \
net_pkt_alloc_debug(_timeout, __func__, __LINE__) net_pkt_alloc_debug(_timeout, __func__, __LINE__)
struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab, struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
s32_t timeout, k_timeout_t timeout,
const char *caller, int line); const char *caller, int line);
#define net_pkt_alloc_from_slab(_slab, _timeout) \ #define net_pkt_alloc_from_slab(_slab, _timeout) \
net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__) net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
struct net_pkt *net_pkt_rx_alloc_debug(s32_t timeout, struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
const char *caller, int line); const char *caller, int line);
#define net_pkt_rx_alloc(_timeout) \ #define net_pkt_rx_alloc(_timeout) \
net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__) net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface, struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_alloc_on_iface(_iface, _timeout) \ #define net_pkt_alloc_on_iface(_iface, _timeout) \
net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__) net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface, struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \ #define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
@ -1333,7 +1330,7 @@ struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
int net_pkt_alloc_buffer_debug(struct net_pkt *pkt, int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
size_t size, size_t size,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, int line); const char *caller, int line);
#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \ #define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \ net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
@ -1343,7 +1340,7 @@ struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_alloc_with_buffer(_iface, _size, _family, \ #define net_pkt_alloc_with_buffer(_iface, _size, _family, \
@ -1356,7 +1353,7 @@ struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line); int line);
#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \ #define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
@ -1373,12 +1370,12 @@ struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
* @details for the time being, 2 pools are used. One for TX and one for RX. * @details for the time being, 2 pools are used. One for TX and one for RX.
* This allocator has to be used for TX. * This allocator has to be used for TX.
* *
* @param timeout Maximum time in milliseconds to wait for an allocation. * @param timeout Maximum time to wait for an allocation.
* *
* @return a pointer to a newly allocated net_pkt on success, NULL otherwise. * @return a pointer to a newly allocated net_pkt on success, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_pkt *net_pkt_alloc(s32_t timeout); struct net_pkt *net_pkt_alloc(k_timeout_t timeout);
#endif #endif
/** /**
@ -1391,13 +1388,13 @@ struct net_pkt *net_pkt_alloc(s32_t timeout);
* then buffer on its local slab/pool (if any). * then buffer on its local slab/pool (if any).
* *
* @param slab The slab to use for allocating the packet * @param slab The slab to use for allocating the packet
* @param timeout Maximum time in milliseconds to wait for an allocation. * @param timeout Maximum time to wait for an allocation.
* *
* @return a pointer to a newly allocated net_pkt on success, NULL otherwise. * @return a pointer to a newly allocated net_pkt on success, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab, struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
s32_t timeout); k_timeout_t timeout);
#endif #endif
/** /**
@ -1406,27 +1403,29 @@ struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
* @details for the time being, 2 pools are used. One for TX and one for RX. * @details for the time being, 2 pools are used. One for TX and one for RX.
* This allocator has to be used for RX. * This allocator has to be used for RX.
* *
* @param timeout Maximum time in milliseconds to wait for an allocation. * @param timeout Maximum time to wait for an allocation.
* *
* @return a pointer to a newly allocated net_pkt on success, NULL otherwise. * @return a pointer to a newly allocated net_pkt on success, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_pkt *net_pkt_rx_alloc(s32_t timeout); struct net_pkt *net_pkt_rx_alloc(k_timeout_t timeout);
#endif #endif
/** /**
* @brief Allocate a network packet for a specific network interface. * @brief Allocate a network packet for a specific network interface.
* *
* @param iface The network interface the packet is supposed to go through. * @param iface The network interface the packet is supposed to go through.
* @param timeout Maximum time in milliseconds to wait for an allocation. * @param timeout Maximum time to wait for an allocation.
* *
* @return a pointer to a newly allocated net_pkt on success, NULL otherwise. * @return a pointer to a newly allocated net_pkt on success, NULL otherwise.
*/ */
#if !defined(NET_PKT_DEBUG_ENABLED) #if !defined(NET_PKT_DEBUG_ENABLED)
struct net_pkt *net_pkt_alloc_on_iface(struct net_if *iface, s32_t timeout); struct net_pkt *net_pkt_alloc_on_iface(struct net_if *iface,
k_timeout_t timeout);
/* Same as above but specifically for RX packet */ /* Same as above but specifically for RX packet */
struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface, s32_t timeout); struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
k_timeout_t timeout);
#endif #endif
/** /**
@ -1440,7 +1439,7 @@ struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface, s32_t timeout);
* @param pkt The network packet requiring buffer to be allocated. * @param pkt The network packet requiring buffer to be allocated.
* @param size The size of buffer being requested. * @param size The size of buffer being requested.
* @param proto The IP protocol type (can be 0 for none). * @param proto The IP protocol type (can be 0 for none).
* @param timeout Maximum time in milliseconds to wait for an allocation. * @param timeout Maximum time to wait for an allocation.
* *
* @return 0 on success, negative errno code otherwise. * @return 0 on success, negative errno code otherwise.
*/ */
@ -1448,7 +1447,7 @@ struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface, s32_t timeout);
int net_pkt_alloc_buffer(struct net_pkt *pkt, int net_pkt_alloc_buffer(struct net_pkt *pkt,
size_t size, size_t size,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout); k_timeout_t timeout);
#endif #endif
/** /**
@ -1458,7 +1457,7 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt,
* @param size The size of buffer. * @param size The size of buffer.
* @param family The family to which the packet belongs. * @param family The family to which the packet belongs.
* @param proto The IP protocol type (can be 0 for none). * @param proto The IP protocol type (can be 0 for none).
* @param timeout Maximum time in milliseconds to wait for an allocation. * @param timeout Maximum time to wait for an allocation.
* *
* @return a pointer to a newly allocated net_pkt on success, NULL otherwise. * @return a pointer to a newly allocated net_pkt on success, NULL otherwise.
*/ */
@ -1467,14 +1466,14 @@ struct net_pkt *net_pkt_alloc_with_buffer(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout); k_timeout_t timeout);
/* Same as above but specifically for RX packet */ /* Same as above but specifically for RX packet */
struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface, struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout); k_timeout_t timeout);
#endif #endif
/** /**
@ -1629,7 +1628,7 @@ int net_pkt_copy(struct net_pkt *pkt_dst,
* *
* @return NULL if error, cloned packet otherwise. * @return NULL if error, cloned packet otherwise.
*/ */
struct net_pkt *net_pkt_clone(struct net_pkt *pkt, s32_t timeout); struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
/** /**
* @brief Clone pkt and increase the refcount of its buffer. * @brief Clone pkt and increase the refcount of its buffer.
@ -1639,7 +1638,8 @@ struct net_pkt *net_pkt_clone(struct net_pkt *pkt, s32_t timeout);
* *
* @return NULL if error, cloned packet otherwise. * @return NULL if error, cloned packet otherwise.
*/ */
struct net_pkt *net_pkt_shallow_clone(struct net_pkt *pkt, s32_t timeout); struct net_pkt *net_pkt_shallow_clone(struct net_pkt *pkt,
k_timeout_t timeout);
/** /**
* @brief Read some data from a net_pkt * @brief Read some data from a net_pkt

View file

@ -360,12 +360,12 @@ void net_pkt_print_frags(struct net_pkt *pkt)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool, struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else /* NET_LOG_LEVEL >= LOG_LEVEL_DBG */ #else /* NET_LOG_LEVEL >= LOG_LEVEL_DBG */
struct net_buf *net_pkt_get_reserve_data(struct net_buf_pool *pool, struct net_buf *net_pkt_get_reserve_data(struct net_buf_pool *pool,
s32_t timeout) k_timeout_t timeout)
#endif /* NET_LOG_LEVEL >= LOG_LEVEL_DBG */ #endif /* NET_LOG_LEVEL >= LOG_LEVEL_DBG */
{ {
struct net_buf *frag; struct net_buf *frag;
@ -405,11 +405,11 @@ struct net_buf *net_pkt_get_reserve_data(struct net_buf_pool *pool,
*/ */
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt,
s32_t timeout, k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, struct net_buf *net_pkt_get_frag(struct net_pkt *pkt,
s32_t timeout) k_timeout_t timeout)
#endif #endif
{ {
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) #if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
@ -443,13 +443,13 @@ struct net_buf *net_pkt_get_frag(struct net_pkt *pkt,
} }
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_buf *net_pkt_get_reserve_rx_data_debug(s32_t timeout, struct net_buf *net_pkt_get_reserve_rx_data_debug(k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
{ {
return net_pkt_get_reserve_data_debug(&rx_bufs, timeout, caller, line); return net_pkt_get_reserve_data_debug(&rx_bufs, timeout, caller, line);
} }
struct net_buf *net_pkt_get_reserve_tx_data_debug(s32_t timeout, struct net_buf *net_pkt_get_reserve_tx_data_debug(k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
{ {
return net_pkt_get_reserve_data_debug(&tx_bufs, timeout, caller, line); return net_pkt_get_reserve_data_debug(&tx_bufs, timeout, caller, line);
@ -457,12 +457,12 @@ struct net_buf *net_pkt_get_reserve_tx_data_debug(s32_t timeout,
#else /* NET_LOG_LEVEL >= LOG_LEVEL_DBG */ #else /* NET_LOG_LEVEL >= LOG_LEVEL_DBG */
struct net_buf *net_pkt_get_reserve_rx_data(s32_t timeout) struct net_buf *net_pkt_get_reserve_rx_data(k_timeout_t timeout)
{ {
return net_pkt_get_reserve_data(&rx_bufs, timeout); return net_pkt_get_reserve_data(&rx_bufs, timeout);
} }
struct net_buf *net_pkt_get_reserve_tx_data(s32_t timeout) struct net_buf *net_pkt_get_reserve_tx_data(k_timeout_t timeout)
{ {
return net_pkt_get_reserve_data(&tx_bufs, timeout); return net_pkt_get_reserve_data(&tx_bufs, timeout);
} }
@ -850,14 +850,14 @@ void net_pkt_print(void)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool, static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool,
size_t size, s32_t timeout, size_t size, k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool, static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool,
size_t size, s32_t timeout) size_t size, k_timeout_t timeout)
#endif #endif
{ {
u32_t alloc_start = k_uptime_get_32(); u64_t end = z_timeout_end_calc(timeout);
struct net_buf *first = NULL; struct net_buf *first = NULL;
struct net_buf *current = NULL; struct net_buf *current = NULL;
@ -882,10 +882,15 @@ static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool,
size -= current->size; size -= current->size;
if (timeout != K_NO_WAIT && timeout != K_FOREVER) { if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) &&
u32_t diff = k_uptime_get_32() - alloc_start; !K_TIMEOUT_EQ(timeout, K_FOREVER)) {
s64_t remaining = end - z_tick_get();
timeout -= MIN(timeout, diff); if (remaining <= 0) {
break;
}
timeout = Z_TIMEOUT_TICKS(remaining);
} }
#if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG #if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
@ -912,11 +917,11 @@ error:
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool, static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool,
size_t size, s32_t timeout, size_t size, k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool, static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool,
size_t size, s32_t timeout) size_t size, k_timeout_t timeout)
#endif #endif
{ {
struct net_buf *buf; struct net_buf *buf;
@ -1088,17 +1093,17 @@ void net_pkt_trim_buffer(struct net_pkt *pkt)
int net_pkt_alloc_buffer_debug(struct net_pkt *pkt, int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
size_t size, size_t size,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else #else
int net_pkt_alloc_buffer(struct net_pkt *pkt, int net_pkt_alloc_buffer(struct net_pkt *pkt,
size_t size, size_t size,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout) k_timeout_t timeout)
#endif #endif
{ {
u32_t alloc_start = k_uptime_get_32(); u64_t end = z_timeout_end_calc(timeout);
struct net_buf_pool *pool = NULL; struct net_buf_pool *pool = NULL;
size_t alloc_len = 0; size_t alloc_len = 0;
size_t hdr_len = 0; size_t hdr_len = 0;
@ -1137,10 +1142,15 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt,
pool = pkt->slab == &tx_pkts ? &tx_bufs : &rx_bufs; pool = pkt->slab == &tx_pkts ? &tx_bufs : &rx_bufs;
} }
if (timeout != K_NO_WAIT && timeout != K_FOREVER) { if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) &&
u32_t diff = k_uptime_get_32() - alloc_start; !K_TIMEOUT_EQ(timeout, K_FOREVER)) {
s64_t remaining = end - z_tick_get();
timeout -= MIN(timeout, diff); if (remaining <= 0) {
timeout = K_NO_WAIT;
} else {
timeout = Z_TIMEOUT_TICKS(remaining);
}
} }
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1165,10 +1175,10 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt,
} }
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, s32_t timeout, static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, s32_t timeout) static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, k_timeout_t timeout)
#endif #endif
{ {
struct net_pkt *pkt; struct net_pkt *pkt;
@ -1225,10 +1235,10 @@ static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, s32_t timeout)
} }
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_pkt *net_pkt_alloc_debug(s32_t timeout, struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
struct net_pkt *net_pkt_alloc(s32_t timeout) struct net_pkt *net_pkt_alloc(k_timeout_t timeout)
#endif #endif
{ {
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1240,11 +1250,11 @@ struct net_pkt *net_pkt_alloc(s32_t timeout)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab, struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
s32_t timeout, k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab, struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
s32_t timeout) k_timeout_t timeout)
#endif #endif
{ {
if (!slab) { if (!slab) {
@ -1259,10 +1269,10 @@ struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
} }
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_pkt *net_pkt_rx_alloc_debug(s32_t timeout, struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
struct net_pkt *net_pkt_rx_alloc(s32_t timeout) struct net_pkt *net_pkt_rx_alloc(k_timeout_t timeout)
#endif #endif
{ {
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1274,11 +1284,13 @@ struct net_pkt *net_pkt_rx_alloc(s32_t timeout)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
static struct net_pkt *pkt_alloc_on_iface(struct k_mem_slab *slab, static struct net_pkt *pkt_alloc_on_iface(struct k_mem_slab *slab,
struct net_if *iface, s32_t timeout, struct net_if *iface,
k_timeout_t timeout,
const char *caller, int line) const char *caller, int line)
#else #else
static struct net_pkt *pkt_alloc_on_iface(struct k_mem_slab *slab, static struct net_pkt *pkt_alloc_on_iface(struct k_mem_slab *slab,
struct net_if *iface, s32_t timeout) struct net_if *iface,
k_timeout_t timeout)
#endif #endif
{ {
@ -1299,11 +1311,12 @@ static struct net_pkt *pkt_alloc_on_iface(struct k_mem_slab *slab,
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface, struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else #else
struct net_pkt *net_pkt_alloc_on_iface(struct net_if *iface, s32_t timeout) struct net_pkt *net_pkt_alloc_on_iface(struct net_if *iface,
k_timeout_t timeout)
#endif #endif
{ {
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1315,11 +1328,12 @@ struct net_pkt *net_pkt_alloc_on_iface(struct net_if *iface, s32_t timeout)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface, struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else #else
struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface, s32_t timeout) struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
k_timeout_t timeout)
#endif #endif
{ {
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1336,7 +1350,7 @@ pkt_alloc_with_buffer(struct k_mem_slab *slab,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else #else
@ -1346,10 +1360,10 @@ pkt_alloc_with_buffer(struct k_mem_slab *slab,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout) k_timeout_t timeout)
#endif #endif
{ {
u32_t alloc_start = k_uptime_get_32(); u64_t end = z_timeout_end_calc(timeout);
struct net_pkt *pkt; struct net_pkt *pkt;
int ret; int ret;
@ -1367,10 +1381,15 @@ pkt_alloc_with_buffer(struct k_mem_slab *slab,
net_pkt_set_family(pkt, family); net_pkt_set_family(pkt, family);
if (timeout != K_NO_WAIT && timeout != K_FOREVER) { if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) &&
u32_t diff = k_uptime_get_32() - alloc_start; !K_TIMEOUT_EQ(timeout, K_FOREVER)) {
s64_t remaining = end - z_tick_get();
timeout -= MIN(timeout, diff); if (remaining <= 0) {
timeout = K_NO_WAIT;
} else {
timeout = Z_TIMEOUT_TICKS(remaining);
}
} }
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1393,7 +1412,7 @@ struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else #else
@ -1401,7 +1420,7 @@ struct net_pkt *net_pkt_alloc_with_buffer(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout) k_timeout_t timeout)
#endif #endif
{ {
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1418,7 +1437,7 @@ struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout, k_timeout_t timeout,
const char *caller, const char *caller,
int line) int line)
#else #else
@ -1426,7 +1445,7 @@ struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
size_t size, size_t size,
sa_family_t family, sa_family_t family,
enum net_ip_protocol proto, enum net_ip_protocol proto,
s32_t timeout) k_timeout_t timeout)
#endif #endif
{ {
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG #if NET_LOG_LEVEL >= LOG_LEVEL_DBG
@ -1725,7 +1744,7 @@ static void clone_pkt_attributes(struct net_pkt *pkt, struct net_pkt *clone_pkt)
} }
} }
struct net_pkt *net_pkt_clone(struct net_pkt *pkt, s32_t timeout) struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout)
{ {
size_t cursor_offset = net_pkt_get_current_offset(pkt); size_t cursor_offset = net_pkt_get_current_offset(pkt);
struct net_pkt *clone_pkt; struct net_pkt *clone_pkt;
@ -1774,7 +1793,7 @@ struct net_pkt *net_pkt_clone(struct net_pkt *pkt, s32_t timeout)
return clone_pkt; return clone_pkt;
} }
struct net_pkt *net_pkt_shallow_clone(struct net_pkt *pkt, s32_t timeout) struct net_pkt *net_pkt_shallow_clone(struct net_pkt *pkt, k_timeout_t timeout)
{ {
struct net_pkt *clone_pkt; struct net_pkt *clone_pkt;
struct net_buf *buf; struct net_buf *buf;