Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1238997pxa; Thu, 20 Aug 2020 06:29:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDvBK3FfcRFhcG/Mye1g/mQ83buDPH/FntN5IVGBCq3y4yzILEvHwBNnrZgFkRx45k+oH7 X-Received: by 2002:a17:906:4f0f:: with SMTP id t15mr3163332eju.337.1597930142770; Thu, 20 Aug 2020 06:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597930142; cv=none; d=google.com; s=arc-20160816; b=rRA0lxhWGxMjmIP9z0lGSYS7h8kgbD48ZzDWzMbsOvGvDmixYRyw3vgNq11deUzcTX BRQ1lLsm79J6tSXmuC1KyF6NriYo306CyzjDqCRs0u7gRfCBetrDuSP4vBi2QIsrDyrL 2wFqzDHU2z4rY8y1SQvxnKT24JwtZv4VpdvUoJsmzohEa8j324ra1PPg2kyJHqcjDOxi rkX9derD6rhWxppYuJGZVeVD/LDCH2KHkkKAlEVl4+ISiCmKvttr6UQz7Pc8FCZNbLDI neCg6uY0mlLl6T/Rcv6wY2VmQO9raa8CN9pJhkLDnVkfnE4ybM/4VBj0+sp1jllIkHQA aXKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nXK6r91mVCFoM3YtBe5lVDBD5gOOHaiArFwgtTpUSD4=; b=1DM6Jd8GQNQCRNXtSF2PsQ4BEPKo7H5LkCcDuKUeJpksfeFawEDeDOHy9+dsxajZdw xUN5k+BWmmDBLLZfp76/w/zWI5IRW97QmfhRpY2lsA195DURWoJBTsQ6xqCiUGXd17SA 2L5hNDmiMG7n00tg1FoYDgvIW33SZA1JbayF92vhtpHU83SxFKLaR3sGYvvDEoozZ9Tq j3sYcju0A+IYN/tOQ93KLlD/nb8Adry7EJBCTRYnPkbw0/xhthBFi9Jgz64adzIpIrvJ JgjesxYI6TNEPEVDJkmZMP9V7KBOg2PnJdYyKTTbuWRAGcFhlnjZH3yq2eEgYik3Ftu9 v3cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0K6eMO3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si1468606ejm.580.2020.08.20.06.28.37; Thu, 20 Aug 2020 06:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0K6eMO3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730773AbgHTNXT (ORCPT + 99 others); Thu, 20 Aug 2020 09:23:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728035AbgHTJeK (ORCPT ); Thu, 20 Aug 2020 05:34:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9C4D522C9F; Thu, 20 Aug 2020 09:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916019; bh=SyegA3bvJrFg8dpHJ5/ardA2mwqjWJ6lgwFOeVX86zA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z0K6eMO3IBhmyJfVKc1PmZGMxR9m5gTy+naIrEj7vSUDgKB2Ki2AHXXT5LdhaeUGd vXtxb9JBgv9YMdoBRuMZm7etqlGt8v+Kt4WZFdQCly7/Vr27M4DlkgtKy0TdFX6J2E sXQbpdvT+YAcOmjtFxHGFEOYiLmJfj3exO5ZONRM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Whitchurch , Alexander Shishkin , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , kernel@axis.com, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.8 215/232] perf bench mem: Always memset source before memcpy Date: Thu, 20 Aug 2020 11:21:06 +0200 Message-Id: <20200820091623.210335929@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Whitchurch [ Upstream commit 1beaef29c34154ccdcb3f1ae557f6883eda18840 ] For memcpy, the source pages are memset to zero only when --cycles is used. This leads to wildly different results with or without --cycles, since all sources pages are likely to be mapped to the same zero page without explicit writes. Before this fix: $ export cmd="./perf stat -e LLC-loads -- ./perf bench \ mem memcpy -s 1024MB -l 100 -f default" $ $cmd 2,935,826 LLC-loads 3.821677452 seconds time elapsed $ $cmd --cycles 217,533,436 LLC-loads 8.616725985 seconds time elapsed After this fix: $ $cmd 214,459,686 LLC-loads 8.674301124 seconds time elapsed $ $cmd --cycles 214,758,651 LLC-loads 8.644480006 seconds time elapsed Fixes: 47b5757bac03c338 ("perf bench mem: Move boilerplate memory allocation to the infrastructure") Signed-off-by: Vincent Whitchurch Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: kernel@axis.com Link: http://lore.kernel.org/lkml/20200810133404.30829-1-vincent.whitchurch@axis.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/bench/mem-functions.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c index 9235b76501be8..19d45c377ac18 100644 --- a/tools/perf/bench/mem-functions.c +++ b/tools/perf/bench/mem-functions.c @@ -223,12 +223,8 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info * return 0; } -static u64 do_memcpy_cycles(const struct function *r, size_t size, void *src, void *dst) +static void memcpy_prefault(memcpy_t fn, size_t size, void *src, void *dst) { - u64 cycle_start = 0ULL, cycle_end = 0ULL; - memcpy_t fn = r->fn.memcpy; - int i; - /* Make sure to always prefault zero pages even if MMAP_THRESH is crossed: */ memset(src, 0, size); @@ -237,6 +233,15 @@ static u64 do_memcpy_cycles(const struct function *r, size_t size, void *src, vo * to not measure page fault overhead: */ fn(dst, src, size); +} + +static u64 do_memcpy_cycles(const struct function *r, size_t size, void *src, void *dst) +{ + u64 cycle_start = 0ULL, cycle_end = 0ULL; + memcpy_t fn = r->fn.memcpy; + int i; + + memcpy_prefault(fn, size, src, dst); cycle_start = get_cycles(); for (i = 0; i < nr_loops; ++i) @@ -252,11 +257,7 @@ static double do_memcpy_gettimeofday(const struct function *r, size_t size, void memcpy_t fn = r->fn.memcpy; int i; - /* - * We prefault the freshly allocated memory range here, - * to not measure page fault overhead: - */ - fn(dst, src, size); + memcpy_prefault(fn, size, src, dst); BUG_ON(gettimeofday(&tv_start, NULL)); for (i = 0; i < nr_loops; ++i) -- 2.25.1