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.94.2) (envelope-from ) id 1sRzuR-00308u-Ni for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 19:56:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sRzuQ-0007VN-DI for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 19:56:54 +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.94.2) (envelope-from ) id 1sRzuQ-0007VF-3P for pgsql-hackers@lists.postgresql.org; Thu, 11 Jul 2024 19:56:54 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRzuJ-001aKj-AO for pgsql-hackers@postgresql.org; Thu, 11 Jul 2024 19:56:52 +0000 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7f684af6af1so61748239f.2 for ; Thu, 11 Jul 2024 12:56:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720727806; x=1721332606; darn=postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Ot8aDdg9LtRuR8TJUZGQeqf7+60pYsb06sYysopWO/o=; b=X9qjEYdfB+c6YztDHG1B8v3nY+M9NWipDp0TTw41a0op0T7mtBTWeFd/aliFbOmse2 nFf5u6tNVidXG9y/TP3W+l6dS95XjVyqgrRRW2YOwWWP5BRXzZGB7FsLJum61nBg5CgJ cOXmD4iJ8ci3+tu3eyIXS9JPsCaWfiL8CSrRTkadvvixoUcPxQHD0mxIfm0dw03sVr7P cXRLhps9oEytSudzT3fSTriATC2fZp6W6u6prl3hdIlAEhQDHrt0M1xXNPWvTcvvkQIM yVm7ACAU2Y0S/mJ0SDtSarHESolPW+aavdLP2yhF5dmYZnJ0Me+ECl5rOLveCwGpTESc a9yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720727806; x=1721332606; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ot8aDdg9LtRuR8TJUZGQeqf7+60pYsb06sYysopWO/o=; b=oJwTJm/jfm/UdCSM+FN+PZjKzR7qP65XB/kqn3T3spqS1L9nR/SQZcGrSb0hxIxKT8 Nwug8IZL1qVuf59xyVgYMaCkXX4UuD2os4oSc2W+kc3l9OPy3RgOIGr7hF5ugVedBWuF ZnwyQCrUyoNjzC1fr/NvTvYNVgsOf6Ug5wEE8/HwjVKIzQiHZtJgE6zjqaOQO703aGM1 6zcFU3kEyIGfeyt8cicwRVMh5hhixgQyZHvpVGCZ/6qdrnoMcLcjR1x+I/sdIHadS6LI jfJiLYYtZeMiqPark2Pk7IjVxcH71V0Hf2fwy5DFrkHZmYVVQZDzTJNOR0i+o++WlGBw ih8A== X-Forwarded-Encrypted: i=1; AJvYcCVDDm9HZdt1kVQpax/R8dUFd3JEjhM8KcdE/nDimld8MhRoAeW5rYMx/ISafL2TIAPYow3C8/DuOAJcHaTDtVASShpVE1w+SgIajwzL X-Gm-Message-State: AOJu0YwaHG4JuXQeHqZzQaMLQebX1xzMtwsCMIy2xxV/XuNHHdOth6rG /+Qw2B6kCuCMbDF+uwuSYIMiKV1BBLbe7XPQDq3QDzGLpNBjktJb X-Google-Smtp-Source: AGHT+IGjRAKb+kMkZEr79N1Nxn6RfysQxhfB93p1cMDCqCT+pN5TLj1YQwMPzmGW4SRKnt5JnJvCnQ== X-Received: by 2002:a05:6602:15d0:b0:7f6:1cb2:8027 with SMTP id ca18e2360f4ac-80003314b73mr1295256039f.17.1720727806350; Thu, 11 Jul 2024 12:56:46 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c0b1c146casm1978849173.156.2024.07.11.12.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 12:56:46 -0700 (PDT) Date: Thu, 11 Jul 2024 14:56:44 -0500 From: Nathan Bossart To: Sami Imseih Cc: Bertrand Drouvot , Tom Lane , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Restart pg_usleep when interrupted Message-ID: References: <7D50DC5B-80C6-47B5-8DA8-A6C68A115EE5@gmail.com> <2100439.1719610468@sss.pgh.pa.us> <373D199B-2312-431D-8018-F2808913F979@gmail.com> <3712E898-03DA-4E03-AF51-D3E24DE68216@gmail.com> <2F781744-69B8-4BC2-A6EF-3998DCCDB634@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2F781744-69B8-4BC2-A6EF-3998DCCDB634@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 11, 2024 at 01:10:25PM -0500, Sami Imseih wrote: >> I'm curious why we wouldn't just subtract "elapsed_time" from "delay" at >> the bottom of the while loop to avoid needing this extra check. > > Can you elaborate further? I am not sure how this will work since delay is a timespec > and elapsed time is an instr_time. > > Also, in every iteration of the loop, the delay must be set to the remaining time. The > purpose of the elapsed_time is to make sure that we donīt surpass requested time > delay as an additional safeguard. I'm imagining something like this: struct timespec delay; TimestampTz end_time; end_time = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), msec); do { long secs; int microsecs; TimestampDifference(GetCurrentTimestamp(), end_time, &secs, µsecs); delay.tv_sec = secs; delay.tv_nsec = microsecs * 1000; } while (nanosleep(&delay, NULL) == -1 && errno == EINTR); -- nathan