Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2356380rdg; Sun, 13 Aug 2023 22:40:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEEb3so98IAJ4qWXJGeF74rCfrtHgHsLqFM6Pm7Qkn5Vmiv1pgoGLDYQx/9U2CRXMnxrTr X-Received: by 2002:a17:902:ab92:b0:1bc:10cf:50d8 with SMTP id f18-20020a170902ab9200b001bc10cf50d8mr7074712plr.23.1691991649279; Sun, 13 Aug 2023 22:40:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691991649; cv=pass; d=google.com; s=arc-20160816; b=DxeMdQ8tO6nLblFTrtGdLTD5e3X95kbOB3jNrnUnOVisYfHwiQOYleD35aBDeaT5x1 z3buz9ZoX4LEkRZl7bdKkhmcQUiP2LtgTmX6UrrMnwNZKMm16i3Fr//pRAs1lRiohXCH fTIfYrdTgehxOpQzUEWEoDVi5Du+vYFpbVsEwZqzzVeseuJX5FO1I96iinHgOIUkonzA QAkUJevaIrbDYuF6A/wMLAgTgT9579n96wYnqBYYlFId6t4mUy3O7yDYDiAIMPRBlqlM LpcdsE4QrULal6MvgYVqtEuJMbb6/lQJFLiXkXLcptfZZ1w/VSmFfWCftAFbrxV28LWG Gp/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=8h3RCDDjOcd80OhiXQOF9okLjuhqzoFntP3tIs8+as8=; fh=4HhbMNb9a953WYs8XhlZFoEs2JqksG8Z63FRdSNsJpo=; b=uyAWg18IxREIFwHfI3AAlPTpoWq6UA7Nm7i07wG1DEVrI2V+MmpVaZFAJbRMEzLDfy 9etOPV48E/rNbJqVgsiK5ewUVEa5Ets1g9zzsAVALIPmcM+iVoQSVRnO8gnUILyShxlA wGV42ga8zlEWAEo7eBizy2HyHJGBEBVyIvHsJYum1vju1TkS5e0IpuwzJwySheJ8V+eE 49zsnZwlWH/mc8ieWGAKLb4bWegXg/cj8yj9F+55R6Ajl/TCXEJCspZVjAo4UEuDeM6E 5QRNde32uF1iFKZ0AD26YA2Zmh/d/zH6UYzQM4GggLDmnLuC5/IxfwXAjnQLSe6iE9nd JOQw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@uclouvain.be header.s=selector1 header.b=Q2NLtFut; arc=pass (i=1 spf=pass spfdomain=uclouvain.be dkim=pass dkdomain=uclouvain.be dmarc=pass fromdomain=uclouvain.be); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=uclouvain.be Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a170902ea0900b001b8a70d11e4si7805230plg.529.2023.08.13.22.40.36; Sun, 13 Aug 2023 22:40:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@uclouvain.be header.s=selector1 header.b=Q2NLtFut; arc=pass (i=1 spf=pass spfdomain=uclouvain.be dkim=pass dkdomain=uclouvain.be dmarc=pass fromdomain=uclouvain.be); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=uclouvain.be Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232499AbjHNCeJ (ORCPT + 99 others); Sun, 13 Aug 2023 22:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232330AbjHNCdp (ORCPT ); Sun, 13 Aug 2023 22:33:45 -0400 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2137.outbound.protection.outlook.com [40.107.249.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38842E65; Sun, 13 Aug 2023 19:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nTi1dYas0QXAP0qbOvkO1v3fWH+OAJozqH3YyVa6+L5xtELs3v4Byxr1Y5HdBdrQe4jJAMSFnUFpzIoUXoFawYTqvB0cF05sxgNF0Jw29tfZbI4ZGf2SbH5pO7qQSGPMh4b9JpOicW7HWAYiZfk4dlX6sEeHDWEhWZFqS2GR5rfopoD5az1Bh+OOzaGD5QEb692xh0bsUczupb51v/ATSLXWKeYpztigYpYaeYpNghgS8I5l8nmi5eeLvqgR/MR88fvQXMujqaOrPFovMwnD2+w6OmtaOrEc0rm5oZRJqzQ44diUyBEjFxN3VJ9NcCe9pc25rjzrQBlg1UQkgKtbzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8h3RCDDjOcd80OhiXQOF9okLjuhqzoFntP3tIs8+as8=; b=gecuXKr/SKjqAec4dJIG1YOgPkv/3B1w8lW1jk9ahNKV07yPJ8By2Ifs0TAuswxpg5XMpuhGOjfkNf/kV+DIU9I4Kx6XuxsKplYGc4sHlS3TKjnRHyq0YzcQWT7hH9Ld62X29oImdUODUrcWvwgCfkPAuLLdK4G/SQfkBMpvZOndVSzsDY8uu6drl88V6FfnJGCBEZIYZj3rvAupDkOQ+rImtUu6CWsbVW2xMXK4o8r/q2+rFPNu6a5dxz5SzI8xIMvWGGB57qYkWZi4BOlqG4AS452sMJ1ECY1v3K5sISyqfagSJNdSHA8NepMquxPine4spwTKc92bhOnAWzIvQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=uclouvain.be; dmarc=pass action=none header.from=uclouvain.be; dkim=pass header.d=uclouvain.be; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uclouvain.be; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8h3RCDDjOcd80OhiXQOF9okLjuhqzoFntP3tIs8+as8=; b=Q2NLtFutjK2hGnibYkW5mPIap5Ug2YTbM4gd5M6K/kNoetZ+uXlbR3UzdxSYAbYZ6Vq7ufFeDkU6z0s4hZp1xir9k5/mu0aJ9OTh1naJf01AKMeUvrtKGjqOzOwFM9lFNzo7i+LDjcaEbdf6FmYNnS1tnYjALdtmE/GElhDwwiNLw0vJa2GK89TD2dml6KAAau7aiKrKi/X5sXly+YOdQcAlg7qvTPABQ1v6i7HP77+eNQzeZgbM/ctz+q7DE0xxyuHlpB6W+UQ5csO9rjKe/APOh1D55R56UXENDVAGLU+mYVJQ4CmaRFPlitwHyR0UCM+dxwmgWzJ2TSbOCpvTJg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=uclouvain.be; Received: from DB9PR03MB7689.eurprd03.prod.outlook.com (2603:10a6:10:2c2::11) by AM7PR03MB6401.eurprd03.prod.outlook.com (2603:10a6:20b:1c3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.24; Mon, 14 Aug 2023 02:33:40 +0000 Received: from DB9PR03MB7689.eurprd03.prod.outlook.com ([fe80::8303:13bd:7736:34cf]) by DB9PR03MB7689.eurprd03.prod.outlook.com ([fe80::8303:13bd:7736:34cf%4]) with mapi id 15.20.6678.022; Mon, 14 Aug 2023 02:33:40 +0000 From: Francois Michel Cc: Francois Michel , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Stephen Hemminger , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/3] [PATCH 2/3] netem: allow using a seeded PRNG for generating random losses Date: Mon, 14 Aug 2023 04:31:39 +0200 Message-ID: <20230814023147.1389074-3-francois.michel@uclouvain.be> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814023147.1389074-1-francois.michel@uclouvain.be> References: <20230814023147.1389074-1-francois.michel@uclouvain.be> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MR1P264CA0034.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2f::21) To DB9PR03MB7689.eurprd03.prod.outlook.com (2603:10a6:10:2c2::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR03MB7689:EE_|AM7PR03MB6401:EE_ X-MS-Office365-Filtering-Correlation-Id: 758c8409-bcfd-4d6a-db73-08db9c6edf17 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nrFTjdc65uCr+hWCtGHKoaylpt6VTXWkIXe7L8kMV4bFC5IVfYGjUQMm3JpW+4MoQEUF0vF3zc4Mh2hKAJeymWgULd9r/F7GHdy+4SWD+arL1VylSC8a32EbLS9H/PK6kovE4GQikAS0q2Utq/RjjjPkJHzAfkNEzG/PWseJR+J7klAUsPLKJXFD3asuCgjHJsP2xeBDjEXDHpyq65cuhAbNigIres2bOBk+wwlB9Wh74PzeW9LX7BWq9VMCXGOZ3GH0ZyPKfLbcRv9Pn7bLkk0K7reOETNBmoyhmv1T2fT/5hr9HOxaUl5EQMFy+dc8WBvlOScsyFsvU0tQ66Niyf28sVElVkNCUqXYJZNQEWFcNLSTML5FET50gqHVysYoFZJGrTke8SqFHPc6li0k8vEJ1Lyr0h9cme6BsrOfu8F7igE+fON7IzwtA52svuVEDYE6+udpaCNS64FQpbhEEbPNZVWVDLhgJsexXuvbs023HrR6dS/nTiPiJVs/QldMxi0PtATDFR3IkVktuokUJN+7r/mP5DlBmitbNeBo4ncfyTSbsxz+VuulrsUCJtKImnlUwmsFAJnaYCWph9T59TqEByST3pALv+PEMAjxM1Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR03MB7689.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(39850400004)(396003)(366004)(376002)(109986019)(451199021)(186006)(1800799006)(38100700002)(52116002)(54906003)(6486002)(478600001)(7416002)(5660300002)(2906002)(36756003)(86362001)(44832011)(4326008)(66476007)(66556008)(66946007)(41300700001)(8936002)(316002)(786003)(8676002)(83380400001)(2616005)(6506007)(1076003)(6512007)(266003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TUJpNXdjNTBTQ3BFRFB2c2NaYVE3eFA3VkY1V2RZMkhUc0VEcjJkVUlqdldV?= =?utf-8?B?VEhFVDRVNklrV2xER0hCcTF5azFaTENEZXZ0ODR0UnNIUU9jMlJBZG0yTkdD?= =?utf-8?B?eW9FNWkzQkc3NG5MZU9CQ3RvQXBIajJ5MkU1Rjg1cWl1bE5qb0VTK25UNGhR?= =?utf-8?B?dXJOWDQrQ3ZNQ3FXQVluYkFKR09aT1J6NGxIb1g5ZWtJeVQzNmtEd25mUEFo?= =?utf-8?B?TG4ydWYrRUgrZStIbnBxS2hCRUZ0dXQ2WkMySWYrUHBRa1d0VGE1UzlYQXNU?= =?utf-8?B?SFJRMXZTUFZtQjZWNGI4dWNXTktIZGE2dHlaODJra2h2NzVkZEluMXpnOUlW?= =?utf-8?B?aGowVElzS21kRE1NbEVJYTFXcEJ2SGx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VE9tT1B6?= =?utf-8?Q?YVl1Gxqv5U8lo9rqeSWdmvaJssQqNrAcfCIDyfUJw3Co?= X-OriginatorOrg: uclouvain.be X-MS-Exchange-CrossTenant-Network-Message-Id: 758c8409-bcfd-4d6a-db73-08db9c6edf17 X-MS-Exchange-CrossTenant-AuthSource: DB9PR03MB7689.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2023 02:33:40.7688 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7ab090d4-fa2e-4ecf-bc7c-4127b4d582ec X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RjA/3vBAT1Ry1PKTBllTH0adz/AK4oh1/I/JjM66gEhQCYpPWezcZjQndUzo0WRbO7sruaxXTSxMpv0usdeZSC7bfkV/1EtmA3iTqp8jJko= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6401 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: François Michel Add the netem_get_random_u32 function to sch_netem.c and use it to generate the random loss events of netem. If no seed was specified by the application through setting TCA_NETEM_PRNG_SEED, the default behaviour is the same as before, i.e. it relies on the unseeded get_random_u32() function. If a seed was provided, it relies on the seeded prng attribute of struct netem_sched_data. Signed-off-by: François Michel --- net/sched/sch_netem.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index d73596d0e912..1190782ef79d 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -154,6 +154,19 @@ struct netem_sched_data { struct disttable *slot_dist; }; +/* netem_get_random_u32 - polls a new random 32-bits integer from + * the prng. + * Uses a deterministic seeded prng if p->deterministic_rng is true. + * Uses get_random_u32() underneath if p is NULL or if p->deterministic_rng + * is false. + */ +static u32 netem_get_random_u32(struct prng *p) +{ + if (p && p->deterministic_rng) + return prandom_u32_state(&p->prng_state); + return get_random_u32(); +} + /* Time stamp put into socket buffer control block * Only valid when skbs are in our internal t(ime)fifo queue. * @@ -207,7 +220,7 @@ static u32 get_crandom(struct crndstate *state) static bool loss_4state(struct netem_sched_data *q) { struct clgstate *clg = &q->clg; - u32 rnd = get_random_u32(); + u32 rnd = netem_get_random_u32(&q->prng); /* * Makes a comparison between rnd and the transition @@ -272,18 +285,19 @@ static bool loss_4state(struct netem_sched_data *q) static bool loss_gilb_ell(struct netem_sched_data *q) { struct clgstate *clg = &q->clg; + struct prng *p = &q->prng; switch (clg->state) { case GOOD_STATE: - if (get_random_u32() < clg->a1) + if (netem_get_random_u32(p) < clg->a1) clg->state = BAD_STATE; - if (get_random_u32() < clg->a4) + if (netem_get_random_u32(p) < clg->a4) return true; break; case BAD_STATE: - if (get_random_u32() < clg->a2) + if (netem_get_random_u32(p) < clg->a2) clg->state = GOOD_STATE; - if (get_random_u32() > clg->a3) + if (netem_get_random_u32(p) > clg->a3) return true; } -- 2.41.0