RE: [PATCH v4 08/10] selftests/resctrl Add Cache QoS Monitoring (CQM) selftest

2019-01-02 Thread Yu, Fenghua
> From: Moger, Babu [mailto:babu.mo...@amd.com]
>   for (int i = 0; i < argc; i++) {
>^
> resctrl_tests.c:39:56: note: previous declaration of 'i' was here
>   int res, c, core_id = 1, span = 250, argc_new = argc, i, no_of_bits = 5;
> ^
> resctrl_tests.c:46:2: error: 'for' loop initial declarations are only allowed 
> in
> C99 mode
>   for (int i = 0; i < argc; i++) {
>   ^
> resctrl_tests.c:46:2: note: use option -std=c99 or -std=gnu99 to compile your
> code

Sure. Will fix this.

Thanks.

-Fenghua


RE: [PATCH v4 08/10] selftests/resctrl Add Cache QoS Monitoring (CQM) selftest

2019-01-02 Thread Moger, Babu
Fenghua, Sai,

Couple of problems with these patches(see below).  Please check again.

> -Original Message-
> From: Fenghua Yu 
> Sent: Friday, December 21, 2018 6:21 PM
> To: Thomas Gleixner ; Ingo Molnar
> ; H Peter Anvin ; Tony Luck
> ; Peter Zijlstra ; Reinette
> Chatre ; Moger, Babu
> ; James Morse ;
> Xiaochen Shen ; Ravi V Shankar
> ; Sai Praneeth Prakhya
> ; Arshiya Hayatkhan Pathan
> 
> Cc: linux-kernel ; Fenghua Yu
> 
> Subject: [PATCH v4 08/10] selftests/resctrl Add Cache QoS Monitoring (CQM)
> selftest
> 
> From: Arshiya Hayatkhan Pathan 
> 
> Cache QoS Monitoring (CQM) selftest starts stressful cache benchmark
> with specified size of memory to access the cache. Last Level cache
> occupancy reported by CQM should be close to the size of the memory.
> 
> Signed-off-by: Arshiya Hayatkhan Pathan
> 
> Signed-off-by: Sai Praneeth Prakhya 
> Signed-off-by: Fenghua Yu 
> ---
>  tools/testing/selftests/resctrl/Makefile  |   2 +-
>  tools/testing/selftests/resctrl/cache.c   | 102 
>  tools/testing/selftests/resctrl/cqm_test.c| 169 +
>  tools/testing/selftests/resctrl/fill_buf.c| 107 
>  tools/testing/selftests/resctrl/mba_test.c|   3 +-
>  tools/testing/selftests/resctrl/mbm_test.c|   3 +-
>  tools/testing/selftests/resctrl/resctrl.h |  30 ++-
>  .../testing/selftests/resctrl/resctrl_tests.c |  82 +--
>  tools/testing/selftests/resctrl/resctrl_val.c | 106 
>  tools/testing/selftests/resctrl/resctrlfs.c   | 231 --
>  10 files changed, 691 insertions(+), 144 deletions(-)
>  create mode 100644 tools/testing/selftests/resctrl/cache.c
>  create mode 100644 tools/testing/selftests/resctrl/cqm_test.c
> 
> diff --git a/tools/testing/selftests/resctrl/Makefile
> b/tools/testing/selftests/resctrl/Makefile
> index bf9f55e71d0c..664561cd76e6 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 resctrlfs.o \
> -  membw.o fill_buf.o mbm_test.o mba_test.o
> +  resctrl_val.o fill_buf.o mbm_test.o mba_test.o cache.o
> cqm_test.o
> 
>  .PHONY: clean
> 
> diff --git a/tools/testing/selftests/resctrl/cache.c
> b/tools/testing/selftests/resctrl/cache.c
> new file mode 100644
> index ..1256590ef804
> --- /dev/null
> +++ b/tools/testing/selftests/resctrl/cache.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include 
> +#include "resctrl.h"
> +
> +struct read_format {
> + __u64 nr;   /* The number of events */
> + struct {
> + __u64 value;/* The value of the event */
> + } values[2];
> +};
> +
> +char cbm_mask[256];
> +unsigned long long_mask;
> +char llc_occup_path[1024];
> +
> +/*
> + * Get LLC Occupancy as reported by RESCTRL FS
> + * For CQM,
> + * 1. If con_mon grp and mon grp given, then read from mon grp in
> + * con_mon grp
> + * 2. If only con_mon grp given, then read from con_mon grp
> + * 3. If both not given, then read from root con_mon grp
> + * For CAT,
> + * 1. If con_mon grp given, then read from it
> + * 2. If con_mon grp not given, then read from root con_mon grp
> + *
> + * Return: =0 on success.  <0 on failure.
> + */
> +static int get_llc_occu_resctrl(unsigned long *llc_occupancy)
> +{
> + FILE *fp;
> +
> + fp = fopen(llc_occup_path, "r");
> + if (!fp) {
> + perror("Failed to open results file");
> +
> + return errno;
> + }
> + if (fscanf(fp, "%lu", llc_occupancy) <= 0) {
> + perror("Could not get llc occupancy");
> + fclose(fp);
> +
> + return -1;
> + }
> + fclose(fp);
> +
> + return 0;
> +}
> +
> +/*
> + * print_results_cache:  the cache results are stored in a file
> + * @filename:file that stores the results
> + * @bm_pid:  child pid that runs benchmark
> + * @llc_value:   perf miss value /
> + *   llc occupancy value reported by resctrl FS
> + *
> + * Return:   0 on success. non-zero on failure.
> + */
> +static int print_results_cache(char *filename, int bm_pid,
> +unsigned long llc_value)
> +{
> + FILE *fp;
> +
> + if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0)
> {
> + printf("Pid: %d \t LLC_value: %lu\n", bm_pid,
>

[PATCH v4 08/10] selftests/resctrl Add Cache QoS Monitoring (CQM) selftest

2018-12-21 Thread Fenghua Yu
From: Arshiya Hayatkhan Pathan 

Cache QoS Monitoring (CQM) selftest starts stressful cache benchmark
with specified size of memory to access the cache. Last Level cache
occupancy reported by CQM should be close to the size of the memory.

Signed-off-by: Arshiya Hayatkhan Pathan 
Signed-off-by: Sai Praneeth Prakhya 
Signed-off-by: Fenghua Yu 
---
 tools/testing/selftests/resctrl/Makefile  |   2 +-
 tools/testing/selftests/resctrl/cache.c   | 102 
 tools/testing/selftests/resctrl/cqm_test.c| 169 +
 tools/testing/selftests/resctrl/fill_buf.c| 107 
 tools/testing/selftests/resctrl/mba_test.c|   3 +-
 tools/testing/selftests/resctrl/mbm_test.c|   3 +-
 tools/testing/selftests/resctrl/resctrl.h |  30 ++-
 .../testing/selftests/resctrl/resctrl_tests.c |  82 +--
 tools/testing/selftests/resctrl/resctrl_val.c | 106 
 tools/testing/selftests/resctrl/resctrlfs.c   | 231 --
 10 files changed, 691 insertions(+), 144 deletions(-)
 create mode 100644 tools/testing/selftests/resctrl/cache.c
 create mode 100644 tools/testing/selftests/resctrl/cqm_test.c

diff --git a/tools/testing/selftests/resctrl/Makefile 
b/tools/testing/selftests/resctrl/Makefile
index bf9f55e71d0c..664561cd76e6 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 resctrlfs.o \
-membw.o fill_buf.o mbm_test.o mba_test.o
+resctrl_val.o fill_buf.o mbm_test.o mba_test.o cache.o 
cqm_test.o
 
 .PHONY: clean
 
diff --git a/tools/testing/selftests/resctrl/cache.c 
b/tools/testing/selftests/resctrl/cache.c
new file mode 100644
index ..1256590ef804
--- /dev/null
+++ b/tools/testing/selftests/resctrl/cache.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include "resctrl.h"
+
+struct read_format {
+   __u64 nr;   /* The number of events */
+   struct {
+   __u64 value;/* The value of the event */
+   } values[2];
+};
+
+char cbm_mask[256];
+unsigned long long_mask;
+char llc_occup_path[1024];
+
+/*
+ * Get LLC Occupancy as reported by RESCTRL FS
+ * For CQM,
+ * 1. If con_mon grp and mon grp given, then read from mon grp in
+ * con_mon grp
+ * 2. If only con_mon grp given, then read from con_mon grp
+ * 3. If both not given, then read from root con_mon grp
+ * For CAT,
+ * 1. If con_mon grp given, then read from it
+ * 2. If con_mon grp not given, then read from root con_mon grp
+ *
+ * Return: =0 on success.  <0 on failure.
+ */
+static int get_llc_occu_resctrl(unsigned long *llc_occupancy)
+{
+   FILE *fp;
+
+   fp = fopen(llc_occup_path, "r");
+   if (!fp) {
+   perror("Failed to open results file");
+
+   return errno;
+   }
+   if (fscanf(fp, "%lu", llc_occupancy) <= 0) {
+   perror("Could not get llc occupancy");
+   fclose(fp);
+
+   return -1;
+   }
+   fclose(fp);
+
+   return 0;
+}
+
+/*
+ * print_results_cache:the cache results are stored in a file
+ * @filename:  file that stores the results
+ * @bm_pid:child pid that runs benchmark
+ * @llc_value: perf miss value /
+ * llc occupancy value reported by resctrl FS
+ *
+ * Return: 0 on success. non-zero on failure.
+ */
+static int print_results_cache(char *filename, int bm_pid,
+  unsigned long llc_value)
+{
+   FILE *fp;
+
+   if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) {
+   printf("Pid: %d \t LLC_value: %lu\n", bm_pid,
+  llc_value);
+   } else {
+   fp = fopen(filename, "a");
+   if (!fp) {
+   perror("Cannot open results file");
+
+   return errno;
+   }
+   fprintf(fp, "Pid: %d \t llc_value: %lu\n", bm_pid,
+   llc_value);
+   fclose(fp);
+   }
+
+   return 0;
+}
+
+int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
+{
+   unsigned long llc_occu_resc = 0, llc_value = 0;
+   int ret;
+
+   /*
+* Measure llc occupancy from resctrl.
+*/
+   if (!strcmp(param->resctrl_val, "cqm")) {
+   ret = get_llc_occu_resctrl(_occu_resc);
+   if (ret < 0)
+   return ret;
+   llc_value = llc_occu_resc;
+   }
+   ret = print_results_cache(param->filename, bm_pid, llc_value);
+   if (ret)
+   return ret;
+
+   return 0;
+}
diff --git a/tools/testing/selftests/resctrl/cqm_test.c 
b/tools/testing/selftests/resctrl/cqm_test.c
new file mode 100644
index ..cddee364c88a
--- /dev/null
+++ b/tools/testing/selftests/resctrl/cqm_test.c
@@