Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5424336imm; Tue, 16 Oct 2018 10:02:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV62RmFZkclknWm1NU5/2obuVjxC1uRmqw5MUUjKvwbH9L3E6n/963xnX+8Y+XAWFSlrIU/Aq X-Received: by 2002:a62:4799:: with SMTP id p25-v6mr22808493pfi.197.1539709325854; Tue, 16 Oct 2018 10:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539709325; cv=none; d=google.com; s=arc-20160816; b=ma+t+k+YyjjjKSnhEdxWQSNCre0HaWmOr8tIpxHOZL1MsnRVQI+Mm8pc8TwwyS6Rbx /5Ee0Qo0gB/vTfSp5aa826/iItyZRyDZyadPlCi6qbwKFJ/ixuSR/9RXGE1J/CuPvVya CJ1HwGZcjWJ6L38SVnfRiprdhMvykLOl/ECfocdFe+WeW+nJY8c1C2vrjvFGEJQuuoK0 C63IafKA0gQewiwBFw0tI723ehtnjyjjRyo1f7S0Xcsqv0sWd92uzlTBey7J1bw0HVaW D3P7mmAV3JJjssJcdZovj9iYpT6thB6ujGPLkpfnN9W9Cj+MDhFMtQSF58TpqeF99gKP Hxcg== 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=U9SidrsHMo0p8bm5QS7Qb7MMRcVzFBmQ4fPWpOuS1i4=; b=R3Q1tAKLxk/tLFTexLlAxaVORQHf9EKQyApJqcYfMAqCH5wU6ZvLmYQz1zNKEdRhTz MH3jlGv/gVfx4UwwT9f2vKLlPAuhoR5FcErZR8/gqrTA98KybExGZ1Ezq04pxJ7OClLQ jzcwOwGK8DhtNCjnV4/J2IqGgaI6KjdffoMbGymFWPCn6z/EoYSn4mgKYTOreSeQUcX1 Wp0AdzEYtfaRktQ7V0yfukXeHTZ38GkZJYfJS+IbcqxxnbaCvQ9yEaxibxi8FtX+z+wG EUD5o6QHEp53AjrclngVoVfRfrY8pmVNBec+/WetRWMLR3pXlGXLtW/NLFVMKrYhTEw+ mksg== 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 d9-v6si14479404pll.414.2018.10.16.10.01.50; Tue, 16 Oct 2018 10:02:05 -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 S1727628AbeJQAwT (ORCPT + 99 others); Tue, 16 Oct 2018 20:52:19 -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 S1727160AbeJQAwS (ORCPT ); Tue, 16 Oct 2018 20:52:18 -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:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,389,1534834800"; d="scan'208";a="100736205" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga002.jf.intel.com with ESMTP; 16 Oct 2018 10:00:57 -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 6/7] selftests/resctrl: Add mba test Date: Tue, 16 Oct 2018 09:56:40 -0700 Message-Id: <1539709001-38018-7-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 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 Signed-off-by: Sai Praneeth Prakhya , Signed-off-by: Fenghua Yu --- 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 + * Sai Praneeth Prakhya , + * Fenghua Yu + */ + +#include +#include +#include +#include +#include +#include + +#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