From: cheloha Date: Sat, 24 Feb 2024 15:21:39 +0000 (+0000) Subject: qwx(4): qwx_dp_rx_tid_del_func: fix dp_reo_cache_flush_elem expiration logic X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=81fa3e72ea1cd2761bc813d536bd3ccb190c5c6c;p=openbsd qwx(4): qwx_dp_rx_tid_del_func: fix dp_reo_cache_flush_elem expiration logic Tweak a few things in qwx_dp_rx_tid_del_func() to make it behave correctly on OpenBSD: - struct dp_reo_cache_flush_elem: make ts a 64-bit count of nanoseconds Linux uses jiffies to timestamp dp_reo_cache_flush_elem. Although OpenBSD has a global jiffies variable, we shouldn't use it outside of drm(4). I would rather not use our global ticks variable, either. We can use getnsecuptime(9), a low-res 64-bit nanosecond timestamp, as a substitute. - qwx_dp_rx_tid_del_func: replace gettime(9) with getnsecuptime(9) - qwx_dp_rx_tid_del_func: convert DP_REO_DESC_FREE_TIMEOUT_MS to nanoseconds - qwx_dp_rx_tid_del_func: reverse timestamp comparison operator This comparison is backwards. Linux uses the time_after() macro to test whether a given entry has expired, so our ported code needs to test whether the current uptime is greater than or equal to a given entry's expiration time. Joint effort with stsp@. Tested by stsp@. ok stsp@ --- diff --git a/sys/dev/ic/qwx.c b/sys/dev/ic/qwx.c index 36b56ae559a..193fdae1420 100644 --- a/sys/dev/ic/qwx.c +++ b/sys/dev/ic/qwx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qwx.c,v 1.51 2024/02/22 21:21:35 stsp Exp $ */ +/* $OpenBSD: qwx.c,v 1.52 2024/02/24 15:21:39 cheloha Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -23155,7 +23155,7 @@ qwx_dp_rx_tid_del_func(struct qwx_dp *dp, void *ctx, struct qwx_softc *sc = dp->sc; struct dp_rx_tid *rx_tid = ctx; struct dp_reo_cache_flush_elem *elem, *tmp; - time_t now; + uint64_t now; if (status == HAL_REO_CMD_DRAIN) { goto free_desc; @@ -23170,7 +23170,7 @@ qwx_dp_rx_tid_del_func(struct qwx_dp *dp, void *ctx, if (!elem) goto free_desc; - now = gettime(); + now = getnsecuptime(); elem->ts = now; memcpy(&elem->data, rx_tid, sizeof(*rx_tid)); @@ -23188,7 +23188,7 @@ qwx_dp_rx_tid_del_func(struct qwx_dp *dp, void *ctx, /* Flush and invalidate aged REO desc from HW cache */ TAILQ_FOREACH_SAFE(elem, &dp->reo_cmd_cache_flush_list, entry, tmp) { if (dp->reo_cmd_cache_flush_count > DP_REO_DESC_FREE_THRESHOLD || - now < elem->ts + DP_REO_DESC_FREE_TIMEOUT_MS) { + now >= elem->ts + MSEC_TO_NSEC(DP_REO_DESC_FREE_TIMEOUT_MS)) { TAILQ_REMOVE(&dp->reo_cmd_cache_flush_list, elem, entry); dp->reo_cmd_cache_flush_count--; #ifdef notyet diff --git a/sys/dev/ic/qwxvar.h b/sys/dev/ic/qwxvar.h index 0399a4328aa..a84553d5bcb 100644 --- a/sys/dev/ic/qwxvar.h +++ b/sys/dev/ic/qwxvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxvar.h,v 1.22 2024/02/22 09:08:08 stsp Exp $ */ +/* $OpenBSD: qwxvar.h,v 1.23 2024/02/24 15:21:39 cheloha Exp $ */ /* * Copyright (c) 2018-2019 The Linux Foundation. @@ -1041,7 +1041,7 @@ struct dp_rx_tid { struct dp_reo_cache_flush_elem { TAILQ_ENTRY(dp_reo_cache_flush_elem) entry; struct dp_rx_tid data; - unsigned long ts; + uint64_t ts; }; TAILQ_HEAD(dp_reo_cmd_cache_flush_head, dp_reo_cache_flush_elem);