Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3841911rwb; Mon, 5 Sep 2022 20:37:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7U/17xkGokgsafLZZpOFAx8L43YM92gbZJpY8um+G8s23pWWEbCTvAJlrOwu6JIkVQ9tzj X-Received: by 2002:a63:8549:0:b0:434:3c39:4fe0 with SMTP id u70-20020a638549000000b004343c394fe0mr8887767pgd.221.1662435466965; Mon, 05 Sep 2022 20:37:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662435466; cv=none; d=google.com; s=arc-20160816; b=ZukY8m2+SlzL45RL6nCWa4sVrHE3M+QrXr4fXVo9SvmAQMUv3XJpIG2hn2W6pYOhZh lGkfFjPtDq9TXq7mZr3L/Ts886Fhil4f/AJTdi7NJioL1NMpN5qYPOvlXTHz0PzYxL9n zzQNNjABr3kYo31fRAjYWfQ2lzXIDam9vmodXB/HXFI+aylbYmGRCF5vPeNIGpHw/XhV 81WPEL4FGORpv1HEpGB9xLVkx+UeftsVN8Dg0XbbSm/2mJhEyxC2CCbsRukdGPTj7BwE lDrR26rkgmPFRStV0oyNSnoPznKcMRUe01wKIjOdl51GqWaee7Dev6a7i1yRoJWH/iae oMCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=LbL6IG/qWiVN6W+ExopzlrYnXCacnoe37ikdPeVUyyA=; b=mjvjQVUJ5RRBpVgqInL0bmeFNfpyJyBjiEscK6XTowqqoRJqnnTX3M9bphmCdJoTd4 z/60dTZmYk6tBEPbuE7CvRUHOjj8vYP2+FDUeCz40qB0e8HvrSvnRv5FHmw8kCi1L8AQ js7WMeefZP6NTnqshTqfFVKuPM/98EhGT3DnBhr7NKKMKpTGSb286lKuxKy8RFU0yCme v8kxFFibYHhF4IRStqa0Dfz+zTcjuaFoyTKSuQTtMQjL3o0WWlT9FVJrWdZN2zDgGaKA ov1Ia0wqcZiCtOS8DFGao9NqwYyoZIrR+c+CAUZtZOpd4b9Lb27D0iHo2Ij9RdgErw7M OSjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h69-20020a638348000000b0042814932da7si1584716pge.403.2022.09.05.20.37.34; Mon, 05 Sep 2022 20:37:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237420AbiIFDcC convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Sep 2022 23:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238340AbiIFDba (ORCPT ); Mon, 5 Sep 2022 23:31:30 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDF36D57B for ; Mon, 5 Sep 2022 20:30:40 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-122-ZNshubgrNpWgD0cjxuFveQ-1; Tue, 06 Sep 2022 04:30:34 +0100 X-MC-Unique: ZNshubgrNpWgD0cjxuFveQ-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 6 Sep 2022 04:30:34 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.040; Tue, 6 Sep 2022 04:30:34 +0100 From: David Laight To: 'Tiezhu Yang' , Peter Zijlstra , Ingo Molnar , "Arnaldo Carvalho de Melo" , Mark Rutland , "Alexander Shishkin" , Jiri Olsa , Namhyung Kim CC: "linux-perf-users@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH 2/3] perf bench syscall: Add close syscall benchmark Thread-Topic: [PATCH 2/3] perf bench syscall: Add close syscall benchmark Thread-Index: AQHYwZ3Hi0lkR53PnkGoJIdk12O6V63Rua3A Date: Tue, 6 Sep 2022 03:30:33 +0000 Message-ID: <3d1e08929fb74938998bd9aa2e370424@AcuMS.aculab.com> References: <1662433577-23266-1-git-send-email-yangtiezhu@loongson.cn> <1662433577-23266-3-git-send-email-yangtiezhu@loongson.cn> In-Reply-To: <1662433577-23266-3-git-send-email-yangtiezhu@loongson.cn> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tiezhu Yang > Sent: 06 September 2022 04:06 > > This commit adds a simple close syscall benchmark, more syscall > benchmarks can be added in the future. > ... > > Signed-off-by: Tiezhu Yang > --- > tools/perf/bench/bench.h | 1 + > tools/perf/bench/syscall.c | 11 +++++++++++ > tools/perf/builtin-bench.c | 1 + > 3 files changed, 13 insertions(+) > > diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h > index 6cefb43..916cd47 100644 ... > diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c > index 746fd71..058394b 100644 > --- a/tools/perf/bench/syscall.c > +++ b/tools/perf/bench/syscall.c > @@ -46,6 +46,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) > case __NR_getppid: > getppid(); > break; > + case __NR_close: > + close(dup(0)); Not really a close() test. The dup(0) call will be significant and may take longer. I'm also not sure that using the syscall number for the test number is entirely sensible. One thing I have measured in the past is the time taken to read in an iov[] array. This can be measured quite nicely using writev() on /dev/null. (No copies ever happen and iov_iter() is never used.) But you need to test a few different iov lengths. I'm also not 100% sure how accurate/repeatable/sensible it is to use the 'wall clock time' for 1000000 iterations. A lot of modern cpu will dynamically change the clock speed underneath you and other system code (like ethernet receive) can badly perturb the results. What you really want to use is a TSC - but they are now useless for counting cycles. The x86 performance counters to have a cycle counter. I've used that to measure single calls of both library functions and system calls. Just 10 iterations give a 'cold cache' value and some very consistent counts (remove real outliers). Indeed the fastest value is really the right one. For functions like the IP checksum you can even show that the code is executing in the expected number of clock cycles (usually limited by memory reads). David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)