@@ -75,6 +75,7 @@ struct io_zc_rx_buf *io_zc_rx_get_buf(struct io_zc_rx_ifq *ifq);
struct io_zc_rx_buf *io_zc_rx_buf_from_page(struct io_zc_rx_ifq *ifq,
struct page *page);
void io_zc_rx_put_buf(struct io_zc_rx_ifq *ifq, struct io_zc_rx_buf *buf);
+void io_zc_rx_set_napi(struct io_zc_rx_ifq *ifq, unsigned napi_id);
static inline dma_addr_t io_zc_rx_buf_dma(struct io_zc_rx_buf *buf)
{
@@ -7,6 +7,7 @@
#include <linux/netdevice.h>
#include <linux/nospec.h>
#include <net/tcp.h>
+#include <net/busy_poll.h>
#include <uapi/linux/io_uring.h>
@@ -41,6 +42,11 @@ struct io_zc_rx_pool {
u32 freelist[];
};
+struct io_zc_refill_data {
+ struct io_zc_rx_ifq *ifq;
+ unsigned count;
+};
+
static inline u32 io_zc_rx_cqring_entries(struct io_zc_rx_ifq *ifq)
{
struct io_rbuf_ring *ring = ifq->ring;
@@ -244,6 +250,12 @@ static void io_zc_rx_destroy_ifq(struct io_zc_rx_ifq *ifq)
kfree(ifq);
}
+void io_zc_rx_set_napi(struct io_zc_rx_ifq *ifq, unsigned napi_id)
+{
+ ifq->napi_id = napi_id;
+}
+EXPORT_SYMBOL(io_zc_rx_set_napi);
+
static void io_zc_rx_destroy_pool_work(struct work_struct *work)
{
struct io_zc_rx_pool *pool = container_of(
@@ -498,14 +510,43 @@ static void io_zc_rx_refill_cache(struct io_zc_rx_ifq *ifq, int count)
pool->cache_count += filled;
}
+static bool io_napi_refill(void *data)
+{
+ struct io_zc_refill_data *rd = data;
+ struct io_zc_rx_ifq *ifq = rd->ifq;
+ struct io_zc_rx_pool *pool = ifq->pool;
+ int i, count = rd->count;
+
+ lockdep_assert_no_hardirq();
+
+ if (!pool->cache_count)
+ io_zc_rx_refill_cache(ifq, POOL_REFILL_COUNT);
+
+ spin_lock_bh(&pool->freelist_lock);
+ for (i = 0; i < count && pool->cache_count; i++) {
+ u32 pgid;
+
+ pgid = pool->cache[--pool->cache_count];
+ pool->freelist[pool->free_count++] = pgid;
+ }
+ spin_unlock_bh(&pool->freelist_lock);
+ return true;
+}
+
static struct io_zc_rx_buf *io_zc_get_buf_task_safe(struct io_zc_rx_ifq *ifq)
{
struct io_zc_rx_pool *pool = ifq->pool;
struct io_zc_rx_buf *buf = NULL;
u32 pgid;
- if (!READ_ONCE(pool->free_count))
- return NULL;
+ if (!READ_ONCE(pool->free_count)) {
+ struct io_zc_refill_data rd = {
+ .ifq = ifq,
+ .count = 1,
+ };
+
+ napi_execute(ifq->napi_id, io_napi_refill, &rd);
+ }
spin_lock_bh(&pool->freelist_lock);
if (pool->free_count) {
@@ -20,6 +20,7 @@ struct io_zc_rx_ifq {
u32 cached_rq_head;
u32 cached_cq_tail;
void *pool;
+ unsigned int napi_id;
unsigned nr_sockets;
struct file *sockets[IO_ZC_MAX_IFQ_SOCKETS];