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 6/7] selftests/resctrl: Add mba test
Date: Tue, 16 Oct 2018 09:56:40 -0700 [thread overview]
Message-ID: <1539709001-38018-7-git-send-email-fenghua.yu@intel.com> (raw)
In-Reply-To: <1539709001-38018-1-git-send-email-fenghua.yu@intel.com>
From: Arshiya Hayatkhan Pathan <arshiya.hayatkhan.pathan@intel.com>
mba test starts a stressful memory bandwidth benchmark and allocates
memory bandwidth from 100% down to 10% for the benchmark process. For
each allocation, compare perf IMC counter and mbm total bytes from
resctrl. The difference between the two values should be within a
threshold to pass the test.
Default benchmark is built-in fill_buf. But users can specify their
own benchmark by option "-ben".
We can add memory bandwidth allocation for multiple processes in the
future.
Signed-off-by: Arshiya Hayatkhan Pathan <arshiya.hayatkhan.pathan@intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
tools/testing/selftests/resctrl/Makefile | 2 +-
tools/testing/selftests/resctrl/mba.c | 144 ++++++++++++++++++++++++
tools/testing/selftests/resctrl/resctrl.h | 3 +
tools/testing/selftests/resctrl/resctrl_tests.c | 10 ++
4 files changed, 158 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/resctrl/mba.c
diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile
index c5a69a2a5a6e..5ba73435b659 100644
--- a/tools/testing/selftests/resctrl/Makefile
+++ b/tools/testing/selftests/resctrl/Makefile
@@ -8,7 +8,7 @@ all: resctrl_tests
resctrl_tests: *.o
$(CC) $(CFLAGS) -o resctrl_tests resctrl_tests.o resctrl.o \
- resctrl_val.o resctrl_membw.o fill_buf.o mbm.o
+ resctrl_val.o resctrl_membw.o fill_buf.o mbm.o mba.o
.PHONY: clean
diff --git a/tools/testing/selftests/resctrl/mba.c b/tools/testing/selftests/resctrl/mba.c
new file mode 100644
index 000000000000..4a3f8b156657
--- /dev/null
+++ b/tools/testing/selftests/resctrl/mba.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Memory Bandwidth Allocation (MBA) test
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "resctrl.h"
+
+int mba_schemata_change(char *resctrl_val_type, int core_id, int span,
+ char *bw_report, char *bm_type,
+ char **benchmark_cmd)
+{
+ char *token_array[8], output[] = "result", *allocation_str, temp[512];
+ unsigned long long bw_imc[1024], bw_resc[1024];
+ struct resctrl_val_param param = {
+ .resctrl_val = resctrl_val_type,
+ .ctrlgrp = "c1",
+ .mongrp = "m1",
+ .cpu_no = core_id,
+ .mum_resctrlfs = 1,
+ .num_of_runs = -1,
+ .filename = "result",
+ .bw_report = bw_report,
+ .bm_type = bm_type
+ };
+ int allocation, x, failed, length;
+ pid_t bm_pid;
+ FILE *fp;
+
+ allocation = 100;
+ length = snprintf(NULL, 0, "%d", allocation);
+ allocation_str = malloc(length + 1);
+ snprintf(allocation_str, length + 1, "%d", allocation);
+ param.schemata = allocation_str;
+
+ bm_pid = fork();
+ printf("Bm_pid is : %d\n", bm_pid);
+
+ if (bm_pid == 0) {
+ resctrl_val(benchmark_cmd, ¶m);
+ PARENT_EXIT("Unable to run benchmark\n");
+ } else if (bm_pid < 0)
+ PERR_EXIT("Failed to fork\n");
+ else {
+ sleep(1);
+ /*
+ * Change schemata percentage from 100 to 10%
+ * Write schemata to specified con_mon grp, mon_grp in
+ * resctrl FS
+ */
+ for (int i = 0; i < 10; i++) {
+ allocation = 100 - 10*i;
+
+ if (strcmp(resctrl_val_type, "mba") == 0) {
+ length = snprintf(NULL, 0, "%d",
+ allocation);
+ allocation_str = malloc(length + 1);
+ snprintf(allocation_str, length + 1,
+ "%d", allocation);
+ write_schemata("c1", allocation_str,
+ core_id, resctrl_val_type);
+ printf("changed schemata to : %d\n",
+ allocation);
+ }
+ sleep(5);
+ }
+ free(allocation_str);
+ kill(bm_pid, SIGINT);
+ }
+
+ printf("\nchecking for pass/fail\n");
+ fp = fopen(output, "r");
+ if (fp == NULL)
+ PERR_EXIT("Error in opening file\n");
+
+ x = 0;
+ while (fgets(temp, 1024, fp) != NULL) {
+ int i = 0;
+ char *token = strtok(temp, ":\t");
+
+ while (token != NULL) {
+ token_array[i++] = token;
+ token = strtok(NULL, ":\t");
+ }
+
+ bw_resc[x] = atoll(token_array[5]);
+ bw_imc[x] = atoll(token_array[3]);
+ x++;
+ }
+
+ if (fclose(fp) == EOF)
+ PERR_EXIT("Error in closing file\n");
+
+ failed = 0;
+ /* Memory bandwidth from 100% down to 10% */
+ for (int i = 0; i < 10; i++) {
+ float avg_bw_imc = 0.0, avg_bw_resc = 0.0;
+ int sum_bw_imc = 0, sum_bw_resc = 0;
+ float avg_diff = 0.0;
+
+ for (int j = 5 * i + 1; j < 5*i+5 ; j++) {
+ sum_bw_imc += bw_imc[j];
+ sum_bw_resc += bw_resc[j];
+ }
+
+ avg_bw_imc = sum_bw_imc / 4.0;
+ avg_bw_resc = sum_bw_resc / 4.0;
+ avg_diff = avg_bw_resc - avg_bw_imc;
+
+ printf("\nschemata percentage: %d \t", 100 - 10 * i);
+ printf("avg_bw_imc: %.2f\t", avg_bw_imc);
+ printf("avg_bw_resc: %.2f\t", avg_bw_resc);
+ printf("avg_diff: %d \t", abs(avg_diff));
+ if (abs(avg_diff) > 300) {
+ printf("failed\n");
+ failed = 1;
+ } else
+ printf("passed\n");
+ }
+
+ if (failed) {
+ printf("\nTest for schemata change using MBA failed");
+ printf("as atleast one test failed!\n");
+ } else
+ printf("\nTests for changing schemata using MBA passed!\n\n");
+
+ if (remove(output))
+ printf("Unable to delete the file\n");
+
+ return 0;
+}
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index 349abf0502f5..41dc4b172672 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -100,5 +100,8 @@ void resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
int mbm_bw_change(char *resctrl_val_type, int core_id, int span,
char *bw_report, char *bm_type, char **benchmark_cmd);
+int mba_schemata_change(char *resctrl_val_type, int core_id, int span,
+ char *bw_report, char *bm_type,
+ char **benchmark_cmd);
#endif /* RESCTRL_H */
diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index b9d1665bb101..93d25355cee4 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -90,5 +90,15 @@ int main(int argc, char **argv)
if (res)
printf("Error in running tests for mbm bw change!\n");
+ printf("\nTest 2: MBA Schemata Change Starting..\n");
+ if (!has_ben) {
+ span = 250;
+ sprintf(benchmark_cmd[1], "%d", span);
+ }
+ res = mba_schemata_change("mba", core_id, span, bw_report,
+ bm_type, benchmark_cmd);
+ if (res)
+ printf("Error in running tests for mba-change-schemata!\n");
+
return 0;
}
--
2.5.0
next prev 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 ` [PATCH 3/7] selftests/resctrl: Add callback to start a benchmark Fenghua Yu
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 ` Fenghua Yu [this message]
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-7-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).