From nobody Thu May 23 21:11:31 2024 X-Original-To: dev-commits-src-main@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 4VlgpC6xwTz5LKwV; Thu, 23 May 2024 21:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VlgpC6Fplz474g; Thu, 23 May 2024 21:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716498691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZramZ3Da6SyJ6lPa14iX74yw0L8qM60msFx71Dv/nyw=; b=pQGhf5oE0XOqEbkSFwdAq4igsCFfn/cnl5o6HYMeuNp0v1r7tLqBWffZMfOrSkmYKRRqqb nqlCVJYOIMEWqvhgVHk9Zb45jhAUEc5hAwdFwX02nvFOIlQ2fWhiq6yZlfdtBks3hrDu+4 Sur9DYs8HO+YtyOw6cjlCRC/bZLGPNEiq0dztrxVbaFbR0zp/JDzJmfA4R4WFrLPNoBRMm PKuRdpmZErWiEeJunnIuW9dUvKY7WZCKp8nnOURNrFWio+Ws+NgZjHqbbD4HjNx7xLNmAF NWnym01s6MJV9WNYrBxZhZY4/6GOTxNRpSEVq9fvwz4vEfqeGg7yaur1VEWs3Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716498691; a=rsa-sha256; cv=none; b=AVMEOnuaxs/pu24axEvIZlHE2+MkHVWmvdsNuU8foqpFFSSDdHAOG7DmAZygSGU7zHG9LZ z8sJBBFFctAZyhXYpsmi4zrJ04oF6wsrppxZo7m8otIjGqjFIw4QVzHDOvXCvaQl8t+AsU CFHHLA0upJkQ0LvIQdfy0chlVuhpY8Zkg2aWlMlQcR6J/wuboWGMuw4AYnBCAvEqkAlMRZ IT3gPeglzcIfW1RYqgBK9tjDpuSP7+0exToEX5WwZNPBJzML7s7FApFHCBXe0gCu943jBj pJZ1qEk3eVn6pNuMbNqzbrhGu9kDkqJJOy5i+ydyGsV+y7IHxLAzIFCTWcrT5g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716498691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZramZ3Da6SyJ6lPa14iX74yw0L8qM60msFx71Dv/nyw=; b=uDqJ4dCmuZ8Z+dpVRtQsWMOZmsu+RI109IWActI3o3q1j8YJjCfZ+/SKoixSX/9XrOL2Y9 hOlGiRdaSVplMoq+r3t410qGQ+O6rxihs2xKsY524AjmdItzuaIw7F335vEmJm8uQKQZ0o NTniHS0hoGU/o0aD4ry9DH/ZHwTlXqs7hN/GSh3EQPwAojQuxkfnb67F8m4nB3R4JK89Du mSkneINowayp3ntD5/2k19SnirROcCCVIUuyyXr3xQxwCKIEpnA+fypUVsa4YvlldWmVrY jCV9Z89F34nLzdiIlJtCg96Yo9hBmIzbDNU6cQo0+O3ekOpll0ShftuP5p8abw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VlgpC5rwyz14b0; Thu, 23 May 2024 21:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44NLBVlq034102; Thu, 23 May 2024 21:11:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44NLBVSK034097; Thu, 23 May 2024 21:11:31 GMT (envelope-from git) Date: Thu, 23 May 2024 21:11:31 GMT Message-Id: <202405232111.44NLBVSK034097@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 674956e19979 - main - sys/netinet/cc: Switch from deprecated random() to prng32() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 674956e1997954e8478e68080061c0530b081515 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=674956e1997954e8478e68080061c0530b081515 commit 674956e1997954e8478e68080061c0530b081515 Author: Henrich Hartzer AuthorDate: 2024-04-10 21:53:02 +0000 Commit: Warner Losh CommitDate: 2024-05-23 21:10:09 +0000 sys/netinet/cc: Switch from deprecated random() to prng32() Related: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277655 Signed-off-by: henrichhartzer@tuta.io Reviewed by: imp, mav Pull Request: https://github.com/freebsd/freebsd-src/pull/1162 --- sys/netinet/cc/cc_cdg.c | 8 +++++--- sys/netinet/cc/cc_chd.c | 9 +++++---- sys/netinet/cc/cc_hd.c | 7 ++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/sys/netinet/cc/cc_cdg.c b/sys/netinet/cc/cc_cdg.c index 1e9236f878d4..7ec9e8ca3ccc 100644 --- a/sys/netinet/cc/cc_cdg.c +++ b/sys/netinet/cc/cc_cdg.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -507,7 +508,8 @@ cdg_cong_signal(struct cc_var *ccv, ccsignal_t signal_type) static inline int prob_backoff(long qtrend) { - int backoff, idx, p; + int backoff, idx; + uint32_t p; backoff = (qtrend > ((MAXGRAD * V_cdg_exp_backoff_scale) << D_P_E)); @@ -519,8 +521,8 @@ prob_backoff(long qtrend) idx = qtrend; /* Backoff probability proportional to rate of queue growth. */ - p = (INT_MAX / (1 << EXP_PREC)) * probexp[idx]; - backoff = (random() < p); + p = (UINT32_MAX / (1 << EXP_PREC)) * probexp[idx]; + backoff = (prng32() < p); } return (backoff); diff --git a/sys/netinet/cc/cc_chd.c b/sys/netinet/cc/cc_chd.c index 52048a7c05ae..92fcf68c41f1 100644 --- a/sys/netinet/cc/cc_chd.c +++ b/sys/netinet/cc/cc_chd.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -85,8 +86,8 @@ */ #define CC_CHD_DELAY 0x02000000 -/* Largest possible number returned by random(). */ -#define RANDOM_MAX INT_MAX +/* Largest possible number returned by prng32(). */ +#define RANDOM_MAX UINT32_MAX static void chd_ack_received(struct cc_var *ccv, ccsignal_t ack_type); static void chd_cb_destroy(struct cc_var *ccv); @@ -159,9 +160,9 @@ chd_window_decrease(struct cc_var *ccv) static __inline int should_backoff(int qdly, int maxqdly, struct chd *chd_data) { - unsigned long p, rand; + uint32_t rand, p; - rand = random(); + rand = prng32(); if (qdly < V_chd_qthresh) { chd_data->loss_compete = 0; diff --git a/sys/netinet/cc/cc_hd.c b/sys/netinet/cc/cc_hd.c index 82486563f97e..def1580d8ffb 100644 --- a/sys/netinet/cc/cc_hd.c +++ b/sys/netinet/cc/cc_hd.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -77,8 +78,8 @@ #include -/* Largest possible number returned by random(). */ -#define RANDOM_MAX INT_MAX +/* Largest possible number returned by prng32(). */ +#define RANDOM_MAX UINT32_MAX static void hd_ack_received(struct cc_var *ccv, ccsignal_t ack_type); static int hd_mod_init(void); @@ -128,7 +129,7 @@ should_backoff(int qdly, int maxqdly) p = (RANDOM_MAX / 100) * V_hd_pmax; } - return (random() < p); + return (prng32() < p); } /*