From a518f48796bc77f842023b8da1324bbbaafd62de Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sat, 13 Mar 2021 08:22:38 -0500 Subject: [PATCH] clock: renmae z_timeout_end_calc -> sys_clock_timeout_end_calc Do not use z_ for internal APIs, z_ is for private APIs within one subsystem only. Signed-off-by: Anas Nashif --- doc/reference/kernel/timing/clocks.rst | 8 ++++---- drivers/ethernet/eth_w5500.c | 2 +- include/sys_clock.h | 2 +- kernel/kheap.c | 2 +- kernel/timeout.c | 2 +- samples/net/zperf/src/zperf_tcp_uploader.c | 2 +- samples/net/zperf/src/zperf_udp_uploader.c | 6 +++--- subsys/net/buf.c | 4 ++-- subsys/net/ip/net_pkt.c | 6 +++--- subsys/net/lib/sockets/sockets.c | 6 +++--- tests/kernel/timer/timer_error_case/src/main.c | 8 ++++---- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/doc/reference/kernel/timing/clocks.rst b/doc/reference/kernel/timing/clocks.rst index 1e9409cf65e..3489e9220a0 100644 --- a/doc/reference/kernel/timing/clocks.rst +++ b/doc/reference/kernel/timing/clocks.rst @@ -313,7 +313,7 @@ code. For example, consider this design: This code requires that the timeout value be inspected, which is no longer possible. For situations like this, the new API provides an -internal :c:func:`z_timeout_end_calc` routine that converts an +internal :c:func:`sys_clock_timeout_end_calc` routine that converts an arbitrary timeout to the uptime value in ticks at which it will expire. So such a loop might look like: @@ -323,7 +323,7 @@ expire. So such a loop might look like: void my_wait_for_event(struct my_subsys *obj, k_timeout_t timeout_in_ms) { /* Compute the end time from the timeout */ - uint64_t end = z_timeout_end_calc(timeout_in_ms); + uint64_t end = sys_clock_timeout_end_calc(timeout_in_ms); while (end > k_uptime_ticks()) { if (is_event_complete(obj)) { @@ -335,7 +335,7 @@ expire. So such a loop might look like: } } -Note that :c:func:`z_timeout_end_calc` returns values in units of +Note that :c:func:`sys_clock_timeout_end_calc` returns values in units of ticks, to prevent conversion aliasing, is always presented at 64 bit uptime precision to prevent rollover bugs, handles special :c:macro:`K_FOREVER` naturally (as ``UINT64_MAX``), and works @@ -344,7 +344,7 @@ identically for absolute timeouts as well as conventional ones. But some care is still required for subsystems that use it. Note that delta timeouts need to be interpreted relative to a "current time", and obviously that time is the time of the call to -:c:func:`z_timeout_end_calc`. But the user expects that the time is +:c:func:`sys_clock_timeout_end_calc`. But the user expects that the time is the time they passed the timeout to you. Care must be taken to call this function just once, as synchronously as possible to the timeout creation in user code. It should not be used on a "stored" timeout diff --git a/drivers/ethernet/eth_w5500.c b/drivers/ethernet/eth_w5500.c index f6f7913a7f9..71aea154fe7 100644 --- a/drivers/ethernet/eth_w5500.c +++ b/drivers/ethernet/eth_w5500.c @@ -157,7 +157,7 @@ static int w5500_writebuf(const struct device *dev, uint16_t offset, uint8_t *bu static int w5500_command(const struct device *dev, uint8_t cmd) { uint8_t reg; - uint64_t end = z_timeout_end_calc(K_MSEC(100)); + uint64_t end = sys_clock_timeout_end_calc(K_MSEC(100)); w5500_spi_write(dev, W5500_S0_CR, &cmd, 1); do { diff --git a/include/sys_clock.h b/include/sys_clock.h index 361bbb19457..a8150c65f62 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -191,7 +191,7 @@ int64_t sys_clock_tick_get(void); #define sys_clock_tick_get_32() (0) #endif -uint64_t z_timeout_end_calc(k_timeout_t timeout); +uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout); #ifdef __cplusplus } diff --git a/kernel/kheap.c b/kernel/kheap.c index e24dab7924f..a3217dd30af 100644 --- a/kernel/kheap.c +++ b/kernel/kheap.c @@ -29,7 +29,7 @@ SYS_INIT(statics_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS); void *k_heap_aligned_alloc(struct k_heap *h, size_t align, size_t bytes, k_timeout_t timeout) { - int64_t now, end = z_timeout_end_calc(timeout); + int64_t now, end = sys_clock_timeout_end_calc(timeout); void *ret = NULL; k_spinlock_key_t key = k_spin_lock(&h->lock); diff --git a/kernel/timeout.c b/kernel/timeout.c index 2c8da9b3c79..fa5afb00d8f 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -302,7 +302,7 @@ static inline int64_t z_vrfy_k_uptime_ticks(void) * synchronously with the user passing a new timeout value. It should * not be used iteratively to adjust a timeout. */ -uint64_t z_timeout_end_calc(k_timeout_t timeout) +uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout) { k_ticks_t dt; diff --git a/samples/net/zperf/src/zperf_tcp_uploader.c b/samples/net/zperf/src/zperf_tcp_uploader.c index 6dd9d860595..82e7dbf3e66 100644 --- a/samples/net/zperf/src/zperf_tcp_uploader.c +++ b/samples/net/zperf/src/zperf_tcp_uploader.c @@ -27,7 +27,7 @@ void zperf_tcp_upload(const struct shell *shell, unsigned int packet_size, struct zperf_results *results) { - int64_t duration = z_timeout_end_calc(K_MSEC(duration_in_ms)); + int64_t duration = sys_clock_timeout_end_calc(K_MSEC(duration_in_ms)); int64_t start_time, last_print_time, end_time, remaining; uint32_t nb_packets = 0U, nb_errors = 0U; uint32_t alloc_errors = 0U; diff --git a/samples/net/zperf/src/zperf_udp_uploader.c b/samples/net/zperf/src/zperf_udp_uploader.c index e986a61afc1..e764599a575 100644 --- a/samples/net/zperf/src/zperf_udp_uploader.c +++ b/samples/net/zperf/src/zperf_udp_uploader.c @@ -167,8 +167,8 @@ void zperf_udp_upload(const struct shell *shell, { uint32_t packet_duration = ((uint32_t)packet_size * 8U * USEC_PER_SEC) / (rate_in_kbps * 1024U); - uint64_t duration = z_timeout_end_calc(K_MSEC(duration_in_ms)); - int64_t print_interval = z_timeout_end_calc(K_SECONDS(1)); + uint64_t duration = sys_clock_timeout_end_calc(K_MSEC(duration_in_ms)); + int64_t print_interval = sys_clock_timeout_end_calc(K_SECONDS(1)); uint64_t delay = packet_duration; uint32_t nb_packets = 0U; int64_t start_time, end_time; @@ -275,7 +275,7 @@ void zperf_udp_upload(const struct shell *shell, "nb_packets=%u\tdelay=%u\tadjust=%d\n", nb_packets, (unsigned int)delay, (int)adjust); - print_interval = z_timeout_end_calc(K_SECONDS(1)); + print_interval = sys_clock_timeout_end_calc(K_SECONDS(1)); } remaining = duration - k_uptime_ticks(); diff --git a/subsys/net/buf.c b/subsys/net/buf.c index fe52dcb6b6d..aa04dc4fbb7 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -230,7 +230,7 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size, k_timeout_t timeout) #endif { - uint64_t end = z_timeout_end_calc(timeout); + uint64_t end = sys_clock_timeout_end_calc(timeout); struct net_buf *buf; unsigned int key; @@ -574,7 +574,7 @@ struct net_buf *net_buf_ref(struct net_buf *buf) struct net_buf *net_buf_clone(struct net_buf *buf, k_timeout_t timeout) { - int64_t end = z_timeout_end_calc(timeout); + int64_t end = sys_clock_timeout_end_calc(timeout); struct net_buf_pool *pool; struct net_buf *clone; diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index c1f42a7d609..efc4aae72e8 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -857,7 +857,7 @@ static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool, size_t size, k_timeout_t timeout) #endif { - uint64_t end = z_timeout_end_calc(timeout); + uint64_t end = sys_clock_timeout_end_calc(timeout); struct net_buf *first = NULL; struct net_buf *current = NULL; @@ -1103,7 +1103,7 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, k_timeout_t timeout) #endif { - uint64_t end = z_timeout_end_calc(timeout); + uint64_t end = sys_clock_timeout_end_calc(timeout); struct net_buf_pool *pool = NULL; size_t alloc_len = 0; size_t hdr_len = 0; @@ -1375,7 +1375,7 @@ pkt_alloc_with_buffer(struct k_mem_slab *slab, k_timeout_t timeout) #endif { - uint64_t end = z_timeout_end_calc(timeout); + uint64_t end = sys_clock_timeout_end_calc(timeout); struct net_pkt *pkt; int ret; diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 97c1b73c522..54d5aea35b0 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -592,7 +592,7 @@ ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len, timeout = K_NO_WAIT; } else { net_context_get_option(ctx, NET_OPT_SNDTIMEO, &timeout, NULL); - buf_timeout = z_timeout_end_calc(MAX_WAIT_BUFS); + buf_timeout = sys_clock_timeout_end_calc(MAX_WAIT_BUFS); } /* Register the callback before sending in order to receive the response @@ -1065,7 +1065,7 @@ static inline ssize_t zsock_recv_stream(struct net_context *ctx, net_context_get_option(ctx, NET_OPT_RCVTIMEO, &timeout, NULL); } - end = z_timeout_end_calc(timeout); + end = sys_clock_timeout_end_calc(timeout); do { struct net_pkt *pkt; @@ -1325,7 +1325,7 @@ int z_impl_zsock_poll(struct zsock_pollfd *fds, int nfds, int poll_timeout) timeout = K_MSEC(poll_timeout); } - end = z_timeout_end_calc(timeout); + end = sys_clock_timeout_end_calc(timeout); pev = poll_events; for (pfd = fds, i = nfds; i--; pfd++) { diff --git a/tests/kernel/timer/timer_error_case/src/main.c b/tests/kernel/timer/timer_error_case/src/main.c index 1b0cb397367..13e77ea80b7 100644 --- a/tests/kernel/timer/timer_error_case/src/main.c +++ b/tests/kernel/timer/timer_error_case/src/main.c @@ -335,7 +335,7 @@ void test_timer_add_timeout(void) ztest_test_pass(); } -extern uint64_t z_timeout_end_calc(k_timeout_t timeout); +extern uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout); extern void sys_clock_announce(int32_t ticks); void test_timeout_end_calc(void) { @@ -343,15 +343,15 @@ void test_timeout_end_calc(void) k_timeout_t timeout; timeout = K_MSEC(DURATION); - ret = z_timeout_end_calc(timeout); + ret = sys_clock_timeout_end_calc(timeout); zassert_true(ret, "---timeout end calc---"); timeout.ticks = TEST_TIMEOUT; - ret = z_timeout_end_calc(timeout); + ret = sys_clock_timeout_end_calc(timeout); zassert_true(ret, "timeout end calc error"); timeout = K_FOREVER; - ret = z_timeout_end_calc(timeout); + ret = sys_clock_timeout_end_calc(timeout); zassert_true(ret, "timeout end calc forever"); }