From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 4CEA94A2BF for ; Wed, 29 Jan 2025 09:54:09 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2377368B90C; Wed, 29 Jan 2025 11:54:06 +0200 (EET) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B973968B443 for ; Wed, 29 Jan 2025 11:53:58 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5426fcb3c69so5439246e87.3 for ; Wed, 29 Jan 2025 01:53:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20230601.gappssmtp.com; s=20230601; t=1738144438; x=1738749238; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8/JxhaHx7djkmIij7sSuU91jbXsIdgd3+QbQ8Wuxrow=; b=bh/YfzhDTpL5sQ36hICqyCM72xCflKI8Vkg66OZ2k3bAwDVOVLTyCVZjxlcC/woiWN 3bUtn0L2gpbkhreRRr9rwFtUEdC0j36due5LEVNTUkmfWgNQmy9lF/3ohlVoEIRH38tq VMDwfkgaG5BlmrNwOyoZt2zG8PeuM8ceeUoPzzxOh0gLkmB/kdvYfj/xNYPUFtErmH7g 1FIfsIWi73wIrZAgngi0KvH5NfAcpg+F8fngqWpY2Wb4PbqPYTFs5t8HkpL3IvuIhgo+ 7QaS+uhoMbdEolb5jeAcLf1dbBFScfQX9Yi/YMDFyu3rhBBsgAFUukN0Q8hPdRVNb2dN DReQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738144438; x=1738749238; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8/JxhaHx7djkmIij7sSuU91jbXsIdgd3+QbQ8Wuxrow=; b=JUke/vLEZHLfHk31HvGKIQlOMB6V6Ea6bgJtwM9RSpH8YR6Cf3tyDWX4AEnI6NGOEr JKW6weVazSbARHaCt5LUaNDJqSr9IsxqhHCIz1b/SoRGiarBEoZHJ0hTqnGmQtgSDgf2 MiYoERHlx+XAlFNjT9fbl7nC+4pR8kNWmWWVM8RvdjxYmtgNKtxTIQufYN9OyyPErPjv DgRmZBKYF0zwj/HUNTIPbxtWJKAy4kQuBkdanGsGMthd5cUpJytOKyHJZdVZAl7B9NsE O32XhxHdldZHtYu7OKCn68X+O/mgcf1mDnBQfFOIBfYK5kpRKCM25xbJsTAaF+oXYnjM 0zjQ== X-Gm-Message-State: AOJu0Yx5Bww7mx87QX9NbuJH2AnDhDXs23a4GfKD7rbqox7FY9rzgOba ojNdGvUK+Lf0E6oxuZieXuPLONRc30YXwI1rMlqrQ340sjENSdJDL9yeSxkHEc12c9li3SC7TYw eGQ== X-Gm-Gg: ASbGncs7yYWBYVrP0VbNCVTtD0Jz6nsQUfZNJclExUPFVU1oDH/hdKvR/afJz3bIxzD 3uyGbzFu8Kvkc247kQPLme0gO6VxMoFi5IACLU92bdYnke+xpQBeNIix1TEjGsYwNGW7O1EubRU QFn3PJjacYXNWyg7Rox+No0RQm/bjJSU/+6MzET1+ZwJbqT8vJ4rRhLObUog9sBNOfvyGBUO3Xs 9uuzTM2qiAAmzSEmzjNFTtHPWtZ268/0CdoGJFp7iW6zJ7ZmqnDxQJ8j0daICzgHWKIYsz5r5B+ FBgfXverhA4sygBB60VsvmbZkYUf6pZKBFMs6H3W4ZvlGQQ= X-Google-Smtp-Source: AGHT+IGGocdlVsdIWC/NzTrlMnwBbmbTjTVU5WRWzwDQ911O3O/iv1/mHb3TEaksJp95UdOCn4Z9+g== X-Received: by 2002:a05:6512:239e:b0:540:1f7d:8bc0 with SMTP id 2adb3069b0e04-543e4c3c25emr862295e87.49.1738144437506; Wed, 29 Jan 2025 01:53:57 -0800 (PST) Received: from localhost (dsl-tkubng21-50de30-198.dhcp.inet.fi. [80.222.48.198]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c83683e4sm1913703e87.144.2025.01.29.01.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2025 01:53:56 -0800 (PST) From: =?UTF-8?q?Martin=20Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Jan 2025 11:53:53 +0200 Message-ID: <20250129095356.2010103-1-martin@martin.st> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] random_seed: Limit the time taken by get_generic_seed X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Michael Niedermayer Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On a Zen 5, on Ubuntu 24.04 (with CLOCKS_PER_SEC 1000000), the value of clock() in this loop increments by 0 most of the time, and when it does increment, it usually increments by 1 compared to the previous round. Due to the "last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t" expression, we only manage to take one step forward in this loop (incrementing i) if clock() increments by 2, while it incremented by 0 in the previous iteration (last_td). As we do mutate the buffer state even on loop iterations where we don't increment i, limit the number of times we consecutively can do this. This is similar to the change done in c4152fc42e480c41efb7f761b1bbe5f0bc43d5bc, to speed it up on systems with very small CLOCKS_PER_SEC. However in this case, CLOCKS_PER_SEC is still very large, but the machine is fast enough to hit every clock increment repeatedly. This makes sure that fate-random-seed actually terminates within a reasonable time on such a system (where it previously could hang, running for many minutes). --- libavutil/random_seed.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c index 8a4e4f1fc0..8f969060a0 100644 --- a/libavutil/random_seed.c +++ b/libavutil/random_seed.c @@ -83,6 +83,7 @@ static uint32_t get_generic_seed(void) static uint32_t buffer[512] = { 0 }; unsigned char digest[20]; uint64_t last_i = i; + int cur_iters = 0; av_assert0(sizeof(tmp) >= av_sha_size); @@ -98,11 +99,13 @@ static uint32_t get_generic_seed(void) for (;;) { clock_t t = clock(); - if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t) { + if (last_t + 2*last_td + (CLOCKS_PER_SEC > 1000) >= t && cur_iters < 128) { last_td = t - last_t; buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (last_td % 3294638521U); + cur_iters++; } else { last_td = t - last_t; + cur_iters = 0; buffer[++i & 511] += last_td % 3294638521U; if ((t - init_t) >= CLOCKS_PER_SEC>>5) if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8) -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".