10000 gnrc/sixlowpan: migrate to ztimer_msec by jue89 · Pull Request #19067 · RIOT-OS/RIOT · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gnrc/sixlowpan: migrate to ztimer_msec #19067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions sys/include/net/gnrc/sixlowpan/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,29 @@ extern "C" {
#endif

/**
* @brief Timeout for reassembly buffer entries in microseconds
* @brief Timeout for reassembly buffer entries in milliseconds
*
* @note Only applicable with
* [gnrc_sixlowpan_frag_rb](@ref net_gnrc_sixlowpan_frag_rb) module
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS
#ifndef CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (3U)
Copy link
Contributor
@kfessel kfessel Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (3U)
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (3000U)

old default was "(3U * US_PER_SEC) " -> 3000 ms or 3 seconds

#else
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US / US_PER_SEC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US / US_PER_SEC)
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US / US_PER_MS)

#endif
#endif

/**
* @brief Timeout for reassembly buffer entries in microseconds
*
* @note Only applicable with
* [gnrc_sixlowpan_frag_rb](@ref net_gnrc_sixlowpan_frag_rb) module
*
* @deprecated Use @ref CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS instead.
* Will be removed after 2023.01 release.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual deprecation cycle is two releases, since the 2023.01 release is just up ahead, I think, 2023.07 is the better release to deprecate. This way users still have some time to adjust ;-).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping?

*/
#ifdef DOXYGEN
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US (3U * US_PER_SEC)
#endif

Expand All @@ -99,7 +116,7 @@ extern "C" {
* When not set, it will cause the reassembly buffer to override the oldest
* entry when a fragment for a new datagram is received. When set, only the
* oldest entry that is older than @ref
* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US will be overwritten (they will
* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS will be overwritten (they will
* still timeout normally if reassembly buffer is not full).
*/
#ifdef DOXYGEN
Expand All @@ -112,13 +129,30 @@ extern "C" {
* @note Only applicable with
* [gnrc_sixlowpan_frag_rb](@ref net_gnrc_sixlowpan_frag_rb) module
*
* @deprecated Use @ref CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS instead.
* Will be removed after 2023.01 release.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

*/
#ifdef DOXYGEN
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER (0U)
#endif

/**
* @brief Deletion timer for reassembly buffer entries in milliseconds
*
* @note Only applicable with
* [gnrc_sixlowpan_frag_rb](@ref net_gnrc_sixlowpan_frag_rb) module
*
* Time to pass between completion of a datagram and the deletion of its
* reassembly buffer entry. If this value is 0, the entry is dropped
* immediately. Use this value to prevent re-creation of a reassembly buffer
* entry on late arriving link-layer duplicates.
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS
#ifndef CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER (0U)
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS (0U)
#else
#define CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER / US_PER_MS)
#endif
#endif

/**
Expand Down Expand Up @@ -154,14 +188,33 @@ extern "C" {
#endif /* CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_SIZE */

/**
* @brief Timeout for a VRB entry in microseconds
* @brief Timeout for a VRB entry in milliseconds
*
* @see https://tools.ietf.org/html/draft-ietf-lwig-6lowpan-virtual-reassembly-01
*
* @note Only applicable with
* [gnrc_sixlowpan_frag_vrb](@ref net_gnrc_sixlowpan_frag_vrb) module.
*/
#ifndef CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_MS
#ifndef CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_US
#define CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_MS (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS)
#else
#define CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_MS (CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_US / US_PER_MS)
#endif
#endif /* CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_MS */

/**
* @brief Timeout for a VRB entry in microseconds
*
* @see https://tools.ietf.org/html/draft-ietf-lwig-6lowpan-virtual 1E79 -reassembly-01
*
* @note Only applicable with
* [gnrc_sixlowpan_frag_vrb](@ref net_gnrc_sixlowpan_frag_vrb) module.
*
* @deprecated Use @ref CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_MS instead.
* Will be removed after 2023.01 release.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

*/
#ifdef DOXYGEN
#define CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_US (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US)
#endif /* CONFIG_GNRC_SIXLOWPAN_FRAG_VRB_TIMEOUT_US */

Expand Down
2 changes: 1 addition & 1 deletion sys/include/net/gnrc/sixlowpan/frag/rb.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef struct {
* @brief The number of bytes currently received of the complete datagram
*/
uint16_t current_size;
uint32_t arrival; /**< time in microseconds of arrival of
uint32_t arrival; /**< time in milliseconds of arrival of
* last received fragment */
} gnrc_sixlowpan_frag_rb_base_t;

Expand Down
3 changes: 1 addition & 2 deletions sys/include/net/gnrc/sixlowpan/frag/sfr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "evtimer_msg.h"
#include "modules.h"
#include "msg.h"
#include "xtimer.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -52,7 +51,7 @@ typedef struct gnrc_sixlowpan_frag_sfr_fb {
* @brief Acknowledgment request timeout event
*/
evtimer_msg_event_t arq_timeout_event;
uint32_t arq_timeout; /**< Time in microseconds the sender should
uint32_t arq_timeout; /**< Time in milliseconds the sender should
* wait for an RFRAG Acknowledgment */
uint8_t cur_seq; /**< Sequence number for next fragment */
uint8_t frags_sent; /**< Number of fragments sent */
10000 Expand Down
8 changes: 3 additions & 5 deletions sys/net/gnrc/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ ifneq (,$(filter gnrc_sixlowpan_frag_minfwd,$(USEMODULE)))
endif

ifneq (,$(filter gnrc_sixlowpan_frag_rb,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += ztimer_msec
endif

ifneq (,$(filter gnrc_sixlowpan_frag_sfr,$(USEMODULE)))
Expand All @@ -237,7 +237,7 @@ ifneq (,$(filter gnrc_sixlowpan_frag_sfr,$(USEMODULE)))
USEMODULE += gnrc_sixlowpan_frag_vrb
USEMODULE += gnrc_sixlowpan_frag_rb
USEMODULE += evtimer
USEMODULE += xtimer
USEMODULE += ztimer_msec
endif

ifneq (,$(filter gnrc_sixlowpan_frag_sfr_congure_%,$(USEMODULE)))
Expand Down Expand Up @@ -287,9 +287,7 @@ endif

ifneq (,$(filter gnrc_sixlowpan_ctx,$(USEMODULE)))
USEMODULE += ipv6_addr
ifeq (,$(filter ztimer_msec,$(USEMODULE)))
USEMODULE += xtimer
endif
USEMODULE += ztimer_msec
endif

ifneq (,$(filter gnrc_ipv6_default,$(USEMODULE)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@

#include "mutex.h"
#include "net/gnrc/sixlowpan/ctx.h"
#if IS_USED(MODULE_ZTIMER_MSEC)
#include "ztimer.h"
#include "timex.h"
#else
#include "xtimer.h"
#endif

#define ENABLE_DEBUG 0
#include "debug.h"
Expand Down Expand Up @@ -136,11 +132,7 @@ gnrc_sixlowpan_ctx_t *gnrc_sixlowpan_ctx_update(uint8_t id, const ipv6_addr_t *p

static uint32_t _current_minute(void)
{
#if IS_USED(MODULE_ZTIMER_MSEC)
return ztimer_now(ZTIMER_MSEC) / (MS_PER_SEC * SEC_PER_MIN);
#else
return xtimer_now_usec() / (US_PER_SEC * SEC_PER_MIN);
#endif
}

static void _update_lifetime(uint8_t id)
Expand Down
12 changes: 6 additions & 6 deletions sys/net/gnrc/network_layer/sixlowpan/frag/rb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ config GNRC_SIXLOWPAN_FRAG_RBUF_SIZE
int "Size of the reassembly buffer"
default 4

config GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US
int "Timeout for reassembly buffer entries in microseconds"
default 3000000
config GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS
int "Timeout for reassembly buffer entries in milliseconds"
default 3000

config GNRC_SIXLOWPAN_FRAG_RBUF_DO_NOT_OVERRIDE
bool "Do not override oldest datagram when reassembly buffer is full"
help
When not set, it will cause the reassembly buffer to override the oldest
entry when a fragment for a new datagram is received. When set, only the
oldest entry that is older than @ref
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US will be overwritten (they
CONFIGMGNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS will be overwritten (they
will still timeout normally if reassembly buffer is not full).

config GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER
int "Deletion timer for reassembly buffer entries in microseconds"
config GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS
int "Deletion timer for reassembly buffer entries in milliseconds"
default 0
help
Time to pass between completion of a datagram and the deletion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "net/sixlowpan.h"
#include "net/sixlowpan/sfr.h"
#include "thread.h"
#include "xtimer.h"
#include "ztimer.h"
#include "utlist.h"

#include "net/gnrc/sixlowpan/frag/rb.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ static gnrc_sixlowpan_frag_rb_t rbuf[CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_SIZE];

static char l2addr_str[3 * IEEE802154_LONG_ADDRESS_LEN];

static xtimer_t _gc_timer;
static ztimer_t _gc_timer;
static msg_t _gc_timer_msg = { .type = GNRC_SIXLOWPAN_FRAG_RB_GC_MSG };

/* ------------------------------------
Expand Down Expand Up @@ -554,7 +554,7 @@ static bool _rbuf_update_ints(gnrc_sixlowpan_frag_rb_base_t *entry,

static void _gc_pkt(gnrc_sixlowpan_frag_rb_t *rbuf)
{
#if CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER > 0
#if CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS > 0
if (rbuf->super.current_size == 0) {
/* packet is scheduled for deletion, but was complete, i.e. pkt is
* already handed up to other layer, i.e. no need to release */
Expand All @@ -566,14 +566,14 @@ static void _gc_pkt(gnrc_sixlowpan_frag_rb_t *rbuf)

void gnrc_sixlowpan_frag_rb_gc(void)
{
uint32_t now_usec = xtimer_now_usec();
uint32_t now_msec = ztimer_now(ZTIMER_MSEC);
unsigned int i;

for (i = 0; i < CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_SIZE; i++) {
/* since pkt occupies pktbuf, aggressivly collect garbage */
if (!gnrc_sixlowpan_frag_rb_entry_empty(&rbuf[i]) &&
((now_usec - rbuf[i].super.arrival) >
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US)) {
((now_msec - rbuf[i].super.arrival) >=
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS)) {
DEBUG("6lo rfrag: entry (%s, ",
gnrc_netif_addr_to_str(rbuf[i].super.src,
rbuf[i].super.src_len,
Expand All @@ -595,7 +595,8 @@ void gnrc_sixlowpan_frag_rb_gc(void)

static inline void _set_rbuf_timeout(void)
{
xtimer_set_msg(&_gc_timer, CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US,
ztimer_set_msg(ZTIMER_MSEC, &_gc_timer,
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS,
&_gc_timer_msg, thread_getpid());
}

Expand All @@ -605,7 +606,7 @@ static int _rbuf_get(const void *src, size_t src_len,
unsigned page)
{
gnrc_sixlowpan_frag_rb_t *res = NULL, *oldest = NULL;
uint32_t now_usec = xtimer_now_usec();
uint32_t now_msec = ztimer_now(ZTIMER_MSEC);

for (unsigned int i = 0; i < CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_SIZE; i++) {
/* check first if entry already available */
Expand Down Expand Up @@ -637,7 +638,7 @@ static int _rbuf_get(const void *src, size_t src_len,
return -1;
}
#endif
rbuf[i].super.arrival = now_usec;
rbuf[i].super.arrival = now_msec;
_set_rbuf_timeout();
return i;
}
Expand All @@ -648,7 +649,7 @@ static int _rbuf_get(const void *src, size_t src_len,
}

/* remember oldest slot */
/* note that xtimer_now will overflow in ~1.2 hours */
/* note that ztimer_now may overflow */
if ((oldest == NULL) ||
(oldest->super.arrival - rbuf[i].super.arrival < UINT32_MAX / 2)) {
oldest = &(rbuf[i]);
Expand All @@ -662,8 +663,8 @@ static int _rbuf_get(const void *src, size_t src_len,
* oldest could have been picked as res) */
assert(!gnrc_sixlowpan_frag_rb_entry_empty(oldest));
if (!IS_ACTIVE(CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DO_NOT_OVERRIDE) ||
((now_usec - oldest->super.arrival) >
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US)) {
((now_msec - oldest->super.arrival) >=
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS)) {
DEBUG("6lo rfrag: reassembly buffer full, remove oldest entry\n");
gnrc_pktbuf_release(oldest->pkt);
gnrc_sixlowpan_frag_rb_remove(oldest);
Expand Down Expand Up @@ -722,7 +723,7 @@ static int _rbuf_get(const void *src, size_t src_len,
memset(res->pkt->data, 0, sizeof(uint64_t));
}
res->super.datagram_size = size;
res->super.arrival = now_usec;
res->super.arrival = now_msec;
memcpy(res->super.src, src, src_len);
memcpy(res->super.dst, dst, dst_len);
res->super.src_len = src_len;
Expand Down Expand Up @@ -750,7 +751,7 @@ static int _rbuf_get(const void *src, size_t src_len,
#ifdef TEST_SUITES
void gnrc_sixlowpan_frag_rb_reset(void)
{
xtimer_remove(&_gc_timer);
ztimer_remove(ZTIMER_MSEC, &_gc_timer);
memset(rbuf_int, 0, sizeof(rbuf_int));
for (unsigned int i = 0; i < CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_SIZE; i++) {
if ((rbuf[i].pkt != NULL) &&
Expand Down Expand Up @@ -782,21 +783,21 @@ void gnrc_sixlowpan_frag_rb_base_rm(gnrc_sixlowpan_frag_rb_base_t *entry)

static void _tmp_rm(gnrc_sixlowpan_frag_rb_t *rbuf)
{
#if CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER > 0U
#if CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS > 0U
/* use garbage-collection to leave the entry for at least
* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER in the reassembly buffer by
* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS in the reassembly buffer by
* setting the arrival time to
* (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US - CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER)
* (CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS - CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS)
* microseconds in the past */
rbuf->super.arrival = xtimer_now_usec() -
(CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_US -
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER);
rbuf->super.arrival = ztimer_now(ZTIMER_MSEC) -
(CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS -
CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS);
/* reset current size to prevent late duplicates to trigger another
* dispatch */
rbuf->super.current_size = 0;
#else /* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER == 0U */
#else /* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS == 0U */
gnrc_sixlowpan_frag_rb_remove(rbuf);
#endif /* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER */
#endif /* CONFIG_GNRC_SIXLOWPAN_FRAG_RBUF_DEL_TIMER_MS */
}

#if IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_STATS)
Expand Down
Loading
0