All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 34/38] trace-cmd: Add option CPUCOUNT to buffer instance options
Date: Wed, 03 Jan 2018 12:52:36 -0500	[thread overview]
Message-ID: <20180103175339.779446639@goodmis.org> (raw)
In-Reply-To: 20180103175202.044283643@goodmis.org

[-- Attachment #1: 0034-trace-cmd-Add-option-CPUCOUNT-to-buffer-instance-opt.patch --]
[-- Type: text/plain, Size: 6518 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

Add a new trace.dat option that allows buffer instances to have a different
number of CPUS than what the top level buffers have.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 trace-cmd.h    |  3 ++-
 trace-input.c  | 27 +++++++++++++++++++++++++++
 trace-output.c | 11 ++++++++++-
 trace-record.c | 55 +++++++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 80 insertions(+), 16 deletions(-)

diff --git a/trace-cmd.h b/trace-cmd.h
index a3d38ec27556..a5409887e6dd 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -93,6 +93,7 @@ enum {
 	TRACECMD_OPTION_UNAME,
 	TRACECMD_OPTION_HOOK,
 	TRACECMD_OPTION_OFFSET,
+	TRACECMD_OPTION_CPUCOUNT,
 };
 
 enum {
@@ -257,7 +258,7 @@ struct tracecmd_option *tracecmd_add_option(struct tracecmd_output *handle,
 					    unsigned short id, int size,
 					    const void *data);
 struct tracecmd_option *tracecmd_add_buffer_option(struct tracecmd_output *handle,
-						   const char *name);
+						   const char *name, int cpus);
 int tracecmd_update_option(struct tracecmd_output *handle,
 			   struct tracecmd_option *option, int size,
 			   const void *data);
diff --git a/trace-input.c b/trace-input.c
index 15d8c1b0b6d6..30b16bab43d7 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -2102,6 +2102,7 @@ static int handle_options(struct tracecmd_input *handle)
 	struct input_buffer_instance *buffer;
 	struct hook_list *hook;
 	char *buf;
+	int cpus;
 
 	for (;;) {
 		if (do_read_check(handle, &option, 2))
@@ -2183,6 +2184,10 @@ static int handle_options(struct tracecmd_input *handle)
 			hook->next = handle->hooks;
 			handle->hooks = hook;
 			break;
+		case TRACECMD_OPTION_CPUCOUNT:
+			cpus = *(int *)buf;
+			handle->cpus = __data2host4(handle->pevent, cpus);
+			break;
 		default:
 			warning("unknown option %d", option);
 			break;
@@ -2206,11 +2211,14 @@ static int read_cpu_data(struct tracecmd_input *handle)
 	unsigned long long max_size = 0;
 	unsigned long long pages;
 	char buf[10];
+	int cpus;
 	int cpu;
 
 	if (do_read_check(handle, buf, 10))
 		return -1;
 
+	cpus = handle->cpus;
+
 	/* check if this handles options */
 	if (strncmp(buf, "options", 7) == 0) {
 		if (handle_options(handle) < 0)
@@ -2293,6 +2301,25 @@ static int read_cpu_data(struct tracecmd_input *handle)
 			goto out_free;
 	}
 
+	/*
+	 * It is possible that an option changed the number of CPUs.
+	 * If that happened, then there's "empty" cpu data saved for
+	 * backward compatibility.
+	 */
+	if (cpus < handle->cpus) {
+		unsigned long long ignore;
+		int once = 0;
+
+		read8(handle, &ignore); /* offset */
+		read8(handle, &ignore); /* size */
+		if (ignore != 0) {
+			if (!once) {
+				warning("ignored CPU data not zero size");
+				once++;
+			}
+		}
+	}
+
 	return 0;
 
  out_free:
diff --git a/trace-output.c b/trace-output.c
index cbacd5426963..02efeeb669d6 100644
--- a/trace-output.c
+++ b/trace-output.c
@@ -1029,7 +1029,8 @@ int tracecmd_update_option(struct tracecmd_output *handle,
 }
 
 struct tracecmd_option *
-tracecmd_add_buffer_option(struct tracecmd_output *handle, const char *name)
+tracecmd_add_buffer_option(struct tracecmd_output *handle, const char *name,
+			   int cpus)
 {
 	struct tracecmd_option *option;
 	char *buf;
@@ -1046,6 +1047,14 @@ tracecmd_add_buffer_option(struct tracecmd_output *handle, const char *name)
 	option = tracecmd_add_option(handle, TRACECMD_OPTION_BUFFER, size, buf);
 	free(buf);
 
+	/*
+	 * In case a buffer instance has different number of CPUs as the
+	 * local machine.
+	 */
+	if (cpus)
+		tracecmd_add_option(handle, TRACECMD_OPTION_CPUCOUNT,
+				    sizeof(int), &cpus);
+
 	return option;
 }
 
diff --git a/trace-record.c b/trace-record.c
index bcc6f2e79cb3..9b389e7d9134 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -2970,21 +2970,53 @@ static struct tracecmd_msg_handle *start_threads(enum trace_type type, int globa
 	return msg_handle;
 }
 
+static void touch_file(const char *file)
+{
+	int fd;
+
+	fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+	if (fd < 0)
+		die("could not create file %s\n", file);
+	close(fd);
+}
+
 static void append_buffer(struct tracecmd_output *handle,
 			  struct tracecmd_option *buffer_option,
 			  struct buffer_instance *instance,
 			  char **temp_files)
 {
+	int cpu_count = instance->cpu_count;
 	int i;
 
-	for (i = 0; i < instance->cpu_count; i++)
+	/*
+	 * Since we can record remote and virtual machines in the same file
+	 * as the host, the buffers may no longer have matching number of
+	 * CPU data as the host. For backward compatibility for older
+	 * trace-cmd versions, which will blindly read the number of CPUs
+	 * for each buffer instance as there are for the host, if there are
+	 * fewer CPUs on the remote machine than on the host, an "empty"
+	 * CPU is needed for each CPU that the host has that the remote does
+	 * not. If there are more CPUs on the remote, older executables will
+	 * simply ignore them (which is OK, we only need to guarantee that
+	 * old executables don't crash).
+	 */
+	if (instance->cpu_count < local_cpu_count)
+		cpu_count = local_cpu_count;
+
+	for (i = 0; i < cpu_count; i++) {
 		temp_files[i] = get_temp_file(instance, i);
+		if (i >= instance->cpu_count)
+			touch_file(temp_files[i]);
+	}
 
 	tracecmd_append_buffer_cpu_data(handle, buffer_option,
-					instance->cpu_count, temp_files);
+					cpu_count, temp_files);
 
-	for (i = 0; i < instance->cpu_count; i++)
+	for (i = 0; i < instance->cpu_count; i++) {
+		if (i >= instance->cpu_count)
+			delete_temp_file(instance, i);
 		put_temp_file(temp_files[i]);
+	}
 }
 
 static void
@@ -3039,16 +3071,6 @@ static void add_uname(struct tracecmd_output *handle)
 	free(str);
 }
 
-static void touch_file(const char *file)
-{
-	int fd;
-
-	fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
-	if (fd < 0)
-		die("could not create file %s\n", file);
-	close(fd);
-}
-
 static void print_stat(struct buffer_instance *instance)
 {
 	int cpu;
@@ -3150,7 +3172,12 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 				die("Failed to allocate buffer options");
 			i = 0;
 			for_each_instance(instance) {
-				buffer_options[i++] = tracecmd_add_buffer_option(handle, instance->name);
+				int cpus = instance->cpu_count != local_cpu_count ?
+					instance->cpu_count : 0;
+
+				buffer_options[i++] = tracecmd_add_buffer_option(handle,
+										 instance->name,
+										 cpus);
 				add_buffer_stat(handle, instance);
 			}
 		}
-- 
2.13.2

  parent reply	other threads:[~2018-01-03 17:53 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 17:52 [PATCH 00/38] trace-cmd: Simplify the msg handling Steven Rostedt
2018-01-03 17:52 ` [PATCH 01/38] trace-cmd recorder: Check if pipe_size was modified by fcntl(F_GETPIPE_SZ) Steven Rostedt
2018-01-03 17:52 ` [PATCH 02/38] pevent: Simplify pointer print logic and fix %pF Steven Rostedt
2018-01-03 17:52 ` [PATCH 03/38] pevent: Handle new pointer processing of bprint strings Steven Rostedt
2018-01-03 17:52 ` [PATCH 04/38] trace-cmd record: Fix clearing out the ctx->instance when used in for_all_instances() Steven Rostedt
2018-01-03 17:52 ` [PATCH 05/38] trace-cmd: Remove the creating of msg out of tracecmd_msg_send() Steven Rostedt
2018-01-03 17:52 ` [PATCH 06/38] trace-cmd: Move tracecmd_msg_send_and_wait_for_msg() into its only user Steven Rostedt
2018-01-03 17:52 ` [PATCH 07/38] trace-cmd: Turn tracecmd_msg data into an anonymous union Steven Rostedt
2018-01-03 17:52 ` [PATCH 08/38] trace-cmd: Remove unused structure tracecmd_msg_error Steven Rostedt
2018-01-03 17:52 ` [PATCH 09/38] trace-cmd: Move size and cmd in tracecmd_msg into its own header struct Steven Rostedt
2018-01-03 17:52 ` [PATCH 10/38] trace-cmd: Move the tracecmd_msg pointers into their own union Steven Rostedt
2018-01-03 17:52 ` [PATCH 11/38] trace-cmd: Just use the buf field for sending pointers Steven Rostedt
2018-01-03 17:52 ` [PATCH 12/38] trace-cmd: Use an array to map msg types and min sizes Steven Rostedt
2018-01-03 17:52 ` [PATCH 13/38] trace-cmd: Merge msg_do_write_check() into msg_write() Steven Rostedt
2018-01-03 17:52 ` [PATCH 14/38] trace-cmd: Simplify msg_free() by using min sizes Steven Rostedt
2018-01-03 17:52 ` [PATCH 15/38] trace-cmd: Add tracecmd_msg_init() helper function Steven Rostedt
2018-01-03 17:52 ` [PATCH 16/38] trace-cmd: Remove mulitplexer tracecmd_msg_create() Steven Rostedt
2018-01-03 17:52 ` [PATCH 17/38] trace-cmd: Simplify msg_read_extra() Steven Rostedt
2018-01-03 17:52 ` [PATCH 18/38] trace-cmd: Have msg_free() zero out msg contents Steven Rostedt
2018-01-03 17:52 ` [PATCH 19/38] trace-cmd: Verify RINIT was received after TINIT msg sent Steven Rostedt
2018-01-03 17:52 ` [PATCH 20/38] trace-cmd: Make send_metadata a flag in the output handle Steven Rostedt
2018-01-03 17:52 ` [PATCH 21/38] trace-cmd: Pass cpu count and port array to make_rinit() Steven Rostedt
2018-01-03 17:52 ` [PATCH 22/38] trace-cmd: Pass cpu_count instead of having it as a global Steven Rostedt
2018-01-03 17:52 ` [PATCH 23/38] trace-cmd: Pass in client_ports instead of using a global variable Steven Rostedt
2018-01-03 17:52 ` [PATCH 24/38] trace-cmd msg: Add debug prints of messages sent and received Steven Rostedt
2018-01-03 17:52 ` [PATCH 25/38] trace-cmd msg: Move the saved closing fd to the caller Steven Rostedt
2018-01-03 17:52 ` [PATCH 26/38] trace-cmd listen: Add better output on error of connections Steven Rostedt
2018-01-03 17:52 ` [PATCH 27/38] trace-cmd msg: Create a msg_handle to pass around for saved state Steven Rostedt
2018-01-03 17:52 ` [PATCH 28/38] trace-cmd msg: Add server structure of msg_handler Steven Rostedt
2018-01-03 20:31   ` [PATCH 28/38 v2] " Steven Rostedt
2018-01-03 17:52 ` [PATCH 29/38] trace-cmd: Remove global use_tcp variable Steven Rostedt
2018-01-03 17:52 ` [PATCH 30/38] trace-cmd: Move protocol version into msg_handler Steven Rostedt
2018-01-03 17:52 ` [PATCH 31/38] tracecmd: Clean up handling of cpu_count Steven Rostedt
2018-01-03 17:52 ` [PATCH 32/38] tracecmd listen: Have pagesize passed as return not parameter Steven Rostedt
2018-01-03 17:52 ` [PATCH 33/38] trace-cmd: Have cpu_count reside in instances and not be global Steven Rostedt
2018-01-03 17:52 ` Steven Rostedt [this message]
2018-01-03 17:52 ` [PATCH 35/38] trace-cmd: Have msg_handle part of the buffer instance Steven Rostedt
2018-01-03 17:52 ` [PATCH 36/38] trace-cmd record: Allow instances to be recorded over the network Steven Rostedt
2018-01-03 17:52 ` [PATCH 37/38] trace-cmd: Have keep and profile be flags of buffer instance Steven Rostedt
2018-01-03 17:52 ` [PATCH 38/38] trace-cmd: Add network handle into " Steven Rostedt

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=20180103175339.779446639@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.