tools/perf/util/pstack.c
Source file repositories/reference/linux-study-clean/tools/perf/util/pstack.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/pstack.c- Extension
.c- Size
- 1469 bytes
- Lines
- 72
- 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
pstack.hdebug.hlinux/kernel.hlinux/zalloc.hstdlib.hstring.h
Detected Declarations
struct pstackfunction pstack__deletefunction pstack__emptyfunction pstack__removefunction pstack__push
Annotated Snippet
struct pstack {
unsigned short top;
unsigned short max_nr_entries;
void *entries[];
};
struct pstack *pstack__new(unsigned short max_nr_entries)
{
struct pstack *pstack = zalloc((sizeof(*pstack) +
max_nr_entries * sizeof(void *)));
if (pstack != NULL)
pstack->max_nr_entries = max_nr_entries;
return pstack;
}
void pstack__delete(struct pstack *pstack)
{
free(pstack);
}
bool pstack__empty(const struct pstack *pstack)
{
return pstack->top == 0;
}
void pstack__remove(struct pstack *pstack, void *key)
{
unsigned short i = pstack->top, last_index = pstack->top - 1;
while (i-- != 0) {
if (pstack->entries[i] == key) {
if (i < last_index)
memmove(pstack->entries + i,
pstack->entries + i + 1,
(last_index - i) * sizeof(void *));
--pstack->top;
return;
}
}
pr_err("%s: %p not on the pstack!\n", __func__, key);
}
void pstack__push(struct pstack *pstack, void *key)
{
if (pstack->top == pstack->max_nr_entries) {
pr_err("%s: top=%d, overflow!\n", __func__, pstack->top);
return;
}
pstack->entries[pstack->top++] = key;
}
void *pstack__peek(struct pstack *pstack)
{
if (pstack->top == 0)
return NULL;
return pstack->entries[pstack->top - 1];
}
Annotation
- Immediate include surface: `pstack.h`, `debug.h`, `linux/kernel.h`, `linux/zalloc.h`, `stdlib.h`, `string.h`.
- Detected declarations: `struct pstack`, `function pstack__delete`, `function pstack__empty`, `function pstack__remove`, `function pstack__push`.
- 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.