Mercurial > core / lisp/ffi/uring/prim.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
b9cd591b9c10
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; uring/prim.lisp --- URING primitives 3 ;; Primitive functions related to IO_URING. 7 ;; These functions operate directly on foreign-allocated types. You 8 ;; can find all of these in liburing.h. The IOURINGINLINE macro 9 ;; declares relevant functions as both static and inline. Functions 10 ;; declarations prefixed by this macro are re-implemented in Lisp 16 ;; io-uring-opcode-supported-p 18 ;; (sb-alien::sap-int (alien-sap (slot (slot *r1* 'sq) 'khead))) 19 (defun io-uring-get-sqe (ring) 20 (let* ((sq (addr (slot ring 'sq))) 22 (next (1+ (slot sq 'sqe-tail))) 24 (when (= 1 (logand (slot ring 'flags) ioring-setup-sqe128)) 26 (if (/= 1 (logand (slot ring 'flags) ioring-setup-sqpoll)) 28 (setf head (deref (slot sq 'khead))) 29 (setf head (slot sq 'khead))) 30 (when (<= (- next head) (slot sq 'ring-entries)) 32 (addr (deref (slot sq 'sqes) (* (alien-size io-uring-sqe) (ash (logand (slot sq 'sqe-tail) (slot sq 'ring-mask)) shift)))) 33 (setf (slot (deref sq) 'sqe-tail) next) 34 (print (cons head next)))))) 39 (defmacro io-uring-for-each-cqe (ring head cqe) 43 (defun io-uring-cq-advance (ring nr) 45 (let* ((cq (addr (slot ring 'cq))) 46 (head (slot cq 'khead))) 48 (setf head (+ nr (deref head)))))) 50 (defun io-uring-cqe-seen (ring cqe) 51 (unless (null-alien cqe) 52 (io-uring-cq-advance ring 1))) 54 (defun io-uring-sqe-set-data (sqe data) ;; the C function returns (* void) 55 (setf (slot sqe 'user-data) data)) 57 (defun io-uring-cqe-get-data (cqe) 58 (slot cqe 'user-data)) 60 (defun io-uring-sqe-set-data64 (sqe data) 61 "Assign a 64-bit value to this sqe which can be retrieved with io-uring-cqe-get-data64 instead of a pointer." 62 (declare (type (unsigned-byte 64) data)) 63 (setf (slot sqe 'user-data) data)) 65 (defun io-uring-cqe-get-data64 (cqe) 66 "Same as IO-URING-CQE-GET-DATA but return value is (unsigned-byte 64) value instead of a pointer." 67 (slot cqe 'user-data)) 69 (defun io-uring-sqe-set-flags (sqe flags) 70 (setf (slot sqe 'flags) flags)) 72 (defun io-uring-prep-rw (op sqe fd addr len offset) 73 (setf (slot sqe 'opcode) op 77 (slot sqe 'off-addr-cmd) offset 78 (slot sqe 'addr-or-splice-off-in) addr 80 (slot sqe 'flags2) (deref (make-alien io-uring-sqe-slot8)) 81 (slot sqe 'buf-opt) (deref (make-alien io-uring-sqe-slot10)) 82 (slot sqe 'personality) 0 83 (slot sqe 'splice-index-addr) (deref (make-alien io-uring-sqe-slot12)) 84 (slot sqe 'addr-or-cmd) (deref (make-alien io-uring-sqe-slot13))) 87 (defun io-uring-prep-splice (sqe fd-in off-in fd-out off-out nbytes splice-flags) 88 (io-uring-prep-rw +io-splice+ sqe fd-out nil nbytes off-out)) 90 (defun io-uring-prep-tee (sqe fd-in fd-out nbytes splice-flags) 91 (io-uring-prep-rw +io-tee+ sqe fd-out nil nbytes 0) 92 (setf (slot sqe 'splice-off-in) 0) 93 (setf (slot sqe 'splice-fd-in) fd-in) 94 (setf (slot sqe 'splice-flags) splice-flags)) 96 (defun io-uring-prep-readv (sqe fd iovecs nr-vecs offset) 97 (io-uring-prep-rw +io-readv+ sqe fd iovecs nr-vecs offset)) 99 (defun io-uring-prep-readv2 (sqe fd iovecs nr-vecs offset flags) 100 (io-uring-prep-rw +io-readv+ sqe fd iovecs nr-vecs offset) 101 (setf (slot sqe 'rw-flags) flags)) 105 (defun io-uring-prep-nop (sqe) 106 (io-uring-prep-rw +io-nop+ sqe -1 nil 0 0)) 108 ;; (with-io-uring (ring) 109 ;; (io-uring-queue-init 160 ring 1) 110 ;; (io-uring-get-sqe ring))