From nobody Fri Jun 18 07:36:33 2021 X-Original-To: arch@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 476B911DF54E for ; Fri, 18 Jun 2021 07:36:49 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4G5rN00WKcz4vf1 for ; Fri, 18 Jun 2021 07:36:47 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (v-critter.freebsd.dk [192.168.55.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by phk.freebsd.dk (Postfix) with ESMTPS id 9BE4989294 for ; Fri, 18 Jun 2021 07:36:39 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.16.1/8.16.1) with ESMTPS id 15I7aYCY068065 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Fri, 18 Jun 2021 07:36:34 GMT (envelope-from phk@critter.freebsd.dk) Received: (from phk@localhost) by critter.freebsd.dk (8.16.1/8.16.1/Submit) id 15I7aYmk068064; Fri, 18 Jun 2021 07:36:34 GMT (envelope-from phk) Message-Id: <202106180736.15I7aYmk068064@critter.freebsd.dk> To: arch@freebsd.org Subject: It's time to kill statistical profiling From: Poul-Henning Kamp List-Id: Discussion related to FreeBSD architecture List-Archive: https://lists.freebsd.org/archives/freebsd-arch List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arch@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <68062.1624001793.1@critter.freebsd.dk> Date: Fri, 18 Jun 2021 07:36:33 +0000 X-Rspamd-Queue-Id: 4G5rN00WKcz4vf1 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of phk@critter.freebsd.dk designates 130.225.244.222 as permitted sender) smtp.mailfrom=phk@critter.freebsd.dk X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_TLS_ALL(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[130.225.244.222:from]; FREEFALL_USER(0.00)[phk]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[arch@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; SPAMHAUS_ZRD(0.00)[130.225.244.222:from:127.0.2.255]; RCVD_COUNT_THREE(0.00)[3]; ARC_NA(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_NA(0.00)[freebsd.dk]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FORGED_SENDER(0.30)[phk@phk.freebsd.dk,phk@critter.freebsd.dk]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:1835, ipnet:130.225.0.0/16, country:EU]; FROM_NEQ_ENVFROM(0.00)[phk@phk.freebsd.dk,phk@critter.freebsd.dk]; MAILMAN_DEST(0.00)[arch] X-ThisMailContainsUnwantedMimeParts: N Warners work to document the kernel timers in D30802 brought stathz up again. To give a representative result, statistical profiling needs to sample no less than approx 0.1% of instructions. On a VAX that meant running the statistical profiling at O(1kHz). On my 4 CPU, two thread, 2GHz laptop that means statistical profiling needs to run at O(10 MHz), which is barely doable. But it is worse: The samples must be unbiased with respect to the system activity, which was already a problem on the VAX and which is totally impossible on modern hardware, with message based interrupts, deep pipelines and telegraphic distance memory[1]. Therefore statistical profiling is worse than useless: it is downright misleading, which is why modern CPUs have hardware performance counters. Instead of documenting stathz, I suggest we retire statistical profiling and convert the profiled libraries to code-coverage profiling (-fprofile-arcs and -ftest-coverage) Poul-Henning [1] One could *possibly* approch unbiased samples, by locking the stathz code path in L1 cache and disable L1 updates, but then the results would be from an entirely different system. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.