Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vLcZs-005H4K-2I for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Nov 2025 07:26:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vLcZr-00B9qD-10 for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Nov 2025 07:26:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vLcZr-00B9nY-00 for pgsql-hackers@lists.postgresql.org; Wed, 19 Nov 2025 07:26:07 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vLcZl-000IaS-2B for pgsql-hackers@postgresql.org; Wed, 19 Nov 2025 07:26:06 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-47118259fd8so46823945e9.3 for ; Tue, 18 Nov 2025 23:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763537161; x=1764141961; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=bStl6vXdApz1SrMpOTop7rzGgimY+UKEz8aUq1wL+nM=; b=ExsgP26ULiF+q31/KjXUK6VyJLa4GZsGmWvuVwC9Ez0LYBI6+1GJ+5LLQJFI+8Pol8 GqsCIvB1XZyQRXNLCY2YUAFIn3xroanjIDr5+bmxhNmCm+ui96FeShIOJqxcGJtIrWTt qt2LAbL1LG0npq0ZwH9gazAdP0XGyNAj1/hDArUx8St8hBbPMamxjSHFKBmQLBIrVR3h IjJkkrlhzBzrmaNtL6B6NPxJKVIbngn2+uAh0nqUYhCW2rYe7/2IWCYOXVTuH9G4nBi1 0bht0Hb4uedbdixEsphXr0fsS+enJHvog2TkEBccHhf9jT3Y7+jn4/y/pjgZcZc3rwBf OyNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763537161; x=1764141961; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bStl6vXdApz1SrMpOTop7rzGgimY+UKEz8aUq1wL+nM=; b=Na/lD1Eq+cURyqLtLVl804K3drs6pnhn1Pi/Q4QDDCQB42zuZ/A8l7UJMtUFaBoTHQ 1UUxSqIFdluiww/KooE5JjL8oJuAHoqoR1mhfo17x3tGabq+agr839zOXnSqZEngZbgx zfBx6l0QPm14MntsmOPiQOXMVIhHXOpzoTL6yObXXwNu8HBZTsCEE022kXAxuV0nE0kC id7zQkYYaVqXP2HEG0MMjPkMkuAT4POhuxKkbXl4M8YZyYsLxBvsk5YM05Tg47YXP7zU AMfUV7b4FO5I3vcCVuN9W+JdFvNjKziERYa2Vs60kcy/rV8dtBJwljHvTU34p6I006dB EkKw== X-Forwarded-Encrypted: i=1; AJvYcCUUIkKlFCgK4/aXB0YT69/yN3lwjxBIsW80wTwtJzeMrXgjmDuFfbmeqDlJYKL+UNqOfzXxzKon6KsEaOJh@postgresql.org X-Gm-Message-State: AOJu0YzjQD+qYasWFkhKOz38USkioFuiXgGKk/ufnKTtllsQCoNROrHp rO7dcdXVqdjpf06CLw1a0FATCcAGm/Ex1QrqsY6Ser6o0ssGObZ1XVd4 X-Gm-Gg: ASbGnctKSLk+l5aL02/vx2tWb8JW4PeO8ZzZke1tjm4iIiqQbRAFTt9pi6ZaJbfmIdB 5UnIfnapcHIGItLNUyi2ukMYuWWipmcLFWlbZyPBnRUkDF0B5i5js0lqZqEHbLsezcJaxUpNKmY UDYexsS9M7SsiS69IO1f+1B2N6e3Yff5IBRU9UlvDiTlO0Eeh2pBi1Jpl6Gtwp2p2rJaF6yv5rZ XWtm9HeWefipXOofBJostJgGCgcO9JRF+V7BvPfErezj/v4z6NTB1Y1N83opF6rgnmpfPGvk2fL ObUzutivuVyXG5hRmg0RGPU79/+7jl75VAEaUkCrVrP7tWU9uHkvhzHik4MV0OoAZW+Orvm8fe5 0md6yFGSDm0kbCGolaLCD+wYvfruCkjLGA75QgeYeW91pZujOOW7BoHFtKWv8AnoAojh/jGK+TZ alMvCa/Q== X-Google-Smtp-Source: AGHT+IEq8Py82Io4rf1n3+y2CsUEoIPtzgueBQ1eAoPSnQjO0+2nMs0JxYYI6xNCOKlCZlm/pxPQqw== X-Received: by 2002:a05:600c:3587:b0:477:8a29:582c with SMTP id 5b1f17b1804b1-4778feb23b3mr183458195e9.34.1763537160680; Tue, 18 Nov 2025 23:26:00 -0800 (PST) Received: from [192.168.2.32] ([165.225.27.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477b1078a80sm30872235e9.14.2025.11.18.23.25.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Nov 2025 23:26:00 -0800 (PST) Message-ID: <57845c37-85e8-4d0e-9456-76833e089c5d@gmail.com> Date: Wed, 19 Nov 2025 08:25:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc? To: Andres Freund Cc: Lukas Fittl , Pavel Stehule , Tomas Vondra , vignesh C , Michael Paquier , Ibrar Ahmed , Maciek Sakrejda , pgsql-hackers References: <20230123174158.rhmrbmjp6ycak64r@awork3.anarazel.de> <20230207181218.47irz3of34qsww5l@awork3.anarazel.de> <989acbcf-e950-7911-c2e2-fe7aa7d15108@gmail.com> <198ef658-a5b7-9862-2017-faf85d59e3a8@gmail.com> <20240601185200.riqzbabh5azna2fr@alap3.anarazel.de> Content-Language: en-US From: David Geier In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22.10.2025 15:32, Andres Freund wrote: > Hi, > > On 2025-09-01 12:36:24 +0200, David Geier wrote: >>> Open questions I have: >>> - Could we rely on checking whether the TSC timesource is invariant (via >>> CPUID), instead of relying on Linux choosing it as a clocksource? >> >> Why do you want to do that? Are you concerned that Linux might pick a >> different clock source even though invariant TSC is available? > > Not sure about Lukas, but I'm slightly concerned about making this a linux > specific mechanism unnecessarily. > Considering [1], Lukas seems to share my concerns that building or own has the risk of missing cases. > >> We could code our own check but looking at the Linux kernel code, this >> is a bit more involved if we want to do it completely right. They check >> e.g. if the TSC is also synchronized across different CPUs, which is not >> the case if they're on different chassis (see unsynchronized_tsc() -> >> apic_is_clustered_box()). > > I think Linux has higher fidelity requirements than our instrumentation usage > - with linux an inaccurate clock would lead to broken timers, wrong wall clock > etc, whereas for us it's just a skewed instrumentation result. That's true. As long as we use the RDTSCP basd code only in places where it doesn't affect "correctness" it's not the end of the world if they're skewed. I'll give it a try to code our own detection mechanism and will share findings here. Then we can make a call based on the learnings. -- David Geier [1] https://www.postgresql.org/message-id/CAP53Pky-BN0Ui%2BA9no3TsU%3DGoMTFpxYSWYtp_LVaDH%3Dy69BxNg%40mail.gmail.com