Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5423979imm; Tue, 16 Oct 2018 10:01:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV618qvhEQdxlCAXBQ5K3GhrTvne/xAx70ptr7ZAMWppJ4Iz5HKP6I6X886nSZaGiCAYK6tTf X-Received: by 2002:a63:bc12:: with SMTP id q18-v6mr20158092pge.353.1539709309755; Tue, 16 Oct 2018 10:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539709309; cv=none; d=google.com; s=arc-20160816; b=de1y9GcmzrtG6RlSNx3jS7SP9t7+q+IFt6ep9oeHWqsV0HmoNerkSyewN+CTkdR48r zYFILsUupK5SJj7ZW/0H6lYe6Oc5unxgvfsEChEjcZvVgWiaj3KEZDYXM4GjQ9/EdBnB 3AVoldmYOTL2FR6V7Umrrd/xx9hYJF7fK7oJe6H1yxYRsJwd+K7yJqS0slT7h12kyb0j hAUNcEvxbxNb0o9fkk6F0sNfJnasZgIBpvaw6b/ePzAUBJW0yFvpXNiD3C2XCn+JGvdz V3hawp+yOzhM3Rt1mhvPSooHiFEoDmSf/dncyY74H9ZkJBawHqHeVAMkT7uWj1IAzheI iMbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KZRrLQAodqyuXmXsRklNqR5zdD4eQ72xhLU5Fy+Zlro=; b=lj0CfQ5slYPhQ0W/hqkq8pHAuEC6ntnikPYlj5/j/nlNtewY+tYBuizdJ5gLocA57R P1UspRxkNr8RCqLIOpluE4uurxDoCRY4zQJLJxhs/D4GgqEEKVRulnaGO9UoBMr9abPh fffYxEsqW6kfGP7UHrCQpQ6CPtX8B3R5Vs9egjz60SZES8vZWVJBThQZBXWlWkKPwXB8 +muWFCQ7XHt9OnvE2KYHzM8CElOTr8/WnYwDC1Z33QBAX6miMjnBL8XQUCbEe12rNVrL t84BF98h17p2kWVHc1paJYW7S8hSlHdEvRJUsZ+nGEbQ/kOY3ASABHdAySubxkNd0Mwe VmLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2-v6si14723428pgl.21.2018.10.16.10.01.32; Tue, 16 Oct 2018 10:01:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727680AbeJQAwU (ORCPT + 99 others); Tue, 16 Oct 2018 20:52:20 -0400 Received: from mga17.intel.com ([192.55.52.151]:15647 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727601AbeJQAwR (ORCPT ); Tue, 16 Oct 2018 20:52:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 10:00:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,389,1534834800"; d="scan'208";a="100736201" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga002.jf.intel.com with ESMTP; 16 Oct 2018 10:00:56 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "H Peter Anvin" , "Tony Luck" , "Reinette Chatre" , "Peter Zijlstra" , "Moger, Babu" , "James Morse" , "Sai Praneeth Prakhya" , "Arshiya Hayatkhan Pathan" , "Ravi V Shankar" Cc: "linux-kernel" , Fenghua Yu Subject: [PATCH 5/7] selftests/resctrl: Add mbm test Date: Tue, 16 Oct 2018 09:56:39 -0700 Message-Id: <1539709001-38018-6-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1539709001-38018-1-git-send-email-fenghua.yu@intel.com> References: <1539709001-38018-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arshiya Hayatkhan Pathan mbm test is the first implemented selftest. It starts a stressful memory bandwidth benchmark and assigns the bandwidth pid in a resctrl monitoring group. Read and compare perf IMC counter and mbm total bytes for the benchmark. The numbers should be close enough 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 monitoring for multiple processes in the future. Signed-off-by: Arshiya Hayatkhan Pathan Signed-off-by: Sai Praneeth Prakhya , Signed-off-by: Fenghua Yu --- tools/testing/selftests/resctrl/Makefile | 8 +- tools/testing/selftests/resctrl/mbm.c | 113 ++++++++++++++++++++++++ tools/testing/selftests/resctrl/resctrl.h | 3 + tools/testing/selftests/resctrl/resctrl_tests.c | 94 ++++++++++++++++++++ 4 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/resctrl/mbm.c create mode 100644 tools/testing/selftests/resctrl/resctrl_tests.c diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile index bd5c5418961e..c5a69a2a5a6e 100644 --- a/tools/testing/selftests/resctrl/Makefile +++ b/tools/testing/selftests/resctrl/Makefile @@ -1,10 +1,16 @@ CC = gcc CFLAGS = -g -Wall +all: resctrl_tests + *.o: *.c $(CC) $(CFLAGS) -c *.c +resctrl_tests: *.o + $(CC) $(CFLAGS) -o resctrl_tests resctrl_tests.o resctrl.o \ + resctrl_val.o resctrl_membw.o fill_buf.o mbm.o + .PHONY: clean clean: - $(RM) *.o *~ + $(RM) *.o *~ resctrl_tests diff --git a/tools/testing/selftests/resctrl/mbm.c b/tools/testing/selftests/resctrl/mbm.c new file mode 100644 index 000000000000..9edf9bd58bf5 --- /dev/null +++ b/tools/testing/selftests/resctrl/mbm.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Memory Bandwidth Monitoring (MBM) test + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ + +#include +#include +#include +#include +#include +#include +#include "resctrl.h" + + +static void +show_bw_info(unsigned long long *bw_imc, unsigned long long *bw_resc, int span) +{ + float avg_bw_imc = 0.0, avg_bw_resc = 0.0, avg_diff = 0.0; + int i, sum_bw_imc = 0, sum_bw_resc = 0; + + for (i = 1; i < 5 ; i++) { + sum_bw_imc += bw_imc[i]; + sum_bw_resc += bw_resc[i]; + } + + 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("\n Span (MB): %d \t", span); + 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"); + else + printf(" passed\n"); +} + +int mbm_bw_change(char *resctrl_val_type, int core_id, int span, + char *bw_report, char *bm_type, char **benchmark_cmd) +{ + char temp[512], *token_array[8], *allocation_str; + 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 = 5, + .filename = "result1", + .bw_report = bw_report, + .bm_type = bm_type + }; + int allocation, x, length, status; + char *output = "result1"; + 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(); + + 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"); + + waitpid(bm_pid, &status, 0); + + printf("\n Checking 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) { + char *token = strtok(temp, ":\t"); + int i = 0; + + 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++; + } + + show_bw_info(bw_imc, bw_resc, span); + + fclose(fp); + 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 ab65bdd0a96f..349abf0502f5 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -98,4 +98,7 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, 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); +int mbm_bw_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 new file mode 100644 index 000000000000..b9d1665bb101 --- /dev/null +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Resctrl tests + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ +#include "resctrl.h" + +int ben_count; + +int main(int argc, char **argv) +{ + int res, c, ben_ind, core_id, span, argc_new, has_ben; + char *bw_report = NULL, *bm_type = NULL; + char **benchmark_cmd = NULL; + + ben_ind = 0, core_id = 0, span = 250, argc_new = argc; + has_ben = 0; + + /* + * We need root privileges to run because + * 1. We write to resctrl FS + * 2. We execute perf commands + */ + if (geteuid() != 0) + FPRINTF_EXIT("Please run this program as root\n"); + + /* + * Extract benchmark command from command line. + */ + for (int i = 0; i < argc; i++) { + if (strcmp(argv[i], "-ben") == 0) { + ben_ind = i + 1; + printf("ben_id:%d\n", ben_ind); + ben_count = argc - ben_ind; + argc_new = ben_ind - 1; + has_ben = 1; + break; + } + } + + while ((c = getopt(argc_new, argv, "p:s:")) != -1) { + switch (c) { + case 'p': + core_id = atoi(optarg); + break; + case 's': + span = atoi(optarg); + break; + } + } + + benchmark_cmd = malloc(10 * sizeof(char *)); + if (!benchmark_cmd) + return -1; + + if (has_ben) { + for (int i = ben_ind; i < argc; i++) { + benchmark_cmd[i - ben_ind] = malloc(1024 * + sizeof(char)); + if (benchmark_cmd[i - ben_ind] == NULL) + return -1; + sprintf(benchmark_cmd[i - ben_ind], "%s", + argv[i]); + } + } else { + for (int i = 0; i < 5; i++) { + benchmark_cmd[i] = malloc(1024 * sizeof(char)); + if (benchmark_cmd[i] == NULL) + return -1; + } + strcpy(benchmark_cmd[0], "fill_buf"); + sprintf(benchmark_cmd[1], "%d", span); + strcpy(benchmark_cmd[2], "1"); + strcpy(benchmark_cmd[3], "1"); + strcpy(benchmark_cmd[4], "0"); + } + + bw_report = "reads"; + bm_type = "fill_buf"; + + printf("\nTest 1 : MBM BW Change Starting..\n"); + res = mbm_bw_change("mbm", core_id, span, bw_report, bm_type, + benchmark_cmd); + if (res) + printf("Error in running tests for mbm bw change!\n"); + + return 0; +} -- 2.5.0