From patchwork Wed Sep 11 21:04:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 1161287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105157-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="B+CKG17C"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FalDdBvH"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46TDwy2T2Jz9s00 for ; Thu, 12 Sep 2019 07:06:58 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; q=dns; s=default; b=EFdHmJXj mAYnxYmKiuqFVhfKnz+8HHmsx/zz5bFrfmnGhvMGXxkAMhLT+Nba+T4KRmcR1LNQ hC2LiCMQpd99PDso5r9kTT6p5fETUq0Bfjfz8jC4FttlCNCTV933aGvhQwgaEAG5 VCxMQXsU2xKokvKPPQePt1Mx3o53clRl8fc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; s=default; bh=3BkM/e7jHiBcXM itgbMk6kxLVIw=; b=B+CKG17CEzrsYQaQbHu8bQ4dOJiQ9bK5BQsMG27jQP7rjo nasZR/sowteo7TrQb/KS+GgmYwDp7hNgLjFlqY29CFrZQycpV+JkuZIztapydIMM w4ua3/KuYRsmCO4SE5qq+zJ6VqZ3rDkUunjj4Fp4Q2iLWkv4xukV3xuMAhn/0= Received: (qmail 96358 invoked by alias); 11 Sep 2019 21:05:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 96135 invoked by uid 89); 11 Sep 2019 21:05:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:mail-pf, HX-HELO:sk:mail-pf X-HELO: mail-pf1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=XDqdIlnMxKCyIRn2Sm9innEWbfMRL1JlJdl4tjkqt58=; b=FalDdBvHyM0Hvs03w16elku3EGeM0xAR6u1K0b0ixU4pQw96giPOXyzW5A4wiosMib gz+L0sJw5BH2/fbZ6lMAXQcoUc830L379NiGaZmSvHnTK2C4xlrjJlf2Uhy1pqi3rGLN MSuQNox0aFhnRwjs/W70DYXjh+7qgeVFYrrbSwf7fCi7mFe/fjZfMe1//4qtPyqJeB/Z ANUU+lJTn/qSn7fK3YXBlIGY3fQ7W1a1G2dhu0YREYBz8IK6D0up9UJgFy5ndTdMeh4U ST4dHZ3dI9aV6XbvfNmeAl3ekZa7C34XPq2t+wDlbFf1Gv+7Kg83jXQTFswyXAu/ShPg Lc3w== From: Isaku Yamahata To: libc-alpha@sourceware.org Cc: isaku.yamahata@intel.com, Isaku Yamahata Subject: [RFC PATCH 11/11] benchtests: simple benchmark to measure nop effects Date: Wed, 11 Sep 2019 14:04:09 -0700 Message-Id: <63d80c2247003fa0116dbcd0188153d79793616f.1568219400.git.isaku.yamahata@gmail.com> In-Reply-To: References: In-Reply-To: References: This is simple benchmark to measure function/nop effects. OS noise is bigger even if it's pinned down to cpu and to make it rt process. $ sudo chrt -r 99 taskset 1 ./a.out Signed-off-by: Isaku Yamahata --- benchtests/bench-nop.c | 128 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 benchtests/bench-nop.c diff --git a/benchtests/bench-nop.c b/benchtests/bench-nop.c new file mode 100644 index 0000000000..bb98b3d371 --- /dev/null +++ b/benchtests/bench-nop.c @@ -0,0 +1,128 @@ +#include +#include +#include + +static inline unsigned long long rdtscp(void) +{ + unsigned int aux; + unsigned long long now = __builtin_ia32_rdtscp (&aux); + return now; +} + +//#define LOOP 10000000 +#define LOOP 1000000 + +void func0(void) +{ + for (int i = 0; i < LOOP; i++) + { + unsigned long ret = syscall(SYS_gettid); + } +} + +void func1(void) +{ + for (int i = 0; i < LOOP; i++) + { + unsigned long ret; + __asm__ volatile( + "syscall\n" + : "=a"(ret) + : "0"(SYS_gettid)); + } +} + +void func2(void) +{ + for (int i = 0; i < LOOP; i++) + { + unsigned long ret; + __asm__ volatile( + "syscall\n" + "nop;nop;nop\n" + : "=a"(ret) + : "0"(SYS_gettid)); + } +} + +void func3(void) +{ + for (int i = 0; i < LOOP; i++) + { + unsigned long ret; + __asm__ volatile( + "syscall\n" + "nop;nop;nop;nop;nop;nop;nop;nop;nop;nop\n" + : "=a"(ret) + : "0"(SYS_gettid)); + } +} + +void func4(void) +{ + for (int i = 0; i < LOOP; i++) + { + unsigned long ret; + __asm__ volatile( + "jmp 1f\n" + "nop\n" + "1:\n" + "syscall\n" + : "=a"(ret) + : "0"(SYS_gettid)); + } +} + +void func5(void) +{ + for (int i = 0; i < LOOP; i++) + { + unsigned long ret; + __asm__ volatile( + "jmp 1f\n" + "nop;nop;nop;nop;nop;nop;nop;nop\n" + "1:\n" + "syscall\n" + : "=a"(ret) + : "0"(SYS_gettid)); + } +} + + +unsigned long long measure(void (*f)(void)) +{ + unsigned long long start = rdtscp(); + (*f)(); + unsigned long long end = rdtscp(); + return end - start; +} + +int main(int argc, char** argv) +{ + printf("measuring syscall func\n"); + unsigned long long time0 = measure(&func0); + + printf("measuring syscall instruction\n"); + unsigned long long time1 = measure(&func1); + + printf("measuring syscall + nop * 3\n"); + unsigned long long time2 = measure(&func2); + + printf("measuring syscall + nop * 10\n"); + unsigned long long time3 = measure(&func3); + + printf("measuring jmp + nop + syscall\n"); + unsigned long long time4 = measure(&func4); + + printf("measuring jmp + nop * 8 + syscall\n"); + unsigned long long time5 = measure(&func5); + + printf("\tfunc\tinst\tnop*3\tnop*10\tjmp+nop\tjmp+nop*8\n"); + printf("ratio\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\n", + time0 * 100.0/time1, + time1 * 100.0/time1, + time2 * 100.0/time1, + time3 * 100.0/time1, + time4 * 100.0/time1, + time5 * 100.0/time1); +}