tools/perf/builtin-daemon.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-daemon.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-daemon.c- Extension
.c- Size
- 32132 bytes
- Lines
- 1544
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
internal/lib.hinttypes.hsubcmd/parse-options.hapi/fd/array.hapi/fs/fs.hlinux/zalloc.hlinux/string.hlinux/limits.hstring.hsys/file.hsignal.hstdlib.htime.hstdio.hunistd.herrno.hsys/inotify.hlibgen.hsys/types.hsys/socket.hsys/un.hsys/stat.hsys/signalfd.hsys/wait.hpoll.hbuiltin.hperf.hdebug.hconfig.hutil.h
Detected Declarations
struct daemon_sessionstruct daemonenum daemon_session_statefunction sig_handlerfunction list_for_each_entryfunction get_session_namefunction session_configfunction server_configfunction client_configfunction check_basefunction setup_client_configfunction setup_server_configfunction daemon_session__runfunction handle_signalfdfunction list_for_each_entryfunction daemon_session__waitfunction daemon__has_alive_sessionfunction list_for_each_entryfunction daemon__waitfunction daemon_session__controlfunction setup_server_socketfunction daemon_session__pingfunction cmd_session_listfunction list_for_each_entryfunction daemon_session__signalfunction cmd_session_killfunction list_for_each_entryfunction cmd_session_pingfunction list_for_each_entryfunction handle_server_socketfunction setup_client_socketfunction daemon_session__killfunction daemon__signalfunction daemon_session__deletefunction daemon_session__removefunction daemon__stopfunction daemon__killfunction daemon__exitfunction daemon__reconfigfunction list_for_each_entry_safefunction setup_config_changesfunction process_inotify_eventfunction handle_config_changesfunction setup_configfunction lockffunction check_lockfunction go_backgroundfunction setup_signalfd
Annotated Snippet
struct daemon_session {
char *base;
char *name;
char *run;
char *control;
int pid;
struct list_head list;
enum daemon_session_state state;
time_t start;
};
struct daemon {
const char *config;
char *config_real;
char *config_base;
const char *csv_sep;
const char *base_user;
char *base;
struct list_head sessions;
FILE *out;
char *perf;
int signal_fd;
time_t start;
};
static struct daemon __daemon = {
.sessions = LIST_HEAD_INIT(__daemon.sessions),
};
static const char * const daemon_usage[] = {
"perf daemon {start|signal|stop|ping} [<options>]",
"perf daemon [<options>]",
NULL
};
static volatile sig_atomic_t done;
static void sig_handler(int sig __maybe_unused)
{
done = true;
}
static struct daemon_session *daemon__add_session(struct daemon *config, char *name)
{
struct daemon_session *session = zalloc(sizeof(*session));
if (!session)
return NULL;
session->name = strdup(name);
if (!session->name) {
free(session);
return NULL;
}
session->pid = -1;
list_add_tail(&session->list, &config->sessions);
return session;
}
static struct daemon_session *daemon__find_session(struct daemon *daemon, char *name)
{
struct daemon_session *session;
list_for_each_entry(session, &daemon->sessions, list) {
if (!strcmp(session->name, name))
return session;
}
return NULL;
}
static int get_session_name(const char *var, char *session, int len)
{
const char *p = var + sizeof("session-") - 1;
while (*p != '.' && *p != 0x0 && len--)
*session++ = *p++;
*session = 0;
return *p == '.' ? 0 : -EINVAL;
}
static int session_config(struct daemon *daemon, const char *var, const char *value)
{
struct daemon_session *session;
char name[100];
if (get_session_name(var, name, sizeof(name) - 1))
return -EINVAL;
Annotation
- Immediate include surface: `internal/lib.h`, `inttypes.h`, `subcmd/parse-options.h`, `api/fd/array.h`, `api/fs/fs.h`, `linux/zalloc.h`, `linux/string.h`, `linux/limits.h`.
- Detected declarations: `struct daemon_session`, `struct daemon`, `enum daemon_session_state`, `function sig_handler`, `function list_for_each_entry`, `function get_session_name`, `function session_config`, `function server_config`, `function client_config`, `function check_base`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.