tools/perf/util/target.c
Source file repositories/reference/linux-study-clean/tools/perf/util/target.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/target.c- Extension
.c- Size
- 3157 bytes
- Lines
- 143
- 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
target.hpwd.hstdio.hstdlib.hstring.hlinux/kernel.hlinux/string.h
Detected Declarations
function Copyrightfunction parse_uidfunction target__strerror
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Helper functions for handling target threads/cpus
*
* Copyright (C) 2012, LG Electronics, Namhyung Kim <namhyung.kim@lge.com>
*/
#include "target.h"
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/kernel.h>
#include <linux/string.h>
enum target_errno target__validate(struct target *target)
{
enum target_errno ret = TARGET_ERRNO__SUCCESS;
if (target->pid)
target->tid = target->pid;
/* CPU and PID are mutually exclusive */
if (target->tid && target->cpu_list) {
target->cpu_list = NULL;
if (ret == TARGET_ERRNO__SUCCESS)
ret = TARGET_ERRNO__PID_OVERRIDE_CPU;
}
/* PID and SYSTEM are mutually exclusive */
if (target->tid && target->system_wide) {
target->system_wide = false;
if (ret == TARGET_ERRNO__SUCCESS)
ret = TARGET_ERRNO__PID_OVERRIDE_SYSTEM;
}
/* BPF and CPU are mutually exclusive */
if (target->bpf_str && target->cpu_list) {
target->cpu_list = NULL;
if (ret == TARGET_ERRNO__SUCCESS)
ret = TARGET_ERRNO__BPF_OVERRIDE_CPU;
}
/* BPF and PID/TID are mutually exclusive */
if (target->bpf_str && target->tid) {
target->tid = NULL;
if (ret == TARGET_ERRNO__SUCCESS)
ret = TARGET_ERRNO__BPF_OVERRIDE_PID;
}
/* BPF and THREADS are mutually exclusive */
if (target->bpf_str && target->per_thread) {
target->per_thread = false;
if (ret == TARGET_ERRNO__SUCCESS)
ret = TARGET_ERRNO__BPF_OVERRIDE_THREAD;
}
/* THREAD and SYSTEM/CPU are mutually exclusive */
if (target->per_thread && (target->system_wide || target->cpu_list)) {
target->per_thread = false;
if (ret == TARGET_ERRNO__SUCCESS)
ret = TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD;
}
return ret;
}
uid_t parse_uid(const char *str)
{
struct passwd pwd, *result;
char buf[1024];
if (str == NULL)
return UINT_MAX;
/* Try user name first */
getpwnam_r(str, &pwd, buf, sizeof(buf), &result);
if (result == NULL) {
/*
* The user name not found. Maybe it's a UID number.
*/
char *endptr;
int uid = strtol(str, &endptr, 10);
if (*endptr != '\0')
return UINT_MAX;
getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
Annotation
- Immediate include surface: `target.h`, `pwd.h`, `stdio.h`, `stdlib.h`, `string.h`, `linux/kernel.h`, `linux/string.h`.
- Detected declarations: `function Copyright`, `function parse_uid`, `function target__strerror`.
- 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.