Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKJSs-000546-54 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 13:35:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pKJSq-0005Fs-5J for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 13:35:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKJSp-0005Fa-Kw for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 13:35:51 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pKJSm-0006K8-EU for pgsql-hackers@postgresql.org; Tue, 24 Jan 2023 13:35:50 +0000 Received: by mail-ej1-x631.google.com with SMTP id bk15so38975023ejb.9 for ; Tue, 24 Jan 2023 05:35:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vG8/Un6kGMOrNtDN9JXf7O4uDA538xtp6KeSeP6YqUo=; b=aynO61SlpMybCgYG7c1CsIBAHWGe9vuEwpTt2UsO2dbK2/+alMeYAXDW2JJ2Ms8FP1 cp62CCJZjtTpysUhPOe3vg9AK2h4MYxYIv883//Z6MgQa16MbleCxLn4imNDoWyMAetk bcUyy731rUcJoVuje00Cj1zGLOROmf/ztq8o+bytSGWGn5Biaf/zQpSKKPpld4PHWI4d Pl+2hxG2hCZr7e374IhMINMNa4rUDuq0+a3geIMtfKsMSVhAey15vQe1IwQojkxb1RQt ootF9SaRj0xOiip9cHqyGo+RQ3h86XrEf3TZ2DLlOodY7H8YAhEPO5EnOYBq/dzIfgE6 iUgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vG8/Un6kGMOrNtDN9JXf7O4uDA538xtp6KeSeP6YqUo=; b=KYBu4QX42oNGftRpYa/DCVxXfijFnz61CJpMLrLXLKK/8qVvUOvZ8n21ZNKozW+BX1 HqXGNvlRRgt++QcrMcmU/LGJYH1oKzu9ChJKyAhSqOkSCU6bWE5l0OHqivUH7WW3GQVq im5kd7AwDbiyOKqNtsW26uyQfEqYd/iJIdot7hwQH93SHmO9dtdzfES2aH+jmKMfkOeO nyxosO1kFPclbNaKJyUCfX7VRcsFD2cz4JnX0HAEmQCMJ7wMCoShmOBLxlc0yO8VIwr1 kHP6UK0Fw5zv9mfg+HJ2scdl/SyrxGX8Zzq4z6D+pl1lRa+OJb5wGl0yLsBMlBkQWcB6 iyjQ== X-Gm-Message-State: AFqh2kpACEZIB4ye1nLouvRWPLoBRM9YKlL0x0LDsdyZpDP2Rtn1w1SI pLrfCam7u2OcDWlLhOccZ5M= X-Google-Smtp-Source: AMrXdXucnZrJzcLsdr86PcWDAXw7G75/2RAyH4twMLjCQBqgZJz+QIxsiPSM3jRR/rYMw3a5KX72vA== X-Received: by 2002:a17:906:762a:b0:7c0:be5d:59a9 with SMTP id c10-20020a170906762a00b007c0be5d59a9mr38951458ejn.20.1674567346872; Tue, 24 Jan 2023 05:35:46 -0800 (PST) Received: from [172.16.209.129] ([147.161.235.10]) by smtp.gmail.com with ESMTPSA id a8-20020a17090680c800b0084d397e0938sm890616ejx.195.2023.01.24.05.35.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Jan 2023 05:35:46 -0800 (PST) Message-ID: <6a3f41fd-7103-28e2-dfa0-a7f1e6b89329@gmail.com> Date: Tue, 24 Jan 2023 14:35:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc? Content-Language: en-US To: Andres Freund Cc: Robert Haas , vignesh C , Lukas Fittl , Michael Paquier , Ibrar Ahmed , Maciek Sakrejda , pgsql-hackers References: <20230113195547.k4nlrmawpijqwlsa@awork3.anarazel.de> <20230117164758.gx4uuzhk5grw7zea@awork3.anarazel.de> <50c9f291-fc60-1d2e-e286-0fb888586e7e@gmail.com> <20230121041200.225hljezqtpijvq4@awork3.anarazel.de> <5a09bfe1-8a6c-de2e-d2b0-62abc5a8fe7a@gmail.com> <20230123202619.yckkxn56iavoq2rn@awork3.anarazel.de> From: David Geier In-Reply-To: <20230123202619.yckkxn56iavoq2rn@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi > > I think at least some should be converted to just accumulate in an > instr_time... I think that's for a later patch though? > Yep, at least quite similar. OK. I coded it up in the latest version of the patch. > Depending on how low we want to keep the error, I don't think we can: > > If I set the allowed deviation to 10**-9, we end up requiring a shift by 29 > for common ghz ranges. Clearly 33bits isn't an interesting range. > > But even if you accept a higher error - we don't have *that* much range > available. Assuming an uint64, the range is ~584 years. If we want 10 years > range, we end up > > math.log(((2**64)-1) / (10 * 365 * 60 * 60 * 24 * 10**9), 2) > ~= 5.87 > > So 5 bits available that we could "use" for multiply/shift. For something like > 2.5ghz, that'd be ~2% error, clearly not acceptable. And even just a year of > range, ends up allowing a failure of 30796s = 8min over a year, still too > high. Thanks for doing the math. Agreed. The latest patch detects overflow and correctly handles it. > But I don't think it's really an issue - normally that branch will never be > taken (at least within the memory of the branch predictor), which on modern > CPUs means it'll just be predicted as not taken. So as long as we tell the > compiler what's the likely branch, it should be fine. At least as long as the > branch compares with a hardcoded number. Yeah. The overflow detection just compares two int64. The "overflow threshold" is pre-computed. > - the restriction just to linux, that'll make testing harder for some, and > ends up encoding too much OS dependency > - I think we need both the barrier and non-barrier variant, otherwise I > suspect we'll end up with inccuracies we don't want > - needs lots more documentation about why certain cpuid registers are used > - cpu microarch dependencies - isn't there, e.g., the case that the scale on > nehalem has to be different than on later architectures? > - lack of facility to evaluate how well the different time sources work Makes sense. I carried that list over to my latest e-mail which also includes the patch to have some sort of summary of where we are in a single place. -- David Geier (ServiceNow)