From patchwork Mon Nov 18 14:59:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Stancek X-Patchwork-Id: 1196815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cIwXd5Ai"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47GsZn62lHz9sPW for ; Tue, 19 Nov 2019 02:00:33 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E575A3C18F7 for ; Mon, 18 Nov 2019 16:00:30 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 5F5B33C18FE for ; Mon, 18 Nov 2019 16:00:14 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id C2C801A008A3 for ; Mon, 18 Nov 2019 16:00:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574089212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WxpCu1Te7wN3c5pwsMKz5BjXPSX1uGgrdXO4StBaHSg=; b=cIwXd5Ai1sdcSWVa6mZtLLMxt1hDYSfaRue4o7Wm58r8ElRtcHZ1ebMMNtBtXae0IQugXD RMZaBI0WiJb8mERvkIS1/yNoNeJ2bP4AuMfPcEzP2iAhM5ZFwuORoCfTsbkMkdLt2bSn3+ /35f5X26VBfEfDh2tF3cIHUlhFnH5uQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-4meSmLIMMISoC0KW2MZ45Q-1; Mon, 18 Nov 2019 10:00:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7096B1E33 for ; Mon, 18 Nov 2019 15:00:09 +0000 (UTC) Received: from dustball.usersys.redhat.com (unknown [10.43.17.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47A37646A6 for ; Mon, 18 Nov 2019 15:00:09 +0000 (UTC) From: Jan Stancek To: ltp@lists.linux.it Date: Mon, 18 Nov 2019 15:59:56 +0100 Message-Id: <5b0f2a837117f3af1351d8b3da357cacecaa1463.1574087532.git.jstancek@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 4meSmLIMMISoC0KW2MZ45Q-1 X-Mimecast-Spam-Score: 0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 2/3] perf_event_open02: make do_work() run for specified time X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" do_work() runtime varies a lot, because it's based on a fixed number of iterations. Set a timer and run for at least specified time. We don't need fine accuracy, just some coarse runtime across all systems. verify() function is using larger value to get more precision for "ratio" calculation. Signed-off-by: Jan Stancek --- .../syscalls/perf_event_open/perf_event_open02.c | 36 +++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c index 584487de8255..5891694eb894 100644 --- a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c +++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c @@ -31,12 +31,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include "config.h" @@ -49,7 +51,6 @@ #include #define MAX_CTRS 1000 -#define LOOPS 100000000 struct read_format { unsigned long long value; @@ -67,6 +68,7 @@ static struct tst_option options[] = { static int ntotal, nhw; static int tsk0 = -1, hwfd[MAX_CTRS], tskfd[MAX_CTRS]; +static int volatile work_done; static int perf_event_open(struct perf_event_attr *event, pid_t pid, int cpu, int group_fd, unsigned long flags) @@ -98,14 +100,34 @@ static void all_counters_set(int state) tst_brk(TBROK | TERRNO, "prctl(%d) failed", state); } -static void do_work(void) +void alarm_handler(int sig LTP_ATTRIBUTE_UNUSED) +{ + work_done = 1; +} + +static void do_work(int time_ms) { int i; + struct sigaction sa; + struct itimerval val; - for (i = 0; i < LOOPS; ++i) - asm volatile (""::"g" (i)); -} + work_done = 0; + memset(&val, 0, sizeof(val)); + val.it_value.tv_sec = time_ms / 1000; + val.it_value.tv_usec = (time_ms % 1000) * 1000; + sa.sa_handler = alarm_handler; + sa.sa_flags = SA_RESETHAND; + SAFE_SIGACTION(SIGALRM, &sa, NULL); + + if (setitimer(ITIMER_REAL, &val, NULL)) + tst_brk(TBROK | TERRNO, "setitimer"); + + while (!work_done) { + for (i = 0; i < 100000; ++i) + asm volatile (""::"g" (i)); + } +} #ifndef __s390__ static int count_hardware_counters(void) @@ -128,7 +150,7 @@ static int count_hardware_counters(void) fdarry[i] = perf_event_open(&hw_event, 0, -1, -1, 0); all_counters_set(PR_TASK_PERF_EVENTS_ENABLE); - do_work(); + do_work(500); all_counters_set(PR_TASK_PERF_EVENTS_DISABLE); if (read(fdarry[i], &buf, sizeof(buf)) != sizeof(buf)) @@ -261,7 +283,7 @@ static void verify(void) } all_counters_set(PR_TASK_PERF_EVENTS_ENABLE); - do_work(); + do_work(4000); /* stop groups with hw counters first before tsk0 */ for (i = 0; i < ntotal; i++) { ioctl(hwfd[i], PERF_EVENT_IOC_DISABLE);