drivers/accel/habanalabs/common/state_dump.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/state_dump.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/state_dump.c- Extension
.c- Size
- 18422 bytes
- Lines
- 719
- Domain
- Driver Families
- Bucket
- drivers/accel
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/vmalloc.huapi/drm/habanalabs_accel.hhabanalabs.h
Detected Declarations
function resize_to_fitfunction hl_snprintf_resizefunction hl_print_resize_sync_enginefunction hl_state_dump_free_sync_to_engine_mapfunction hash_for_each_safefunction hl_state_dump_get_sync_to_enginefunction hl_state_dump_free_sync_objectsfunction hl_state_dump_print_syncs_single_blockfunction hl_state_dump_print_syncsfunction hl_state_dump_alloc_read_sm_block_monitorsfunction hl_state_dump_free_monitorsfunction hl_state_dump_print_monitors_single_blockfunction hl_state_dump_print_monitorsfunction hl_state_dump_print_engine_fencesfunction hl_state_dump_print_fencesfunction hl_state_dump
Annotated Snippet
if (!leading0) {
*wrptr = '0' + bit;
++wrptr;
}
}
*wrptr = '\0';
return buf;
}
/**
* resize_to_fit - helper function, resize buffer to fit given amount of data
* @buf: destination buffer double pointer
* @size: pointer to the size container
* @desired_size: size the buffer must contain
*
* Returns 0 on success or error code on failure.
* On success, the size of buffer is at least desired_size. Buffer is allocated
* via vmalloc and must be freed with vfree.
*/
static int resize_to_fit(char **buf, size_t *size, size_t desired_size)
{
char *resized_buf;
size_t new_size;
if (*size >= desired_size)
return 0;
/* Not enough space to print all, have to resize */
new_size = max_t(size_t, PAGE_SIZE, round_up(desired_size, PAGE_SIZE));
resized_buf = vmalloc(new_size);
if (!resized_buf)
return -ENOMEM;
memcpy(resized_buf, *buf, *size);
vfree(*buf);
*buf = resized_buf;
*size = new_size;
return 1;
}
/**
* hl_snprintf_resize() - print formatted data to buffer, resize as needed
* @buf: buffer double pointer, to be written to and resized, must be either
* NULL or allocated with vmalloc.
* @size: current size of the buffer
* @offset: current offset to write to
* @format: format of the data
*
* This function will write formatted data into the buffer. If buffer is not
* large enough, it will be resized using vmalloc. Size may be modified if the
* buffer was resized, offset will be advanced by the number of bytes written
* not including the terminating character
*
* Returns 0 on success or error code on failure
*
* Note that the buffer has to be manually released using vfree.
*/
int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,
const char *format, ...)
{
va_list args;
size_t length;
int rc;
if (*buf == NULL && (*size != 0 || *offset != 0))
return -EINVAL;
va_start(args, format);
length = vsnprintf(*buf + *offset, *size - *offset, format, args);
va_end(args);
rc = resize_to_fit(buf, size, *offset + length + 1);
if (rc < 0)
return rc;
else if (rc > 0) {
/* Resize was needed, write again */
va_start(args, format);
length = vsnprintf(*buf + *offset, *size - *offset, format,
args);
va_end(args);
}
*offset += length;
return 0;
}
/**
Annotation
- Immediate include surface: `linux/vmalloc.h`, `uapi/drm/habanalabs_accel.h`, `habanalabs.h`.
- Detected declarations: `function resize_to_fit`, `function hl_snprintf_resize`, `function hl_print_resize_sync_engine`, `function hl_state_dump_free_sync_to_engine_map`, `function hash_for_each_safe`, `function hl_state_dump_get_sync_to_engine`, `function hl_state_dump_free_sync_objects`, `function hl_state_dump_print_syncs_single_block`, `function hl_state_dump_print_syncs`, `function hl_state_dump_alloc_read_sm_block_monitors`.
- Atlas domain: Driver Families / drivers/accel.
- 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.