From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> Add communication for an agent proxy. When an agent is also running as a proxy, it will be able to receive a TRACE_PROXY message. This will contain the same data as a TRACE_REQ, but also include the number of CPUs the recorder has (as the recorder may be running on the guest, and the agent on the host), as well as the number of siblings guests that will be sent afterward. The sibling messages will come at a later time. Currently there are no users of this API. Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- .../include/private/trace-cmd-private.h | 12 +++ lib/trace-cmd/trace-msg.c | 90 ++++++++++++++++--- 2 files changed, 89 insertions(+), 13 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 77b387b494ee..8824dcae0b16 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -378,6 +378,7 @@ long tracecmd_flush_recording(struct tracecmd_recorder *recorder); enum tracecmd_msg_flags { TRACECMD_MSG_FL_USE_TCP = 1 << 0, TRACECMD_MSG_FL_USE_VSOCK = 1 << 1, + TRACECMD_MSG_FL_PROXY = 1 << 2, }; #define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX" @@ -431,10 +432,21 @@ int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle, int argc, char **argv, bool use_fifos, unsigned long long trace_id, struct tracecmd_tsync_protos *protos); +int tracecmd_msg_send_trace_proxy(struct tracecmd_msg_handle *msg_handle, + int argc, char **argv, bool use_fifos, + unsigned long long trace_id, + struct tracecmd_tsync_protos *protos, + unsigned int nr_cpus, + unsigned int siblings); int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle, int *argc, char ***argv, bool *use_fifos, unsigned long long *trace_id, struct tracecmd_tsync_protos **protos); +int tracecmd_msg_recv_trace_proxy(struct tracecmd_msg_handle *msg_handle, + int *argc, char ***argv, bool *use_fifos, + unsigned long long *trace_id, + struct tracecmd_tsync_protos **protos, + unsigned int *cpus, unsigned int *siblings); int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle, int nr_cpus, int page_size, diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index 9899fa8796e2..c16e8e81e50a 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -71,6 +71,12 @@ struct tracecmd_msg_trace_req { u64 trace_id; } __packed; +struct tracecmd_msg_trace_proxy { + struct tracecmd_msg_trace_req req; + be32 cpus; + be32 siblings; +} __packed; + struct tracecmd_msg_trace_resp { be32 flags; be32 cpus; @@ -101,7 +107,8 @@ struct tracecmd_msg_header { C(TRACE_REQ, 6, sizeof(struct tracecmd_msg_trace_req)), \ C(TRACE_RESP, 7, sizeof(struct tracecmd_msg_trace_resp)),\ C(CLOSE_RESP, 8, 0), \ - C(TIME_SYNC, 9, sizeof(struct tracecmd_msg_tsync)), + C(TIME_SYNC, 9, sizeof(struct tracecmd_msg_tsync)), \ + C(TRACE_PROXY, 10, sizeof(struct tracecmd_msg_trace_proxy)), #undef C #define C(a,b,c) MSG_##a = b @@ -134,6 +141,7 @@ struct tracecmd_msg { struct tracecmd_msg_tinit tinit; struct tracecmd_msg_rinit rinit; struct tracecmd_msg_trace_req trace_req; + struct tracecmd_msg_trace_proxy trace_proxy; struct tracecmd_msg_trace_resp trace_resp; struct tracecmd_msg_tsync tsync; }; @@ -1007,7 +1015,7 @@ static int make_trace_req(struct tracecmd_msg *msg, int argc, char **argv, msg->buf = buf; msg->hdr.size = htonl(ntohl(msg->hdr.size) + size); - return 0; + return size; } int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle, @@ -1026,6 +1034,26 @@ int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle, return tracecmd_msg_send(msg_handle, &msg); } +int tracecmd_msg_send_trace_proxy(struct tracecmd_msg_handle *msg_handle, + int argc, char **argv, bool use_fifos, + unsigned long long trace_id, + struct tracecmd_tsync_protos *protos, + unsigned int nr_cpus, + unsigned int siblings) +{ + struct tracecmd_msg msg; + int ret; + + tracecmd_msg_init(MSG_TRACE_PROXY, &msg); + ret = make_trace_req(&msg, argc, argv, use_fifos, trace_id, protos); + if (ret < 0) + return ret; + + msg.trace_proxy.cpus = htonl(nr_cpus); + msg.trace_proxy.siblings = htonl(siblings); + return tracecmd_msg_send(msg_handle, &msg); +} + static int get_trace_req_protos(char *buf, int length, struct tracecmd_tsync_protos **protos) { @@ -1119,16 +1147,12 @@ out: } -/* - * NOTE: On success, the returned `argv` should be freed with: - * free(argv[0]); - * free(argv); - * and `tsync_protos` with free(tsync_protos); - */ -int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle, - int *argc, char ***argv, bool *use_fifos, - unsigned long long *trace_id, - struct tracecmd_tsync_protos **protos) +static int msg_recv_trace_req_proxy(struct tracecmd_msg_handle *msg_handle, + int *argc, char ***argv, bool *use_fifos, + unsigned long long *trace_id, + struct tracecmd_tsync_protos **protos, + unsigned int *cpus, + unsigned int *siblings) { struct tracecmd_msg msg; unsigned int param_id; @@ -1141,7 +1165,16 @@ int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle, if (ret < 0) return ret; - if (ntohl(msg.hdr.cmd) != MSG_TRACE_REQ) { + switch (ntohl(msg.hdr.cmd)) { + case MSG_TRACE_PROXY: + if (cpus) + *cpus = ntohl(msg.trace_proxy.cpus); + if (siblings) + *siblings = ntohl(msg.trace_proxy.siblings); + /* fall through */ + case MSG_TRACE_REQ: + break; + default: ret = -ENOTSUP; goto out; } @@ -1192,6 +1225,37 @@ out: return ret; } +/* + * NOTE: On success, the returned `argv` should be freed with: + * free(argv[0]); + * free(argv); + * and `tsync_protos` with free(tsync_protos); + */ +int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle, + int *argc, char ***argv, bool *use_fifos, + unsigned long long *trace_id, + struct tracecmd_tsync_protos **protos) +{ + return msg_recv_trace_req_proxy(msg_handle, argc, argv, use_fifos, + trace_id, protos, NULL, NULL); +} + +/* + * NOTE: On success, the returned `argv` should be freed with: + * free(argv[0]); + * free(argv); + * and `tsync_protos` with free(tsync_protos); + */ +int tracecmd_msg_recv_trace_proxy(struct tracecmd_msg_handle *msg_handle, + int *argc, char ***argv, bool *use_fifos, + unsigned long long *trace_id, + struct tracecmd_tsync_protos **protos, + unsigned int *cpus, unsigned int *siblings) +{ + return msg_recv_trace_req_proxy(msg_handle, argc, argv, use_fifos, + trace_id, protos, cpus, siblings); +} + /** * tracecmd_msg_send_time_sync - Send a time sync packet * @msg_handle: message handle, holding the communication context -- 2.35.1