changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/ffi/uring/uring.lisp

changeset 698: 96958d3eb5b0
parent: 5bd0eb9fa1fa
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; uring/uring.lisp --- top-level interface
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :uring)
7 
8 (defvar *default-io-entry-count* 256)
9 
10 ;; (defconstant +io-syscall-setup+ nr-io-uring-setup) ;425
11 ;; (defconstant +io-syscall-register+ nr-io-uring-register) ;426
12 ;; (defconstant +io-syscall-enter+ nr-io-uring-enter) ;427
13 
14 ;; TODO 2024-04-02: tlab? dynamic-space hacks? there's almost
15 ;; certainly a better way to do this than mmapping regions in
16 ;; package-local structs.
17 (defstruct io-memory-map
18  (sq-mmap (make-mmapped-region) :type mmapped-region)
19  (sqe-mmap (make-mmapped-region) :type mmapped-region)
20  (cq-mmap (make-mmapped-region) :type mmapped-region))
21 
22 (defun parse-io-uring-params (params)
23  "Parse IO-URING-PARAMS foreign struct, return an IO-PARAMS struct."
24  (let ((res 0))
25  (loop while params
26  do (1+ res))
27  res))
28 
29 (defstruct io-params
30  (sq-entries *default-io-entry-count* :type fixnum)
31  (cq-entries *default-io-entry-count* :type fixnum)
32  (flags 0 :type fixnum)
33  (sq-thread-cpu 0 :type fixnum)
34  (sq-thread-idle 0 :type fixnum)
35  (features 0 :type fixnum)
36  (wq-fd 0 :type fixnum)
37  ;; resv
38  (sq-off (make-submission-queue-offsets) :type submission-queue-offsets) ;; offsets are 40bytes each
39  (cq-off (make-completion-queue-offsets) :type completion-queue-offsets))
40 
41 (defmacro define-io-param-flag (name const)
42  "Create a predicate method with NAME which checks for presence of flag
43 CONST in FLAGS slot of IO-PARAMS. A SETF expansion is also defined
44 which accepts a boolean value and automatically adjusts the slot."
45  `(progn
46  (defmethod ,name ((self io-params))
47  (not (= 0 (logand (io-params-flags self) ,const))))
48  (defmethod (setf ,name) (val (self io-params))
49  (with-slots (flags) self
50  (setf flags (logior flags ,const))))))
51 
52 (defmacro define-io-param-feature (name const)
53  "Create a predicate method with NAME which checks for presence of flag
54 CONST in FEATURES slot of IO-PARAMS. A SETF expansion is also defined
55 which accepts a boolean value and automatically adjust the slot."
56  `(progn
57  (defmethod ,name ((self io-params))
58  (not (= 0 (logand (io-params-features self) ,const))))
59  (defmethod (setf ,name) (val (self io-params))
60  (with-slots (features) self
61  (setf features (logior features ,const))))))
62 
63 (define-io-param-flag setup-sqpoll-p ioring-setup-sqpoll)
64 (define-io-param-flag setup-iopoll-p ioring-setup-iopoll)
65 (define-io-param-flag setup-single-issuer-p ioring-setup-single-issuer)
66 (define-io-param-feature feat-single-mmap-p ioring-feat-single-mmap)
67 (define-io-param-feature feat-nodrop-p ioring-feat-nodrop)
68 (define-io-param-feature feat-submit-stable-p ioring-feat-submit-stable)
69 (define-io-param-feature feat-rw-cur-pos-p ioring-feat-rw-cur-pos)
70 (define-io-param-feature feat-cur-personality-p ioring-feat-cur-personality)
71 (define-io-param-feature feat-fast-poll-p ioring-feat-fast-poll)
72 (define-io-param-feature feat-poll-32bits-p ioring-feat-poll-32bits)
73 (define-io-param-feature feat-sqpoll-nonfixed-p ioring-feat-sqpoll-nonfixed)
74 (define-io-param-feature feat-ext-arg-p ioring-feat-ext-arg)
75 (define-io-param-feature feat-native-workers-p ioring-feat-native-workers)
76 (define-io-param-feature feat-rsrc-tags-p ioring-feat-rsrc-tags)
77 (define-io-param-feature feat-cqe-skip-p ioring-feat-cqe-skip)
78 (define-io-param-feature feat-linked-file-p ioring-feat-linked-file)
79 
80 ;; (defmethod build ((self io-params) &key &allow-other-keys)
81 ;; (with-slots (sq-entries cq-entries flags sq-thread-cpu sq-thread-idle features wq-fd sq-off cq-off) self
82 ;; (with-io-uring-params res ((sq-entries sq-entries) (cq-entries cq-entries) (flags flags)
83 ;; (sq-thread-cpu sq-thread-cpu) (sq-thread-idle sq-thread-idle) (features features)
84 ;; (wq-fd wq-fd) (sq-off (deref (build sq-off))) (cq-off (deref (build cq-off))))
85 ;; res)))
86 
87 ;; io-uring instance
88 (defvar *default-io-params* (make-io-params))
89 
90 (defstruct uring
91  (sq nil :type submission-queue)
92  (cq nil :type completion-queue)
93  (fd -1 :type sb-posix:file-descriptor) ;; owned fd
94  (params *default-io-params* :type io-params)
95  (memory nil :type io-memory-map))
96 
97 (defstruct uring-builder
98  (params *default-io-params* :type io-params)
99  (dontfork nil :type boolean))
100 
101 (defmethod build ((self uring-builder) &key (entries *default-io-entry-count*))
102  (make-uring :sq (make-submission-queue) :cq (make-completion-queue) :memory (make-io-memory-map)))
103 
104 (defun setup-queue (fd p)
105  "Setup a URING struct given a reference to a FILE-DESCRIPTOR and IO-PARAMS.")
106 
107 (defun make-queue (&optional (entries *default-io-entry-count*))
108  "Create a new URING instance with default params. N is the size of the
109 queue, which must be a power of two."
110  (build (make-uring-builder) :entries entries))
111 
112 #+nil (make-queue 2)
113 (defmethod build-submitter ((self uring-builder))
114  (make-io-submitter))