DMOVER(9)
๐ DMOVER(9) โ the hardware-assisted data mover interface, explained by your favorite kernel bestie
ok so this is the dmover page from the Kernel Developer's Manual, and honestly? it's giving "the CPU is too busy, let the hardware do it" main character energy. buckle up ๐
โจ NAME โจ
dmover_backend_register, dmover_backend_unregister, dmover_session_create, dmover_session_destroy, dmover_request_alloc, dmover_request_free, dmover_process, dmover_done โ the hardware-assisted data mover interface. that's the whole squad, bestie ๐
๐ธ SYNOPSIS ๐ธ
first things first, you gotta include this:
#include <dev/dmover/dmovervar.h>
๐ซถ client interface routines
int
dmover_session_create(const char *, struct dmover_session **);
void
dmover_session_destroy(struct dmover_session *);
struct dmover_request *
dmover_request_alloc(struct dmover_session *, dmover_buffer *);
void
dmover_request_free(struct dmover_request *);
void
dmover_process(struct dmover_request *);
๐ฆ back-end interface routines
void
dmover_backend_register(struct dmover_backend *);
void
dmover_backend_unregister(struct dmover_backend *);
void
dmover_done(struct dmover_request *);
๐ DESCRIPTION ๐
okay so the dmover facility is literally an interface to hardware-assisted data movers. like, actual hardware whose whole job is moving data around so the CPU doesn't have to. iconic behavior, no cap.
what can it do? glad you asked:
- copy data from one location in memory to another
- clear a region of memory
- fill a region of memory with a pattern
- do simple operations on multiple regions of memory โ an XOR, for example โ all without intervention by the CPU ๐ฅ
the drivers for these hardware-assisted data movers introduce themselves to dmover by registering their capabilities. that's the vibe check. ๐
when a client wants to use a dmover function, it creates a session for that function, and that session identifies which back-ends are actually capable of performing it. then the client enqueues requests on that session, and the back-ends process them asynchronously. the client can either block until the request is done, or have a call-back invoked once the request completes. choose your fighter ๐
when a client creates a session, dmover goes and finds the back-ends capable of handling the requested function. then, when a request is scheduled for processing, the dmover scheduler picks the best back-end to process it from the list of candidates โ trying to load balance while also weighing up the relative performance of each back-end. it's giving talent show judging panel โจ
here's the structural tea โ โ a dmover function always has one output region. a function may have zero or more input regions, or it may use an immediate value as an input. for functions that use input regions, the length of every input region and the output region must be the same. all dmover functions with the same name will have the same number of inputs and the same type of inputs.
โ ๏ธ if a back-end tries to register a function that violates this invariant, behavior is undefined. like, we're not mad, we're just disappointed. don't do it. ๐
the dmover facility supports several types of buffer descriptors. for functions that use input regions, each input buffer descriptor and the output buffer descriptor must be of the same type. that restriction may be removed in a future revision of the interface (so like, watch this space ๐).
the dmover facility may need to interrupt request processing and restart it. clients of dmover should be careful to avoid unwanted side-effects if that happens. specifically โ for functions that use input regions, no input region may overlap with the output region. that's a hard no, bestie ๐ซ
๐ง DATA STRUCTURES ๐ง
dmover shares a few data structures between the client and the back-end so they can describe sessions and requests. sharing is caring ๐
typedef enum {
DMOVER_BUF_LINEAR,
DMOVER_BUF_UIO
} dmover_buffer_type;
typedef struct {
void *l_addr;
size_t l_len;
} dmover_buf_linear;
typedef union {
dmover_buf_linear dmbuf_linear;
struct uio *dmbuf_uio;
} dmover_buffer;
together, these data types describe the buffer data structures that the dmover facility understands. and yes โ additional buffer types may be added in future revisions of the dmover interface. the lore keeps expanding ๐
the dmover_assignment structure holds the info about the back-end that a request is currently assigned to. its public members are:
struct dmover_backend *das_backendโ a pointer to the back-end.const struct dmover_algdesc *das_algdescโ a pointer to the algorithm description that the back-end provided for the request's function.
the dmover_session structure has these public members:
void *dses_cookieโ a pointer to client private data.int dses_ninputsโ the number of inputs used by the selected function.
and the dmover_request structure has these public members โ this is the big one, stay with me ๐ซถ
TAILQ_ENTRY(dmover_request) dreq_dmbqโ linkage on the back-end's queue of pending requests.struct dmover_session *dreq_sessionโ pointer to the session this request is associated with. this one is intended for use by the back-end.struct dmover_assignment *dreq_assignmentโ pointer to thedmover_assignmentstructure describing the back-end the request is currently assigned to. the back-end gets assigned when the request is scheduled withdmover_process().void (*dreq_callback)(struct dmover_request *)โ pointer to an optional call-back function from the client. if you provide it, it gets invoked when the request is complete. this field must beNULLifDMOVER_REQ_WAITis set indreq_flags.void *dreq_cookieโ pointer to client private data that's specific to the request.void *dreq_dmbcookieโ pointer to back-end private data, for use while the back-end is actively processing a request.volatile int dreq_flagsโ the flags, and here's what they mean:DMOVER_REQ_DONEโ the request has been completed. if you're not using a call-back, the client can poll this bit to figure out whether a request has been processed.DMOVER_REQ_ERRORโ an error occurred while processing the request.DMOVER_REQ_RUNNINGโ the request is currently being executed by the back-end. once a command is running it cannot be cancelled and must run to completion. no take-backsies ๐ญDMOVER_REQ_WAITโ if the client sets this,dmover_process()will wait for the request to complete usingcv_wait(9). this flag may only be used if the caller has a valid thread context. and if this flag is set, a callback may not be used.
int dreq_errorโ if theDMOVER_REQ_ERRORbit is set, this holds theerrno(2)value indicating the error that happened during processing.dmover_buffer_type dreq_outbuf_typeโ the type of the output buffer.dmover_buffer dreq_outbufโ the output buffer itself.uint8_t dreq_immediate[8]โ this is the input for algorithms that use an immediate value. values smaller than 8 bytes should use the least-significant bytes first. for example, a 32-bit integer would occupy bytes0,1,2, and3. put it in the right order, babe ๐งฎdmover_buffer_type dreq_inbuf_typeโ the type of the input buffer. only used if thedmoverfunction has one or more inputs.dmover_buffer *dreq_inbufโ a pointer to an array of input buffers. again, only used if thedmoverfunction has one or more inputs. the number of inputs โ and therefore the number of valid elements in the array โ is specified by the algorithm description for the session.
๐ CLIENT INTERFACE ๐
these are the functions you get as a client. slay, enjoy ๐
dmover_session_create(function, sessionp)
dmover_session_create() creates a data mover session for the specified data movement function, function. a handle to the brand-new session is returned in sessionp. new session, who dis โจ
and these are the valid data movement function names, bestie:
- โzeroโ โ fill a memory region with zeros. this algorithm has an input count of
0. - โfill8โ โ fill a memory region with an 8-bit pattern. this algorithm has an input count of
0. the pattern is provided in thedreq_imm8member of thedmover_requeststructure. - โcopyโ โ copy a memory region from one location to another. this algorithm has an input count of
1. - โxor2โ โ perform an XOR operation on 2 inputs. this algorithm has an input count of
2. - โxor3โ โ perform an XOR operation on 3 inputs. this algorithm has an input count of
3. - โxor4โ โ perform an XOR operation on 4 inputs. this algorithm has an input count of
4. - โxor5โ โ perform an XOR operation on 5 inputs. this algorithm has an input count of
5. - โxor6โ โ perform an XOR operation on 6 inputs. this algorithm has an input count of
6. - โxor7โ โ perform an XOR operation on 7 inputs. this algorithm has an input count of
7. - โxor8โ โ perform an XOR operation on 8 inputs. this algorithm has an input count of
8.
users of the dmover facility are encouraged to use the following aliases for the well-known function names, because doing so saves space and reduces the chance of programming errors. less typing, fewer typos, everyone wins ๐
DMOVER_FUNC_ZEROโ โzeroโ (dmover_funcname_zero)DMOVER_FUNC_FILL8โ โfill8โ (dmover_funcname_fill8)DMOVER_FUNC_COPYโ โcopyโ (dmover_funcname_copy)DMOVER_FUNC_XOR2โ โxor2โ (dmover_funcname_xor2)DMOVER_FUNC_XOR3โ โxor3โ (dmover_funcname_xor3)DMOVER_FUNC_XOR4โ โxor4โ (dmover_funcname_xor4)DMOVER_FUNC_XOR5โ โxor5โ (dmover_funcname_xor5)DMOVER_FUNC_XOR6โ โxor6โ (dmover_funcname_xor6)DMOVER_FUNC_XOR7โ โxor7โ (dmover_funcname_xor7)DMOVER_FUNC_XOR8โ โxor8โ (dmover_funcname_xor8)
dmover_session_destroy(session)
dmover_session_destroy() tears down a data mover session and releases all resources associated with it. it's giving closure, but make it memory management ๐ฆ
dmover_request_alloc(session, inbuf)
dmover_request_alloc() allocates a dmover request structure and associates it with the specified session. if the inbuf argument is not NULL, then inbuf is used as the array of input buffer descriptors in the request. otherwise โ if inbuf is NULL and the dmover function requires input buffers โ the input buffer descriptors get allocated automatically using malloc(9). convenient, honestly ๐ซถ
If the request structure or input buffer descriptors can't be allocated, dmover_request_alloc() just returns NULL โ that's the fail signal, bestie. ๐
dmover_request_free(req)โ frees a dmover request structure. If the dmover function needs input buffers and the input buffer descriptors tied toreqwere allocated bydmover_request_alloc(), those input buffer descriptors get freed too. โจdmover_process(req)โ submits the dmover requestreqfor processing. The call-back specified by the request is invoked when processing is complete. ๐
Thedmover_session_create()anddmover_session_destroy()functions must not be called from interrupt context. ๐ซ
The dmover_request_alloc(), dmover_request_free(), and dmover_process() functions may be called from interrupt handlers at levels IPL_VM, IPL_SOFTCLOCK, and IPL_SOFTNET, or in non-interrupt context. ๐
The request completion call-back is called from a software interrupt handler at IPL_SOFTCLOCK. โฐ
๐ ๏ธ BACK-END INTERFACE ๐ ๏ธ
A back-end describes the dmover functions it can perform using an array of dmover_algdesc structures:
struct dmover_algdesc {
const char *dad_name; /* algorithm name */
void *dad_data; /* opaque algorithm description */
int dad_ninputs; /* number of inputs */
};
The dad_name member points to a valid dmover function name which the client may specify. The dad_data member points to a back-end-specific description of the algorithm. ๐งฉ
A back-end presents itself to the dmover facility using the dmover_backend structure. The back-end must initialize the following members of the structure:
const char *dmb_nameโ this is the name of the back-end. ๐ท๏ธu_int dmb_speedโ this is an estimate of the number of kilobytes/second that the back-end can process. โกvoid *dmb_cookieโ this is a pointer to back-end private data. ๐ชconst struct dmover_algdesc *dmb_algdescsโ this points to an array ofdmover_algdescstructures which describe the functions the data mover can perform. ๐๏ธint dmb_nalgdescsโ this is the number of elements in thedmb_algdescsarray. ๐ขvoid (*dmb_process)(struct dmover_backend *)โ this is the entry point to the back-end used to process requests. ๐
When invoked by the dmover facility, the back-end's (*dmb_process)() function should examine the pending request queue in its dmover_backend structure:
TAILQ_HEAD(, dmover_request) dmb_pendreqsโ this is the queue of pending requests. ๐int dmb_npendreqsโ this is the number of requests in thedmb_pendreqsqueue. ๐งฎ
If an error occurs when processing the request, the DMOVER_REQ_ERROR bit must be set in the dreq_flags member of the request, and the dreq_error member set to an errno(2) value to indicate the error. โ ๏ธ
When the back-end has finished processing the request, it must call the dmover_done() function. This function eventually invokes the client's call-back routine. ๐
If a hardware-assisted data mover uses interrupts, the interrupt handlers should be registered at IPL_VM. ๐ฅ๏ธ
The following functions are provided to the back-ends:
dmover_backend_register(backend)โ thedmover_backend_register()function registers the back-endbackendwith the dmover facility. โdmover_backend_unregister(backend)โ thedmover_backend_unregister()function removes the back-endbackendfrom the dmover facility. The back-end must already be registered. โdmover_done(req)โ thedmover_done()function is called by the back-end when it has finished processing a request, whether the request completed successfully or not. ๐
The dmover_backend_register() and dmover_backend_unregister() functions must not be called from interrupt context. ๐
โโ๏ธ
The dmover_done() function may be called at IPL_VM, IPL_SOFTCLOCK, IPL_SOFTNET, or in non-interrupt context. ๐
๐ EXAMPLES ๐
The following is an example of a client using dmover to zero-fill a region of memory. In this example, the CPU will be able to context switch to another thread and perform work while the hardware-assisted data mover clears the specified block of memory. ๐ง โจ
int
hw_bzero(void *buf, size_t len)
{
struct dmover_session *dses;
struct dmover_request *dreq;
int error;
error = dmover_session_create(DMOVER_FUNC_ZERO, &dses);
if (error)
return (error);
dreq = dmover_request_alloc(dses, NULL);
if (dreq == NULL) {
dmover_session_destroy(dses);
return (ENOMEM);
}
dreq->dreq_flags = DMOVER_REQ_WAIT;
dreq->dreq_callback = NULL;
dreq->dreq_outbuf.dreq_outbuf_type = DMOVER_BUF_LINEAR;
dreq->dreq_outbuf.dmbuf_linear.l_addr = buf;
dreq->dreq_outbuf.dmbuf_linear.l_len = len;
dmover_process(dreq);
error = (dreq->dreq_flags & DMOVER_REQ_ERROR) ?
dreq->dreq_error : 0;
dmover_request_free(dreq);
dmover_session_destroy(dses);
return (error);
}
๐ SEE ALSO ๐
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
The dmover facility first appeared in NetBSD 2.0. ๐
๐ AUTHORS ๐
The dmover facility was designed and implemented by Jason R. Thorpe โจthorpej@wasabisystems.comโฉ and contributed by Wasabi Systems, Inc. ๐
๐ BUGS ๐
The mechanism by which a back-end should advertise its performance to the request scheduler is not well-defined. Therefore, the load-balancing mechanism within the request scheduler is also not well-defined. ๐ญ It's giving "we'll figure it out later" energy, ngl.
This iconic little page is from Debian, dated December 4, 2007, and it's the DMOVER(9) manual page. Periodt. ๐ ๐ซถ
๐ฆ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2002 Wasabi Systems, Inc
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms