Commit 51bef926 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by David S. Miller

nfp: avoid using getnstimeofday64()

getnstimeofday64 is deprecated in favor of the ktime_get() family of
functions. The direct replacement would be ktime_get_real_ts64(),
but I'm picking the basic ktime_get() instead:

- using a ktime_t simplifies the code compared to timespec64
- using monotonic time instead of real time avoids issues caused
  by a concurrent settimeofday() or during a leap second adjustment.
Acked-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 44c58899
...@@ -73,7 +73,7 @@ struct nfp_app; ...@@ -73,7 +73,7 @@ struct nfp_app;
struct nfp_fl_mask_id { struct nfp_fl_mask_id {
struct circ_buf mask_id_free_list; struct circ_buf mask_id_free_list;
struct timespec64 *last_used; ktime_t *last_used;
u8 init_unallocated; u8 init_unallocated;
}; };
......
...@@ -158,7 +158,6 @@ static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id) ...@@ -158,7 +158,6 @@ static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id)
{ {
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
struct circ_buf *ring; struct circ_buf *ring;
struct timespec64 now;
ring = &priv->mask_ids.mask_id_free_list; ring = &priv->mask_ids.mask_id_free_list;
/* Checking if buffer is full. */ /* Checking if buffer is full. */
...@@ -169,8 +168,7 @@ static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id) ...@@ -169,8 +168,7 @@ static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id)
ring->head = (ring->head + NFP_FLOWER_MASK_ELEMENT_RS) % ring->head = (ring->head + NFP_FLOWER_MASK_ELEMENT_RS) %
(NFP_FLOWER_MASK_ENTRY_RS * NFP_FLOWER_MASK_ELEMENT_RS); (NFP_FLOWER_MASK_ENTRY_RS * NFP_FLOWER_MASK_ELEMENT_RS);
getnstimeofday64(&now); priv->mask_ids.last_used[mask_id] = ktime_get();
priv->mask_ids.last_used[mask_id] = now;
return 0; return 0;
} }
...@@ -178,7 +176,7 @@ static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id) ...@@ -178,7 +176,7 @@ static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id)
static int nfp_mask_alloc(struct nfp_app *app, u8 *mask_id) static int nfp_mask_alloc(struct nfp_app *app, u8 *mask_id)
{ {
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
struct timespec64 delta, now; ktime_t reuse_timeout;
struct circ_buf *ring; struct circ_buf *ring;
u8 temp_id, freed_id; u8 temp_id, freed_id;
...@@ -198,10 +196,10 @@ static int nfp_mask_alloc(struct nfp_app *app, u8 *mask_id) ...@@ -198,10 +196,10 @@ static int nfp_mask_alloc(struct nfp_app *app, u8 *mask_id)
memcpy(&temp_id, &ring->buf[ring->tail], NFP_FLOWER_MASK_ELEMENT_RS); memcpy(&temp_id, &ring->buf[ring->tail], NFP_FLOWER_MASK_ELEMENT_RS);
*mask_id = temp_id; *mask_id = temp_id;
getnstimeofday64(&now); reuse_timeout = ktime_add_ns(priv->mask_ids.last_used[*mask_id],
delta = timespec64_sub(now, priv->mask_ids.last_used[*mask_id]); NFP_FL_MASK_REUSE_TIME_NS);
if (timespec64_to_ns(&delta) < NFP_FL_MASK_REUSE_TIME_NS) if (ktime_before(ktime_get(), reuse_timeout))
goto err_not_found; goto err_not_found;
memcpy(&ring->buf[ring->tail], &freed_id, NFP_FLOWER_MASK_ELEMENT_RS); memcpy(&ring->buf[ring->tail], &freed_id, NFP_FLOWER_MASK_ELEMENT_RS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment