tools/testing/selftests/ublk/utils.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/ublk/utils.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/ublk/utils.h- Extension
.h- Size
- 2584 bytes
- Lines
- 133
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct allocatorfunction allocator_initfunction allocator_deinitfunction allocator_getfunction allocator_putfunction allocator_get_valfunction ilog2function ublk_errfunction ublk_logfunction ublk_dbg
Annotated Snippet
struct allocator {
unsigned int size;
cpu_set_t *set;
};
static inline int allocator_init(struct allocator *a, unsigned size)
{
a->set = CPU_ALLOC(size);
a->size = size;
if (a->set)
return 0;
return -ENOMEM;
}
static inline void allocator_deinit(struct allocator *a)
{
CPU_FREE(a->set);
a->set = NULL;
a->size = 0;
}
static inline int allocator_get(struct allocator *a)
{
int i;
for (i = 0; i < a->size; i += 1) {
size_t set_size = CPU_ALLOC_SIZE(a->size);
if (!CPU_ISSET_S(i, set_size, a->set)) {
CPU_SET_S(i, set_size, a->set);
return i;
}
}
return -1;
}
static inline void allocator_put(struct allocator *a, int i)
{
size_t set_size = CPU_ALLOC_SIZE(a->size);
if (i >= 0 && i < a->size)
CPU_CLR_S(i, set_size, a->set);
}
static inline int allocator_get_val(struct allocator *a, int i)
{
size_t set_size = CPU_ALLOC_SIZE(a->size);
return CPU_ISSET_S(i, set_size, a->set);
}
static inline unsigned int ilog2(unsigned int x)
{
if (x == 0)
return 0;
return (sizeof(x) * 8 - 1) - __builtin_clz(x);
}
#define UBLK_DBG_DEV (1U << 0)
#define UBLK_DBG_THREAD (1U << 1)
#define UBLK_DBG_IO_CMD (1U << 2)
#define UBLK_DBG_IO (1U << 3)
#define UBLK_DBG_CTRL_CMD (1U << 4)
#define UBLK_LOG (1U << 5)
extern unsigned int ublk_dbg_mask;
static inline void ublk_err(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
static inline void ublk_log(const char *fmt, ...)
{
if (ublk_dbg_mask & UBLK_LOG) {
va_list ap;
va_start(ap, fmt);
vfprintf(stdout, fmt, ap);
va_end(ap);
}
}
static inline void ublk_dbg(int level, const char *fmt, ...)
Annotation
- Detected declarations: `struct allocator`, `function allocator_init`, `function allocator_deinit`, `function allocator_get`, `function allocator_put`, `function allocator_get_val`, `function ilog2`, `function ublk_err`, `function ublk_log`, `function ublk_dbg`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.