From: Steven Rostedt <rostedt@goodmis.org>
To: Slavomir Kaslev <kaslevs@vmware.com>
Cc: linux-trace-devel@vger.kernel.org, slavomir.kaslev@gmail.com
Subject: Re: [RFC PATCH v8 07/13] trace-cmd: Add VM kernel tracing over vsockets transport
Date: Tue, 12 Mar 2019 19:07:55 -0400 [thread overview]
Message-ID: <20190312190755.15e7f603@gandalf.local.home> (raw)
In-Reply-To: <20190222180539.27439-8-kaslevs@vmware.com>
On Fri, 22 Feb 2019 20:05:33 +0200
Slavomir Kaslev <kaslevs@vmware.com> wrote:
> +static void agent_serve(unsigned int port)
> +{
> + int sd, cd, nr_cpus;
> + pid_t pid;
> +
> + signal(SIGCHLD, handle_sigchld);
> +
> + nr_cpus = count_cpus();
> + page_size = getpagesize();
> +
> + sd = make_vsock(port);
> + if (sd < 0)
> + die("Failed to open vsocket");
> +
> + for (;;) {
> + cd = accept(sd, NULL, NULL);
> + if (cd < 0) {
> + if (errno == EINTR)
> + continue;
> + die("accept");
> + }
> +
> + if (handler_pid)
> + goto busy;
> +
> + pid = fork();
Also, for debugging purposes, I add a --debug option that prevents
forking, and the process is handled directly. The patch below is sorta
the idea.
This way we can run both the agent and host under gdb and step through
the communication, without having to deal with "set follow-fork" modes.
-- Steve
> + if (pid == 0) {
> + close(sd);
> + signal(SIGCHLD, SIG_DFL);
> + agent_handle(cd, nr_cpus, page_size);
> + }
> + if (pid > 0)
> + handler_pid = pid;
> +
> +busy:
> + close(cd);
> + }
> +}
> +
diff --git a/tracecmd/trace-agent.c b/tracecmd/trace-agent.c
index 02dda47..da6ff12 100644
--- a/tracecmd/trace-agent.c
+++ b/tracecmd/trace-agent.c
@@ -170,6 +170,15 @@ static void handle_sigchld(int sig)
}
}
+static pid_t do_fork()
+{
+ /* in debug mode, we do not fork off children */
+ if (debug)
+ return 0;
+
+ return fork();
+}
+
static void agent_serve(unsigned int port)
{
int sd, cd, nr_cpus;
@@ -195,7 +204,7 @@ static void agent_serve(unsigned int port)
if (handler_pid)
goto busy;
- pid = fork();
+ pid = do_fork();
if (pid == 0) {
close(sd);
signal(SIGCHLD, SIG_DFL);
@@ -209,6 +218,10 @@ busy:
}
}
+enum {
+ DO_DEBUG = 255
+};
+
void trace_agent(int argc, char **argv)
{
bool do_daemon = false;
@@ -225,6 +238,7 @@ void trace_agent(int argc, char **argv)
static struct option long_options[] = {
{"port", required_argument, NULL, 'p'},
{"help", no_argument, NULL, '?'},
+ {"debug", no_argument, NULL, DO_DEBUG},
{NULL, 0, NULL, 0}
};
@@ -242,6 +256,9 @@ void trace_agent(int argc, char **argv)
case 'D':
do_daemon = true;
break;
+ case DO_DEBUG:
+ debug = true;
+ break;
default:
usage(argv);
}
next prev parent reply other threads:[~2019-03-12 23:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 18:05 [RFC PATCH v8 00/13] Add VM kernel tracing over vsockets and FIFOs Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 01/13] trace-cmd: Minor cleanup in tracecmd_start_recording() Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 02/13] trace-cmd: Minor cleanup in print_stat() Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 03/13] trace-cmd: Detect if vsockets are available Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 04/13] trace-cmd: Add tracecmd_create_recorder_virt function Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 05/13] trace-cmd: Add TRACE_REQ and TRACE_RESP messages Slavomir Kaslev
2019-02-22 21:09 ` Steven Rostedt
2019-03-12 18:48 ` Slavomir Kaslev
2019-03-12 19:18 ` Steven Rostedt
2019-02-22 18:05 ` [RFC PATCH v8 06/13] trace-cmd: Add buffer instance flags for tracing in guest and agent context Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 07/13] trace-cmd: Add VM kernel tracing over vsockets transport Slavomir Kaslev
2019-03-12 19:23 ` Steven Rostedt
2019-03-12 23:07 ` Steven Rostedt [this message]
2019-02-22 18:05 ` [RFC PATCH v8 08/13] trace-cmd: Use splice(2) for vsockets if available Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 09/13] trace-cmd: Add `trace-cmd setup-guest` command Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 10/13] trace-cmd: Try to autodetect number of guest CPUs in setup-guest if not specified Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 11/13] trace-cmd: Add setup-guest flag for attaching FIFOs to the guest VM config Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 12/13] trace-cmd: Add splice() recording from FIFO without additional pipe buffer Slavomir Kaslev
2019-02-22 18:05 ` [RFC PATCH v8 13/13] trace-cmd: Add VM tracing over FIFOs transport Slavomir Kaslev
2019-03-12 19:28 ` Steven Rostedt
-- strict thread matches above, loose matches on Subject: below --
2019-04-02 13:42 [RFC PATCH v8 00/11] Add VM kernel tracing over vsockets and FIFOs Slavomir Kaslev
2019-04-02 13:42 ` [RFC PATCH v8 07/13] trace-cmd: Add VM kernel tracing over vsockets transport Slavomir Kaslev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190312190755.15e7f603@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=kaslevs@vmware.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=slavomir.kaslev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).