From patchwork Fri Jan 18 18:27:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BD3E139A for ; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A38929C19 for ; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E76A29C41; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9EA429BFC for ; Fri, 18 Jan 2019 18:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729252AbfARS2R (ORCPT ); Fri, 18 Jan 2019 13:28:17 -0500 Received: from mail-eopbgr680080.outbound.protection.outlook.com ([40.107.68.80]:40721 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728704AbfARS1M (ORCPT ); Fri, 18 Jan 2019 13:27:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bAS6+v81Ry2N987NykGdDPIwB+uYE7At/woMuHPqDyk=; b=zFKf6XpYdDofrVk2Rbj6i+zMLmabIPd+0zTnMTGjgjVhqFKugJKOjo6w6bjRCSI4Ryr6hE7tX1atDFHPWMWoEKxN0xDsELXw2SB/N2FFS/85qc5fLa2UtWZET9GEQagrVdpm+ia9dvgHv8O4aJeIhvaFNAc+poBeYdiG6JnO6kk= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1276.namprd12.prod.outlook.com (10.168.237.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:02 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:02 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 01/13] selftests/resctrl: Add README for resctrl tests Thread-Topic: [PATCH v5 01/13] selftests/resctrl: Add README for resctrl tests Thread-Index: AQHUr1toReNS/q/OK0qxlHYs77jZAQ== Date: Fri, 18 Jan 2019 18:27:02 +0000 Message-ID: <20190118182646.16594-2-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1276;20:cxAi8h319b5RgSqbwNib4QMWlnyVtmxS53ZmyxDhAd9UjP+J3pRk/rSRXkBH8NbJhdr2Fx5jQvTwm3bgowFajYJhOPpTzldudifwMzmcZUIAAatWVqIYAMHF12G63TCFQufvEWJ4CD43UiC2cHAMciNoau74mFhHkuj2xufvUM/9FRVum5jSSMB4W9oVWUqwaSaZoXVxxXuVqRiov8+//ayoMofabn9NpBE8udLJbLrZW9R3UBLMVF9P9l1V77kj x-ms-office365-filtering-correlation-id: 8b4a7ac8-ce81-4028-085d-08d67d728a97 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1276; x-ms-traffictypediagnostic: DM5PR12MB1276: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(376002)(346002)(366004)(396003)(39860400002)(199004)(189003)(14444005)(305945005)(3846002)(53936002)(6512007)(54906003)(110136005)(4326008)(99286004)(102836004)(6486002)(8676002)(25786009)(476003)(7736002)(316002)(6436002)(2616005)(446003)(11346002)(106356001)(486006)(386003)(68736007)(186003)(2906002)(50226002)(76176011)(81156014)(81166006)(52116002)(26005)(71200400001)(6506007)(97736004)(478600001)(8936002)(2501003)(71190400001)(72206003)(1076003)(256004)(66066001)(7416002)(2201001)(105586002)(36756003)(86362001)(6116002)(14454004)(5660300001)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1276;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: UXXe2RcgYyy+PDeoIxNhE0a0eydsV93PQ+037O7iviIjOxzkXFDR6xuIA679PKRctSV30S6wYApBe4S26uR03Ap0hJZLa5Ut59jErALXl4IpIENG337N/C1aXsDuJ7FNvOvpzWYbiqZgrboSMgDR99bwn5NCs79sn3tB/E33yQNEX8uYZl9IlSpqJd5JigDUK6m61aNkUQWz0O46IX2EtGY4zFzcHD1bcaWz4AUO+ZiVTDSjl48IR3W+vtXlB5eKcglcfaBCQgJ8eKkb15tM45P+qNgIelLdyLrCTbPkgI6L6BCsJOk/M6tNh6pEQZAw8CqYWQcnNBuaAKwJrmxEg2x3cYewhdcWPr8GNqEwe6y5T/x4B/vxGU5ohIYnhYGqET8S2kJIak20PA/SmI7gT5MdsbVZ8mirtcu+kil8vDQ= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b4a7ac8-ce81-4028-085d-08d67d728a97 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:01.6276 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1276 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fenghua Yu resctrl tests will be implemented. README is added for the tool first. Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/README | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/testing/selftests/resctrl/README diff --git a/tools/testing/selftests/resctrl/README b/tools/testing/selftests/resctrl/README new file mode 100644 index 0000000..f9621d6 --- /dev/null +++ b/tools/testing/selftests/resctrl/README @@ -0,0 +1,53 @@ +resctrl_tests - resctrl file system test suit + +Authors: + Fenghua Yu + Sai Praneeth Prakhya , + Arshiya Hayatkhan Pathan + +resctrl_tests tests various resctrl functionalities and interfaces including +both software and hardware. + +Currently it supports Memory Bandwidth Monitoring test and Memory Bandwidth +Allocation test on Intel RDT hardware. More tests will be added in the future. +And the test suit can be extended to cover AMD QoS and ARM MPAM hardware +as well. + +BUILD +----- + +Run "make" to build executable file "resctrl_tests". + +RUN +--- + +To use resctrl_tests, root or sudoer privileges are required. This is because +the test needs to mount resctrl file system and change contents in the file +system. + +Executing the test without any parameter will run all supported tests: + + sudo ./resctrl_tests + +OVERVIEW OF EXECUTION +--------------------- + +A test case has four stages: + + - setup: mount resctrl file system, create group, setup schemata, move test + process pids to tasks, start benchmark. + - execute: let benchmark run + - verify: get resctrl data and verify the data with another source, e.g. + perf event. + - teardown: umount resctrl and clear temporary files. + +ARGUMENTS +--------- + +Parameter '-h' shows usage information. + +usage: resctrl_tests [-h] [-b "benchmark_cmd [options]"] [-t test list] [-n no_of_bits] + -b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM default benchmark is builtin fill_buf + -t test list: run tests specified in the test list, e.g. -t mbm, mba, cqm, cat + -n no_of_bits: run cache tests using specified no of bits in cache bit mask + -h: help From patchwork Fri Jan 18 18:27:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02E8E6C5 for ; Fri, 18 Jan 2019 18:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3DED29BD5 for ; Fri, 18 Jan 2019 18:27:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7CCB29BE0; Fri, 18 Jan 2019 18:27:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1D029BFC for ; Fri, 18 Jan 2019 18:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728457AbfARS1P (ORCPT ); Fri, 18 Jan 2019 13:27:15 -0500 Received: from mail-eopbgr680080.outbound.protection.outlook.com ([40.107.68.80]:40721 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728995AbfARS1N (ORCPT ); Fri, 18 Jan 2019 13:27:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6QCT8mQ/pG3581XHKWVxgCcrwsmSSzQ2CF14iZVhamk=; b=wkI/+NVD/stRCXVpJrzxm00mLjNhqWdBVIt0Phpbkq7F0Q9MPgunAdA3dJhiHKMugjqdgAhaeRK7odG5ZApCvXyELWu7wQf9M1JyD8YruVkAZyt5F8X7Nx7WAVfWfhfeQ7ve5gB0XOjbp/H6vtv7XVD7KKHTW/iljHWFikdWrCM= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1276.namprd12.prod.outlook.com (10.168.237.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:04 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:04 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 02/13] selftests/resctrl: Add basic resctrl file system operations and data Thread-Topic: [PATCH v5 02/13] selftests/resctrl: Add basic resctrl file system operations and data Thread-Index: AQHUr1tp4GFqh9pgNEm5+mAHGqQGYQ== Date: Fri, 18 Jan 2019 18:27:04 +0000 Message-ID: <20190118182646.16594-3-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1276;20:sSje81M1smUcVg/G8UekDdQ7x1kmSdAA7CHl7h3i3NgXM0uYFj6Eo3cWr5ufrQmRs9HoRsssracF7kQmqs/rtdY1I891m2g9p3w/13S3TtWbcRcHhIGhZrT6lARCr6juWGD3fth5BOZ3q9sz9548QrN25SJmqnPFLqj/DffrrKbHGh6yJk6ViYffnvR4q9GtWkicrhCiPMgcdvWttW+9wYlIZZU4pJHYy3TX+BaN+pl4HwZWzy2eqnlhn+hVRdoF x-ms-office365-filtering-correlation-id: aacb0496-fea4-46fa-14e3-08d67d728b45 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1276; x-ms-traffictypediagnostic: DM5PR12MB1276: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(376002)(346002)(366004)(396003)(39860400002)(199004)(189003)(30864003)(14444005)(305945005)(3846002)(53936002)(6512007)(54906003)(110136005)(4326008)(99286004)(102836004)(6486002)(8676002)(25786009)(476003)(7736002)(316002)(6436002)(2616005)(446003)(11346002)(106356001)(486006)(386003)(68736007)(186003)(2906002)(50226002)(76176011)(81156014)(81166006)(52116002)(26005)(71200400001)(6506007)(97736004)(478600001)(8936002)(2501003)(71190400001)(72206003)(1076003)(256004)(66066001)(7416002)(2201001)(105586002)(36756003)(86362001)(6116002)(14454004)(5660300001)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1276;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 3V2I/vXhhsr1Llkvw//AxUMGAkfYxlWI2UcA63UW1odLZGHujzgwcqRW9MutbORAw691cO/gXPOe4kvB6Xd/f+gKvM8Q0JK/N0THsxr7/ulq5ioaZbvU7D7KbN0tMaqYeCrJnI1lYXbe96fL8dOkTwLv8/wB1RPl48pFYYtQ5LrlfUXxZUVpFKHL1K+0977GRAnr3ig/6UiZ2iXklapeaOA/fyS+Z+ASdXufuDCT12PJHC5vIeYuI7X/mUQ8WcrU+7wgVIRvjgH1VhuwvPPc39NUGaXPvFXDxCQ+q2XO+vaRYUrfAMNVY41utfJgN5OqErpUKSwX83kIzJRDBXAr7vHu39gntpuFAN94Erz+1uH8BPHKQGERjf3BKXZxehYY/9/gbeYMd2JK9emghEcjvwahfF51dUmLKfoQqsAwzJ8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: aacb0496-fea4-46fa-14e3-08d67d728b45 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:02.7526 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1276 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sai Praneeth Prakhya The basic resctrl file system operations and data are added for future usage by resctrl selftest tool. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Arshiya Hayatkhan Pathan Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/Makefile | 10 + tools/testing/selftests/resctrl/resctrl.h | 47 +++ tools/testing/selftests/resctrl/resctrlfs.c | 457 ++++++++++++++++++++++++++++ 3 files changed, 514 insertions(+) create mode 100644 tools/testing/selftests/resctrl/Makefile create mode 100644 tools/testing/selftests/resctrl/resctrl.h create mode 100644 tools/testing/selftests/resctrl/resctrlfs.c diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile new file mode 100644 index 0000000..bd5c541 --- /dev/null +++ b/tools/testing/selftests/resctrl/Makefile @@ -0,0 +1,10 @@ +CC = gcc +CFLAGS = -g -Wall + +*.o: *.c + $(CC) $(CFLAGS) -c *.c + +.PHONY: clean + +clean: + $(RM) *.o *~ diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h new file mode 100644 index 0000000..17fcb5e --- /dev/null +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#define _GNU_SOURCE +#ifndef RESCTRL_H +#define RESCTRL_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RESCTRL_PATH "/sys/fs/resctrl" +#define PHYS_ID_PATH "/sys/devices/system/cpu/cpu" + +#define PARENT_EXIT(err_msg) \ + do { \ + perror(err_msg); \ + kill(ppid, SIGKILL); \ + exit(EXIT_FAILURE); \ + } while (0) + +pid_t bm_pid, ppid; + +int remount_resctrlfs(bool mum_resctrlfs); +int get_resource_id(int cpu_no, int *resource_id); +int validate_bw_report_request(char *bw_report); +int validate_resctrl_feature_request(char *resctrl_val); +int taskset_benchmark(pid_t bm_pid, int cpu_no); +void run_benchmark(int signum, siginfo_t *info, void *ucontext); +int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, + char *resctrl_val); +int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, + char *resctrl_val); +int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, + int group_fd, unsigned long flags); +int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op); + +#endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c new file mode 100644 index 0000000..3e5e88a --- /dev/null +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -0,0 +1,457 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Basic resctrl file system operations + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ +#include "resctrl.h" + +#define RESCTRL_MBM "L3 monitoring detected" +#define RESCTRL_MBA "MB allocation detected" +#define MAX_RESCTRL_FEATURES 2 + +/* + * remount_resctrlfs - Remount resctrl FS at /sys/fs/resctrl + * @mum_resctrlfs: Should the resctrl FS be remounted? + * + * If not mounted, mount it. + * If mounted and mum_resctrlfs then remount resctrl FS. + * If mounted and !mum_resctrlfs then noop + * + * Return: 0 on success, non-zero on failure + */ +int remount_resctrlfs(bool mum_resctrlfs) +{ + DIR *dp; + struct dirent *ep; + unsigned int count = 0; + + /* + * If kernel is built with CONFIG_RESCTRL, then /sys/fs/resctrl should + * be present by default + */ + dp = opendir(RESCTRL_PATH); + if (dp) { + while ((ep = readdir(dp)) != NULL) + count++; + closedir(dp); + } else { + perror("Unable to read /sys/fs/resctrl"); + + return -1; + } + + /* + * If resctrl FS has more than two entries, it means that resctrl FS has + * already been mounted. The two default entries are "." and "..", these + * are present even when resctrl FS is not mounted + */ + if (count > 2) { + if (mum_resctrlfs) { + if (umount(RESCTRL_PATH) != 0) { + perror("Unable to umount resctrl"); + + return errno; + } + printf("Remount: done!\n"); + } else { + printf("Mounted already. Not remounting!\n"); + + return 0; + } + } + + if (mount("resctrl", RESCTRL_PATH, "resctrl", 0, NULL) != 0) { + perror("Unable to mount resctrl FS at /sys/fs/resctrl"); + + return errno; + } + + return 0; +} + +int umount_resctrlfs(void) +{ + if (umount(RESCTRL_PATH)) { + perror("Unable to umount resctrl"); + + return errno; + } + + return 0; +} + +/* + * get_resource_id - Get socket number/l3 id for a specified CPU + * @cpu_no: CPU number + * @resource_id: Socket number or l3_id + * + * Return: >= 0 on success, < 0 on failure. + */ +int get_resource_id(int cpu_no, int *resource_id) +{ + char phys_pkg_path[1024]; + FILE *fp; + + sprintf(phys_pkg_path, "%s%d/topology/physical_package_id", + PHYS_ID_PATH, cpu_no); + fp = fopen(phys_pkg_path, "r"); + if (!fp) { + perror("Failed to open physical_package_id"); + + return -1; + } + if (fscanf(fp, "%d", resource_id) <= 0) { + perror("Could not get socket number or l3 id"); + fclose(fp); + + return -1; + } + fclose(fp); + + return 0; +} + +/* + * taskset_benchmark - Taskset PID (i.e. benchmark) to a specified cpu + * @bm_pid: PID that should be binded + * @cpu_no: CPU number at which the PID would be binded + * + * Return: 0 on success, non-zero on failure + */ +int taskset_benchmark(pid_t bm_pid, int cpu_no) +{ + cpu_set_t my_set; + + CPU_ZERO(&my_set); + CPU_SET(cpu_no, &my_set); + + if (sched_setaffinity(bm_pid, sizeof(cpu_set_t), &my_set)) { + perror("Unable to taskset benchmark"); + + return -1; + } + + printf("Taskset benchmark: done!\n"); + + return 0; +} + +/* + * run_benchmark - Run a specified benchmark or fill_buf (default benchmark) + * in specified signal. Direct benchmark stdio to /dev/null. + * @signum: signal number + * @info: signal info + * @ucontext: user context in signal handling + * + * Return: void + */ +void run_benchmark(int signum, siginfo_t *info, void *ucontext) +{ + int span, operation, ret; + char **benchmark_cmd; + FILE *fp; + + benchmark_cmd = info->si_ptr; + + /* + * Direct stdio of child to /dev/null, so that only parent writes to + * stdio (console) + */ + fp = freopen("/dev/null", "w", stdout); + if (!fp) + PARENT_EXIT("Unable to direct benchmark status to /dev/null"); + + if (strcmp(benchmark_cmd[0], "fill_buf") == 0) { + /* Execute default fill_buf benchmark */ + span = atoi(benchmark_cmd[1]); + operation = atoi(benchmark_cmd[4]); + if (run_fill_buf(span, 1, 1, operation)) + fprintf(stderr, "Error in running fill buffer\n"); + } else { + /* Execute specified benchmark */ + ret = execvp(benchmark_cmd[0], benchmark_cmd); + if (ret) + perror("wrong\n"); + } + + fclose(stdout); + PARENT_EXIT("Unable to run specified benchmark"); +} + +/* + * create_grp - Create a group only if one doesn't exist + * @grp_name: Name of the group + * @grp: Full path and name of the group + * @parent_grp: Full path and name of the parent group + * + * Return: 0 on success, non-zero on failure + */ +static int create_grp(const char *grp_name, char *grp, const char *parent_grp) +{ + int found_grp = 0; + struct dirent *ep; + DIR *dp; + + /* Check if requested grp exists or not */ + dp = opendir(parent_grp); + if (dp) { + while ((ep = readdir(dp)) != NULL) { + if (strcmp(ep->d_name, grp_name) == 0) + found_grp = 1; + } + closedir(dp); + } else { + perror("Unable to open resctrl for group"); + + return -1; + } + + /* Requested grp doesn't exist, hence create it */ + if (found_grp == 0) { + if (mkdir(grp, 0) == -1) { + perror("Unable to create group"); + + return -1; + } + } + + return 0; +} + +static int write_pid_to_tasks(char *tasks, pid_t pid) +{ + FILE *fp; + + fp = fopen(tasks, "w"); + if (!fp) { + perror("Failed to open tasks file"); + + return -1; + } + if (fprintf(fp, "%d\n", pid) < 0) { + perror("Failed to wr pid to tasks file"); + fclose(fp); + + return -1; + + } + fclose(fp); + + return 0; +} + +/* + * write_bm_pid_to_resctrl - Write a PID (i.e. benchmark) to resctrl FS + * @bm_pid: PID that should be written + * @ctrlgrp: Name of the control monitor group (con_mon grp) + * @mongrp: Name of the monitor group (mon grp) + * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) + * + * If a con_mon grp is requested, create it and write pid to it, otherwise + * write pid to root con_mon grp. + * If a mon grp is requested, create it and write pid to it, otherwise + * pid is not written, this means that pid is in con_mon grp and hence + * should consult con_mon grp's mon_data directory for results. + * + * Return: 0 on success, non-zero on failure + */ +int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, + char *resctrl_val) +{ + char controlgroup[256], monitorgroup[256], monitorgroup_p[256]; + char tasks[256]; + int ret; + + if (ctrlgrp) + sprintf(controlgroup, "%s/%s", RESCTRL_PATH, ctrlgrp); + else + sprintf(controlgroup, "%s", RESCTRL_PATH); + + /* Create control and monitoring group and write pid into it */ + ret = create_grp(ctrlgrp, controlgroup, RESCTRL_PATH); + if (ret) + return ret; + sprintf(tasks, "%s/tasks", controlgroup); + ret = write_pid_to_tasks(tasks, bm_pid); + if (ret) + return ret; + + /* Create mon grp and write pid into it for "mbm" test */ + if ((strcmp(resctrl_val, "mbm") == 0)) { + if (mongrp) { + sprintf(monitorgroup_p, "%s/mon_groups", controlgroup); + sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp); + ret = create_grp(mongrp, monitorgroup, monitorgroup_p); + if (ret) + return ret; + + sprintf(tasks, "%s/mon_groups/%s/tasks", + controlgroup, mongrp); + ret = write_pid_to_tasks(tasks, bm_pid); + if (ret) + return ret; + } + } + + printf("Write benchmark to resctrl FS: done!\n"); + + return 0; +} + +/* + * write_schemata - Update schemata of a con_mon grp + * @ctrlgrp: Name of the con_mon grp + * @schemata: Schemata that should be updated to + * @cpu_no: CPU number that the benchmark PID is binded to + * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) + * + * Update schemata of a con_mon grp *only* if requested resctrl feature is + * allocation type + * + * Return: 0 on success, non-zero on failure + */ +int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) +{ + char controlgroup[1024], schema[1024]; + int resource_id; + FILE *fp; + + if (strcmp(resctrl_val, "mba") == 0) { + if (!schemata) { + printf("Schemata empty, so not updating\n"); + + return 0; + } + if (get_resource_id(cpu_no, &resource_id) < 0) { + perror("Failed to get resource id"); + return -1; + } + + if (ctrlgrp) + sprintf(controlgroup, "%s/%s/schemata", RESCTRL_PATH, + ctrlgrp); + else + sprintf(controlgroup, "%s/schemata", RESCTRL_PATH); + sprintf(schema, "%s%d%c%s", "MB:", resource_id, '=', schemata); + + fp = fopen(controlgroup, "w"); + if (!fp) { + perror("Failed to open control group"); + + return -1; + } + + if (fprintf(fp, "%s\n", schema) < 0) { + perror("Failed to write schemata in control group"); + fclose(fp); + + return -1; + } + fclose(fp); + + printf("Write schemata to resctrl FS: done!\n"); + } + + return 0; +} + +/* + * validate_resctrl_feature_request - Check if requested feature is valid. + * @resctrl_val: Requested feature + * + * Return: 0 on success, non-zero on failure + */ +int validate_resctrl_feature_request(char *resctrl_val) +{ + int resctrl_features_supported[MAX_RESCTRL_FEATURES] = {0, 0}; + const char *resctrl_features_list[MAX_RESCTRL_FEATURES] = { + "mbm", "mba"}; + int i, valid_resctrl_feature = -1; + char line[1024]; + FILE *fp; + + if (!resctrl_val) { + fprintf(stderr, "resctrl feature cannot be NULL\n"); + + return -1; + } + + /* Is the resctrl feature request valid? */ + for (i = 0; i < MAX_RESCTRL_FEATURES; i++) { + if (strcmp(resctrl_features_list[i], resctrl_val) == 0) + valid_resctrl_feature = i; + } + if (valid_resctrl_feature == -1) { + fprintf(stderr, "Not a valid resctrl feature request\n"); + + return -1; + } + + /* Enumerate resctrl features supported by this platform */ + if (system("dmesg > dmesg") != 0) { + perror("Could not create custom dmesg file"); + + return -1; + } + + fp = fopen("dmesg", "r"); + if (!fp) { + perror("Could not read custom created dmesg"); + + return -1; + } + + while (fgets(line, 1024, fp)) { + if ((strstr(line, RESCTRL_MBM)) != NULL) + resctrl_features_supported[0] = 1; + if ((strstr(line, RESCTRL_MBA)) != NULL) + resctrl_features_supported[1] = 1; + } + fclose(fp); + + if (system("rm -rf dmesg") != 0) + perror("Unable to remove 'dmesg' file"); + + /* Is the resctrl feature request supported? */ + if (!resctrl_features_supported[valid_resctrl_feature]) { + fprintf(stderr, "resctrl feature not supported!"); + + return -1; + } + + return 0; +} + +int validate_bw_report_request(char *bw_report) +{ + if (strcmp(bw_report, "reads") == 0) + return 0; + if (strcmp(bw_report, "writes") == 0) + return 0; + if (strcmp(bw_report, "nt-writes") == 0) { + strcpy(bw_report, "writes"); + return 0; + } + if (strcmp(bw_report, "total") == 0) + return 0; + + fprintf(stderr, "Requested iMC B/W report type unavailable\n"); + + return -1; +} + +int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, + int group_fd, unsigned long flags) +{ + int ret; + + ret = syscall(__NR_perf_event_open, hw_event, pid, cpu, + group_fd, flags); + return ret; +} From patchwork Fri Jan 18 18:27:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6E9B186E for ; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A588329BFC for ; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9882029C4C; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 208F429C36 for ; Fri, 18 Jan 2019 18:28:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728973AbfARS1M (ORCPT ); Fri, 18 Jan 2019 13:27:12 -0500 Received: from mail-eopbgr700066.outbound.protection.outlook.com ([40.107.70.66]:43360 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728956AbfARS1L (ORCPT ); Fri, 18 Jan 2019 13:27:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2tbpZJ3CcEwMF/P3Tx95AdtA5OI0LW6cm2lH6AoroVU=; b=NP4xfudsGoy1ZNZ85//xs3V2zJYcRr+jpYxUENE41QONa0QEiucjHRLmEsDCeR27nP8MB3ygZP88EB5C0PJqUlazggLSrnJ8vGgTw68SAt0gyIyIaykvUWD25ff93aJVTlbtMx0qPELullbUzmiCPquq2l9CQfXFwhtgyKoIRAY= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2376.namprd12.prod.outlook.com (52.132.141.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Fri, 18 Jan 2019 18:27:05 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:05 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 03/13] selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system Thread-Topic: [PATCH v5 03/13] selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system Thread-Index: AQHUr1tpjr0DJKuKKUKfYlfzuM+Zmw== Date: Fri, 18 Jan 2019 18:27:05 +0000 Message-ID: <20190118182646.16594-4-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB2376;20:ThBng5M6O31WP1uHQCG9dYCcds531VQN4DoXayuShdNkbIJv8lXJYFWHWWwCHTN+gZ+DT9i7q5amQk+vPfgHYzDsH6WEjQgHAujOOryPjnC5UQTZcH6DwZFfvEnazDorUatm4Nz2g7P/xK2qOIxDQq+PjD1bG96r6W4KpE4Jq7LNPFjTz28hea4EE//lgMU6WKrUVGsAg4YdrnfvQknJEkpfcdZ9Fo3dfx4rf2guSVB24DwKbEb2xM/6usi4Md+Q x-ms-office365-filtering-correlation-id: 9fff7c5a-e01b-4291-f674-08d67d728c48 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB2376; x-ms-traffictypediagnostic: DM5PR12MB2376: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(39860400002)(136003)(396003)(346002)(366004)(189003)(199004)(1076003)(25786009)(26005)(52116002)(4326008)(186003)(102836004)(2201001)(6506007)(76176011)(72206003)(86362001)(386003)(3846002)(71200400001)(71190400001)(256004)(14444005)(6486002)(54906003)(99286004)(305945005)(110136005)(6436002)(7736002)(486006)(6512007)(316002)(2616005)(446003)(2906002)(97736004)(476003)(11346002)(478600001)(7416002)(105586002)(53936002)(106356001)(81166006)(8936002)(8676002)(5660300001)(36756003)(68736007)(66066001)(6116002)(50226002)(14454004)(2501003)(81156014)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB2376;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: YIb54COCITFTpyfGx6FPtR0GZNM7iInMCH+4OhRq4cwytdSUhECjA8MtOnSRfei5EhUCloCl+XEhQX1Tz9W11J38mQKQfedOCkl2dWDR0IR0eEMXfrpC2oM8pU1ucq/UQRPsUbX1dEkwCEiySfABUzOgeYkr1IoXbZMyyWPmisgMSY5hcgRoHkoWIB/EM1Ra4VT1E+uzjv/OodFoYiCjtGIeza0iBKa7khMm9oH1UJ76o0iCAS/qapo4WkTiKU3dnFouP7qolmNITIoYRoP5fZP1sht0M8yS0f1CCcBDRUp1mn3xL8WHrXsJ7RIVyJiIeAHVbgGcEMoP8gWL0y5GmgGgZQohvaA4Qr23CwE2fKlaDVK9/3MQ1H+vLM1Fruvdhe1qRcss+QFfM1AuICQ58KKLAlazbz+qN8zdxLo/lf8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fff7c5a-e01b-4291-f674-08d67d728c48 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:04.4714 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2376 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sai Praneeth Prakhya Total memory bandwidth can be monitored from perf IMC counter and from resctrl file system. Later the two will be compared to verify the total memory bandwidth read from resctrl is correct. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Arshiya Hayatkhan Pathan Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/resctrl_val.c | 118 ++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 tools/testing/selftests/resctrl/resctrl_val.c diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c new file mode 100644 index 0000000..12301ac --- /dev/null +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Memory bandwidth monitoring and allocation library + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ +#include "resctrl.h" + +#define UNCORE_IMC "uncore_imc" +#define READ_FILE_NAME "events/cas_count_read" +#define WRITE_FILE_NAME "events/cas_count_write" +#define DYN_PMU_PATH "/sys/bus/event_source/devices" +#define SCALE 0.00006103515625 +#define MAX_IMCS 20 +#define MAX_TOKENS 5 +#define READ 0 +#define WRITE 1 +#define CON_MON_MBM_LOCAL_BYTES_PATH \ + "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/mbm_local_bytes" + +#define CON_MBM_LOCAL_BYTES_PATH \ + "%s/%s/mon_data/mon_L3_%02d/mbm_local_bytes" + +#define MON_MBM_LOCAL_BYTES_PATH \ + "%s/mon_groups/%s/mon_data/mon_L3_%02d/mbm_local_bytes" + +#define MBM_LOCAL_BYTES_PATH \ + "%s/mon_data/mon_L3_%02d/mbm_local_bytes" + +struct membw_read_format { + __u64 value; /* The value of the event */ + __u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */ + __u64 time_running; /* if PERF_FORMAT_TOTAL_TIME_RUNNING */ + __u64 id; /* if PERF_FORMAT_ID */ +}; + +struct imc_counter_config { + __u32 type; + __u64 event; + __u64 umask; + struct perf_event_attr pe; + struct membw_read_format return_value; + int fd; +}; +static struct imc_counter_config imc_counters_config[MAX_IMCS][2]; + +void membw_initialize_perf_event_attr(int i, int j) +{ + memset(&imc_counters_config[i][j].pe, 0, + sizeof(struct perf_event_attr)); + imc_counters_config[i][j].pe.type = imc_counters_config[i][j].type; + imc_counters_config[i][j].pe.size = sizeof(struct perf_event_attr); + imc_counters_config[i][j].pe.disabled = 1; + imc_counters_config[i][j].pe.inherit = 1; + imc_counters_config[i][j].pe.exclude_guest = 1; + imc_counters_config[i][j].pe.config = + imc_counters_config[i][j].umask << 8 | + imc_counters_config[i][j].event; + imc_counters_config[i][j].pe.sample_type = PERF_SAMPLE_IDENTIFIER; + imc_counters_config[i][j].pe.read_format = + PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING; +} + +void membw_ioctl_perf_event_ioc_reset_enable(int i, int j) +{ + ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_RESET, 0); + ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_ENABLE, 0); +} + +void membw_ioctl_perf_event_ioc_disable(int i, int j) +{ + ioctl(imc_counters_config[i][j].fd, PERF_EVENT_IOC_DISABLE, 0); +} + +/* + * get_event_and_umask: Parse config into event and umask + * @cas_count_cfg: Config + * @count: iMC number + * @op: Operation (read/write) + */ +void get_event_and_umask(char *cas_count_cfg, int count, bool op) +{ + char *token[MAX_TOKENS]; + int i = 0; + + strcat(cas_count_cfg, ","); + token[0] = strtok(cas_count_cfg, "=,"); + + for (i = 1; i < MAX_TOKENS; i++) + token[i] = strtok(NULL, "=,"); + + for (i = 0; i < MAX_TOKENS; i++) { + if (!token[i]) + break; + if (strcmp(token[i], "event") == 0) { + if (op == READ) + imc_counters_config[count][READ].event = + strtol(token[i + 1], NULL, 16); + else + imc_counters_config[count][WRITE].event = + strtol(token[i + 1], NULL, 16); + } + if (strcmp(token[i], "umask") == 0) { + if (op == READ) + imc_counters_config[count][READ].umask = + strtol(token[i + 1], NULL, 16); + else + imc_counters_config[count][WRITE].umask = + strtol(token[i + 1], NULL, 16); + } + } +} + From patchwork Fri Jan 18 18:27:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 498D36C5 for ; Fri, 18 Jan 2019 18:28:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35FEE29BD5 for ; Fri, 18 Jan 2019 18:28:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29C5A29C19; Fri, 18 Jan 2019 18:28:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7CAB29BD5 for ; Fri, 18 Jan 2019 18:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728971AbfARS1Q (ORCPT ); Fri, 18 Jan 2019 13:27:16 -0500 Received: from mail-eopbgr700066.outbound.protection.outlook.com ([40.107.70.66]:43360 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728991AbfARS1N (ORCPT ); Fri, 18 Jan 2019 13:27:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a2CewgVRt31uTCyzt0iqEgteSJRr/+OYm30JAQlpkz4=; b=lCO6i0Qojgw9EcBPkbCJdGDka4zBl8YqYo/ZWsHQQlWm3Vffn6ncPM2J6jbrGs+618t5+j3nfdxCkq5h4VhqbSmcs8JwG0dwAiPChXc5PdiMej+7KYDUYCNQl/52r/Zneu3qjeQVUvXK3wuDIlQdRbUWTjSx3J3JHYrtqpS3pLY= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2376.namprd12.prod.outlook.com (52.132.141.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Fri, 18 Jan 2019 18:27:07 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:07 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 04/13] selftests/resctrl: Add callback to start a benchmark Thread-Topic: [PATCH v5 04/13] selftests/resctrl: Add callback to start a benchmark Thread-Index: AQHUr1tq4A0jWUdbA0ulzxlnni3GvQ== Date: Fri, 18 Jan 2019 18:27:06 +0000 Message-ID: <20190118182646.16594-5-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB2376;20:1FBAvpprXZPf3/AOvj8hsq7+w5hxoqbDd3P4DmZz8QoJHFzrC3Mdm9sC0AGSVVkX22LvIQaGqsBwYTrA48cyd/6+x1/EWjFZkn7UwjHp5Y4WFJBjnMqpIchA8eblQi9TpX2LVAA0vdCUaGgU09IHwX7bOcUHbKDlEyIRfI43o2MpFDsYrLQjIrSLS46kKVkWT2Nw5tXI2ch0J/gMwzjwSSdFWKiFjyfQid0Oj+Mg7iTkwdN3YLiakhXuoiFdqlz7 x-ms-office365-filtering-correlation-id: ab6a8584-5eb7-4195-2a0c-08d67d728cfe x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB2376; x-ms-traffictypediagnostic: DM5PR12MB2376: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(39860400002)(136003)(396003)(346002)(366004)(189003)(199004)(1076003)(25786009)(26005)(52116002)(4326008)(186003)(102836004)(2201001)(6506007)(76176011)(72206003)(86362001)(386003)(3846002)(71200400001)(71190400001)(256004)(14444005)(6486002)(54906003)(99286004)(305945005)(110136005)(6436002)(7736002)(486006)(6512007)(316002)(2616005)(446003)(2906002)(97736004)(476003)(11346002)(478600001)(7416002)(105586002)(53946003)(53936002)(106356001)(81166006)(8936002)(8676002)(5660300001)(36756003)(30864003)(68736007)(66066001)(6116002)(50226002)(14454004)(2501003)(81156014)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB2376;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: BxwN6dfVoZ2y8skQMzd2DU4EUiORuxIp41znHCMGo/qkjQyHUQDCVJ9TOEHq066xioFCGhWuwIGKvnL/0+ea8ctuRPGoh28F1iF94a2H5D+ScbQ5Fju3QsMA95k37BYwu0DtKVvzggU+iIHACw5kc7qz2DhzMyZBMf3aFyPNS86AZFQGBKv0+v/mh7wKYECVjeNUJKZYVAU7TdP6aN+GS4C0WB07t53NLXoaHCpFjOSrhJPVbfZPl1IQQyDOp0OJlwnv0osd3ap2hM5gV+KFGXLd/gxejbQxMK7qR/8qlwMqmwVAHJffbLKUM+HuAVoLV2Jb9NLLFaICobeltgg0z7LQNuev6E8ilkwxvcvv0NGT50OkyPRlbdzEHPYk4oMg4Zdc/4P6aIQXR1qf1wPnxG5PA1fA0jO4leam5QYl1qU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab6a8584-5eb7-4195-2a0c-08d67d728cfe X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:05.6745 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2376 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sai Praneeth Prakhya The callback starts a child process and puts the child pid in created resctrl group with specified memory bandwidth in schemata. The child starts running benchmark. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Arshiya Hayatkhan Pathan Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/resctrl.h | 27 ++ tools/testing/selftests/resctrl/resctrl_val.c | 586 ++++++++++++++++++++++++++ 2 files changed, 613 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 17fcb5e..f30a2dc 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -3,6 +3,7 @@ #ifndef RESCTRL_H #define RESCTRL_H #include +#include #include #include #include @@ -28,10 +29,35 @@ exit(EXIT_FAILURE); \ } while (0) +/* + * resctrl_val_param: resctrl test parameters + * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) + * @ctrlgrp: Name of the control monitor group (con_mon grp) + * @mongrp: Name of the monitor group (mon grp) + * @cpu_no: CPU number to which the benchmark would be binded + * @span: Memory bytes accessed in each benchmark iteration + * @mum_resctrlfs: Should the resctrl FS be remounted? + * @filename: Name of file to which the o/p should be written + * @bw_report: Bandwidth report type (reads vs writes) + * @setup: Call back function to setup test environment + */ +struct resctrl_val_param { + char *resctrl_val; + char ctrlgrp[64]; + char mongrp[64]; + int cpu_no; + int span; + int mum_resctrlfs; + char filename[64]; + char *bw_report; + int (*setup)(int num, ...); +}; + pid_t bm_pid, ppid; int remount_resctrlfs(bool mum_resctrlfs); int get_resource_id(int cpu_no, int *resource_id); +int umount_resctrlfs(void); int validate_bw_report_request(char *bw_report); int validate_resctrl_feature_request(char *resctrl_val); int taskset_benchmark(pid_t bm_pid, int cpu_no); @@ -43,5 +69,6 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op); +int membw_val(char **benchmark_cmd, struct resctrl_val_param *param); #endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 12301ac..8b32595 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -11,6 +11,7 @@ */ #include "resctrl.h" +#define MB (1024 * 1024) #define UNCORE_IMC "uncore_imc" #define READ_FILE_NAME "events/cas_count_read" #define WRITE_FILE_NAME "events/cas_count_write" @@ -47,6 +48,9 @@ struct imc_counter_config { struct membw_read_format return_value; int fd; }; + +static char mbm_total_path[1024]; +static int imcs; static struct imc_counter_config imc_counters_config[MAX_IMCS][2]; void membw_initialize_perf_event_attr(int i, int j) @@ -116,3 +120,585 @@ void get_event_and_umask(char *cas_count_cfg, int count, bool op) } } +static int open_perf_event(int i, int cpu_no, int j) +{ + imc_counters_config[i][j].fd = + perf_event_open(&imc_counters_config[i][j].pe, -1, cpu_no, -1, + PERF_FLAG_FD_CLOEXEC); + + if (imc_counters_config[i][j].fd == -1) { + fprintf(stderr, "Error opening leader %llx\n", + imc_counters_config[i][j].pe.config); + + return -1; + } + + return 0; +} + +/* Get type and config (read and write) of an iMC counter */ +static int read_from_imc_dir(char *imc_dir, int count) +{ + char cas_count_cfg[1024], imc_counter_cfg[1024], imc_counter_type[1024]; + FILE *fp; + + /* Get type of iMC counter */ + sprintf(imc_counter_type, "%s%s", imc_dir, "type"); + fp = fopen(imc_counter_type, "r"); + if (!fp) { + perror("Failed to open imc counter type file"); + + return -1; + } + if (fscanf(fp, "%u", &imc_counters_config[count][READ].type) <= 0) { + perror("Could not get imc type"); + fclose(fp); + + return -1; + } + fclose(fp); + + imc_counters_config[count][WRITE].type = + imc_counters_config[count][READ].type; + + /* Get read config */ + sprintf(imc_counter_cfg, "%s%s", imc_dir, READ_FILE_NAME); + fp = fopen(imc_counter_cfg, "r"); + if (!fp) { + perror("Failed to open imc config file"); + + return -1; + } + if (fscanf(fp, "%s", cas_count_cfg) <= 0) { + perror("Could not get imc cas count read"); + fclose(fp); + + return -1; + } + fclose(fp); + + get_event_and_umask(cas_count_cfg, count, READ); + + /* Get write config */ + sprintf(imc_counter_cfg, "%s%s", imc_dir, WRITE_FILE_NAME); + fp = fopen(imc_counter_cfg, "r"); + if (!fp) { + perror("Failed to open imc config file"); + + return -1; + } + if (fscanf(fp, "%s", cas_count_cfg) <= 0) { + perror("Could not get imc cas count write"); + fclose(fp); + + return -1; + } + fclose(fp); + + get_event_and_umask(cas_count_cfg, count, WRITE); + + return 0; +} + +/* + * A system can have 'n' number of iMC (Integrated Memory Controller) + * counters, get that 'n'. For each iMC counter get it's type and config. + * Also, each counter has two configs, one for read and the other for write. + * A config again has two parts, event and umask. + * Enumerate all these details into an array of structures. + * + * Return: >= 0 on success. < 0 on failure. + */ +static int num_of_imcs(void) +{ + unsigned int count = 0; + char imc_dir[1024]; + struct dirent *ep; + int ret; + DIR *dp; + + dp = opendir(DYN_PMU_PATH); + if (dp) { + while ((ep = readdir(dp))) { + if (strstr(ep->d_name, UNCORE_IMC)) { + sprintf(imc_dir, "%s/%s/", DYN_PMU_PATH, + ep->d_name); + ret = read_from_imc_dir(imc_dir, count); + if (ret) { + closedir(dp); + + return ret; + } + count++; + } + } + closedir(dp); + if (count == 0) { + perror("Unable find iMC counters!\n"); + + return -1; + } + } else { + perror("Unable to open PMU directory!\n"); + + return -1; + } + + return count; +} + +static int initialize_mem_bw_imc(void) +{ + int imc, j; + + imcs = num_of_imcs(); + if (imcs <= 0) + return imcs; + + /* Initialize perf_event_attr structures for all iMC's */ + for (imc = 0; imc < imcs; imc++) { + for (j = 0; j < 2; j++) + membw_initialize_perf_event_attr(imc, j); + } + + return 0; +} + +/* + * get_mem_bw_imc: Memory band width as reported by iMC counters + * @cpu_no: CPU number that the benchmark PID is binded to + * @bw_report: Bandwidth report type (reads, writes) + * + * Memory B/W utilized by a process on a socket can be calculated using + * iMC counters. Perf events are used to read these counters. + * + * Return: >= 0 on success. < 0 on failure. + */ +static float get_mem_bw_imc(int cpu_no, char *bw_report) +{ + float reads, writes, of_mul_read, of_mul_write; + int imc, j, ret; + + /* Start all iMC counters to log values (both read and write) */ + reads = 0, writes = 0, of_mul_read = 1, of_mul_write = 1; + for (imc = 0; imc < imcs; imc++) { + for (j = 0; j < 2; j++) { + ret = open_perf_event(imc, cpu_no, j); + if (ret) + return -1; + } + for (j = 0; j < 2; j++) + membw_ioctl_perf_event_ioc_reset_enable(imc, j); + } + + sleep(1); + + /* Stop counters after a second to get results (both read and write) */ + for (imc = 0; imc < imcs; imc++) { + for (j = 0; j < 2; j++) + membw_ioctl_perf_event_ioc_disable(imc, j); + } + + /* + * Get results which are stored in struct type imc_counter_config + * Take over flow into consideration before calculating total b/w + */ + for (imc = 0; imc < imcs; imc++) { + struct imc_counter_config *r = + &imc_counters_config[imc][READ]; + struct imc_counter_config *w = + &imc_counters_config[imc][WRITE]; + + if (read(r->fd, &r->return_value, + sizeof(struct membw_read_format)) == -1) { + perror("Couldn't get read b/w through iMC"); + + return -1; + } + + if (read(w->fd, &w->return_value, + sizeof(struct membw_read_format)) == -1) { + perror("Couldn't get write bw through iMC"); + + return -1; + } + + __u64 r_time_enabled = r->return_value.time_enabled; + __u64 r_time_running = r->return_value.time_running; + + if (r_time_enabled != r_time_running) + of_mul_read = (float)r_time_enabled / + (float)r_time_running; + + __u64 w_time_enabled = w->return_value.time_enabled; + __u64 w_time_running = w->return_value.time_running; + + if (w_time_enabled != w_time_running) + of_mul_write = (float)w_time_enabled / + (float)w_time_running; + reads += r->return_value.value * of_mul_read * SCALE; + writes += w->return_value.value * of_mul_write * SCALE; + } + + for (imc = 0; imc < imcs; imc++) { + close(imc_counters_config[imc][READ].fd); + close(imc_counters_config[imc][WRITE].fd); + } + + if (strcmp(bw_report, "reads") == 0) + return reads; + + if (strcmp(bw_report, "writes") == 0) + return writes; + + return (reads + writes); +} + +void set_mbm_path(const char *ctrlgrp, const char *mongrp, int resource_id) +{ + if (ctrlgrp && mongrp) + sprintf(mbm_total_path, CON_MON_MBM_LOCAL_BYTES_PATH, + RESCTRL_PATH, ctrlgrp, mongrp, resource_id); + else if (!ctrlgrp && mongrp) + sprintf(mbm_total_path, MON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, + mongrp, resource_id); + else if (ctrlgrp && !mongrp) + sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, + ctrlgrp, resource_id); + else if (!ctrlgrp && !mongrp) + sprintf(mbm_total_path, MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, + resource_id); +} + +/* + * initialize_mem_bw_resctrl: Appropriately populate "mbm_total_path" + * @ctrlgrp: Name of the control monitor group (con_mon grp) + * @mongrp: Name of the monitor group (mon grp) + * @cpu_no: CPU number that the benchmark PID is binded to + * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) + */ +static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mongrp, + int cpu_no, char *resctrl_val) +{ + int resource_id; + + if (get_resource_id(cpu_no, &resource_id) < 0) { + perror("Could not get resource_id"); + return; + } + + if (strcmp(resctrl_val, "mbm") == 0) + set_mbm_path(ctrlgrp, mongrp, resource_id); + + if ((strcmp(resctrl_val, "mba") == 0)) { + if (ctrlgrp) + sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, + RESCTRL_PATH, ctrlgrp, resource_id); + else + sprintf(mbm_total_path, MBM_LOCAL_BYTES_PATH, + RESCTRL_PATH, resource_id); + } +} + +/* + * Get MBM Local bytes as reported by resctrl FS + * For MBM, + * 1. If con_mon grp and mon grp are given, then read from con_mon grp's mon grp + * 2. If only con_mon grp is given, then read from con_mon grp + * 3. If both are not given, then read from root con_mon grp + * For MBA, + * 1. If con_mon grp is given, then read from it + * 2. If con_mon grp is not given, then read from root con_mon grp + */ +static unsigned long get_mem_bw_resctrl(void) +{ + unsigned long mbm_total = 0; + FILE *fp; + + fp = fopen(mbm_total_path, "r"); + if (!fp) { + perror("Failed to open total bw file"); + + return -1; + } + if (fscanf(fp, "%lu", &mbm_total) <= 0) { + perror("Could not get mbm local bytes"); + fclose(fp); + + return -1; + } + fclose(fp); + + return mbm_total; +} + +pid_t bm_pid, ppid; + +static void ctrlc_handler(int signum, siginfo_t *info, void *ptr) +{ + kill(bm_pid, SIGKILL); + printf("Ending\n\n"); + + exit(EXIT_SUCCESS); +} + +/* + * print_results_bw: the memory bandwidth results are stored in a file + * @filename: file that stores the results + * @bm_pid: child pid that runs benchmark + * @bw_imc: perf imc counter value + * @bw_resc: memory bandwidth value + * + * Return: 0 on success. non-zero on failure. + */ +static int print_results_bw(char *filename, int bm_pid, float bw_imc, + unsigned long bw_resc) +{ + unsigned long diff = labs(bw_imc - bw_resc); + FILE *fp; + + if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) { + printf("Pid: %d \t Mem_BW_iMC: %f \t ", bm_pid, bw_imc); + printf("Mem_BW_resc: %lu \t Difference: %lu\n", bw_resc, diff); + } else { + fp = fopen(filename, "a"); + if (!fp) { + perror("Cannot open results file"); + + return errno; + } + if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n", + bm_pid, bw_imc, bw_resc, diff) <= 0) { + fclose(fp); + perror("Could not log results."); + + return errno; + } + fclose(fp); + } + + return 0; +} + +static int +measure_vals(struct resctrl_val_param *param, unsigned long *bw_resc_start) +{ + unsigned long bw_imc, bw_resc, bw_resc_end; + int ret; + + /* + * Measure memory bandwidth from resctrl and from + * another source which is perf imc value or could + * be something else if perf imc event is not available. + * Compare the two values to validate resctrl value. + * It takes 1sec to measure the data. + */ + bw_imc = get_mem_bw_imc(param->cpu_no, param->bw_report); + if (bw_imc <= 0) + return bw_imc; + + bw_resc_end = get_mem_bw_resctrl(); + if (bw_resc_end <= 0) + return bw_resc_end; + + bw_resc = (bw_resc_end - *bw_resc_start) / MB; + ret = print_results_bw(param->filename, bm_pid, bw_imc, bw_resc); + if (ret) + return ret; + + *bw_resc_start = bw_resc_end; + + return 0; +} + +/* + * membw_val: execute benchmark and measure memory bandwidth on + * the benchmark + * @benchmark_cmd: benchmark command and its arguments + * @param: parameters passed to membw_val() + * + * Return: 0 on success. non-zero on failure. + */ +int membw_val(char **benchmark_cmd, struct resctrl_val_param *param) +{ + int ret = 0, pipefd[2], pipe_message = 0; + char *resctrl_val = param->resctrl_val; + unsigned long bw_resc_start = 0; + struct sigaction sigact; + union sigval value; + FILE *fp; + + if (strcmp(param->filename, "") == 0) + sprintf(param->filename, "stdio"); + + if (strcmp(param->bw_report, "") == 0) + param->bw_report = "total"; + + ret = validate_resctrl_feature_request(resctrl_val); + if (ret) + return ret; + + if ((strcmp(resctrl_val, "mba")) == 0 || + (strcmp(resctrl_val, "mbm")) == 0) { + ret = validate_bw_report_request(param->bw_report); + if (ret) + return ret; + } + + ret = remount_resctrlfs(param->mum_resctrlfs); + if (ret) + return ret; + + /* + * If benchmark wasn't successfully started by child, then child should + * kill parent, so save parent's pid + */ + ppid = getpid(); + + /* File based synchronization between parent and child */ + fp = fopen("sig", "w"); + if (!fp) { + perror("Failed to open sig file"); + + return -1; + } + if (fprintf(fp, "%d\n", 0) <= 0) { + perror("Unable to establish sync bw parent & child"); + fclose(fp); + + return -1; + } + fclose(fp); + + if (pipe(pipefd)) { + perror("Unable to create pipe"); + + return -1; + } + + /* + * Fork to start benchmark, save child's pid so that it can be killed + * when needed + */ + bm_pid = fork(); + if (bm_pid == -1) { + perror("Unable to fork"); + + return -1; + } + + if (bm_pid == 0) { + /* + * Mask all signals except SIGUSR1, parent uses SIGUSR1 to + * start benchmark + */ + sigfillset(&sigact.sa_mask); + sigdelset(&sigact.sa_mask, SIGUSR1); + + sigact.sa_sigaction = run_benchmark; + sigact.sa_flags = SA_SIGINFO; + + /* Register for "SIGUSR1" signal from parent */ + if (sigaction(SIGUSR1, &sigact, NULL)) + PARENT_EXIT("Can't register child for signal"); + + /* Tell parent that child is ready */ + close(pipefd[0]); + pipe_message = 1; + write(pipefd[1], &pipe_message, sizeof(pipe_message)); + close(pipefd[1]); + + /* Suspend child until delivery of "SIGUSR1" from parent */ + sigsuspend(&sigact.sa_mask); + + PARENT_EXIT("Child is done"); + } + + printf("Benchmark PID: %d\n", bm_pid); + + /* + * Register CTRL-C handler for parent, as it has to kill benchmark + * before exiting + */ + sigact.sa_sigaction = ctrlc_handler; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = SA_SIGINFO; + if (sigaction(SIGINT, &sigact, NULL) || + sigaction(SIGHUP, &sigact, NULL)) { + perror("Can't register parent for CTRL-C handler"); + ret = errno; + goto out; + } + + value.sival_ptr = benchmark_cmd; + + /* Taskset benchmark to specified cpu */ + ret = taskset_benchmark(bm_pid, param->cpu_no); + if (ret) + goto out; + + /* Write benchmark to specified control&monitoring grp in resctrl FS */ + ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, + resctrl_val); + if (ret) + goto out; + + if ((strcmp(resctrl_val, "mbm") == 0) || + (strcmp(resctrl_val, "mba") == 0)) { + ret = initialize_mem_bw_imc(); + if (ret) + goto out; + + initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp, + param->cpu_no, resctrl_val); + } + + /* Parent waits for child to be ready. */ + close(pipefd[1]); + while (pipe_message != 1) + read(pipefd[0], &pipe_message, sizeof(pipe_message)); + close(pipefd[0]); + + /* Signal child to start benchmark */ + if (sigqueue(bm_pid, SIGUSR1, value) == -1) { + perror("Unable to signal child to start execution"); + ret = errno; + goto out; + } + + /* Give benchmark enough time to fully run */ + sleep(1); + + /* Test runs until the callback setup() tells the test to stop. */ + while (1) { + if (strcmp(resctrl_val, "mbm") == 0) { + ret = param->setup(1, param); + if (ret) { + ret = 0; + break; + } + + ret = measure_vals(param, &bw_resc_start); + if (ret) + break; + } else if ((strcmp(resctrl_val, "mba") == 0)) { + ret = param->setup(1, param); + if (ret) { + ret = 0; + break; + } + + ret = measure_vals(param, &bw_resc_start); + if (ret) + break; + } else { + break; + } + } + +out: + kill(bm_pid, SIGKILL); + umount_resctrlfs(); + + return ret; +} From patchwork Fri Jan 18 18:27:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C03C4139A for ; Fri, 18 Jan 2019 18:28:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B06AF29BFC for ; Fri, 18 Jan 2019 18:28:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4CF729C36; Fri, 18 Jan 2019 18:28:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2299529BFC for ; Fri, 18 Jan 2019 18:28:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728914AbfARS1P (ORCPT ); Fri, 18 Jan 2019 13:27:15 -0500 Received: from mail-eopbgr700066.outbound.protection.outlook.com ([40.107.70.66]:43360 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729030AbfARS1O (ORCPT ); Fri, 18 Jan 2019 13:27:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WAHzit5IafEMWyuF4F7vXaIOY6TgBG5O4y1XDZXhbtg=; b=oahhYomBsXymE8A/WY16gZgE6FJ6hST3bpkp9QgS5Km5MlrgieSwiw5D9Cq1X9ldEwoBZAUDZYYtfpMT0R+cZ821gYbMDqNChqF+0AyLfZGvBT7n/gZ1mNqJVfV85dyrQxR5geptNmoGJc9bBJGdtqxIVvj+DtSmdsNQg678l0g= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2376.namprd12.prod.outlook.com (52.132.141.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Fri, 18 Jan 2019 18:27:08 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:08 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 05/13] selftests/resctrl: Add built in benchmark Thread-Topic: [PATCH v5 05/13] selftests/resctrl: Add built in benchmark Thread-Index: AQHUr1trRq5PsAhpckCYHNa1ji4/Cg== Date: Fri, 18 Jan 2019 18:27:08 +0000 Message-ID: <20190118182646.16594-6-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB2376;20:6eDXJXyFDzqJjbJSRqYYtFqyjXbNdNUHnPXRAbvXMOrXLlLbOAq8Nno0A782mDkAg8xfEAj0XcvnY6AiHjIf3nhwivgwQSxxhUhM963btJPPn3Uu79etwMpciv1oMohGJ7fThyxhRN1PV2Let8VLo6MFeb3zBFJqRYJ8PtEeK2VQALy5CDsDlEpAt1mHDuVx3WO9RmD/lqVfJwURqU5FQRbJ9CVnBlOG8wqOzfkdZIPwTqYMF3MrnO4XsESy1t5V x-ms-office365-filtering-correlation-id: d484659f-6528-4cd4-3541-08d67d728dcb x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB2376; x-ms-traffictypediagnostic: DM5PR12MB2376: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(39860400002)(136003)(396003)(346002)(366004)(189003)(199004)(1076003)(25786009)(26005)(52116002)(4326008)(186003)(102836004)(2201001)(6506007)(76176011)(72206003)(86362001)(386003)(3846002)(71200400001)(71190400001)(256004)(6486002)(54906003)(99286004)(305945005)(110136005)(6436002)(7736002)(486006)(6512007)(316002)(2616005)(446003)(2906002)(97736004)(476003)(11346002)(478600001)(7416002)(105586002)(53936002)(106356001)(81166006)(8936002)(8676002)(5660300001)(36756003)(68736007)(66066001)(6116002)(50226002)(14454004)(2501003)(81156014)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB2376;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: h6K3AGh8YLFBUu/Yrwy+AI5pFBecEw2m9q7/viPP35hlO1eZdNmeMwiOzaK307/2H2wjf5nBHTvQBrwToCrx4219xsKUVP1Wdd7BmfwCPS/Vacd0EzAwALRR7n9jUQYA0ybUkIEFh+qFtPBF3+hw6ITG7p77ris/jrKTBViLYJmROYeZl5224SfDASiddunlYIAzv/eEHtlctv5Mf4EuB/Kh5gKZxR49WqnSPmRRiQqTIbI6mZUqW/OZC/2GPWBKCXOmSFxtbACuT6W09k34OHj/ScJt46nH/OM1UjI7guLM3udIvjQ6QsREsDEWkcQPnCZdkl9uyRgUo/CK3g8685FDYnyfo11hIF4ExyHAeVWRypBt0RKkD2wsknhze7PlVcsEgreYddtcUXrKn32HsLroqgiU3cqYz+Di5Mx7pkc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d484659f-6528-4cd4-3541-08d67d728dcb X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:07.0027 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2376 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sai Praneeth Prakhya Built-in benchmark fill_buf generates stressful memory bandwidth and cache traffic. Later it will be used as a default benchmark by various resctrl tests such as MBA (Memory Bandwidth Allocation) and MBM (Memory Bandwidth Monitoring) tests. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Arshiya Hayatkhan Pathan Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/fill_buf.c | 175 +++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 tools/testing/selftests/resctrl/fill_buf.c diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c new file mode 100644 index 0000000..d9950b5 --- /dev/null +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * fill_buf benchmark + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "resctrl.h" + +#define CL_SIZE (64) +#define PAGE_SIZE (4 * 1024) +#define MB (1024 * 1024) + +static unsigned char *startptr; + +static void sb(void) +{ + asm volatile("sfence\n\t" + : : : "memory"); +} + +static void ctrl_handler(int signo) +{ + free(startptr); + printf("\nEnding\n"); + sb(); + exit(EXIT_SUCCESS); +} + +static void cl_flush(void *p) +{ + asm volatile("clflush (%0)\n\t" + : : "r"(p) : "memory"); +} + +static void mem_flush(void *p, size_t s) +{ + char *cp = (char *)p; + size_t i = 0; + + s = s / CL_SIZE; /* mem size in cache llines */ + + for (i = 0; i < s; i++) + cl_flush(&cp[i * CL_SIZE]); + + sb(); +} + +static void *malloc_and_init_memory(size_t s) +{ + uint64_t *p64; + size_t s64; + + void *p = memalign(PAGE_SIZE, s); + + p64 = (uint64_t *)p; + s64 = s / sizeof(uint64_t); + + while (s64 > 0) { + *p64 = (uint64_t)rand(); + p64 += (CL_SIZE / sizeof(uint64_t)); + s64 -= (CL_SIZE / sizeof(uint64_t)); + } + + return p; +} + +static void fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr) +{ + while (1) { + unsigned char sum, *p; + + p = start_ptr; + /* Read two chars in each cache line to stress cache */ + while (p < (end_ptr - 1024)) { + sum += p[0] + p[32] + p[64] + p[96] + p[128] + + p[160] + p[192] + p[224] + p[256] + p[288] + + p[320] + p[352] + p[384] + p[416] + p[448] + + p[480] + p[512] + p[544] + p[576] + p[608] + + p[640] + p[672] + p[704] + p[736] + p[768] + + p[800] + p[832] + p[864] + p[896] + p[928] + + p[960] + p[992]; + p += 1024; + } + } +} + +static void fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr) +{ + while (1) { + while (start_ptr < end_ptr) { + *start_ptr = '1'; + start_ptr += (CL_SIZE / 2); + } + start_ptr = startptr; + } +} + +static void +fill_cache(unsigned long long buf_size, int malloc_and_init, + int memflush, int op) +{ + unsigned char *start_ptr, *end_ptr; + unsigned long long i; + + if (malloc_and_init) { + start_ptr = malloc_and_init_memory(buf_size); + printf("Started benchmark with memalign\n"); + } else { + start_ptr = malloc(buf_size); + printf("Started benchmark with malloc\n"); + } + + if (!start_ptr) + return; + + startptr = start_ptr; + end_ptr = start_ptr + buf_size; + + /* + * It's better to touch the memory once to avoid any compiler + * optimizations + */ + if (!malloc_and_init) { + for (i = 0; i < buf_size; i++) + *start_ptr++ = (unsigned char)rand(); + } + + start_ptr = startptr; + + /* Flush the memory before using to avoid "cache hot pages" effect */ + if (memflush) { + mem_flush(start_ptr, buf_size); + printf("Started benchmark with memflush\n"); + } else { + printf("Started benchmark *without* memflush\n"); + } + + if (op == 0) + fill_cache_read(start_ptr, end_ptr); + else + fill_cache_write(start_ptr, end_ptr); + + free(startptr); +} + +int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op) +{ + unsigned long long cache_size = span * MB; + + /* set up ctrl-c handler */ + if (signal(SIGINT, ctrl_handler) == SIG_ERR) + printf("Failed to catch SIGINT!\n"); + if (signal(SIGHUP, ctrl_handler) == SIG_ERR) + printf("Failed to catch SIGHUP!\n"); + + printf("Cache size in Bytes = %llu\n", cache_size); + + fill_cache(cache_size, malloc_and_init_memory, memflush, op); + + return -1; +} From patchwork Fri Jan 18 18:27:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AB466C5 for ; Fri, 18 Jan 2019 18:27:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7670429BD5 for ; Fri, 18 Jan 2019 18:27:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6983029BFC; Fri, 18 Jan 2019 18:27:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9160F29BD5 for ; Fri, 18 Jan 2019 18:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729093AbfARS1U (ORCPT ); Fri, 18 Jan 2019 13:27:20 -0500 Received: from mail-eopbgr700066.outbound.protection.outlook.com ([40.107.70.66]:43360 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728900AbfARS1T (ORCPT ); Fri, 18 Jan 2019 13:27:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oE91zWFA8bU77usMkHTAROAgWUtVlINyk3/kU5RIwbo=; b=F1rEXP7IvdFASqjVhRmM5XjaKKCfSwuXEzg7N4FvyXsYw6McjPw0GwObjd7Z57rjTIG9qoPwhKbxP5HcVPtora9Dz4V1wI4mbDVQRrrU+mi84MFhq7sOwmiXgqqdjNSu74RlP2E2emsBo38xoepvvJYqWsgM+xqin84YWPahWhE= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2376.namprd12.prod.outlook.com (52.132.141.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Fri, 18 Jan 2019 18:27:09 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:09 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 06/13] selftests/resctrl: Add MBM test Thread-Topic: [PATCH v5 06/13] selftests/resctrl: Add MBM test Thread-Index: AQHUr1tsA07g9caREkehNOLr8hN7VA== Date: Fri, 18 Jan 2019 18:27:09 +0000 Message-ID: <20190118182646.16594-7-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB2376;20:LhOZkt34iJcHFBfKFbb4p05G05ypMwjPi3YFVMbu7Pu3ouzzUFp3SW9vhcfPMttteLKrLYqQEhCRfbb2jMSBKckv8X/cTGSYIGBvjzcF8QDsSQ1dkdCuZtgydBJup661XjnN3OVFPrM+aPAVtEdfZIK3K975Zizjr0uNpI4XvdkyA3Cj68R5kxMSUoVdQNQHfhpZXRlL9h45K9QkmrG4JuRS5giMlBbYy5gTN7ZYv/6g7XoeNtY75Cf90nTGPJZ5 x-ms-office365-filtering-correlation-id: 404c334e-6166-4761-df64-08d67d728e76 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB2376; x-ms-traffictypediagnostic: DM5PR12MB2376: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(39860400002)(136003)(396003)(346002)(366004)(189003)(199004)(1076003)(25786009)(26005)(52116002)(4326008)(186003)(102836004)(2201001)(6506007)(76176011)(72206003)(86362001)(386003)(3846002)(71200400001)(71190400001)(256004)(14444005)(6486002)(54906003)(99286004)(305945005)(110136005)(6436002)(7736002)(486006)(6512007)(316002)(2616005)(446003)(2906002)(97736004)(476003)(11346002)(478600001)(7416002)(105586002)(53936002)(106356001)(81166006)(8936002)(8676002)(5660300001)(36756003)(68736007)(66066001)(6116002)(50226002)(14454004)(2501003)(81156014)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB2376;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: lluZGtBPL4iqbi/layl+eZsbmUguNBeF4qGnpGxvtu5OajZRAT/wrahCUIiki+Jt8Y1NUHdB/UWTP2t7yO4NxFOHon86xMGT0BM4hgMki7H3p+OO1rqP7JTnJ+x4boLsqy0mKagluJz2NQfq38XvYww8SnALLjglOAWMqIpoDyanNpaOEYPnombgb2b5C0etLDTr2V3LhqarERDemdC+SJ5bf5wF/tsKI1Cv53pRIEq6L3ljuwjl0VoyvqQiM7nv2Lg+p0e/2QFHyBHp7BqEwKAgiFoAGg7QO7zXGcyWQARYgJarFkv1IqqcisY5anaBWs77S/5PkvLrfRvKncypAXqlA0AzY+ZgFZFViTVeFIwzzCF4O6XB4mdW9HBu9JoZHleA4nmIob25evHSmFj43yEbzGgQC1p3qZ3rqID4UOY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 404c334e-6166-4761-df64-08d67d728e76 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:08.1277 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2376 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arshiya Hayatkhan Pathan MBM (Memory Bandwidth Monitoring) 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 "-b". 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 Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/Makefile | 8 +- tools/testing/selftests/resctrl/mbm_test.c | 145 ++++++++++++++++++++++++ tools/testing/selftests/resctrl/resctrl.h | 3 + tools/testing/selftests/resctrl/resctrl_tests.c | 123 ++++++++++++++++++++ tools/testing/selftests/resctrl/resctrl_val.c | 2 + 5 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/resctrl/mbm_test.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 bd5c541..eaa8b45 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 resctrlfs.o \ + resctrl_val.o fill_buf.o mbm_test.o + .PHONY: clean clean: - $(RM) *.o *~ + $(RM) *.o *~ resctrl_tests diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c new file mode 100644 index 0000000..fc1b8ba --- /dev/null +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -0,0 +1,145 @@ +// 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 "resctrl.h" + +#define RESULT_FILE_NAME "result_mbm" +#define MAX_DIFF 300 +#define NUM_OF_RUNS 5 + +static void +show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span) +{ + unsigned long avg_bw_imc = 0, avg_bw_resc = 0; + unsigned long sum_bw_imc = 0, sum_bw_resc = 0; + long avg_diff = 0; + int runs; + + /* + * Discard the first value which is inaccurate due to monitoring setup + * transition phase. + */ + for (runs = 1; runs < NUM_OF_RUNS ; runs++) { + sum_bw_imc += bw_imc[runs]; + sum_bw_resc += bw_resc[runs]; + } + + avg_bw_imc = sum_bw_imc / 4; + avg_bw_resc = sum_bw_resc / 4; + avg_diff = avg_bw_resc - avg_bw_imc; + + printf("\nSpan (MB): %d \t", span); + printf("avg_bw_imc: %lu\t", avg_bw_imc); + printf("avg_bw_resc: %lu\t", avg_bw_resc); + printf("avg_diff: %lu\t", labs(avg_diff)); + + if (labs(avg_diff) > MAX_DIFF) + printf(" failed\n"); + else + printf(" passed\n"); +} + +static int check_results(int span) +{ + unsigned long bw_imc[NUM_OF_RUNS], bw_resc[NUM_OF_RUNS]; + char temp[1024], *token_array[8]; + char output[] = RESULT_FILE_NAME; + int runs; + FILE *fp; + + printf("\nChecking for pass/fail\n"); + + fp = fopen(output, "r"); + if (!fp) { + perror("Error in opening file\n"); + + return errno; + } + + runs = 0; + while (fgets(temp, 1024, fp)) { + char *token = strtok(temp, ":\t"); + int i = 0; + + while (token) { + token_array[i++] = token; + token = strtok(NULL, ":\t"); + } + + bw_resc[runs] = atol(token_array[5]); + bw_imc[runs] = atol(token_array[3]); + runs++; + } + + show_bw_info(bw_imc, bw_resc, span); + + fclose(fp); + + return 0; +} + +static int mbm_setup(int num, ...) +{ + struct resctrl_val_param *p; + static int num_of_runs; + va_list param; + int ret = 0; + + /* Run NUM_OF_RUNS times */ + if (num_of_runs++ >= NUM_OF_RUNS) + return -1; + + va_start(param, num); + p = va_arg(param, struct resctrl_val_param *); + va_end(param); + + /* Set up shemata with 100% allocation on the first run. */ + if (num_of_runs == 0) + ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, + p->resctrl_val); + + return ret; +} + +void mbm_test_cleanup(void) +{ + remove(RESULT_FILE_NAME); +} + +int mbm_bw_change(int span, int core_id, char *bw_report, char **benchmark_cmd) +{ + struct resctrl_val_param param = { + .resctrl_val = "mbm", + .ctrlgrp = "c1", + .mongrp = "m1", + .span = span, + .cpu_no = core_id, + .mum_resctrlfs = 1, + .filename = RESULT_FILE_NAME, + .bw_report = bw_report, + .setup = mbm_setup + }; + int ret; + + remove(RESULT_FILE_NAME); + + ret = membw_val(benchmark_cmd, ¶m); + if (ret) + return ret; + + ret = check_results(span); + if (ret) + return ret; + + mbm_test_cleanup(); + + return 0; +} diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index f30a2dc..90d1fd1 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -70,5 +70,8 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op); int membw_val(char **benchmark_cmd, struct resctrl_val_param *param); +int mbm_bw_change(int span, int core_id, char *bw_report, char **benchmark_cmd); +void tests_cleanup(void); +void mbm_test_cleanup(void); #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 0000000..8a33809 --- /dev/null +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -0,0 +1,123 @@ +// 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" + +#define BENCHMARK_ARGS 64 +#define BENCHMARK_ARG_SIZE 64 + +int ben_count; + +static void cmd_help(void) +{ + printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list]\n"); + printf("\t-b benchmark_cmd [options]: run specified benchmark\n"); + printf("\t default benchmark is builtin fill_buf\n"); + printf("\t-t test list: run tests specified in the test list, "); + printf("e.g. -t mbm,mba\n"); + printf("\t-h: help\n"); +} + +void tests_cleanup(void) +{ + mbm_test_cleanup(); +} + +int main(int argc, char **argv) +{ + char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; + int res, c, core_id = 0, span = 250, argc_new = argc, i; + bool has_ben = false, mbm_test = true; + char *benchmark_cmd[BENCHMARK_ARGS]; + char bw_report[64], bm_type[64]; + + while ((c = getopt(argc_new, argv, "ht:b:")) != -1) { + char *token; + + switch (c) { + case 't': + token = strtok(optarg, ","); + + mbm_test = false; + while (token) { + if (!strcmp(token, "mbm")) { + mbm_test = true; + } else { + printf("invalid argument\n"); + + return -1; + } + token = strtok(NULL, ":\t"); + } + break; + case 'b': + /* Extract benchmark command from command line. */ + token = strtok(optarg, " "); + i = 0; + while (token) { + benchmark_cmd[i] = benchmark_cmd_area[i]; + strcpy(benchmark_cmd[i++], token); + if (i >= BENCHMARK_ARGS) { + printf("Too many benchmark args\n"); + + return -1; + } + token = strtok(NULL, " "); + } + benchmark_cmd[i] = NULL; + has_ben = true; + break; + case 'h': + cmd_help(); + + return 0; + default: + printf("invalid argument\n"); + + return -1; + } + } + + /* + * We need root privileges to run because + * 1. We write to resctrl FS + * 2. We execute perf commands + */ + if (geteuid() != 0) { + perror("Please run this program as root\n"); + + return errno; + } + + if (!has_ben) { + /* If no benchmark is given by "-b" argument, use fill_buf. */ + for (i = 0; i < 5; i++) + benchmark_cmd[i] = benchmark_cmd_area[i]; + 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"); + benchmark_cmd[5] = NULL; + } + + sprintf(bw_report, "reads"); + sprintf(bm_type, "fill_buf"); + + if (mbm_test) { + printf("\nMBM BW Change Starting..\n"); + res = mbm_bw_change(span, core_id, bw_report, benchmark_cmd); + if (res) + printf("Error in running tests for mbm bw change!\n"); + } + + return 0; +} diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 8b32595..86a513e 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -437,6 +437,8 @@ static unsigned long get_mem_bw_resctrl(void) static void ctrlc_handler(int signum, siginfo_t *info, void *ptr) { kill(bm_pid, SIGKILL); + umount_resctrlfs(); + tests_cleanup(); printf("Ending\n\n"); exit(EXIT_SUCCESS); From patchwork Fri Jan 18 18:27:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BBC66C5 for ; Fri, 18 Jan 2019 18:27:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4718B29BD5 for ; Fri, 18 Jan 2019 18:27:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A19D29BFC; Fri, 18 Jan 2019 18:27:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7075429BD5 for ; Fri, 18 Jan 2019 18:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729141AbfARS1Y (ORCPT ); Fri, 18 Jan 2019 13:27:24 -0500 Received: from mail-eopbgr700066.outbound.protection.outlook.com ([40.107.70.66]:43360 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729089AbfARS1Y (ORCPT ); Fri, 18 Jan 2019 13:27:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1KX1C6YmJlpwjj8W8GTxcZPo4WqoaKL66XbTBz0nuH8=; b=cj8acWLNdx5PC9GSortBm5pkKgZWM/CbAhjeq6h1VSzKMbM0UcfrYx554sNstsGKYraoefMjvAiRrR8Zeimydy7y2EAvsYqpFefJXO/Y0ZmtRxkaYAT+AK66TjuVHPKh/64yOh/wXx0XC8AbM1VsOocaSJ1karFchsEsMCQ0PPY= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2376.namprd12.prod.outlook.com (52.132.141.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Fri, 18 Jan 2019 18:27:10 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:10 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 07/13] selftests/resctrl: Add MBA test Thread-Topic: [PATCH v5 07/13] selftests/resctrl: Add MBA test Thread-Index: AQHUr1ts8ZJ2ptqirkuWPe/Cdr5bPA== Date: Fri, 18 Jan 2019 18:27:10 +0000 Message-ID: <20190118182646.16594-8-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB2376;20:HzxuwIdjrzYF/sfzX1xVpQI5O9YeX11WgeXlEiIKPW+912xWhu6wyp8pNqLvOmNx4IDNW3HAeZb95OufvlD1U4RrMqk9xOksDSLwDf1ZUWBnEa3VS6v+X7No4SkxWUHhnDQtvt6PYM4UjVQ3d5abcsWUuwk7XiEqtxCtm3TE0wSm+cgC5yGbaAJg78pW7z8U2Z+O98KO8KRcfutTCa+EqDZ7dVRsOxwSWDWYsRMmQu3H5a1apSbbXbTrYBdOuxwT x-ms-office365-filtering-correlation-id: 3182eeb2-5a6a-4ea4-12f8-08d67d728f2c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB2376; x-ms-traffictypediagnostic: DM5PR12MB2376: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(39860400002)(136003)(396003)(346002)(366004)(189003)(199004)(1076003)(25786009)(26005)(52116002)(4326008)(186003)(102836004)(2201001)(6506007)(76176011)(72206003)(86362001)(386003)(3846002)(71200400001)(71190400001)(256004)(14444005)(6486002)(54906003)(99286004)(305945005)(110136005)(6436002)(7736002)(486006)(6512007)(316002)(2616005)(446003)(2906002)(97736004)(476003)(11346002)(478600001)(7416002)(105586002)(53936002)(106356001)(81166006)(8936002)(8676002)(5660300001)(36756003)(68736007)(66066001)(6116002)(50226002)(14454004)(2501003)(81156014)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB2376;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: BUHK5s1hXm87jM35oWgJSw1KxQKTaoFXCSxDOKazOmh1veNUi2waBHTO7aNhqy8tly7zNxpP2wxQ3qu/H8ulxVB/0VZpGJIv6SjYf6825j8aJ1sinAS8ICfT81xgR2JMXBQMaZuRj+ZgFinwT/ydrolzTgDgFuXKWrMW3b/kO0W+6pXtBvPT5ghZnc8ATrTnCRXfAfZ9YqNuMQjytzrHLok9UXqcGrM2Ne5jY1Y3XeIXhP7B+Kh6qi7fj4Qyi/TSsQR/9ZITDszYs6e3bsMhqZ1fg3ABFTHcdCZRSsTTtYar0/Yy79TzHlW9h18Dbx8a+Q5et9CSQjJq0WD1qjCF5yrCzUtonnHLbk+BNP0g1NlXD3tk6+W7L5wpP5CkfSpeJXuFnw8rNPdFu543tl4Y70XHwQLTf97BY3/ZQ733k0I= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3182eeb2-5a6a-4ea4-12f8-08d67d728f2c X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:09.3152 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2376 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arshiya Hayatkhan Pathan MBA (Memory Bandwidth Allocation) 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 "-b". 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 Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/Makefile | 2 +- tools/testing/selftests/resctrl/mba_test.c | 173 ++++++++++++++++++++++++ tools/testing/selftests/resctrl/resctrl.h | 2 + tools/testing/selftests/resctrl/resctrl_tests.c | 15 +- 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/resctrl/mba_test.c diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile index eaa8b45..141cbdb 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 \ - resctrl_val.o fill_buf.o mbm_test.o + resctrl_val.o fill_buf.o mbm_test.o mba_test.o .PHONY: clean diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c new file mode 100644 index 0000000..7a5d869 --- /dev/null +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -0,0 +1,173 @@ +// 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 "resctrl.h" + +#define RESULT_FILE_NAME "result_mba" +#define NUM_OF_RUNS 5 +#define MAX_DIFF 300 +#define ALLOCATION_MAX 100 +#define ALLOCATION_MIN 10 +#define ALLOCATION_STEP 10 + +/* + * Change schemata percentage from 100 to 10%. Write schemata to specified + * con_mon grp, mon_grp in resctrl FS. + * For each allocation, run 5 times in order to get average values. + */ +static int mba_setup(int num, ...) +{ + static int runs_per_allocation, allocation = 100; + struct resctrl_val_param *p; + char allocation_str[64]; + va_list param; + + va_start(param, num); + p = va_arg(param, struct resctrl_val_param *); + va_end(param); + + if (runs_per_allocation >= NUM_OF_RUNS) + runs_per_allocation = 0; + + /* Only set up schemata once every NUM_OF_RUNS of allocations */ + if (runs_per_allocation++ != 0) + return 0; + + if (allocation < ALLOCATION_MIN || allocation > ALLOCATION_MAX) + return -1; + + sprintf(allocation_str, "%d", allocation); + + write_schemata(p->ctrlgrp, allocation_str, p->cpu_no, p->resctrl_val); + printf("changed schemata to : %d\n", allocation); + allocation -= ALLOCATION_STEP; + + return 0; +} + +static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) +{ + int allocation, failed = 0, runs; + + /* Memory bandwidth from 100% down to 10% */ + for (allocation = 0; allocation < ALLOCATION_MAX / ALLOCATION_STEP; + allocation++) { + unsigned long avg_bw_imc = 0, avg_bw_resc = 0; + unsigned long sum_bw_imc = 0, sum_bw_resc = 0; + long avg_diff = 0; + + /* + * The first run is discarded due to inaccurate value from + * phase transition. + */ + for (runs = NUM_OF_RUNS * allocation + 1; + runs < NUM_OF_RUNS * allocation + NUM_OF_RUNS ; runs++) { + sum_bw_imc += bw_imc[runs]; + sum_bw_resc += bw_resc[runs]; + } + + avg_bw_imc = sum_bw_imc / (NUM_OF_RUNS - 1); + avg_bw_resc = sum_bw_resc / (NUM_OF_RUNS - 1); + avg_diff = avg_bw_resc - avg_bw_imc; + + printf("\nschemata percentage: %d \t", + ALLOCATION_MAX - ALLOCATION_STEP * allocation); + printf("avg_bw_imc: %lu\t", avg_bw_imc); + printf("avg_bw_resc: %lu\t", avg_bw_resc); + printf("avg_diff: %lu\t", labs(avg_diff)); + if (labs(avg_diff) > MAX_DIFF) { + 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"); + } +} + +static int check_results(void) +{ + char *token_array[8], output[] = RESULT_FILE_NAME, temp[512]; + unsigned long bw_imc[1024], bw_resc[1024]; + int runs; + FILE *fp; + + printf("\nchecking for pass/fail\n"); + fp = fopen(output, "r"); + if (!fp) { + perror("Error in opening file\n"); + + return errno; + } + + runs = 0; + while (fgets(temp, 1024, fp)) { + char *token = strtok(temp, ":\t"); + int fields = 0; + + while (token) { + token_array[fields++] = token; + token = strtok(NULL, ":\t"); + } + + /* Field 3 is perf imc value */ + bw_imc[runs] = atol(token_array[3]); + /* Field 5 is resctrl value */ + bw_resc[runs] = atol(token_array[5]); + runs++; + } + + fclose(fp); + + show_mba_info(bw_imc, bw_resc); + + return 0; +} + +void mba_test_cleanup(void) +{ + remove(RESULT_FILE_NAME); +} + +int mba_schemata_change(int core_id, char *bw_report, char **benchmark_cmd) +{ + struct resctrl_val_param param = { + .resctrl_val = "mba", + .ctrlgrp = "c1", + .mongrp = "m1", + .cpu_no = core_id, + .mum_resctrlfs = 1, + .filename = RESULT_FILE_NAME, + .bw_report = bw_report, + .setup = mba_setup + }; + int ret; + + remove(RESULT_FILE_NAME); + + ret = membw_val(benchmark_cmd, ¶m); + if (ret) + return ret; + + ret = check_results(); + if (ret) + return ret; + + mba_test_cleanup(); + + return 0; +} diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 90d1fd1..f54a034 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -73,5 +73,7 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int mbm_bw_change(int span, int core_id, char *bw_report, char **benchmark_cmd); void tests_cleanup(void); void mbm_test_cleanup(void); +int mba_schemata_change(int core_id, char *bw_report, char **benchmark_cmd); +void mba_test_cleanup(void); #endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 8a33809..e4d00fb 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -29,13 +29,14 @@ static void cmd_help(void) void tests_cleanup(void) { mbm_test_cleanup(); + mba_test_cleanup(); } int main(int argc, char **argv) { char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; int res, c, core_id = 0, span = 250, argc_new = argc, i; - bool has_ben = false, mbm_test = true; + bool has_ben = false, mbm_test = true, mba_test = true; char *benchmark_cmd[BENCHMARK_ARGS]; char bw_report[64], bm_type[64]; @@ -47,9 +48,12 @@ int main(int argc, char **argv) token = strtok(optarg, ","); mbm_test = false; + mba_test = false; while (token) { if (!strcmp(token, "mbm")) { mbm_test = true; + } else if (!strcmp(token, "mba")) { + mba_test = true; } else { printf("invalid argument\n"); @@ -119,5 +123,14 @@ int main(int argc, char **argv) printf("Error in running tests for mbm bw change!\n"); } + if (mba_test) { + printf("\nMBA Schemata Change Starting..\n"); + if (!has_ben) + sprintf(benchmark_cmd[1], "%d", span); + res = mba_schemata_change(core_id, bw_report, benchmark_cmd); + if (res) + printf("Error in tests for mba-change-schemata!\n"); + } + return 0; } From patchwork Fri Jan 18 18:27:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C823139A for ; Fri, 18 Jan 2019 18:27:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15C0B29BD5 for ; Fri, 18 Jan 2019 18:27:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0883829BFC; Fri, 18 Jan 2019 18:27:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFA4D29BD5 for ; Fri, 18 Jan 2019 18:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729089AbfARS1c (ORCPT ); Fri, 18 Jan 2019 13:27:32 -0500 Received: from mail-eopbgr700066.outbound.protection.outlook.com ([40.107.70.66]:43360 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729139AbfARS11 (ORCPT ); Fri, 18 Jan 2019 13:27:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=it7AaTxRlcq88z3J3Gg1T0zfXX7N33goAW8cusJ4lvo=; b=TKZBsRoVPPFDDUUIrnn5t0n5ld8jPMCGU6UgLl3zfsr3dSM84ZKTRfAHHSAZ762QZJgzX/erITUkI2IPAzWouO58/dcaAS2Bl3dmk36CfBXk/dkLY1N4Litn5v9vXKYnQNXWFCUz445WCUVz5nzQIc0e9yj+oE+ObPIcQtuvzWc= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2376.namprd12.prod.outlook.com (52.132.141.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.24; Fri, 18 Jan 2019 18:27:11 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:11 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 08/13] selftests/resctrl Add Cache QoS Monitoring (CQM) selftest Thread-Topic: [PATCH v5 08/13] selftests/resctrl Add Cache QoS Monitoring (CQM) selftest Thread-Index: AQHUr1tt1V9Rke6C/U2tVePdjBaWbw== Date: Fri, 18 Jan 2019 18:27:11 +0000 Message-ID: <20190118182646.16594-9-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB2376;20:j3Rl//CXUkgAXCIXLZZ0w2dGplNhcTTQbyzgvLx91FWg8OkIIe4Sz03f6OCrMmGfVunRY0ys8r0tvrepYzsKXbVL0Qbfpeb7JpOhgz84p8lxwZd6IJHIXrY9O38f5FjGFlwqP3qtcU6NInVfK83b2hgxsT0XQgDBnSWTN62BffT5p3ytVgrUhb8f88Rc9/s0ZwqsnN2bWg8sFUrV9FkU4opPle5VwBV7tWz11FeLXiDLJ103b25Zcwx79Ai6/qnA x-ms-office365-filtering-correlation-id: 11a383f9-f696-46da-5978-08d67d728ff4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB2376; x-ms-traffictypediagnostic: DM5PR12MB2376: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(39860400002)(136003)(396003)(346002)(366004)(189003)(199004)(1076003)(25786009)(26005)(52116002)(4326008)(186003)(102836004)(2201001)(6506007)(76176011)(72206003)(86362001)(386003)(3846002)(71200400001)(71190400001)(256004)(14444005)(6486002)(54906003)(99286004)(305945005)(110136005)(6436002)(7736002)(486006)(6512007)(316002)(2616005)(446003)(2906002)(97736004)(476003)(11346002)(478600001)(7416002)(105586002)(53946003)(53936002)(106356001)(81166006)(8936002)(8676002)(5660300001)(36756003)(30864003)(68736007)(66066001)(6116002)(50226002)(14454004)(2501003)(81156014)(921003)(1121003)(579004)(569006);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB2376;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 1o8T2p+c40QdCGd/9Ye707qWc1HaCT4EE24AsMWjd5TUfLT9spMA6Cbdkxa2q2oQuBygOg1aZfneVJVdvAAfNXcdbBjEkDnCc2CEhnuND9+aBtP3sXAzwJpKytN4kx+4YoK/SQ1KSRjZzCpJM2b2uX9oFXwOsO5ulie6k17BwqaugUYAol6Osr+KHy7ryWrdPHPZXa5vv27b5EJ5hysRRLfwTSVlx8JrnrKdSoqMekwH9Gs6CdGdFxkLj+7HJLmKZ17fzDnZR+EZIAB9W/dJ6+Bt7gIiEqhu5XoLyEJTrE3wRDDGmJm5NG6DsA9NZQtceDSPMuy2oyCZ1I6nPYwiSzr9qMng6vkRWCqoTB9qXgbfClfXmx5ShS+ANo1dVPAims4PFj5S7kKKoXEhiFffGr4QzQEZH2fORfjJRyzlqlY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11a383f9-f696-46da-5978-08d67d728ff4 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:10.6278 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2376 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Babu Moger --- 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 | 28 ++- tools/testing/selftests/resctrl/resctrl_tests.c | 82 ++++++--- tools/testing/selftests/resctrl/resctrl_val.c | 101 ++++++----- tools/testing/selftests/resctrl/resctrlfs.c | 217 ++++++++++++++++++++++-- 10 files changed, 679 insertions(+), 135 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 141cbdb..664561c 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 \ - resctrl_val.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 0000000..1256590 --- /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(&llc_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 0000000..cddee36 --- /dev/null +++ b/tools/testing/selftests/resctrl/cqm_test.c @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cache Monitoring Technology (CQM) test + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ +#include "resctrl.h" +#include + +#define RESULT_FILE_NAME "result_cqm" +#define NUM_OF_RUNS 5 +#define MAX_DIFF 2000000 +#define MAX_DIFF_PERCENT 15 + +int count_of_bits; +char cbm_mask[256]; +unsigned long long_mask; +unsigned long cache_size; + +static int cqm_setup(int num, ...) +{ + struct resctrl_val_param *p; + va_list param; + + va_start(param, num); + p = va_arg(param, struct resctrl_val_param *); + va_end(param); + + /* Run NUM_OF_RUNS times */ + if (p->num_of_runs >= NUM_OF_RUNS) + return -1; + + p->num_of_runs++; + + return 0; +} + +static void show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits, + unsigned long span) +{ + unsigned long avg_llc_occu_resc = 0; + long avg_diff = 0; + float diff_percent; + + avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1); + avg_diff = (long long)abs(span - avg_llc_occu_resc); + + printf("\nResults are displayed in (Bytes)\n"); + printf("\nNumber of bits: %d \t", no_of_bits); + printf("Avg_llc_occu_resc: %lu \t", avg_llc_occu_resc); + printf("llc_occu_exp (span): %lu \t", span); + + diff_percent = (((float)span - avg_llc_occu_resc) / span) * 100; + + printf("Diff: %ld \t", avg_diff); + printf("Percent diff=%d\t", abs((int)diff_percent)); + + if ((abs((int)diff_percent) <= MAX_DIFF_PERCENT) || + (abs(avg_diff) <= MAX_DIFF)) + printf("Passed\n"); + else + printf("Failed\n"); +} + +static int check_results(struct resctrl_val_param *param, int no_of_bits) +{ + char *token_array[8], temp[512]; + unsigned long sum_llc_occu_resc = 0; + int runs = 0; + FILE *fp; + + printf("\nchecking for pass/fail\n"); + fp = fopen(param->filename, "r"); + if (!fp) { + perror("Error in opening file\n"); + + return errno; + } + + while (fgets(temp, 1024, fp)) { + char *token = strtok(temp, ":\t"); + int fields = 0; + + while (token) { + token_array[fields++] = token; + token = strtok(NULL, ":\t"); + } + + /* Field 3 is llc occ resc value */ + if (runs > 0) + sum_llc_occu_resc += atol(token_array[3]); + runs++; + } + fclose(fp); + show_cache_info(sum_llc_occu_resc, no_of_bits, param->span); + + return 0; +} + +void cqm_test_cleanup(void) +{ + remove(RESULT_FILE_NAME); +} + +int cqm_resctrl_val(int core_id, int n, char **benchmark_cmd) +{ + int ret, mum_resctrlfs; + + cache_size = 0; + mum_resctrlfs = 1; + + ret = remount_resctrlfs(mum_resctrlfs); + if (ret) + return ret; + + ret = get_cbm_mask("L3"); + if (ret) + return ret; + + long_mask = strtoul(cbm_mask, NULL, 16); + + ret = get_cache_size(core_id, 3, &cache_size); + if (ret) + return ret; + printf("cache size :%lu\n", cache_size); + + count_of_bits = count_bits(long_mask); + + if (n < 1 || n > count_of_bits) { + printf("Invalid input value for numbr_of_bits n!\n"); + printf("Please Enter value in range 1 to %d\n", count_of_bits); + return -1; + } + + struct resctrl_val_param param = { + .resctrl_val = "cqm", + .ctrlgrp = "c1", + .mongrp = "m1", + .cpu_no = core_id, + .mum_resctrlfs = 0, + .filename = RESULT_FILE_NAME, + .mask = ~(long_mask << n) & long_mask, + .span = cache_size * n / count_of_bits, + .num_of_runs = 0, + .setup = cqm_setup, + }; + + if (strcmp(benchmark_cmd[0], "fill_buf") == 0) + sprintf(benchmark_cmd[1], "%llu", param.span); + + remove(RESULT_FILE_NAME); + + ret = resctrl_val(benchmark_cmd, ¶m); + if (ret) + return ret; + + ret = check_results(¶m, n); + if (ret) + return ret; + + cqm_test_cleanup(); + + return 0; +} diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index d9950b5..7c3579a 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -78,54 +78,63 @@ static void *malloc_and_init_memory(size_t s) return p; } -static void fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr) +static void fill_one_span_read(unsigned char *start_ptr, unsigned char *end_ptr) { - while (1) { - unsigned char sum, *p; - - p = start_ptr; - /* Read two chars in each cache line to stress cache */ - while (p < (end_ptr - 1024)) { - sum += p[0] + p[32] + p[64] + p[96] + p[128] + - p[160] + p[192] + p[224] + p[256] + p[288] + - p[320] + p[352] + p[384] + p[416] + p[448] + - p[480] + p[512] + p[544] + p[576] + p[608] + - p[640] + p[672] + p[704] + p[736] + p[768] + - p[800] + p[832] + p[864] + p[896] + p[928] + - p[960] + p[992]; - p += 1024; - } + unsigned char sum, *p; + + sum = 0; + p = start_ptr; + while (p < end_ptr) { + sum += *p; + p += (CL_SIZE / 2); } } -static void fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr) +static +void fill_one_span_write(unsigned char *start_ptr, unsigned char *end_ptr) { - while (1) { - while (start_ptr < end_ptr) { - *start_ptr = '1'; - start_ptr += (CL_SIZE / 2); - } - start_ptr = startptr; + unsigned char *p; + + p = start_ptr; + while (p < end_ptr) { + *p = '1'; + p += (CL_SIZE / 2); } } -static void -fill_cache(unsigned long long buf_size, int malloc_and_init, - int memflush, int op) +static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, + char *resctrl_val) +{ + while (1) + fill_one_span_read(start_ptr, end_ptr); + + return 0; +} + +static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, + char *resctrl_val) +{ + while (1) + fill_one_span_write(start_ptr, end_ptr); + + return 0; +} + +static int +fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, + int op, char *resctrl_val) { unsigned char *start_ptr, *end_ptr; unsigned long long i; + int ret; - if (malloc_and_init) { + if (malloc_and_init) start_ptr = malloc_and_init_memory(buf_size); - printf("Started benchmark with memalign\n"); - } else { + else start_ptr = malloc(buf_size); - printf("Started benchmark with malloc\n"); - } if (!start_ptr) - return; + return -1; startptr = start_ptr; end_ptr = start_ptr + buf_size; @@ -142,24 +151,29 @@ static void fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr) start_ptr = startptr; /* Flush the memory before using to avoid "cache hot pages" effect */ - if (memflush) { + if (memflush) mem_flush(start_ptr, buf_size); - printf("Started benchmark with memflush\n"); - } else { - printf("Started benchmark *without* memflush\n"); - } if (op == 0) - fill_cache_read(start_ptr, end_ptr); + ret = fill_cache_read(start_ptr, end_ptr, resctrl_val); else - fill_cache_write(start_ptr, end_ptr); + ret = fill_cache_write(start_ptr, end_ptr, resctrl_val); + + if (ret) { + printf("\n Errror in fill cache read/write...\n"); + return -1; + } free(startptr); + + return 0; } -int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op) +int run_fill_buf(unsigned long long span, int malloc_and_init_memory, + int memflush, int op, char *resctrl_val) { - unsigned long long cache_size = span * MB; + unsigned long long cache_size = span; + int ret; /* set up ctrl-c handler */ if (signal(SIGINT, ctrl_handler) == SIG_ERR) @@ -167,9 +181,12 @@ int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op) if (signal(SIGHUP, ctrl_handler) == SIG_ERR) printf("Failed to catch SIGHUP!\n"); - printf("Cache size in Bytes = %llu\n", cache_size); - - fill_cache(cache_size, malloc_and_init_memory, memflush, op); + ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op, + resctrl_val); + if (ret) { + printf("\n Errror in fill cache\n"); + return -1; + } - return -1; + return 0; } diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 7a5d869..66be852 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -57,6 +57,7 @@ static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) { int allocation, failed = 0, runs; + printf("\nResults are displayed in (MB)\n"); /* Memory bandwidth from 100% down to 10% */ for (allocation = 0; allocation < ALLOCATION_MAX / ALLOCATION_STEP; allocation++) { @@ -159,7 +160,7 @@ int mba_schemata_change(int core_id, char *bw_report, char **benchmark_cmd) remove(RESULT_FILE_NAME); - ret = membw_val(benchmark_cmd, ¶m); + ret = resctrl_val(benchmark_cmd, ¶m); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index fc1b8ba..ce3eab1 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -36,6 +36,7 @@ avg_bw_resc = sum_bw_resc / 4; avg_diff = avg_bw_resc - avg_bw_imc; + printf("\nResults are displayed in (MB)\n"); printf("\nSpan (MB): %d \t", span); printf("avg_bw_imc: %lu\t", avg_bw_imc); printf("avg_bw_resc: %lu\t", avg_bw_resc); @@ -131,7 +132,7 @@ int mbm_bw_change(int span, int core_id, char *bw_report, char **benchmark_cmd) remove(RESULT_FILE_NAME); - ret = membw_val(benchmark_cmd, ¶m); + ret = resctrl_val(benchmark_cmd, ¶m); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index f54a034..a4f8040 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -16,11 +16,18 @@ #include #include #include +#include #include #include +#include +#include +#include +#include +#define MB (1024 * 1024) #define RESCTRL_PATH "/sys/fs/resctrl" #define PHYS_ID_PATH "/sys/devices/system/cpu/cpu" +#define CBM_MASK_PATH "/sys/fs/resctrl/info" #define PARENT_EXIT(err_msg) \ do { \ @@ -46,14 +53,20 @@ struct resctrl_val_param { char ctrlgrp[64]; char mongrp[64]; int cpu_no; - int span; + unsigned long long span; int mum_resctrlfs; char filename[64]; char *bw_report; + unsigned long mask; + int num_of_runs; int (*setup)(int num, ...); + }; pid_t bm_pid, ppid; +extern char cbm_mask[256]; +extern unsigned long long_mask; +extern char llc_occup_path[1024]; int remount_resctrlfs(bool mum_resctrlfs); int get_resource_id(int cpu_no, int *resource_id); @@ -68,12 +81,21 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, char *resctrl_val); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); -int run_fill_buf(int span, int malloc_and_init_memory, int memflush, int op); -int membw_val(char **benchmark_cmd, struct resctrl_val_param *param); +int run_fill_buf(unsigned long long span, int malloc_and_init_memory, + int memflush, int op, char *resctrl_val); +int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param); int mbm_bw_change(int span, int core_id, char *bw_report, char **benchmark_cmd); void tests_cleanup(void); void mbm_test_cleanup(void); int mba_schemata_change(int core_id, char *bw_report, char **benchmark_cmd); void mba_test_cleanup(void); +int get_cbm_mask(char *cache_type); +int get_cache_size(int cpu_no, int cache_num, unsigned long *cache_size); +void ctrlc_handler(int signum, siginfo_t *info, void *ptr); +int cqm_resctrl_val(int core_id, int n, char **benchmark_cmd); +unsigned int count_bits(unsigned long n); +void cqm_test_cleanup(void); +int get_core_sibling(int cpu_no); +int measure_cache_vals(struct resctrl_val_param *param, int bm_pid); #endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index e4d00fb..6d4a1cf 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -14,15 +14,14 @@ #define BENCHMARK_ARGS 64 #define BENCHMARK_ARG_SIZE 64 -int ben_count; - static void cmd_help(void) { - printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list]\n"); - printf("\t-b benchmark_cmd [options]: run specified benchmark\n"); + printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n"); + printf("\t-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM"); printf("\t default benchmark is builtin fill_buf\n"); printf("\t-t test list: run tests specified in the test list, "); - printf("e.g. -t mbm,mba\n"); + printf("e.g. -t mbm, mba, cqm\n"); + printf("\t-n no_of_bits: run cache tests using specified no of bits in cache bit mask\n"); printf("\t-h: help\n"); } @@ -30,17 +29,30 @@ void tests_cleanup(void) { mbm_test_cleanup(); mba_test_cleanup(); + cqm_test_cleanup(); } int main(int argc, char **argv) { char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; - int res, c, core_id = 0, span = 250, argc_new = argc, i; + int res, c, core_id = 1, span = 250, argc_new = argc, i, no_of_bits = 5; + int ben_count, ben_ind; bool has_ben = false, mbm_test = true, mba_test = true; + bool cqm_test = true; char *benchmark_cmd[BENCHMARK_ARGS]; char bw_report[64], bm_type[64]; - while ((c = getopt(argc_new, argv, "ht:b:")) != -1) { + for (i = 0; i < argc; i++) { + if (strcmp(argv[i], "-b") == 0) { + ben_ind = i + 1; + ben_count = argc - ben_ind; + argc_new = ben_ind - 1; + has_ben = 1; + break; + } + } + + while ((c = getopt(argc_new, argv, "ht:n:p:")) != -1) { char *token; switch (c) { @@ -49,11 +61,14 @@ int main(int argc, char **argv) mbm_test = false; mba_test = false; + cqm_test = false; while (token) { if (!strcmp(token, "mbm")) { mbm_test = true; } else if (!strcmp(token, "mba")) { mba_test = true; + } else if (!strcmp(token, "cqm")) { + cqm_test = true; } else { printf("invalid argument\n"); @@ -62,22 +77,11 @@ int main(int argc, char **argv) token = strtok(NULL, ":\t"); } break; - case 'b': - /* Extract benchmark command from command line. */ - token = strtok(optarg, " "); - i = 0; - while (token) { - benchmark_cmd[i] = benchmark_cmd_area[i]; - strcpy(benchmark_cmd[i++], token); - if (i >= BENCHMARK_ARGS) { - printf("Too many benchmark args\n"); - - return -1; - } - token = strtok(NULL, " "); - } - benchmark_cmd[i] = NULL; - has_ben = true; + case 'n': + no_of_bits = atoi(optarg); + break; + case 'p': + core_id = atoi(optarg); break; case 'h': cmd_help(); @@ -101,16 +105,26 @@ int main(int argc, char **argv) return errno; } - if (!has_ben) { + if (has_ben) { + /* Extract benchmark command from command line. */ + for (i = ben_ind; i < argc; i++) { + benchmark_cmd[i - ben_ind] = benchmark_cmd_area[i]; + sprintf(benchmark_cmd[i - ben_ind], "%s", argv[i]); + } + benchmark_cmd[ben_count] = benchmark_cmd_area[ben_count]; + sprintf(benchmark_cmd[ben_count], "%s", "NULL"); + } else { /* If no benchmark is given by "-b" argument, use fill_buf. */ - for (i = 0; i < 5; i++) + for (i = 0; i < 6; i++) benchmark_cmd[i] = benchmark_cmd_area[i]; + 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"); - benchmark_cmd[5] = NULL; + strcpy(benchmark_cmd[5], ""); + benchmark_cmd[6] = NULL; } sprintf(bw_report, "reads"); @@ -118,18 +132,32 @@ int main(int argc, char **argv) if (mbm_test) { printf("\nMBM BW Change Starting..\n"); + if (!has_ben) + sprintf(benchmark_cmd[5], "%s", "mbm"); res = mbm_bw_change(span, core_id, bw_report, benchmark_cmd); if (res) printf("Error in running tests for mbm bw change!\n"); + mbm_test_cleanup(); } if (mba_test) { printf("\nMBA Schemata Change Starting..\n"); if (!has_ben) - sprintf(benchmark_cmd[1], "%d", span); + sprintf(benchmark_cmd[5], "%s", "mba"); res = mba_schemata_change(core_id, bw_report, benchmark_cmd); if (res) printf("Error in tests for mba-change-schemata!\n"); + mba_test_cleanup(); + } + + if (cqm_test) { + printf("\nCQM Test Starting..\n"); + if (!has_ben) + sprintf(benchmark_cmd[5], "%s", "cqm"); + res = cqm_resctrl_val(core_id, no_of_bits, benchmark_cmd); + if (res) + printf("Error in CQM test!\n"); + cqm_test_cleanup(); } return 0; diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 86a513e..e33f2ec 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -11,7 +11,6 @@ */ #include "resctrl.h" -#define MB (1024 * 1024) #define UNCORE_IMC "uncore_imc" #define READ_FILE_NAME "events/cas_count_read" #define WRITE_FILE_NAME "events/cas_count_write" @@ -33,6 +32,18 @@ #define MBM_LOCAL_BYTES_PATH \ "%s/mon_data/mon_L3_%02d/mbm_local_bytes" +#define CON_MON_LCC_OCCUP_PATH \ + "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" + +#define CON_LCC_OCCUP_PATH \ + "%s/%s/mon_data/mon_L3_%02d/llc_occupancy" + +#define MON_LCC_OCCUP_PATH \ + "%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" + +#define LCC_OCCUP_PATH \ + "%s/mon_data/mon_L3_%02d/llc_occupancy" + struct membw_read_format { __u64 value; /* The value of the event */ __u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */ @@ -207,12 +218,12 @@ static int read_from_imc_dir(char *imc_dir, int count) * A config again has two parts, event and umask. * Enumerate all these details into an array of structures. * - * Return: >= 0 on success. < 0 on failure. + * Return: > 0 on success. <= 0 on failure. */ static int num_of_imcs(void) { unsigned int count = 0; - char imc_dir[1024]; + char imc_dir[512]; struct dirent *ep; int ret; DIR *dp; @@ -434,16 +445,6 @@ static unsigned long get_mem_bw_resctrl(void) pid_t bm_pid, ppid; -static void ctrlc_handler(int signum, siginfo_t *info, void *ptr) -{ - kill(bm_pid, SIGKILL); - umount_resctrlfs(); - tests_cleanup(); - printf("Ending\n\n"); - - exit(EXIT_SUCCESS); -} - /* * print_results_bw: the memory bandwidth results are stored in a file * @filename: file that stores the results @@ -482,6 +483,42 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc, return 0; } +static void set_cqm_path(const char *ctrlgrp, const char *mongrp, char sock_num) +{ + if (strlen(ctrlgrp) && strlen(mongrp)) + sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH, + ctrlgrp, mongrp, sock_num); + else if (!strlen(ctrlgrp) && strlen(mongrp)) + sprintf(llc_occup_path, MON_LCC_OCCUP_PATH, RESCTRL_PATH, + mongrp, sock_num); + else if (strlen(ctrlgrp) && !strlen(mongrp)) + sprintf(llc_occup_path, CON_LCC_OCCUP_PATH, RESCTRL_PATH, + ctrlgrp, sock_num); + else if (!strlen(ctrlgrp) && !strlen(mongrp)) + sprintf(llc_occup_path, LCC_OCCUP_PATH, RESCTRL_PATH, sock_num); +} + +/* + * initialize_llc_occu_resctrl: Appropriately populate "llc_occup_path" + * @ctrlgrp: Name of the control monitor group (con_mon grp) + * @mongrp: Name of the monitor group (mon grp) + * @cpu_no: CPU number that the benchmark PID is binded to + * @resctrl_val: Resctrl feature (Eg: cat, cqm.. etc) + */ +static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp, + int cpu_no, char *resctrl_val) +{ + int resource_id; + + if (get_resource_id(cpu_no, &resource_id) < 0) { + perror("Unable to resource_id"); + return; + } + + if (strcmp(resctrl_val, "cqm") == 0) + set_cqm_path(ctrlgrp, mongrp, resource_id); +} + static int measure_vals(struct resctrl_val_param *param, unsigned long *bw_resc_start) { @@ -514,28 +551,24 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc, } /* - * membw_val: execute benchmark and measure memory bandwidth on + * resctrl_val: execute benchmark and measure memory bandwidth on * the benchmark * @benchmark_cmd: benchmark command and its arguments - * @param: parameters passed to membw_val() + * @param: parameters passed to resctrl_val() * * Return: 0 on success. non-zero on failure. */ -int membw_val(char **benchmark_cmd, struct resctrl_val_param *param) +int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) { int ret = 0, pipefd[2], pipe_message = 0; char *resctrl_val = param->resctrl_val; unsigned long bw_resc_start = 0; struct sigaction sigact; union sigval value; - FILE *fp; if (strcmp(param->filename, "") == 0) sprintf(param->filename, "stdio"); - if (strcmp(param->bw_report, "") == 0) - param->bw_report = "total"; - ret = validate_resctrl_feature_request(resctrl_val); if (ret) return ret; @@ -557,21 +590,6 @@ int membw_val(char **benchmark_cmd, struct resctrl_val_param *param) */ ppid = getpid(); - /* File based synchronization between parent and child */ - fp = fopen("sig", "w"); - if (!fp) { - perror("Failed to open sig file"); - - return -1; - } - if (fprintf(fp, "%d\n", 0) <= 0) { - perror("Unable to establish sync bw parent & child"); - fclose(fp); - - return -1; - } - fclose(fp); - if (pipe(pipefd)) { perror("Unable to create pipe"); @@ -653,7 +671,9 @@ int membw_val(char **benchmark_cmd, struct resctrl_val_param *param) initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp, param->cpu_no, resctrl_val); - } + } else if (strcmp(resctrl_val, "cqm") == 0) + initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp, + param->cpu_no, resctrl_val); /* Parent waits for child to be ready. */ close(pipefd[1]); @@ -673,7 +693,8 @@ int membw_val(char **benchmark_cmd, struct resctrl_val_param *param) /* Test runs until the callback setup() tells the test to stop. */ while (1) { - if (strcmp(resctrl_val, "mbm") == 0) { + if ((strcmp(resctrl_val, "mbm") == 0) || + (strcmp(resctrl_val, "mba") == 0)) { ret = param->setup(1, param); if (ret) { ret = 0; @@ -683,14 +704,14 @@ int membw_val(char **benchmark_cmd, struct resctrl_val_param *param) ret = measure_vals(param, &bw_resc_start); if (ret) break; - } else if ((strcmp(resctrl_val, "mba") == 0)) { + } else if (strcmp(resctrl_val, "cqm") == 0) { ret = param->setup(1, param); if (ret) { ret = 0; break; } - - ret = measure_vals(param, &bw_resc_start); + sleep(1); + ret = measure_cache_vals(param, bm_pid); if (ret) break; } else { diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 3e5e88a..3c88afa 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -13,7 +13,11 @@ #define RESCTRL_MBM "L3 monitoring detected" #define RESCTRL_MBA "MB allocation detected" -#define MAX_RESCTRL_FEATURES 2 +#define RESCTRL_CQM "L3 monitoring detected" +#define MAX_RESCTRL_FEATURES 4 +#define CORE_SIBLINGS_PATH "/sys/bus/cpu/devices/cpu" + +char cbm_mask[256]; /* * remount_resctrlfs - Remount resctrl FS at /sys/fs/resctrl @@ -58,7 +62,7 @@ int remount_resctrlfs(bool mum_resctrlfs) return errno; } - printf("Remount: done!\n"); + printf("umount: done!\n"); } else { printf("Mounted already. Not remounting!\n"); @@ -118,6 +122,134 @@ int get_resource_id(int cpu_no, int *resource_id) } /* + * get_cache_size - Get cache size for a specified CPU + * @cpu_no: CPU number + * @cache_num: Cache level 2 for L2, 3 for L3 + * @cache_size: pointer to cache_size + * + * Return: = 0 on success, < 0 on failure. + */ +int get_cache_size(int cpu_no, int cache_num, unsigned long *cache_size) +{ + char cache_path[1024], cache_str[64]; + FILE *fp; + int length, i; + + sprintf(cache_path, "/sys/bus/cpu/devices/cpu%d/cache/index%d/size", + cpu_no, cache_num); + fp = fopen(cache_path, "r"); + if (!fp) { + perror("Failed to open cache size"); + + return -1; + } + if (fscanf(fp, "%s", cache_str) <= 0) { + perror("Could not get cache_size"); + fclose(fp); + + return -1; + } + fclose(fp); + + length = (int)strlen(cache_str); + + *cache_size = 0; + + for (i = 0; i < length; i++) { + if ((cache_str[i] >= '0') && (cache_str[i] <= '9')) + + *cache_size = *cache_size * 10 + (cache_str[i] - '0'); + + else if (cache_str[i] == 'K') + + *cache_size = *cache_size * 1024; + + else if (cache_str[i] == 'M') + + *cache_size = *cache_size * 1024 * 1024; + + else + break; + } + + return 0; +} + +/* + * get_cbm_mask - Get cbm mask for given cache + * @cache_type: Cache level L2/L3 + * + * Mask is stored in cbm_mask which is global variable. + * + * Return: = 0 on success, < 0 on failure. + */ +int get_cbm_mask(char *cache_type) +{ + char cbm_mask_path[1024]; + FILE *fp; + + sprintf(cbm_mask_path, "%s/%s/cbm_mask", CBM_MASK_PATH, cache_type); + + fp = fopen(cbm_mask_path, "r"); + if (!fp) { + perror("Failed to open cache level"); + + return -1; + } + if (fscanf(fp, "%s", cbm_mask) <= 0) { + perror("Could not get max cbm_mask"); + fclose(fp); + + return -1; + } + fclose(fp); + + return 0; +} + +/* + * get_core_sibling - Get sibling core id from the same socket for given CPU + * @cpu_no: CPU number + * + * Return: > 0 on success, < 0 on failure. + */ +int get_core_sibling(int cpu_no) +{ + char core_siblings_path[1024], cpu_list_str[64]; + int sibling_core_id = -1; + FILE *fp; + + sprintf(core_siblings_path, "%s%d/topology/core_siblings_list", + CORE_SIBLINGS_PATH, cpu_no); + + fp = fopen(core_siblings_path, "r"); + if (!fp) { + perror("Failed to open core siblings path"); + + return -1; + } + if (fscanf(fp, "%s", cpu_list_str) <= 0) { + perror("Could not get core_siblings list"); + fclose(fp); + + return -1; + } + fclose(fp); + + char *token = strtok(cpu_list_str, "-,"); + + while (token) { + sibling_core_id = atoi(token); + /* Skipping core 0 as we don't want to run test on core 0 */ + if (sibling_core_id != 0) + break; + token = strtok(NULL, "-,"); + } + + return sibling_core_id; +} + +/* * taskset_benchmark - Taskset PID (i.e. benchmark) to a specified cpu * @bm_pid: PID that should be binded * @cpu_no: CPU number at which the PID would be binded @@ -153,8 +285,10 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no) */ void run_benchmark(int signum, siginfo_t *info, void *ucontext) { - int span, operation, ret; + unsigned long long buffer_span; + int span, operation, ret, malloc_and_init_memory, memflush; char **benchmark_cmd; + char resctrl_val[64]; FILE *fp; benchmark_cmd = info->si_ptr; @@ -170,8 +304,18 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext) if (strcmp(benchmark_cmd[0], "fill_buf") == 0) { /* Execute default fill_buf benchmark */ span = atoi(benchmark_cmd[1]); + malloc_and_init_memory = atoi(benchmark_cmd[2]); + memflush = atoi(benchmark_cmd[3]); operation = atoi(benchmark_cmd[4]); - if (run_fill_buf(span, 1, 1, operation)) + sprintf(resctrl_val, "%s", benchmark_cmd[5]); + + if (strcmp(resctrl_val, "cqm") != 0) + buffer_span = span * MB; + else + buffer_span = span; + + if (run_fill_buf(buffer_span, malloc_and_init_memory, memflush, + operation, resctrl_val)) fprintf(stderr, "Error in running fill buffer\n"); } else { /* Execute specified benchmark */ @@ -198,6 +342,14 @@ static int create_grp(const char *grp_name, char *grp, const char *parent_grp) struct dirent *ep; DIR *dp; + /* + * At this point, we are guaranteed to have resctrl FS mounted and if + * length of grp_name == 0, it means, user wants to use root con_mon + * grp, so do nothing + */ + if (strlen(grp_name) == 0) + return 0; + /* Check if requested grp exists or not */ dp = opendir(parent_grp); if (dp) { @@ -239,7 +391,6 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) fclose(fp); return -1; - } fclose(fp); @@ -264,11 +415,11 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, char *resctrl_val) { - char controlgroup[256], monitorgroup[256], monitorgroup_p[256]; - char tasks[256]; + char controlgroup[128], monitorgroup[512], monitorgroup_p[256]; + char tasks[1024]; int ret; - if (ctrlgrp) + if (strlen(ctrlgrp)) sprintf(controlgroup, "%s/%s", RESCTRL_PATH, ctrlgrp); else sprintf(controlgroup, "%s", RESCTRL_PATH); @@ -282,9 +433,10 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, if (ret) return ret; - /* Create mon grp and write pid into it for "mbm" test */ - if ((strcmp(resctrl_val, "mbm") == 0)) { - if (mongrp) { + /* Create mon grp and write pid into it for "mbm" and "cqm" test */ + if ((strcmp(resctrl_val, "cqm") == 0) || + (strcmp(resctrl_val, "mbm") == 0)) { + if (strlen(mongrp)) { sprintf(monitorgroup_p, "%s/mon_groups", controlgroup); sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp); ret = create_grp(mongrp, monitorgroup, monitorgroup_p); @@ -322,7 +474,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) int resource_id; FILE *fp; - if (strcmp(resctrl_val, "mba") == 0) { + if ((strcmp(resctrl_val, "mba") == 0) || + (strcmp(resctrl_val, "cqm") == 0)) { if (!schemata) { printf("Schemata empty, so not updating\n"); @@ -333,12 +486,18 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) return -1; } - if (ctrlgrp) + if (strlen(ctrlgrp) != 0) sprintf(controlgroup, "%s/%s/schemata", RESCTRL_PATH, ctrlgrp); else sprintf(controlgroup, "%s/schemata", RESCTRL_PATH); - sprintf(schema, "%s%d%c%s", "MB:", resource_id, '=', schemata); + + if (!strcmp(resctrl_val, "cqm")) + sprintf(schema, "%s%d%c%s", "L3:", resource_id, '=', + schemata); + if (strcmp(resctrl_val, "mba") == 0) + sprintf(schema, "%s%d%c%s", "MB:", resource_id, '=', + schemata); fp = fopen(controlgroup, "w"); if (!fp) { @@ -355,7 +514,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) } fclose(fp); - printf("Write schemata to resctrl FS: done!\n"); + printf("Write schemata with %s to resctrl FS: done!\n", schema); } return 0; @@ -369,9 +528,9 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) */ int validate_resctrl_feature_request(char *resctrl_val) { - int resctrl_features_supported[MAX_RESCTRL_FEATURES] = {0, 0}; + int resctrl_features_supported[MAX_RESCTRL_FEATURES] = {0, 0, 0, 0}; const char *resctrl_features_list[MAX_RESCTRL_FEATURES] = { - "mbm", "mba"}; + "mbm", "mba", "cqm"}; int i, valid_resctrl_feature = -1; char line[1024]; FILE *fp; @@ -412,6 +571,8 @@ int validate_resctrl_feature_request(char *resctrl_val) resctrl_features_supported[0] = 1; if ((strstr(line, RESCTRL_MBA)) != NULL) resctrl_features_supported[1] = 1; + if ((strstr(line, RESCTRL_CQM)) != NULL) + resctrl_features_supported[3] = 1; } fclose(fp); @@ -455,3 +616,25 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, group_fd, flags); return ret; } + +void ctrlc_handler(int signum, siginfo_t *info, void *ptr) +{ + kill(bm_pid, SIGKILL); + umount_resctrlfs(); + tests_cleanup(); + printf("Ending\n\n"); + + exit(EXIT_SUCCESS); +} + +unsigned int count_bits(unsigned long n) +{ + unsigned int count = 0; + + while (n) { + count += n & 1; + n >>= 1; + } + + return count; +} From patchwork Fri Jan 18 18:27:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 383FB139A for ; Fri, 18 Jan 2019 18:28:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 246A629BD5 for ; Fri, 18 Jan 2019 18:28:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17E5429C19; Fri, 18 Jan 2019 18:28:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0C6D29BD5 for ; Fri, 18 Jan 2019 18:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729111AbfARS2F (ORCPT ); Fri, 18 Jan 2019 13:28:05 -0500 Received: from mail-eopbgr790057.outbound.protection.outlook.com ([40.107.79.57]:56814 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728952AbfARS1S (ORCPT ); Fri, 18 Jan 2019 13:27:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J+eQyu6Z4w26JP7RHp+Wt9WHf8gCIbAu9D5lHWBxGQY=; b=QMxFkPuSxWu1y0H6F7Y2hVXNm6Rf4daQYLPzCzcjFt77Uj7v0nZ92PSgcj+5a0fnAJflwKnxo5xCCNj3JCZUEIq/ItCxOHuW4V9QZnkGjT4ArTjRXr22+UAkreG0xnbzWe3iwPjiBFVw8NUl6o5CfkMpFAu21xuUBnkAgyaVYJ4= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1737.namprd12.prod.outlook.com (10.175.89.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:13 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:13 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 09/13] selftests/resctrl: Add Cache Allocation Technology (CAT) selftest Thread-Topic: [PATCH v5 09/13] selftests/resctrl: Add Cache Allocation Technology (CAT) selftest Thread-Index: AQHUr1tuMAuUihI1BEqVk1MGnCW0+A== Date: Fri, 18 Jan 2019 18:27:12 +0000 Message-ID: <20190118182646.16594-10-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1737;20:W1jWZmpQD3xZ9QN+XKbblIwOhteH6ZYNgZf4OLuHohAUZ5klXSTB9xydDKdDVpqQ4NnjU7kKzirTvR7aA1lwa7ekDe6KFKvYJ9SWPzxva6Zp9XjR6oRev1Y7fZeXkqBhcTFkB/UGexCYLXU3ry2BVA+oFd79tbCApujaF9jCExdX/gtTwA5b8H1jgnQqVMABNiZWqZmVgU+s+uZGND96Dx7xReIwIb9PVezxMO0+STXSmWO2mxA/ziBQJo/VECbX x-ms-office365-filtering-correlation-id: 37058dde-9abf-44ed-51c1-08d67d7290ae x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1737; x-ms-traffictypediagnostic: DM5PR12MB1737: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(39860400002)(366004)(136003)(189003)(199004)(54906003)(50226002)(6512007)(8676002)(6436002)(99286004)(1076003)(110136005)(53936002)(6486002)(7416002)(25786009)(8936002)(36756003)(26005)(4326008)(53946003)(186003)(81156014)(316002)(6116002)(81166006)(3846002)(6346003)(476003)(71200400001)(105586002)(2616005)(68736007)(2906002)(71190400001)(14454004)(106356001)(486006)(2201001)(14444005)(6506007)(5660300001)(97736004)(102836004)(72206003)(256004)(11346002)(2501003)(30864003)(7736002)(86362001)(52116002)(66066001)(478600001)(305945005)(76176011)(386003)(446003)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1737;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: A9ubRcMuBm+BIf2OmKSNePccxihuZ18blDgzKfsv5wEgGh6t95w+PQctutGWx1ONQWt1JNrp2V3sdatdr/bsoTgthiilRzDpI0ZFd0RNiKI2t485VysxwQljRoKV0nzEWyQ3l1mo3X03gGl7l2wQoyNkelUWiqcJjDXT+fkUg6IrgHMaKAaxEd36///dfV20kqugaycirST8PZM3yhq51JIU6fWuiJAX9wU+kkDc3/7xIpen2doYjmHb6T4UQLb9RBtdU4RxGiTl3bfFv27+M8jPyTAPiR9OiDcKO2s/CiUxsALr/3MhRigFx60gqlGA+jU923bAYp7+akU+AO7N2Z0Kylme5qgtjrgOqQ9gPwPtitW19SE6R6UY97m9aUQNQDu6eN0iXHp6YMpYs43Zfygi8Sg7zHYYzuc4e5Q7VVo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37058dde-9abf-44ed-51c1-08d67d7290ae X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:11.8309 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1737 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arshiya Hayatkhan Pathan Cache Allocation Technology (CAT) selftest allocates a portion of last level cache and starts a benchmark to read each cache line in this portion of cache. Measure the cache misses in perf and the misses should be equal to the number of cache lines in this portion of cache. We don't use CQM to calculate cache usage because some CAT enabled platforms don't have CQM. Signed-off-by: Arshiya Hayatkhan Pathan Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/Makefile | 2 +- tools/testing/selftests/resctrl/cache.c | 175 ++++++++++++++++- tools/testing/selftests/resctrl/cat_test.c | 243 ++++++++++++++++++++++++ tools/testing/selftests/resctrl/fill_buf.c | 10 +- tools/testing/selftests/resctrl/resctrl.h | 3 + tools/testing/selftests/resctrl/resctrl_tests.c | 15 +- tools/testing/selftests/resctrl/resctrlfs.c | 8 +- 7 files changed, 448 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/resctrl/cat_test.c diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile index 664561c..0282222 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 \ - resctrl_val.o fill_buf.o mbm_test.o mba_test.o cache.o cqm_test.o + resctrl_val.o fill_buf.o mbm_test.o mba_test.o cache.o cqm_test.o cat_test.o .PHONY: clean diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 1256590..c98b7bc 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -10,10 +10,107 @@ struct read_format { } values[2]; }; +static struct perf_event_attr pea_llc_miss; +static struct read_format rf_cqm; +static int fd_lm; char cbm_mask[256]; unsigned long long_mask; char llc_occup_path[1024]; +static void initialize_perf_event_attr(void) +{ + pea_llc_miss.type = PERF_TYPE_HARDWARE; + pea_llc_miss.size = sizeof(struct perf_event_attr); + pea_llc_miss.read_format = PERF_FORMAT_GROUP; + pea_llc_miss.exclude_kernel = 1; + pea_llc_miss.exclude_hv = 1; + pea_llc_miss.exclude_idle = 1; + pea_llc_miss.exclude_callchain_kernel = 1; + pea_llc_miss.inherit = 1; + pea_llc_miss.exclude_guest = 1; + pea_llc_miss.disabled = 1; +} + +static void ioctl_perf_event_ioc_reset_enable(void) +{ + ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0); + ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0); +} + +static int perf_event_open_llc_miss(pid_t pid, int cpu_no) +{ + fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, + PERF_FLAG_FD_CLOEXEC); + if (fd_lm == -1) { + perror("Error opening leader"); + ctrlc_handler(0, NULL, NULL); + return -1; + } + + return 0; +} + +static int initialize_llc_perf(void) +{ + memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); + memset(&rf_cqm, 0, sizeof(struct read_format)); + + /* Initialize perf_event_attr structures for HW_CACHE_MISSES */ + initialize_perf_event_attr(); + + pea_llc_miss.config = PERF_COUNT_HW_CACHE_MISSES; + + rf_cqm.nr = 1; + + return 0; +} + +static int reset_enable_llc_perf(pid_t pid, int cpu_no) +{ + int ret = 0; + + ret = perf_event_open_llc_miss(pid, cpu_no); + if (ret < 0) + return ret; + + /* Start counters to log values */ + ioctl_perf_event_ioc_reset_enable(); + + return 0; +} + +/* + * get_llc_perf: llc cache miss through perf events + * @cpu_no: CPU number that the benchmark PID is binded to + * + * Perf events like HW_CACHE_MISSES could be used to validate number of + * cache lines allocated. + * + * Return: =0 on success. <0 on failure. + */ +static int get_llc_perf(unsigned long *llc_perf_miss) +{ + __u64 total_misses; + + /* Stop counters after one span to get miss rate */ + + ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); + + if (read(fd_lm, &rf_cqm, sizeof(struct read_format)) == -1) { + perror("Could not get llc misses through perf"); + + return -1; + } + + total_misses = rf_cqm.values[0].value; + + close(fd_lm); + + *llc_perf_miss = total_misses; + + return 0; +} + /* * Get LLC Occupancy as reported by RESCTRL FS * For CQM, @@ -82,10 +179,20 @@ static int print_results_cache(char *filename, int bm_pid, int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) { - unsigned long llc_occu_resc = 0, llc_value = 0; + unsigned long llc_perf_miss = 0, llc_occu_resc = 0, llc_value = 0; int ret; /* + * Measure cache miss from perf. + */ + if (!strcmp(param->resctrl_val, "cat")) { + ret = get_llc_perf(&llc_perf_miss); + if (ret < 0) + return ret; + llc_value = llc_perf_miss; + } + + /* * Measure llc occupancy from resctrl. */ if (!strcmp(param->resctrl_val, "cqm")) { @@ -100,3 +207,69 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) return 0; } + +/* + * cache_val: execute benchmark and measure LLC occupancy resctrl + * and perf cache miss for the benchmark + * @param: parameters passed to cache_val() + * + * Return: 0 on success. non-zero on failure. + */ +int cat_val(struct resctrl_val_param *param) +{ + int malloc_and_init_memory = 1, memflush = 1, opeartion = 1, ret = 0; + char *resctrl_val = param->resctrl_val; + pid_t bm_pid; + + if (strcmp(param->filename, "") == 0) + sprintf(param->filename, "stdio"); + + bm_pid = getpid(); + + /* Taskset benchmark to specified cpu */ + ret = taskset_benchmark(bm_pid, param->cpu_no); + if (ret) + return ret; + + /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/ + ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, + resctrl_val); + if (ret) + return ret; + + if ((strcmp(resctrl_val, "cat") == 0)) { + ret = initialize_llc_perf(); + if (ret) + return ret; + } + + /* Test runs until the callback setup() tells the test to stop. */ + while (1) { + if (strcmp(resctrl_val, "cat") == 0) { + ret = param->setup(1, param); + if (ret) { + ret = 0; + break; + } + ret = reset_enable_llc_perf(bm_pid, param->cpu_no); + if (ret) + break; + + if (run_fill_buf(param->span, malloc_and_init_memory, + memflush, opeartion, resctrl_val)) { + fprintf(stderr, "Error-running fill buffer\n"); + ret = -1; + break; + } + + sleep(1); + ret = measure_cache_vals(param, bm_pid); + if (ret) + break; + } else { + break; + } + } + + return ret; +} diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c new file mode 100644 index 0000000..57d501d --- /dev/null +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cache Allocation Technology (CAT) test + * + * Copyright (C) 2018 Intel Corporation + * + * Authors: + * Arshiya Hayatkhan Pathan + * Sai Praneeth Prakhya , + * Fenghua Yu + */ +#include "resctrl.h" +#include + +#define RESULT_FILE_NAME1 "result_cat1" +#define RESULT_FILE_NAME2 "result_cat2" +#define NUM_OF_RUNS 5 +#define MAX_DIFF_PERCENT 4 +#define MAX_DIFF 1000000 + +int count_of_bits; +char cbm_mask[256]; +unsigned long long_mask; +unsigned long cache_size; + +/* + * Change schemata. Write schemata to specified + * con_mon grp, mon_grp in resctrl FS. + * Run 5 times in order to get average values. + */ +static int cat_setup(int num, ...) +{ + struct resctrl_val_param *p; + char schemata[64]; + va_list param; + int ret = 0; + + va_start(param, num); + p = va_arg(param, struct resctrl_val_param *); + va_end(param); + + /* Run NUM_OF_RUNS times */ + if (p->num_of_runs >= NUM_OF_RUNS) + return -1; + + if (p->num_of_runs == 0) { + sprintf(schemata, "%lx", p->mask); + ret = write_schemata(p->ctrlgrp, schemata, p->cpu_no, + p->resctrl_val); + } + p->num_of_runs++; + + return ret; +} + +static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits, + unsigned long span) +{ + unsigned long allocated_cache_lines = span / 64; + unsigned long avg_llc_perf_miss = 0; + float diff_percent; + + avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1); + diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) / + allocated_cache_lines * 100; + printf("Results are displayed in (Bytes)\n"); + printf("\nNumber of bits: %d \t", no_of_bits); + printf("Avg_llc_perf_miss: %lu \t", avg_llc_perf_miss); + printf("Allocated cache lines: %lu \t", allocated_cache_lines); + printf("Percent diff=%d \t", abs((int)diff_percent)); + + if (abs((int)diff_percent) > MAX_DIFF_PERCENT) + printf("Failed\n"); + else + printf("Passed\n"); +} + +static int check_results(struct resctrl_val_param *param) +{ + char *token_array[8], temp[512]; + unsigned long sum_llc_perf_miss = 0; + int runs = 0, no_of_bits = 0; + FILE *fp; + + printf("\nChecking for pass/fail\n"); + fp = fopen(param->filename, "r"); + if (!fp) { + perror("Error in opening file\n"); + + return errno; + } + + while (fgets(temp, 1024, fp)) { + char *token = strtok(temp, ":\t"); + int fields = 0; + + while (token) { + token_array[fields++] = token; + token = strtok(NULL, ":\t"); + } + /* + * Discard the first value which is inaccurate due to monitoring + * setup transition phase. + */ + if (runs > 0) + sum_llc_perf_miss += atol(token_array[3]); + runs++; + } + + fclose(fp); + no_of_bits = count_bits(param->mask); + + show_cache_info(sum_llc_perf_miss, no_of_bits, param->span); + + return 0; +} + +void cat_test_cleanup(void) +{ + remove(RESULT_FILE_NAME1); + remove(RESULT_FILE_NAME2); +} + +int cat_perf_miss_val(int core_id, int n) +{ + unsigned long l_mask, l_mask_1; + int ret, pipefd[2], pipe_message, mum_resctrlfs, sibling_core_id; + pid_t bm_pid; + + cache_size = 0; + mum_resctrlfs = 1; + + ret = remount_resctrlfs(mum_resctrlfs); + if (ret) + return ret; + + ret = validate_resctrl_feature_request("cat"); + if (ret) + return ret; + + /* Get default cbm mask for L3 cache */ + ret = get_cbm_mask("L3"); + if (ret) + return ret; + + long_mask = strtoul(cbm_mask, NULL, 16); + + /* Get L3 cache size */ + ret = get_cache_size(core_id, 3, &cache_size); + if (ret) + return ret; + + /* Get max number of bits from default-cabm mask */ + count_of_bits = count_bits(long_mask); + + if (n < 1 || n > count_of_bits - 1) { + printf("Invalid input value for no_of_bits n!\n"); + printf("Please Enter value in range 1 to %d\n", + count_of_bits - 1); + return -1; + } + + /* Get core id from same socket for running another thread */ + sibling_core_id = get_core_sibling(core_id); + if (sibling_core_id < 0) + return -1; + + struct resctrl_val_param param = { + .resctrl_val = "cat", + .cpu_no = core_id, + .mum_resctrlfs = 0, + .setup = cat_setup, + }; + + l_mask = long_mask >> n; + l_mask_1 = ~l_mask & long_mask; + + /* Set param values for parent thread which will be allocated bitmask + * with (max_bits - n) bits + */ + param.span = cache_size * (count_of_bits - n) / count_of_bits; + strcpy(param.ctrlgrp, "c2"); + strcpy(param.mongrp, "m2"); + strcpy(param.filename, RESULT_FILE_NAME1); + param.mask = l_mask; + param.num_of_runs = 0; + + if (pipe(pipefd)) { + perror("Unable to create pipe"); + return -1; + } + ret = remount_resctrlfs(mum_resctrlfs); + if (ret) + return ret; + + bm_pid = fork(); + + /* Set param values for child thread which will be allocated bitmask + * with n bits + */ + if (bm_pid == 0) { + param.mask = l_mask_1; + strcpy(param.ctrlgrp, "c1"); + strcpy(param.mongrp, "m1"); + param.span = cache_size * n / count_of_bits; + strcpy(param.filename, RESULT_FILE_NAME2); + param.num_of_runs = 0; + param.cpu_no = sibling_core_id; + } + + remove(param.filename); + + ret = cat_val(¶m); + if (ret) + return ret; + + ret = check_results(¶m); + if (ret) + return ret; + + if (bm_pid == 0) { + /* Tell parent that child is ready */ + close(pipefd[0]); + pipe_message = 1; + write(pipefd[1], &pipe_message, sizeof(pipe_message)); + close(pipefd[1]); + while (1); + } else { + /* Parent waits for child to be ready. */ + close(pipefd[1]); + pipe_message = 0; + while (pipe_message != 1) + read(pipefd[0], &pipe_message, sizeof(pipe_message)); + close(pipefd[0]); + kill(bm_pid, SIGKILL); + } + + cat_test_cleanup(); + if (bm_pid) + umount_resctrlfs(); + + return 0; +} diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 7c3579a..671d801 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -105,8 +105,11 @@ void fill_one_span_write(unsigned char *start_ptr, unsigned char *end_ptr) static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, char *resctrl_val) { - while (1) + while (1) { fill_one_span_read(start_ptr, end_ptr); + if (!strcmp(resctrl_val, "cat")) + break; + } return 0; } @@ -114,8 +117,11 @@ static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr, char *resctrl_val) { - while (1) + while (1) { fill_one_span_write(start_ptr, end_ptr); + if (!strcmp(resctrl_val, "cat")) + break; + } return 0; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index a4f8040..3da2afe 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -91,7 +91,10 @@ int run_fill_buf(unsigned long long span, int malloc_and_init_memory, void mba_test_cleanup(void); int get_cbm_mask(char *cache_type); int get_cache_size(int cpu_no, int cache_num, unsigned long *cache_size); +int cat_val(struct resctrl_val_param *param); +void cat_test_cleanup(void); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); +int cat_perf_miss_val(int core_id, int no_of_bits); int cqm_resctrl_val(int core_id, int n, char **benchmark_cmd); unsigned int count_bits(unsigned long n); void cqm_test_cleanup(void); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 6d4a1cf..2397c3b 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -20,7 +20,7 @@ static void cmd_help(void) printf("\t-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM"); printf("\t default benchmark is builtin fill_buf\n"); printf("\t-t test list: run tests specified in the test list, "); - printf("e.g. -t mbm, mba, cqm\n"); + printf("e.g. -t mbm, mba, cqm, cat\n"); printf("\t-n no_of_bits: run cache tests using specified no of bits in cache bit mask\n"); printf("\t-h: help\n"); } @@ -30,6 +30,7 @@ void tests_cleanup(void) mbm_test_cleanup(); mba_test_cleanup(); cqm_test_cleanup(); + cat_test_cleanup(); } int main(int argc, char **argv) @@ -38,7 +39,7 @@ int main(int argc, char **argv) int res, c, core_id = 1, span = 250, argc_new = argc, i, no_of_bits = 5; int ben_count, ben_ind; bool has_ben = false, mbm_test = true, mba_test = true; - bool cqm_test = true; + bool cqm_test = true, cat_test = true; char *benchmark_cmd[BENCHMARK_ARGS]; char bw_report[64], bm_type[64]; @@ -62,6 +63,7 @@ int main(int argc, char **argv) mbm_test = false; mba_test = false; cqm_test = false; + cat_test = false; while (token) { if (!strcmp(token, "mbm")) { mbm_test = true; @@ -69,6 +71,8 @@ int main(int argc, char **argv) mba_test = true; } else if (!strcmp(token, "cqm")) { cqm_test = true; + } else if (!strcmp(token, "cat")) { + cat_test = true; } else { printf("invalid argument\n"); @@ -159,6 +163,13 @@ int main(int argc, char **argv) printf("Error in CQM test!\n"); cqm_test_cleanup(); } + if (cat_test) { + printf("\nCAT Test Starting..\n"); + res = cat_perf_miss_val(core_id, no_of_bits); + if (res) + printf("Error in CAT test!\n"); + cat_test_cleanup(); + } return 0; } diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 3c88afa..146a10e 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -14,6 +14,7 @@ #define RESCTRL_MBM "L3 monitoring detected" #define RESCTRL_MBA "MB allocation detected" #define RESCTRL_CQM "L3 monitoring detected" +#define RESCTRL_L3_CAT "L3 allocation detected" #define MAX_RESCTRL_FEATURES 4 #define CORE_SIBLINGS_PATH "/sys/bus/cpu/devices/cpu" @@ -475,6 +476,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) FILE *fp; if ((strcmp(resctrl_val, "mba") == 0) || + (strcmp(resctrl_val, "cat") == 0) || (strcmp(resctrl_val, "cqm") == 0)) { if (!schemata) { printf("Schemata empty, so not updating\n"); @@ -492,7 +494,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) else sprintf(controlgroup, "%s/schemata", RESCTRL_PATH); - if (!strcmp(resctrl_val, "cqm")) + if (!strcmp(resctrl_val, "cat") || !strcmp(resctrl_val, "cqm")) sprintf(schema, "%s%d%c%s", "L3:", resource_id, '=', schemata); if (strcmp(resctrl_val, "mba") == 0) @@ -530,7 +532,7 @@ int validate_resctrl_feature_request(char *resctrl_val) { int resctrl_features_supported[MAX_RESCTRL_FEATURES] = {0, 0, 0, 0}; const char *resctrl_features_list[MAX_RESCTRL_FEATURES] = { - "mbm", "mba", "cqm"}; + "mbm", "mba", "cat", "cqm"}; int i, valid_resctrl_feature = -1; char line[1024]; FILE *fp; @@ -571,6 +573,8 @@ int validate_resctrl_feature_request(char *resctrl_val) resctrl_features_supported[0] = 1; if ((strstr(line, RESCTRL_MBA)) != NULL) resctrl_features_supported[1] = 1; + if ((strstr(line, RESCTRL_L3_CAT)) != NULL) + resctrl_features_supported[2] = 1; if ((strstr(line, RESCTRL_CQM)) != NULL) resctrl_features_supported[3] = 1; } From patchwork Fri Jan 18 18:27:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F7246C5 for ; Fri, 18 Jan 2019 18:28:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EBF929BD5 for ; Fri, 18 Jan 2019 18:28:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51A1329C19; Fri, 18 Jan 2019 18:28:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E715B29BD5 for ; Fri, 18 Jan 2019 18:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728535AbfARS14 (ORCPT ); Fri, 18 Jan 2019 13:27:56 -0500 Received: from mail-eopbgr790057.outbound.protection.outlook.com ([40.107.79.57]:56814 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729083AbfARS1U (ORCPT ); Fri, 18 Jan 2019 13:27:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ERHtLO9KoM7azHHx/q861wlQTxqDvLFDzgBAjhc6X9Q=; b=XfOS8MSrGkjFrsT6xNmpvU6X437ILUIBepKUBsTEcVFkoPLuXR0vPKBrKPzpDvS53zmVZDqEK+w5s68GxweRTrs4dL2D76RZFM6p6/xE7XHKeLXGjoi3522LwyW3jZbsWN2HbOFhwfbu3qt7G9LuZYhfFja6pkpZL24/zcTxl4E= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1737.namprd12.prod.outlook.com (10.175.89.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:14 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:14 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 10/13] selftests/resctrl: Add the test in MAINTAINERS Thread-Topic: [PATCH v5 10/13] selftests/resctrl: Add the test in MAINTAINERS Thread-Index: AQHUr1tv9/B41hRmakuDO6KWkA8Wkg== Date: Fri, 18 Jan 2019 18:27:14 +0000 Message-ID: <20190118182646.16594-11-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1737;20:0xmxO0WA1L6tvhkPZAhGYSy1kVnMs1EgBjhib6p6UPyC5PFIySt+NxT1pJmdWsCl6QiRD+1WG9mgr6CR1NiZ7X9K7VGautqgTG7gVRumuxwTcizW0DyFBzIbcsiprnaclvzv0DssOvgOF+8lLb0iCtTc3UFc1I4Mg62GuQRl4k/woqbfZQMky1Y5/uFq0PUtDEJT/crz3qFxYwF8VGJDzgckoZjHmstJ7Nz6/HEQ6Kd4vcLg36yBU+f/PCANhOVw x-ms-office365-filtering-correlation-id: 3e769b80-8c8a-45ee-c2d2-08d67d72917d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1737; x-ms-traffictypediagnostic: DM5PR12MB1737: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(39860400002)(366004)(136003)(189003)(199004)(54906003)(50226002)(6512007)(8676002)(6436002)(99286004)(1076003)(110136005)(53936002)(6486002)(7416002)(25786009)(8936002)(36756003)(26005)(4326008)(186003)(81156014)(316002)(6116002)(81166006)(3846002)(6346003)(476003)(71200400001)(105586002)(2616005)(68736007)(2906002)(71190400001)(14454004)(106356001)(486006)(2201001)(14444005)(6506007)(5660300001)(97736004)(102836004)(72206003)(256004)(11346002)(2501003)(7736002)(4744005)(86362001)(52116002)(66066001)(478600001)(305945005)(76176011)(386003)(446003)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1737;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: p6U/H5nRn5sVttgFuDXsQWnZT1O4NrEfcqD86T7cgf7mzgqPuZQoImYzSHY4TVRoMrEbL46zEox6ifjtZFYjvYx1fiqquSCioyPsGFNc61zda6BOTecoozqdDY4QU7S2OFOmM02Tlf88lnMk8VJbgVvYEhPjyKDcl9GWudmo5b1HMRtn/0Xq2uowfglisC1GhogVkid/safYH+Jksj8yBkT8K1EgfvKhtWEDUGNXdlQhVcsYfhYomT0hx5a+gtDhIdoE3KLuLMkyQyg0yEwVRKqYaMpVIaXUCI+Gzby66sHOUTB6YnitDE0H6eohK0eAt1bK3+Pkmz011V3iSi7pu5HvJEwjuJUVFj5wnU56iHprbEkbs+wHR0aHEKvHAKJp3/rQTRGMT7KUUF7q+FSnjttqBD8a5Kc4rpM1PaGJBTc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e769b80-8c8a-45ee-c2d2-08d67d72917d X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:13.1903 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1737 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fenghua Yu The resctrl selftest will be maintained by RDT maintainers. Signed-off-by: Fenghua Yu Signed-off-by: Babu Moger --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 32d44447..16359bc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12815,6 +12815,7 @@ S: Supported F: arch/x86/kernel/cpu/resctrl/ F: arch/x86/include/asm/resctrl_sched.h F: Documentation/x86/resctrl* +F: tools/testing/selftests/resctrl/ READ-COPY UPDATE (RCU) M: "Paul E. McKenney" From patchwork Fri Jan 18 18:27:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0A31139A for ; Fri, 18 Jan 2019 18:27:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E00FF29BD5 for ; Fri, 18 Jan 2019 18:27:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3EAE29C19; Fri, 18 Jan 2019 18:27:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DC9C29BD5 for ; Fri, 18 Jan 2019 18:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729114AbfARS1W (ORCPT ); Fri, 18 Jan 2019 13:27:22 -0500 Received: from mail-eopbgr790057.outbound.protection.outlook.com ([40.107.79.57]:56814 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729102AbfARS1V (ORCPT ); Fri, 18 Jan 2019 13:27:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=csku/qK7hd8ZoFIvf7O7lTUDMQHd0H8w1bej8qLYFok=; b=ek024r4OpjWJnE08YHl6yI4J2gPTPqlaI/hT+RlHO5bnrxGAOfk2zTnTnlCTx4DNdEDsTwGCVs52F7DTc1kLOxSwHbVVWYy5rFQRHrBhXmPiLCcPjYCgwf5Be77xzB6/nf0Cfjq9FZ1OxOianCA6JH7r2xL4rMcL8wfVNmOM0to= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1737.namprd12.prod.outlook.com (10.175.89.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:15 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:15 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 11/13] selftests/resctrl: Add vendor detection mechanism Thread-Topic: [PATCH v5 11/13] selftests/resctrl: Add vendor detection mechanism Thread-Index: AQHUr1tvBMGnddDBJEG8QhQMFdIGjg== Date: Fri, 18 Jan 2019 18:27:15 +0000 Message-ID: <20190118182646.16594-12-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1737;20:XhL3NqBqr0GgaWkLt+B44yKCPmPT85TJy4E2ZUZW8quI7YB91t6Nn3sfY9bt8aarfgouT5N0uQuumWB5kM/YM2VfCTFcC+YF0v+HKpiO86fbEj01tvTU5VuaS48J4975CHy9RfopSZQntoQU/Xb6hSsgr/NW6YqTb4ao0JuQaa7gfCpi222OZUC8gep9YCVQbJhz6a732w6ld9prfMwZhnKt+MTiYaqSTm6mBE153zfEs2z3xWTGI/JstQ4z7VZR x-ms-office365-filtering-correlation-id: abcebf74-7421-465c-f617-08d67d729232 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1737; x-ms-traffictypediagnostic: DM5PR12MB1737: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(39860400002)(366004)(136003)(189003)(199004)(54906003)(50226002)(6512007)(8676002)(6436002)(99286004)(1076003)(110136005)(53936002)(6486002)(7416002)(25786009)(8936002)(36756003)(26005)(4326008)(186003)(81156014)(316002)(6116002)(81166006)(3846002)(6346003)(476003)(71200400001)(105586002)(2616005)(68736007)(2906002)(71190400001)(14454004)(106356001)(486006)(2201001)(14444005)(6506007)(5660300001)(97736004)(102836004)(72206003)(256004)(11346002)(2501003)(7736002)(86362001)(52116002)(66066001)(478600001)(305945005)(76176011)(386003)(446003)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1737;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ELM8zQIRS3SARqvz6g6V1rI4+crrtixZCYIWshWnogqMeGisgR+pPzxyZ/a55fpfWS9HLqdL1JCCW2HT8ERkToFMSS7kYT1bZnJKCrYqQEb80ecXFwL+VkVf+OQbG4rhHYBV/3GLogk79rrUZChhIXbzZgqtxQoiyjOx1iYls1PJ8yt2xYfGcBVaqwRqBvvujRMGizfDEkcksis288NSi4izU/fk3gBwD9ZcvkSleI+Lwx81Tk0mAP20Fx6Oile2E+43B+bm9RDwRejtV5h5OsRs+EnlJPtF5h4c3rQHs+WS9S1grlRdp79mNhitz9oxZtnC05YG9gcHv/rdiWSPUhhKm+HVeRDgbGjp5IYeGn/UnDij0ex1K+OloveWW4+wExKu/zlBGwjHHGu0mUvGckV3NpJlSFW4zkv1soktp9U= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: abcebf74-7421-465c-f617-08d67d729232 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:14.3935 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1737 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP RESCTRL feature is supported both on Intel and AMD now. Some features are implemented differently. Add vendor detection mechanism. Use the vendor check where there are differences. Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/resctrl.h | 13 +++++ tools/testing/selftests/resctrl/resctrl_tests.c | 68 +++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 3da2afe..1ec97d1 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -63,10 +63,23 @@ struct resctrl_val_param { }; +/** + * Results of CPUID operation are stored in this structure. + * It consists of 4x32bits IA registers: EAX, EBX, ECX and EDX. + */ +struct cpuid_out { + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; +}; + pid_t bm_pid, ppid; extern char cbm_mask[256]; extern unsigned long long_mask; extern char llc_occup_path[1024]; +extern int genuine_intel; +extern int authentic_amd; int remount_resctrlfs(bool mum_resctrlfs); int get_resource_id(int cpu_no, int *resource_id); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 2397c3b..e8cbcd5 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -14,6 +14,69 @@ #define BENCHMARK_ARGS 64 #define BENCHMARK_ARG_SIZE 64 +/** + * This variables provides information about the vendor + */ +int genuine_intel = 0; +int authentic_amd = 0; + +void +lcpuid(const unsigned leaf, + const unsigned subleaf, + struct cpuid_out *out) +{ + if (out == NULL) + return; + +#ifdef __x86_64__ + asm volatile("mov %4, %%eax\n\t" + "mov %5, %%ecx\n\t" + "cpuid\n\t" + "mov %%eax, %0\n\t" + "mov %%ebx, %1\n\t" + "mov %%ecx, %2\n\t" + "mov %%edx, %3\n\t" + : "=g" (out->eax), "=g" (out->ebx), "=g" (out->ecx), + "=g" (out->edx) + : "g" (leaf), "g" (subleaf) + : "%eax", "%ebx", "%ecx", "%edx"); +#else + asm volatile("push %%ebx\n\t" + "mov %4, %%eax\n\t" + "mov %5, %%ecx\n\t" + "cpuid\n\t" + "mov %%eax, %0\n\t" + "mov %%ebx, %1\n\t" + "mov %%ecx, %2\n\t" + "mov %%edx, %3\n\t" + "pop %%ebx\n\t" + : "=g" (out->eax), "=g" (out->ebx), "=g" (out->ecx), + "=g" (out->edx) + : "g" (leaf), "g" (subleaf) + : "%eax", "%ecx", "%edx"); +#endif +} + +int detect_vendor(void) +{ + int ret = 0; + struct cpuid_out vendor; + + lcpuid(0x0, 0x0, &vendor); + if (vendor.ebx == 0x756e6547 && vendor.edx == 0x49656e69 && + vendor.ecx == 0x6c65746e) { + genuine_intel = 1; + } else if (vendor.ebx == 0x68747541 && vendor.edx == 0x69746E65 && + vendor.ecx == 0x444D4163) { + authentic_amd = 1; + } else { + ret = -EFAULT; + } + + return ret; +} + + static void cmd_help(void) { printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n"); @@ -109,6 +172,11 @@ int main(int argc, char **argv) return errno; } + /* + * Detect vendor + */ + detect_vendor(); + if (has_ben) { /* Extract benchmark command from command line. */ for (i = ben_ind; i < argc; i++) { From patchwork Fri Jan 18 18:27:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 112E66C5 for ; Fri, 18 Jan 2019 18:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0178129BD5 for ; Fri, 18 Jan 2019 18:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E981A29C36; Fri, 18 Jan 2019 18:27:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 885BD29BE0 for ; Fri, 18 Jan 2019 18:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729093AbfARS1t (ORCPT ); Fri, 18 Jan 2019 13:27:49 -0500 Received: from mail-eopbgr790057.outbound.protection.outlook.com ([40.107.79.57]:56814 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729111AbfARS1W (ORCPT ); Fri, 18 Jan 2019 13:27:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GeLLPCNQ7S0sKk0Hu1EPMfRY62uAivpPwRIiM56e7UA=; b=hGQ1cGKkfI/IG8053aJboq6ugLLs3WY9KM40Zb0pf3+K997BVcdtoFGXpU1u7MdAt83HpsjHIa/Qoj2sTgKUvdjlzAITWvkrw9KWDE9lMO3hUFLIOMGHPpyH4cDYkqTo3hJWFKisqBmEHZiFpda8Ml1xRfBl9KVDybEMWrKitZA= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1737.namprd12.prod.outlook.com (10.175.89.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:16 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:16 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 12/13] selftests/resctrl: Use cache index3 id for AMD schemata masks Thread-Topic: [PATCH v5 12/13] selftests/resctrl: Use cache index3 id for AMD schemata masks Thread-Index: AQHUr1twpCulb6PvAkeyosiniRhTow== Date: Fri, 18 Jan 2019 18:27:16 +0000 Message-ID: <20190118182646.16594-13-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1737;20:XZ69fp1UeQxNPkuLM0pDKz1nFYNGKyvr8/BI0XtTODNmFusfrwADA7d3ThUJXLTCeRCkJ5DLlAg2qz0w/Acdpnadd85UwnZt6C5KJXSj7/6lx/cqJUYD/6m6A2KPkpMkY7aAp3n0xfqFH8Lc8a7IY7OLKqTmLZwFx+mNVJWz0s5qLNcAqmpPfKdyby0UpdtVmasrlk2HdXH8BbWocvyKBls2aCoS+3y4wU51o5fv4O0rWbS1pPM3SmmwlUfWKkhm x-ms-office365-filtering-correlation-id: aebba7bb-6b26-41ef-b2ce-08d67d7292f1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1737; x-ms-traffictypediagnostic: DM5PR12MB1737: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(39860400002)(366004)(136003)(189003)(199004)(54906003)(50226002)(6512007)(8676002)(6436002)(99286004)(1076003)(110136005)(53936002)(6486002)(7416002)(25786009)(8936002)(36756003)(26005)(4326008)(186003)(81156014)(316002)(6116002)(81166006)(3846002)(6346003)(476003)(71200400001)(105586002)(2616005)(68736007)(2906002)(71190400001)(14454004)(106356001)(486006)(2201001)(14444005)(6506007)(5660300001)(97736004)(102836004)(72206003)(256004)(11346002)(2501003)(7736002)(4744005)(86362001)(52116002)(66066001)(478600001)(305945005)(76176011)(386003)(446003)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1737;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: bOiwqJAYRAY/rtFWCJtMr9hhjgysze1JtOGoZgRT+TFE+HiNSRMo4hCeOBZGnkT0bDjPHUB9pj/D2szdVguiUSmTM+JueYhupbqzrB6iNWsWPzHrNAOhmdNtAuW9yxypTuyMSVwIFtYwIZWRYDi3xqbzoSWIJ2CA9hXJhkeO/8UILQcjp2YakACyyBHPKcXgaCFS2zEUgvqHeDjjjq2gZSldvpmXI8eKYEhKM3/0c1HWix0Snz8V0PZ5UwJIQwZVcjLZDYa1YjoXMVJj/qZOrmu/3rq2HIittZ/7u03F7fNrA+bYAqqMtecKzuSPyu3VRTSbbmYNg5evKMniguNtgWDsds24qp9f9G5LB6DD5wSWQfRvCzpnffNcv12hHScACfE0+zbLeFGuowJ/EnJ/yUMquiVqYHPhU0SCmIx4djo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: aebba7bb-6b26-41ef-b2ce-08d67d7292f1 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:15.6279 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1737 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP AMD uses the cache l3 boundary for schemata masks. Update it accordigly. Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/resctrlfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 146a10e..15cda1b 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -103,8 +103,13 @@ int get_resource_id(int cpu_no, int *resource_id) char phys_pkg_path[1024]; FILE *fp; - sprintf(phys_pkg_path, "%s%d/topology/physical_package_id", - PHYS_ID_PATH, cpu_no); + if (authentic_amd) + sprintf(phys_pkg_path, "%s%d/cache/index3/id", + PHYS_ID_PATH, cpu_no); + else + sprintf(phys_pkg_path, "%s%d/topology/physical_package_id", + PHYS_ID_PATH, cpu_no); + fp = fopen(phys_pkg_path, "r"); if (!fp) { perror("Failed to open physical_package_id"); From patchwork Fri Jan 18 18:27:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10771425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8564A139A for ; Fri, 18 Jan 2019 18:27:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74FEB29BD5 for ; Fri, 18 Jan 2019 18:27:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68F9429BFC; Fri, 18 Jan 2019 18:27:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1150C29BD5 for ; Fri, 18 Jan 2019 18:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728900AbfARS1Y (ORCPT ); Fri, 18 Jan 2019 13:27:24 -0500 Received: from mail-eopbgr790057.outbound.protection.outlook.com ([40.107.79.57]:56814 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729119AbfARS1X (ORCPT ); Fri, 18 Jan 2019 13:27:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5o85UoV6APNnSm8CUo3/lm7UUT3Wz0xToPBBvSe+Acw=; b=Q3KOSSMCMaTCEpyg1uqMn0jFrL6XaSu2gfYvVvLCEV1RGaV/bAhLByweyVhkA30o4gQD0oA7oRBi0cvbZpnd9VDLieRuSTf84Gup05FSwriHXvu9MfFuvh5OYcgJQfFhfytJ9bzE5e7yjPkt2jg9YuYVD1bATcHjz4XuWp5i/4o= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1737.namprd12.prod.outlook.com (10.175.89.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Fri, 18 Jan 2019 18:27:18 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::9dfd:2b7b:1999:aff2%2]) with mapi id 15.20.1537.018; Fri, 18 Jan 2019 18:27:18 +0000 From: "Moger, Babu" To: "fenghua.yu@intel.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "tony.luck@intel.com" , "peterz@infradead.org" , "reinette.chatre@intel.com" , "Moger, Babu" , "james.morse@arm.com" , "xiaochen.shen@intel.com" , "ravi.v.shankar@intel.com" , "sai.praneeth.prakhya@intel.com" , "arshiya.hayatkhan.pathan@intel.com" CC: "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: [PATCH v5 13/13] selftests/resctrl: Disable MBA and MBM tests for AMD Thread-Topic: [PATCH v5 13/13] selftests/resctrl: Disable MBA and MBM tests for AMD Thread-Index: AQHUr1txhAdfIPGEpEyiEQVQaYWKQA== Date: Fri, 18 Jan 2019 18:27:17 +0000 Message-ID: <20190118182646.16594-14-babu.moger@amd.com> References: <20190118182646.16594-1-babu.moger@amd.com> In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR12MB1737;20:iM/39GoVtMxh3QmwIAsK7kCmvzt2r6dWtSiXfiuD9lzyHOuzGVv/J9qCmxXxNNfuTbrEUHsi9mS6RRKD30/Hlc1n4g4/+AqaonH2a4Vtf56ePvQV42vU/AlTbu2g3UoXwiXFMn6LQfkn8vxuIJl9EuOnMb2hWuIOJ6AOVPQTQbfnWAKV3bSSqGSuDRSWEfU+zYoohswIi6D38tFMnQPTHZNw4KVya1CKokqyfpLLrD6Cvf1GF1J2jaN53IkrlXjw x-ms-office365-filtering-correlation-id: 1523d5ed-d48a-4343-6f85-08d67d7293b0 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1737; x-ms-traffictypediagnostic: DM5PR12MB1737: x-microsoft-antispam-prvs: x-forefront-prvs: 0921D55E4F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(39860400002)(366004)(136003)(189003)(199004)(54906003)(50226002)(6512007)(8676002)(6436002)(99286004)(1076003)(110136005)(53936002)(6486002)(7416002)(25786009)(8936002)(36756003)(26005)(4326008)(186003)(81156014)(316002)(6116002)(81166006)(3846002)(6346003)(476003)(71200400001)(105586002)(2616005)(68736007)(2906002)(71190400001)(14454004)(106356001)(486006)(2201001)(6506007)(5660300001)(97736004)(102836004)(72206003)(256004)(11346002)(2501003)(7736002)(86362001)(52116002)(66066001)(478600001)(305945005)(76176011)(386003)(446003)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1737;H:DM5PR12MB2471.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: deGcOQcLm2BleILtwQGibxGKV6m3AP5xeymp+aYj/rrw6P32AC+r1CDwxYK84K4JxgfBkTkOCvPvDO3Uek4vBMDWG+EEI/fnOaFT9niR3vKM7MccF8b5vG6Tra62Bel6KUlhCC8N+X3wnlQE2s1f1zEZd78xNlE5KI2Oh07m45Y+5UovsgSIjSUlFLMkLgJcMs8+L44KDFz+iOiKCLL/CSdrIjxUBIhMvGgjsZAXYSDMYBsHIXAyNCdu/Mq7Z4LX2qZn3mH1EYM2Vj494yPIq8G4OkPokqpSxkJ/pess0EGR9f/t4MRlu4r0YLLFCsOfb99SNGKj9mWrJICtwM133NagDqa7sPWxp3vHJK1/KSYuTFI1GLzLNghuD2TeB4uTiO5KBfo4hHZmpAlzNVcxRH35z8x0mvU6tXl2hgGJsI4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1523d5ed-d48a-4343-6f85-08d67d7293b0 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2019 18:27:16.8779 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1737 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For now, disable MBA and MBM tests for AMD. Deciding test pass/fail is not clear right now. We can enable when we have some clarity. Signed-off-by: Babu Moger --- tools/testing/selftests/resctrl/cat_test.c | 2 +- tools/testing/selftests/resctrl/resctrl_tests.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 57d501d..badf2d1 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -69,7 +69,7 @@ static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits, printf("Allocated cache lines: %lu \t", allocated_cache_lines); printf("Percent diff=%d \t", abs((int)diff_percent)); - if (abs((int)diff_percent) > MAX_DIFF_PERCENT) + if (genuine_intel && (abs((int)diff_percent) > MAX_DIFF_PERCENT)) printf("Failed\n"); else printf("Passed\n"); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index e8cbcd5..b12f2c5 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -202,7 +202,7 @@ int main(int argc, char **argv) sprintf(bw_report, "reads"); sprintf(bm_type, "fill_buf"); - if (mbm_test) { + if (genuine_intel && mbm_test) { printf("\nMBM BW Change Starting..\n"); if (!has_ben) sprintf(benchmark_cmd[5], "%s", "mbm"); @@ -212,7 +212,7 @@ int main(int argc, char **argv) mbm_test_cleanup(); } - if (mba_test) { + if (genuine_intel && mba_test) { printf("\nMBA Schemata Change Starting..\n"); if (!has_ben) sprintf(benchmark_cmd[5], "%s", "mba");