~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/resctrl/mbm_test.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Memory Bandwidth Monitoring (MBM) test
  4  *
  5  * Copyright (C) 2018 Intel Corporation
  6  *
  7  * Authors:
  8  *    Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
  9  *    Fenghua Yu <fenghua.yu@intel.com>
 10  */
 11 #include "resctrl.h"
 12 
 13 #define RESULT_FILE_NAME        "result_mbm"
 14 #define MAX_DIFF_PERCENT        8
 15 #define NUM_OF_RUNS             5
 16 
 17 static int
 18 show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, size_t span)
 19 {
 20         unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
 21         long avg_bw_imc = 0, avg_bw_resc = 0;
 22         int runs, ret, avg_diff_per;
 23         float avg_diff = 0;
 24 
 25         /*
 26          * Discard the first value which is inaccurate due to monitoring setup
 27          * transition phase.
 28          */
 29         for (runs = 1; runs < NUM_OF_RUNS ; runs++) {
 30                 sum_bw_imc += bw_imc[runs];
 31                 sum_bw_resc += bw_resc[runs];
 32         }
 33 
 34         avg_bw_imc = sum_bw_imc / 4;
 35         avg_bw_resc = sum_bw_resc / 4;
 36         avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc;
 37         avg_diff_per = (int)(avg_diff * 100);
 38 
 39         ret = avg_diff_per > MAX_DIFF_PERCENT;
 40         ksft_print_msg("%s Check MBM diff within %d%%\n",
 41                        ret ? "Fail:" : "Pass:", MAX_DIFF_PERCENT);
 42         ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per);
 43         ksft_print_msg("Span (MB): %zu\n", span / MB);
 44         ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc);
 45         ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc);
 46 
 47         return ret;
 48 }
 49 
 50 static int check_results(size_t span)
 51 {
 52         unsigned long bw_imc[NUM_OF_RUNS], bw_resc[NUM_OF_RUNS];
 53         char temp[1024], *token_array[8];
 54         char output[] = RESULT_FILE_NAME;
 55         int runs, ret;
 56         FILE *fp;
 57 
 58         ksft_print_msg("Checking for pass/fail\n");
 59 
 60         fp = fopen(output, "r");
 61         if (!fp) {
 62                 ksft_perror(output);
 63 
 64                 return -1;
 65         }
 66 
 67         runs = 0;
 68         while (fgets(temp, sizeof(temp), fp)) {
 69                 char *token = strtok(temp, ":\t");
 70                 int i = 0;
 71 
 72                 while (token) {
 73                         token_array[i++] = token;
 74                         token = strtok(NULL, ":\t");
 75                 }
 76 
 77                 bw_resc[runs] = strtoul(token_array[5], NULL, 0);
 78                 bw_imc[runs] = strtoul(token_array[3], NULL, 0);
 79                 runs++;
 80         }
 81 
 82         ret = show_bw_info(bw_imc, bw_resc, span);
 83 
 84         fclose(fp);
 85 
 86         return ret;
 87 }
 88 
 89 static int mbm_init(const struct resctrl_val_param *param, int domain_id)
 90 {
 91         int ret;
 92 
 93         ret = initialize_mem_bw_imc();
 94         if (ret)
 95                 return ret;
 96 
 97         initialize_mem_bw_resctrl(param, domain_id);
 98 
 99         return 0;
100 }
101 
102 static int mbm_setup(const struct resctrl_test *test,
103                      const struct user_params *uparams,
104                      struct resctrl_val_param *p)
105 {
106         int ret = 0;
107 
108         /* Run NUM_OF_RUNS times */
109         if (p->num_of_runs >= NUM_OF_RUNS)
110                 return END_OF_TESTS;
111 
112         /* Set up shemata with 100% allocation on the first run. */
113         if (p->num_of_runs == 0 && resctrl_resource_exists("MB"))
114                 ret = write_schemata(p->ctrlgrp, "100", uparams->cpu, test->resource);
115 
116         p->num_of_runs++;
117 
118         return ret;
119 }
120 
121 static int mbm_measure(const struct user_params *uparams,
122                        struct resctrl_val_param *param, pid_t bm_pid)
123 {
124         return measure_mem_bw(uparams, param, bm_pid, "reads");
125 }
126 
127 static void mbm_test_cleanup(void)
128 {
129         remove(RESULT_FILE_NAME);
130 }
131 
132 static int mbm_run_test(const struct resctrl_test *test, const struct user_params *uparams)
133 {
134         struct resctrl_val_param param = {
135                 .ctrlgrp        = "c1",
136                 .filename       = RESULT_FILE_NAME,
137                 .init           = mbm_init,
138                 .setup          = mbm_setup,
139                 .measure        = mbm_measure,
140         };
141         int ret;
142 
143         remove(RESULT_FILE_NAME);
144 
145         ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
146         if (ret)
147                 return ret;
148 
149         ret = check_results(DEFAULT_SPAN);
150         if (ret && (get_vendor() == ARCH_INTEL))
151                 ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
152 
153         return ret;
154 }
155 
156 static bool mbm_feature_check(const struct resctrl_test *test)
157 {
158         return resctrl_mon_feature_exists("L3_MON", "mbm_total_bytes") &&
159                resctrl_mon_feature_exists("L3_MON", "mbm_local_bytes");
160 }
161 
162 struct resctrl_test mbm_test = {
163         .name = "MBM",
164         .resource = "MB",
165         .vendor_specific = ARCH_INTEL,
166         .feature_check = mbm_feature_check,
167         .run_test = mbm_run_test,
168         .cleanup = mbm_test_cleanup,
169 };
170 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php