linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fenghua Yu <fenghua.yu@intel.com>
To: "Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>, "H Peter Anvin" <hpa@zytor.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Moger, Babu" <Babu.Moger@amd.com>,
	"James Morse" <james.morse@arm.com>,
	"Sai Praneeth Prakhya" <sai.praneeth.prakhya@intel.com>,
	"Arshiya Hayatkhan Pathan" <arshiya.hayatkhan.pathan@intel.com>,
	"Ravi V Shankar" <ravi.v.shankar@intel.com>
Cc: "linux-kernel" <linux-kernel@vger.kernel.org>,
	Fenghua Yu <fenghua.yu@intel.com>
Subject: [PATCH 3/7] selftests/resctrl: Add callback to start a benchmark
Date: Tue, 16 Oct 2018 09:56:37 -0700	[thread overview]
Message-ID: <1539709001-38018-4-git-send-email-fenghua.yu@intel.com> (raw)
In-Reply-To: <1539709001-38018-1-git-send-email-fenghua.yu@intel.com>

From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>

The callback starts a child and puts the child pid in created
resctrl group with specified memory bandwidth in schemata. The child
starts running benchmark. Later the callback will be used by tests
to start the benchmark.

Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Arshiya Hayatkhan Pathan <arshiya.hayatkhan.pathan@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
 tools/testing/selftests/resctrl/resctrl.h     |  27 ++++
 tools/testing/selftests/resctrl/resctrl_val.c | 192 ++++++++++++++++++++++++++
 2 files changed, 219 insertions(+)
 create mode 100644 tools/testing/selftests/resctrl/resctrl_val.c

diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index 1da8f871a01a..ab65bdd0a96f 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -51,6 +51,32 @@
 		exit(EXIT_FAILURE);		\
 	} while (0)
 
+/*
+ * resctrl_val:		Functional validation of resctrl features
+ * @resctrl_val:	Resctrl feature (Eg: mbm, mba.. etc)
+ * @ctrlgrp:		Name of the control monitor group (con_mon grp)
+ * @mongrp:		Name of the monitor group (mon grp)
+ * @schemata:		Schemata while validating allocation type features
+ * @cpu_no:		CPU number to which the benchmark would be binded
+ * @mum_resctrlfs:	Should the resctrl FS be remounted?
+ * @num_of_runs:	Number of runs before exiting
+ * @filename:		Name of file to which the o/p should be written
+ * @bw_report:		Bandwidth report type (reads vs writes)
+ */
+struct resctrl_val_param {
+	char *resctrl_val;
+	char ctrlgrp[64];
+	char mongrp[64];
+	char *schemata;
+	int cpu_no;
+	int span;
+	int mum_resctrlfs;
+	int num_of_runs;
+	char filename[64];
+	char *bw_report;
+	char *bm_type;
+};
+
 pid_t bm_pid, ppid;
 int ben_count;
 
@@ -70,5 +96,6 @@ void write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
 int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
 		    int group_fd, unsigned long flags);
 int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op);
+void resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
 
 #endif /* RESCTRL_H */
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
new file mode 100644
index 000000000000..6d5f9e7f5421
--- /dev/null
+++ b/tools/testing/selftests/resctrl/resctrl_val.c
@@ -0,0 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Core controller to start benchmark and memory bandwidth tests
+ *
+ * Copyright (C) 2018 Intel Corporation
+ *
+ * Authors:
+ *    Arshiya Hayatkhan Pathan <arshiya.hayatkhan.pathan@intel.com>
+ *    Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
+ *    Fenghua Yu <fenghua.yu@intel.com>
+ */
+#include "resctrl_membw.h"
+#include "resctrl.h"
+
+pid_t bm_pid, ppid;
+
+static void print_results_bw(char *filename,  int bm_pid, float bw_imc,
+			     unsigned long long bw_resc)
+{
+	int diff = abs(bw_imc - bw_resc);
+	FILE *fp;
+
+	if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) {
+		printf("Pid: %d \t Mem_BW_iMC: %f \t ", bm_pid, bw_imc);
+		printf("Mem_BW_resc: %llu \t Difference: %d\n", bw_resc, diff);
+	} else {
+		fp = fopen(filename, "a");
+		if (!fp)
+			CHILD_EXIT("Cannot open file 'a'");
+		if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t ",
+			    bm_pid, bw_imc) <= 0 ||
+		    fprintf(fp, "Mem_BW_resc: %llu \t Difference: %d\n",
+			    bw_resc, diff) <= 0) {
+			fclose(fp);
+			CHILD_EXIT("Could not log results.");
+		}
+		fclose(fp);
+	}
+}
+
+void resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
+{
+	unsigned long long bw_resc, bw_resc_start, bw_resc_end;
+	char *resctrl_val = param->resctrl_val;
+	int runs_flag, count_of_run, sig;
+	struct sigaction sigact;
+	union sigval value;
+	float bw_imc;
+	FILE *fp;
+
+	bw_resc_start = 0, count_of_run = 0, sig = 0;
+
+	if (strcmp(param->filename, "") == 0)
+		sprintf(param->filename, "stdio");
+
+	if (strcmp(param->bw_report, "") == 0)
+		param->bw_report = "total";
+
+	if (param->num_of_runs > 0)
+		runs_flag = 1;
+	else
+		runs_flag = 0;
+
+	validate_resctrl_feature_request(resctrl_val);
+
+	if ((strcmp(resctrl_val, "mba")) == 0 ||
+	    (strcmp(resctrl_val, "mbm")) == 0)
+		validate_bw_report_request(param->bw_report);
+
+	if ((runs_flag) && (param->num_of_runs <= 0))
+		FPRINTF_EXIT("Num of runs should be a real no > 0\n");
+
+	remount_resctrlfs(param->mum_resctrlfs);
+
+	/*
+	 * If benchmark wasn't successfully started by child, then child should
+	 * kill parent, so save parent's pid
+	 */
+	ppid = getpid();
+
+	/* File based synchronization between parent and child */
+	fp = fopen("sig", "w");
+	if (!fp || (fprintf(fp, "%d\n", 0) <= 0) || (fclose(fp) == EOF))
+		PERR_EXIT("Unable to establish sync bw parent & child");
+
+	/*
+	 * Fork to start benchmark, save child's pid so that it can be killed
+	 * when needed
+	 */
+	bm_pid = fork();
+	if (bm_pid == -1)
+		PERR_EXIT("Unable to fork");
+
+	if (bm_pid == 0) {
+		/*
+		 * Mask all signals except SIGUSR1, parent uses SIGUSR1 to
+		 * start benchmark
+		 */
+		sigfillset(&sigact.sa_mask);
+		sigdelset(&sigact.sa_mask, SIGUSR1);
+
+		sigact.sa_sigaction = run_benchmark;
+		sigact.sa_flags = SA_SIGINFO;
+
+		/* Register for "SIGUSR1" signal from parent */
+		if (sigaction(SIGUSR1, &sigact, NULL))
+			PARENT_EXIT("Can't register child for signal");
+
+		/* Signal parent that child is ready */
+		fp = fopen("sig", "w");
+		if ((fp == NULL) || (fprintf(fp, "%d\n", 1) <= 0) ||
+		    (fclose(fp) == EOF))
+			PARENT_EXIT("can't signal that child is ready");
+
+		/* Suspend child until delivery of "SIGUSR1" from parent */
+		sigsuspend(&sigact.sa_mask);
+	}
+
+	printf("Benchmark PID: %d\n", bm_pid);
+
+	/*
+	 * Register CTRL-C handler for parent, as it has to kill benchmark
+	 * before exiting
+	 */
+	sigact.sa_sigaction = ctrlc_handler;
+	sigemptyset(&sigact.sa_mask);
+	sigact.sa_flags = SA_SIGINFO;
+	if (sigaction(SIGINT, &sigact, NULL) ||
+	    sigaction(SIGHUP, &sigact, NULL))
+		CHILD_EXIT("Can't register parent for CTRL-C handler");
+
+	value.sival_ptr = benchmark_cmd;
+
+	/* Taskset benchmark to specified cpu */
+	taskset_benchmark(bm_pid, param->cpu_no);
+
+	/* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/
+	write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp,
+				resctrl_val);
+
+	/* Write schemata to specified con_mon grp, mon_grp in resctrl FS */
+	write_schemata(param->ctrlgrp, param->schemata, param->cpu_no,
+		       resctrl_val);
+
+	if ((strcmp(resctrl_val, "mbm") == 0) ||
+	    (strcmp(resctrl_val, "mba") == 0)) {
+		initialize_mem_bw_imc();
+		initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp,
+					  param->cpu_no, resctrl_val);
+	}
+
+	/*
+	 * Parent should signal child to start executing benchmark only upon
+	 * receiving a signal from child saying that it's ready
+	 */
+	while (sig == 0) {
+		fp = fopen("sig", "r");
+		if (!fp)
+			CHILD_EXIT("Unable to open 'sig' file");
+		fscanf(fp, "%d\n", &sig);
+		if (fclose(fp) == EOF)
+			CHILD_EXIT("Unable to close 'sig' file");
+	}
+	if (system(RM_SIG_FILE) != 0)
+		perror("Unable to remove 'sig' file");
+
+	/* Signal child to start benchmark */
+	if (sigqueue(bm_pid, SIGUSR1, value) == -1)
+		CHILD_EXIT("Unable to signal child to start execution");
+
+	while (1) {
+		if (param->num_of_runs != -1 &&
+		    count_of_run >= param->num_of_runs) {
+			ctrlc_handler(0, NULL, NULL);
+			break;
+		}
+
+		if ((strcmp(resctrl_val, "mbm") == 0) ||
+		    (strcmp(resctrl_val, "mba") == 0)) {
+			bw_imc = get_mem_bw_imc(param->cpu_no,
+						param->bw_report);
+			bw_resc_end = get_mem_bw_resctrl();
+			bw_resc = (bw_resc_end - bw_resc_start) / MB;
+			print_results_bw(param->filename, bm_pid, bw_imc,
+					 bw_resc);
+			bw_resc_start = bw_resc_end;
+		}
+		count_of_run++;
+	}
+
+	exit(EXIT_SUCCESS);
+}
-- 
2.5.0


  parent reply	other threads:[~2018-10-16 17:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16 16:56 [PATCH 0/7] selftests/resctrl: Add resctrl selftest Fenghua Yu
2018-10-16 16:56 ` [PATCH 1/7] selftests/resctrl: Add basic resctrl file system operations and data Fenghua Yu
2018-10-16 16:56 ` [PATCH 2/7] selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system Fenghua Yu
2018-10-16 16:56 ` Fenghua Yu [this message]
2018-10-16 16:56 ` [PATCH 4/7] selftests/resctrl: Add built in benchmark Fenghua Yu
2018-10-16 16:56 ` [PATCH 5/7] selftests/resctrl: Add mbm test Fenghua Yu
2018-10-16 16:56 ` [PATCH 6/7] selftests/resctrl: Add mba test Fenghua Yu
2018-10-16 16:56 ` [PATCH 7/7] selftests/resctrl: Add the test in MAINTAINERS Fenghua Yu
2018-10-16 17:40 ` [PATCH 0/7] selftests/resctrl: Add resctrl selftest Moger, Babu
     [not found]   ` <FFF73D592F13FD46B8700F0A279B802F485D47DE@ORSMSX114.amr.corp.intel.com>
2018-10-16 20:32     ` Fenghua Yu
2018-10-17 14:40       ` Moger, Babu
2018-10-17 17:28         ` Prakhya, Sai Praneeth
2018-10-17 18:28           ` Moger, Babu
2018-10-17 18:31             ` Prakhya, Sai Praneeth
2018-10-17 18:03         ` Moger, Babu
2018-10-17 18:23           ` Moger, Babu
     [not found]           ` <CALBSrqBXdXfNdZ1yJ_-zUSkk_2m_8R-VHNqk8DH3HmxCti4hhA@mail.gmail.com>
2018-10-17 20:24             ` Fenghua Yu

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=1539709001-38018-4-git-send-email-fenghua.yu@intel.com \
    --to=fenghua.yu@intel.com \
    --cc=Babu.Moger@amd.com \
    --cc=arshiya.hayatkhan.pathan@intel.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=reinette.chatre@intel.com \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.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).