tools/perf/util/comm.c
Source file repositories/reference/linux-study-clean/tools/perf/util/comm.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/comm.c- Extension
.c- Size
- 5302 bytes
- Lines
- 238
- 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
comm.herrno.hstring.hinternal/rc_check.hlinux/refcount.hlinux/zalloc.htools/libc_compat.hrwsem.h
Detected Declarations
function comm_str__putfunction comm_str__searchfunction comm_strs__remove_if_lastfunction comm__overridefunction comm__free
Annotated Snippet
if (comm_strs->num_strs == comm_strs->capacity) {
struct comm_str **tmp;
tmp = reallocarray(comm_strs->strs,
comm_strs->capacity + 16,
sizeof(*comm_strs->strs));
if (!tmp) {
up_write(&comm_strs->lock);
return NULL;
}
comm_strs->strs = tmp;
comm_strs->capacity += 16;
}
result = comm_str__new(str);
if (result) {
int low = 0, high = comm_strs->num_strs - 1;
int insert = comm_strs->num_strs; /* Default to inserting at the end. */
while (low <= high) {
int mid = low + (high - low) / 2;
int cmp = strcmp(comm_str__str(comm_strs->strs[mid]), str);
if (cmp < 0) {
low = mid + 1;
} else {
high = mid - 1;
insert = mid;
}
}
memmove(&comm_strs->strs[insert + 1], &comm_strs->strs[insert],
(comm_strs->num_strs - insert) * sizeof(struct comm_str *));
comm_strs->num_strs++;
comm_strs->strs[insert] = result;
}
}
up_write(&comm_strs->lock);
return comm_str__get(result);
}
struct comm *comm__new(const char *str, u64 timestamp, bool exec)
{
struct comm *comm = zalloc(sizeof(*comm));
if (!comm)
return NULL;
comm->start = timestamp;
comm->exec = exec;
comm->comm_str = comm_strs__findnew(str);
if (!comm->comm_str) {
free(comm);
return NULL;
}
return comm;
}
int comm__override(struct comm *comm, const char *str, u64 timestamp, bool exec)
{
struct comm_str *new, *old = comm->comm_str;
new = comm_strs__findnew(str);
if (!new)
return -ENOMEM;
comm_str__put(old);
comm->comm_str = new;
comm->start = timestamp;
if (exec)
comm->exec = true;
return 0;
}
void comm__free(struct comm *comm)
{
comm_str__put(comm->comm_str);
free(comm);
}
const char *comm__str(const struct comm *comm)
{
return comm_str__str(comm->comm_str);
}
Annotation
- Immediate include surface: `comm.h`, `errno.h`, `string.h`, `internal/rc_check.h`, `linux/refcount.h`, `linux/zalloc.h`, `tools/libc_compat.h`, `rwsem.h`.
- Detected declarations: `function comm_str__put`, `function comm_str__search`, `function comm_strs__remove_if_last`, `function comm__override`, `function comm__free`.
- 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.