tools/perf/util/s390-sample-raw.c
Source file repositories/reference/linux-study-clean/tools/perf/util/s390-sample-raw.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/s390-sample-raw.c- Extension
.c- Size
- 10498 bytes
- Lines
- 378
- 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
unistd.hstdio.hstring.hinttypes.hsys/stat.hlinux/compiler.hlinux/err.hasm/byteorder.hdebug.hsession.hevlist.hcolor.hhashmap.hsample-raw.hs390-cpumcf-kernel.hutil/pmu.hutil/sample.h
Detected Declarations
struct get_counter_name_datastruct pai_datafunction Licensefunction ctrset_validfunction s390_cpumcfdg_testctrfunction s390_cpumcfdg_dumptrailfunction get_counterset_startfunction get_counter_name_callbackfunction get_counter_name_hash_fnfunction get_counter_name_hashmap_equal_fnfunction s390_cpumcfdg_dumpfunction s390_pai_all_testfunction s390_pai_all_dumpfunction evlist__s390_sample_raw
Annotated Snippet
struct get_counter_name_data {
long wanted;
const char *result;
};
static int get_counter_name_callback(void *vdata, struct pmu_event_info *info)
{
struct get_counter_name_data *data = vdata;
int rc, event_nr;
const char *event_str;
if (info->str == NULL)
return 0;
event_str = strstr(info->str, "event=");
if (!event_str)
return 0;
rc = sscanf(event_str, "event=%x", &event_nr);
if (rc == 1 && event_nr == data->wanted) {
data->result = info->name;
return 1; /* Terminate the search. */
}
return 0;
}
static size_t get_counter_name_hash_fn(long key, void *ctx __maybe_unused)
{
return key;
}
static bool get_counter_name_hashmap_equal_fn(long key1, long key2, void *ctx __maybe_unused)
{
return key1 == key2;
}
/* Scan the PMU and extract the logical name of a counter from the event. Input
* is the counter set and counter number with in the set. Construct the event
* number and use this as key. If they match return the name of this counter.
* If no match is found a NULL pointer is returned.
*/
static char *get_counter_name(int set, int nr, struct perf_pmu *pmu)
{
static struct hashmap *cache;
static struct perf_pmu *cache_pmu;
long cache_key = get_counterset_start(set) + nr;
struct get_counter_name_data data = {
.wanted = cache_key,
.result = NULL,
};
char *result = NULL;
if (!pmu)
return NULL;
if (cache_pmu == pmu && hashmap__find(cache, cache_key, &result))
return strdup(result);
perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=*/ true,
&data, get_counter_name_callback);
result = strdup(data.result ?: "<unknown>");
if (cache_pmu == NULL) {
struct hashmap *tmp = hashmap__new(get_counter_name_hash_fn,
get_counter_name_hashmap_equal_fn,
/*ctx=*/NULL);
if (!IS_ERR(tmp)) {
cache = tmp;
cache_pmu = pmu;
}
}
if (cache_pmu == pmu && result) {
char *old_value = NULL, *new_value = strdup(result);
if (new_value) {
hashmap__set(cache, cache_key, new_value, /*old_key=*/NULL, &old_value);
/*
* Free in case of a race, but resizing would be broken
* in that case.
*/
free(old_value);
}
}
return result;
}
static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *sample)
Annotation
- Immediate include surface: `unistd.h`, `stdio.h`, `string.h`, `inttypes.h`, `sys/stat.h`, `linux/compiler.h`, `linux/err.h`, `asm/byteorder.h`.
- Detected declarations: `struct get_counter_name_data`, `struct pai_data`, `function License`, `function ctrset_valid`, `function s390_cpumcfdg_testctr`, `function s390_cpumcfdg_dumptrail`, `function get_counterset_start`, `function get_counter_name_callback`, `function get_counter_name_hash_fn`, `function get_counter_name_hashmap_equal_fn`.
- 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.