From patchwork Tue Mar 15 10:29:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 12781272 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B05DC433EF for ; Tue, 15 Mar 2022 10:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347119AbiCOKdQ (ORCPT ); Tue, 15 Mar 2022 06:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347124AbiCOKcy (ORCPT ); Tue, 15 Mar 2022 06:32:54 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2136.outbound.protection.outlook.com [40.107.93.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B870C506D5 for ; Tue, 15 Mar 2022 03:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ses6/joZDFtOuQJeJNT9wFfXDQbxnyz+EwpTLeuUUYuyvptQ12EC+kffmESeClOa9uvuk7zCw+Ta2ar6nUB11VDunogdspP2Kw3uYVSy/LIpzOqSgpZapSz6H/UaB7IgUbWpZ6AncO3ly3eGH1lfRnDPo7ITCgt3xmsE+m/AwsfuxZLAx/bl68Y7x+oM1HnMsQHAH6vW4uqFrwv/m5Uso9YjqRaaMajWBjqvLvCEiIJtzIS9rcb0YpuK+eeegp1d0IYV9YudCekSrtIvGYm2u42JUn1bmyum8I5SfXi3xIDbLXnHl2ILuBMLaNnUETP7tVifa4dVnipcjgg/KCZ+ig== 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=z0o4A0+Q3OvBkjrTSsa+hjafeIbv9w7AXHzox2NJsv0=; b=Vp58bcl6rbz4NdPbLca3OZCHH8qb5xBArAVvwU4QDFum6h6QxWbjcrHDm8iY8n99o1lfbDtn+9VaEhF01XGXU/Pwj815PUn55SU3y/7OP3IGkvIcqOnWrmejtykUt8eYBx36gRGH7GgqnB48WUWL7inNv4Fqca1jPsvfiE56gzCOTDo3bV00Yx3fHoFxhCgZLfm51bKcaWadJtnYEILpN8jrrEy7+LPQBKVUrF5JpKcbkZcPUtTqCdqPWMrTgF6OyKydanHarq9wPfzonUQoOVcIjPPJ9jSbeMCcNpZgY1pDhnApFKp83wA+a8xHKdI0jJkr6But45Wi782T+3ZaIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z0o4A0+Q3OvBkjrTSsa+hjafeIbv9w7AXHzox2NJsv0=; b=Bii+UEh4OIlDuzSRQp75HvhzzMAN/PV+2EvDkYMSx5pi2msDZgoa0ScItYASCZMrE4EHZ4vEpqKFzSNapjkPr21LQCriF7ulJ14DNBskzk8VPEG4TUJGaj9Oz4PPrEYBeTog67F9nQwpdqMvIQCKF/sQVJda6rB8RA1bkTiwNL0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from DM6PR13MB4431.namprd13.prod.outlook.com (2603:10b6:5:1bb::21) by MWHPR1301MB1919.namprd13.prod.outlook.com (2603:10b6:301:2f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.10; Tue, 15 Mar 2022 10:31:39 +0000 Received: from DM6PR13MB4431.namprd13.prod.outlook.com ([fe80::e035:ce64:e29e:54f6]) by DM6PR13MB4431.namprd13.prod.outlook.com ([fe80::e035:ce64:e29e:54f6%5]) with mapi id 15.20.5081.014; Tue, 15 Mar 2022 10:31:38 +0000 From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Louis Peens , Simon Horman , bpf@vger.kernel.org, oss-drivers@corigine.com, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [bpf-next] samples/bpf: xdpsock: Fix race when running for fix duration of time Date: Tue, 15 Mar 2022 11:29:48 +0100 Message-Id: <20220315102948.466436-1-niklas.soderlund@corigine.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: AS8PR04CA0145.eurprd04.prod.outlook.com (2603:10a6:20b:127::30) To DM6PR13MB4431.namprd13.prod.outlook.com (2603:10b6:5:1bb::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fdbd6ae-2157-49e7-fa44-08da066efcec X-MS-TrafficTypeDiagnostic: MWHPR1301MB1919:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TZqLJz/HC4xM4Au1iZCF4XUrQB3EkraWIBW4a0gGn0KKE2vhGYdGo0NpZeQJUwzrUETlgq5qV23fjPeCpJZSul1NZ9xSshM0enOkPHVHwkYHY4ErzFRg+cfgHzhPmnAdbq/h6QBwwwv0hGtVYB+EuqdACIpZTQYWShcmgrfLUuHAPOxDxfnfscZC1StL96dAN1wUHB1+4VuEe1qnGcyOvxzVrBCLgU6IU26cDZyPSjf6oWOQknHt4tuT5LI/PcV43LZECrgNI9LFrjSaikvax9yD9zHwo55AScXIOG0fwjHvIaPeBIf9t648kZHXnD8q5Pywu0W/EQCXCzmcZif0D2gFRU9TNO9FctuHB2pXks7RdcKFgRs7IXzm+BmwJMoPgla1U6FSHZ8yjo+s3ZJA0jedD7JBCARHxetoiKqmc/5gUFXfAKs8UUo+11/dXn/EU9eddPdEFepyp0t5+CydvTsjXL3YtUao6YdGPm+lxPQX1E81Xlo0+2O2336HDoBIccyDze4HvHxuanvAokjMWMHbUPcqpIcG0L+bOg0uldlEqtWag7EXJieakWJYz0cs6eEgBeKRG9eWpasnOMfSs7bSCWJdpiYlOD/Yw3dvgun2pk5CmEihqOAr79FSw0yg13tgpSzBbuIe5m4jGu3cOPZkFM5mrpbjg04EZJSoTbwZ8p7gsJV8eubx0zqrZilMeoYZB4VoXB/O70TsTM4JFnstfHBlxuvbnmBBhvy+BsYMIk7UBOmuhbJ8/zAJicGo X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR13MB4431.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(376002)(366004)(346002)(396003)(136003)(39840400004)(83380400001)(26005)(1076003)(107886003)(66574015)(2616005)(38100700002)(186003)(38350700002)(86362001)(54906003)(110136005)(66476007)(4326008)(8676002)(66556008)(66946007)(2906002)(316002)(8936002)(36756003)(6666004)(5660300002)(6512007)(6506007)(508600001)(6486002)(52116002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?g0kspqf2biUu4Fg/Vc1wKknD9X9W?= =?utf-8?q?SOmJ1fX0IK1PjDzuVR6WARdip+v6lU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ETuWBjKlBPKXt8mkNrQZc4APXjrZzSRq4qAAX?= =?utf-8?q?VSAP0oeKuxkO/b427Ts/W64IGn2WWfx76X/86rwXVKQlYVQ34VrQDki4s/FyuEKyw?= =?utf-8?q?d76U/qObScE4P/MiQe6tMAQjPAupFSGJAY0E5zU+rTZpPT5PStcreIo38bygc1MGJ?= =?utf-8?q?xl+Gbrb/nwnbdg4ufJ81kjxsC4kser5aSxnb0AN2c/ssGGlyuA8u65YFQUgmhjZos?= =?utf-8?q?eSvvwGK1xLMSu1NRw40el1+d171XVQ0RKJonjYwdiB2IVE17n9ECpRQBaGEB/Nwk6?= =?utf-8?q?wx3PVP3uyD0b/4AlNJTp0SKgRqFtwexECd6FkZosR8Q/oqGwIDH+Ieonj8zatos7H?= =?utf-8?q?WkWsXAhYZI3UsZsfm0pAToxpPuluGmUXSAp1eQqoXbkxNCwDCFSsSmpS8CHxg3PVj?= =?utf-8?q?Ql6tDiIJ4l/RYR73s9D4qi5GEp2WA3KBufblXtkLJL477Vc6dAa/auygfdG3NO2LU?= =?utf-8?q?lNG3LEqnhhYiE9MV+9l3ZWKNhlNKrylXW1gA=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5fdbd6ae-2157-49e7-fa44-08da066efcec X-MS-Exchange-CrossTenant-AuthSource: DM6PR13MB4431.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2022 10:31:38.7623 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IgT05SROV1QA+ZKHIzgny1Jw30y2voosVJ47m1BXKvkaTL8bhS67/qIp+eHQftR8dk0kIvfzy2R52muh8+udFouZ00PABPHT+3kNXKBW+jY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1301MB1919 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net When running xdpsock for a fix duration of time before terminating using --duration=, there is a race condition that may cause xdpsock to terminate immediately. When running for a fixed duration of time the check to determine when to terminate execution is in is_benchmark_done() and is being executed in the context of the poller thread, if (opt_duration > 0) { unsigned long dt = (get_nsecs() - start_time); if (dt >= opt_duration) benchmark_done = true; } However start_time is only set after the poller thread have been created. This leaves a small window when the poller thread is starting and calls is_benchmark_done() for the first time that start_time is not yet set. In that case start_time have its initial value of 0 and the duration check fails as it do not correlate correctly for the applications start time and immediately sets benchmark_done which in turn terminates the xdpsock application. Fix this by setting start_time before creating the poller thread. Signed-off-by: Niklas Söderlund Signed-off-by: Simon Horman --- samples/bpf/xdpsock_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 19288a2bbc756d3f..6f3fe30ad283cf0a 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1984,15 +1984,15 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); + prev_time = get_nsecs(); + start_time = prev_time; + if (!opt_quiet) { ret = pthread_create(&pt, NULL, poller, NULL); if (ret) exit_with_error(ret); } - prev_time = get_nsecs(); - start_time = prev_time; - /* Configure sched priority for better wake-up accuracy */ memset(&schparam, 0, sizeof(schparam)); schparam.sched_priority = opt_schprio;