^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Guest agent for virtio-trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2012 Hitachi, Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Created by Yoshihiro Yunomae <yoshihiro.yunomae.ez@hitachi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "trace-agent.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PAGE_SIZE (sysconf(_SC_PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define PIPE_DEF_BUFS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define PIPE_MIN_SIZE (PAGE_SIZE*PIPE_DEF_BUFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define PIPE_MAX_SIZE (1024*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define READ_PATH_FMT \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) "/sys/kernel/debug/tracing/per_cpu/cpu%d/trace_pipe_raw"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define WRITE_PATH_FMT "/dev/virtio-ports/trace-path-cpu%d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define CTL_PATH "/dev/virtio-ports/agent-ctl-path"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) pthread_mutex_t mutex_notify = PTHREAD_MUTEX_INITIALIZER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) pthread_cond_t cond_wakeup = PTHREAD_COND_INITIALIZER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int get_total_cpus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int nr_cpus = (int)sysconf(_SC_NPROCESSORS_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (nr_cpus <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) pr_err("Could not read cpus\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) } else if (nr_cpus > MAX_CPUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) pr_err("Exceed max cpus(%d)\n", (int)MAX_CPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return nr_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static void *agent_info_new(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct agent_info *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) s = zalloc(sizeof(struct agent_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (s == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) pr_err("agent_info zalloc error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) s->pipe_size = PIPE_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) s->use_stdout = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) s->cpus = get_total_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) s->ctl_fd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* read/write threads init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) for (i = 0; i < s->cpus; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) s->rw_ti[i] = rw_thread_info_new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static unsigned long parse_size(const char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned long value, round;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) value = strtoul(arg, &ptr, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) switch (*ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) case 'K': case 'k':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) value <<= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) case 'M': case 'm':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) value <<= 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (value > PIPE_MAX_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) pr_err("Pipe size must be less than 1MB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) } else if (value < PIPE_MIN_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) pr_err("Pipe size must be over 64KB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Align buffer size with page unit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) round = value & (PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) value = value - round;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void usage(char const *prg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) pr_err("usage: %s [-h] [-o] [-s <size of pipe>]\n", prg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static const char *make_path(int cpu_num, bool this_is_write_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) buf = zalloc(PATH_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (buf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) pr_err("Could not allocate buffer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (this_is_write_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* write(output) path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ret = snprintf(buf, PATH_MAX, WRITE_PATH_FMT, cpu_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* read(input) path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ret = snprintf(buf, PATH_MAX, READ_PATH_FMT, cpu_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) pr_err("Failed to generate %s path(CPU#%d):%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) this_is_write_path ? "read" : "write", cpu_num, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static const char *make_input_path(int cpu_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return make_path(cpu_num, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static const char *make_output_path(int cpu_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return make_path(cpu_num, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void *agent_info_init(struct agent_info *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) const char *in_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) const char *out_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* init read/write threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) for (cpu = 0; cpu < s->cpus; cpu++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* set read(input) path per read/write thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) in_path = make_input_path(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (in_path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* set write(output) path per read/write thread*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (!s->use_stdout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) out_path = make_output_path(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (out_path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* stdout mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pr_debug("stdout mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) rw_thread_init(cpu, in_path, out_path, s->use_stdout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) s->pipe_size, s->rw_ti[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* init controller of read/write threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) s->ctl_fd = rw_ctl_init((const char *)CTL_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void *parse_args(int argc, char *argv[], struct agent_info *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) while ((cmd = getopt(argc, argv, "hos:")) != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* stdout mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case 'o':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) s->use_stdout = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* size of pipe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) case 's':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) size = parse_size(optarg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) s->pipe_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) case 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) usage(argv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) agent_info_init(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static void agent_main_loop(struct agent_info *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pthread_t rw_thread_per_cpu[MAX_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Start all read/write threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) for (cpu = 0; cpu < s->cpus; cpu++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) rw_thread_per_cpu[cpu] = rw_thread_run(s->rw_ti[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) rw_ctl_loop(s->ctl_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* Finish all read/write threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) for (cpu = 0; cpu < s->cpus; cpu++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ret = pthread_join(rw_thread_per_cpu[cpu], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pr_err("pthread_join() error:%d (cpu %d)\n", ret, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static void agent_info_free(struct agent_info *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) close(s->ctl_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) for (i = 0; i < s->cpus; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) close(s->rw_ti[i]->in_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) close(s->rw_ti[i]->out_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) close(s->rw_ti[i]->read_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) close(s->rw_ti[i]->write_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) free(s->rw_ti[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) free(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int main(int argc, char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct agent_info *s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) s = agent_info_new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) parse_args(argc, argv, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) agent_main_loop(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) agent_info_free(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }