tools/testing/selftests/ublk/batch.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/ublk/batch.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/ublk/batch.c- Extension
.c- Size
- 15729 bytes
- Lines
- 608
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kublk.h
Detected Declarations
function ublk_alloc_commit_buffunction ublk_free_commit_buffunction ublk_commit_elem_buf_sizefunction ublk_commit_buf_sizefunction free_batch_commit_buffunction alloc_batch_commit_buffunction ublk_thread_nr_queuesfunction ublk_batch_preparefunction free_batch_fetch_buffunction alloc_batch_fetch_buffunction ublk_batch_alloc_buffunction ublk_batch_free_buffunction ublk_init_batch_cmdfunction ublk_setup_commit_sqefunction ublk_batch_queue_fetchfunction ublk_batch_start_fetchfunction ublk_compl_batch_fetchfunction __ublk_batch_queue_prep_io_cmdsfunction ublk_batch_queue_prep_io_cmdsfunction ublk_batch_compl_commit_cmdfunction ublk_batch_compl_cmdfunction __ublk_batch_commit_io_cmdsfunction ublk_batch_commit_io_cmdsfunction __ublk_batch_init_commitfunction ublk_batch_init_commitfunction ublk_batch_prep_commitfunction ublk_batch_complete_iofunction ublk_batch_setup_map
Annotated Snippet
if (!t->fetch[i].br) {
ublk_err("Buffer ring register failed %d\n", ret);
return ret;
}
}
return 0;
}
int ublk_batch_alloc_buf(struct ublk_thread *t)
{
int ret;
ublk_assert(t->nr_commit_buf < 2 * UBLK_MAX_QUEUES);
ret = alloc_batch_commit_buf(t);
if (ret)
return ret;
return alloc_batch_fetch_buf(t);
}
void ublk_batch_free_buf(struct ublk_thread *t)
{
free_batch_commit_buf(t);
free_batch_fetch_buf(t);
}
static void ublk_init_batch_cmd(struct ublk_thread *t, __u16 q_id,
struct io_uring_sqe *sqe, unsigned op,
unsigned short elem_bytes,
unsigned short nr_elem,
unsigned short buf_idx)
{
struct ublk_batch_io *cmd;
__u64 user_data;
cmd = (struct ublk_batch_io *)ublk_get_sqe_cmd(sqe);
ublk_set_sqe_cmd_op(sqe, op);
sqe->fd = 0; /* dev->fds[0] */
sqe->opcode = IORING_OP_URING_CMD;
sqe->flags = IOSQE_FIXED_FILE;
cmd->q_id = q_id;
cmd->flags = 0;
cmd->reserved = 0;
cmd->elem_bytes = elem_bytes;
cmd->nr_elem = nr_elem;
user_data = build_user_data(buf_idx, _IOC_NR(op), nr_elem, q_id, 0);
io_uring_sqe_set_data64(sqe, user_data);
t->cmd_inflight += 1;
ublk_dbg(UBLK_DBG_IO_CMD, "%s: thread %u qid %d cmd_op %x data %lx "
"nr_elem %u elem_bytes %u buf_size %u buf_idx %d "
"cmd_inflight %u\n",
__func__, t->idx, q_id, op, user_data,
cmd->nr_elem, cmd->elem_bytes,
nr_elem * elem_bytes, buf_idx, t->cmd_inflight);
}
static void ublk_setup_commit_sqe(struct ublk_thread *t,
struct io_uring_sqe *sqe,
unsigned short buf_idx)
{
struct ublk_batch_io *cmd;
cmd = (struct ublk_batch_io *)ublk_get_sqe_cmd(sqe);
/* Use plain user buffer instead of fixed buffer */
cmd->flags |= t->cmd_flags;
}
static void ublk_batch_queue_fetch(struct ublk_thread *t,
struct ublk_queue *q,
unsigned short buf_idx)
{
unsigned short nr_elem = t->fetch[buf_idx].fetch_buf_size / 2;
struct io_uring_sqe *sqe;
io_uring_buf_ring_add(t->fetch[buf_idx].br, t->fetch[buf_idx].fetch_buf,
t->fetch[buf_idx].fetch_buf_size,
0, 0, 0);
io_uring_buf_ring_advance(t->fetch[buf_idx].br, 1);
ublk_io_alloc_sqes(t, &sqe, 1);
ublk_init_batch_cmd(t, q->q_id, sqe, UBLK_U_IO_FETCH_IO_CMDS, 2, nr_elem,
Annotation
- Immediate include surface: `kublk.h`.
- Detected declarations: `function ublk_alloc_commit_buf`, `function ublk_free_commit_buf`, `function ublk_commit_elem_buf_size`, `function ublk_commit_buf_size`, `function free_batch_commit_buf`, `function alloc_batch_commit_buf`, `function ublk_thread_nr_queues`, `function ublk_batch_prepare`, `function free_batch_fetch_buf`, `function alloc_batch_fetch_buf`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.