linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hamza Mahfooz <someguy@effective-light.com>
To: linux-kernel@vger.kernel.org
Cc: Thomas Renninger <trenn@suse.com>, Shuah Khan <shuah@kernel.org>,
	linux-pm@vger.kernel.org,
	Hamza Mahfooz <someguy@effective-light.com>,
	Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
Subject: [PATCH 1/2] cpupower: implement the multi-cpu monitoring of programs
Date: Wed, 12 May 2021 07:26:57 -0400	[thread overview]
Message-ID: <20210512112658.89965-1-someguy@effective-light.com> (raw)

If we look inside cpupower/ToDo, the current 6th point makes mention of
a method to implement multi-cpu monitoring without introducing noise to
the tested program itself.

Suggested-by: Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>
Signed-off-by: Hamza Mahfooz <someguy@effective-light.com>
---
 .../utils/idle_monitor/cpupower-monitor.c     | 28 +++++++++++++------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
index 7c77045fef52..5fc9b38be4e5 100644
--- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
@@ -278,7 +278,7 @@ void list_monitors(void)
 	}
 }
 
-int fork_it(char **argv)
+int fork_it(int cpu, char **argv)
 {
 	int status;
 	unsigned int num;
@@ -315,9 +315,9 @@ int fork_it(char **argv)
 
 	timediff = timespec_diff_us(start, end);
 	if (WIFEXITED(status))
-		printf(_("%s took %.5f seconds and exited with status %d\n"),
-			argv[0], timediff / (1000.0 * 1000),
-			WEXITSTATUS(status));
+		printf(_("cpu %d: %s took %.5f seconds and exited with status %d\n"),
+			cpu, argv[0],
+			timediff / (1000.0 * 1000), WEXITSTATUS(status));
 	return 0;
 }
 
@@ -388,7 +388,8 @@ int cmd_monitor(int argc, char **argv)
 {
 	unsigned int num;
 	struct cpuidle_monitor *test_mon;
-	int cpu;
+	int cpu, status;
+	pid_t child_pid;
 
 	cmdline(argc, argv);
 	cpu_count = get_cpu_topology(&cpu_top);
@@ -440,10 +441,21 @@ int cmd_monitor(int argc, char **argv)
 	/*
 	 * if any params left, it must be a command to fork
 	 */
-	if (argc - optind)
-		fork_it(argv + optind);
-	else
+	if (argc - optind) {
+		for (cpu = 0; cpu < cpu_count; cpu++) {
+			child_pid = fork();
+			if (!child_pid) {
+				bind_cpu(cpu);
+				fork_it(cpu, argv + optind);
+				exit(EXIT_SUCCESS);
+			} else if (waitpid(child_pid, &status, 0) == -1) {
+				perror("waitpid");
+				exit(EXIT_FAILURE);
+			}
+		}
+	} else {
 		do_interval_measure(interval);
+	}
 
 	/* ToDo: Topology parsing needs fixing first to do
 	   this more generically */
-- 
2.31.1


             reply	other threads:[~2021-05-12 11:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 11:26 Hamza Mahfooz [this message]
2021-05-12 11:26 ` [PATCH 2/2] cpupower: removed a completed task from the list Hamza Mahfooz
2021-05-12 14:45   ` Shuah Khan
2021-05-12 20:30     ` Hamza Mahfooz
2021-05-12 14:44 ` [PATCH 1/2] cpupower: implement the multi-cpu monitoring of programs Shuah Khan

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=20210512112658.89965-1-someguy@effective-light.com \
    --to=someguy@effective-light.com \
    --cc=Janakarajan.Natarajan@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=trenn@suse.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).