From patchwork Mon Oct 19 07:24:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Badicioiu X-Patchwork-Id: 55217 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 6EEE022F11 for ; Mon, 19 Oct 2015 07:25:11 +0000 (UTC) Received: by wiclg3 with SMTP id lg3sf7612984wic.3 for ; Mon, 19 Oct 2015 00:25:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:mime-version:spamdiagnosticoutput:spamdiagnosticmetadata :subject:precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:content-type:content-transfer-encoding :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ve4vdI2EVvXfVAxfg8jozgJ3lDJK1sXtb/8OqBrQLuk=; b=h601FXwtY5cq6qLkToslO4XtOnpWzR9tYNoo4sOZPdhhko77ZmkNw+zYMh3d7cEXTg HnzI+PK86TYyj2u7l8ed/WE8DWnSXJfkEDEGx/k8juNn+GX73KkQaZjJsbdu98kt+StC +7XlNV7xmSpNnFbiq/YG8ppQ1cwziudlv/b8oUTibZXMJFZryc5N7QUScKFfxF5BcpYC zx3RSEWV9HwLomFWcnzq/ruAsuIch7lbhd6bHZjF1+6ko0akwZNitNSg/coU5ybCWyNZ wv8azbLEB2ywfPRIuic2aIqSrPg/9j/rwBH1unCwiqqBJz7026HGljj531/nyyI09flJ WxxA== X-Gm-Message-State: ALoCoQk+xsLW/6+VC8lZM2Fkn9hi+ab/Ea76qcVujUuU5Ex2zTUWBIwBEf9OugJFBjIsoldW0dy+ X-Received: by 10.181.11.195 with SMTP id ek3mr744366wid.7.1445239510770; Mon, 19 Oct 2015 00:25:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.148.143 with SMTP id w137ls490606lfd.105.gmail; Mon, 19 Oct 2015 00:25:10 -0700 (PDT) X-Received: by 10.112.148.38 with SMTP id tp6mr13673541lbb.110.1445239510582; Mon, 19 Oct 2015 00:25:10 -0700 (PDT) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id d79si21849164lfe.74.2015.10.19.00.25.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 00:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lfaz124 with SMTP id z124so101931336lfa.1 for ; Mon, 19 Oct 2015 00:25:10 -0700 (PDT) X-Received: by 10.25.40.130 with SMTP id o124mr8766420lfo.41.1445239510341; Mon, 19 Oct 2015 00:25:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1297828lbq; Mon, 19 Oct 2015 00:25:09 -0700 (PDT) X-Received: by 10.107.40.201 with SMTP id o192mr25276018ioo.83.1445239508945; Mon, 19 Oct 2015 00:25:08 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b138si25056675ioe.67.2015.10.19.00.25.08; Mon, 19 Oct 2015 00:25:08 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id CB1CE61B76; Mon, 19 Oct 2015 07:25:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 36203619C9; Mon, 19 Oct 2015 07:24:55 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id AC6D8619CE; Mon, 19 Oct 2015 07:24:51 +0000 (UTC) Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0060.outbound.protection.outlook.com [207.46.100.60]) by lists.linaro.org (Postfix) with ESMTPS id 25605619C3 for ; Mon, 19 Oct 2015 07:24:49 +0000 (UTC) Received: from CH1PR03CA010.namprd03.prod.outlook.com (10.255.156.155) by BL2PR03MB322.namprd03.prod.outlook.com (10.141.68.17) with Microsoft SMTP Server (TLS) id 15.1.300.14; Mon, 19 Oct 2015 07:24:44 +0000 Received: from BN1BFFO11FD005.protection.gbl (10.255.156.132) by CH1PR03CA010.outlook.office365.com (10.255.156.155) with Microsoft SMTP Server (TLS) id 15.1.300.14 via Frontend Transport; Mon, 19 Oct 2015 07:24:43 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning linaro.org discourages use of 192.88.158.2 as permitted sender) Received: from az84smr01.freescale.net (192.88.158.2) by BN1BFFO11FD005.mail.protection.outlook.com (10.58.144.68) with Microsoft SMTP Server (TLS) id 15.1.300.4 via Frontend Transport; Mon, 19 Oct 2015 07:24:43 +0000 Received: from fsr-fed2064-008.ea.freescale.net (fsr-fed2064-008.ea.freescale.net [10.171.95.70]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t9J7OffO025470; Mon, 19 Oct 2015 00:24:42 -0700 From: To: Date: Mon, 19 Oct 2015 10:24:39 +0300 Message-ID: <1445239479-7406-1-git-send-email-alexandru.badicioiu@linaro.org> X-Mailer: git-send-email 1.9.3 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130897130837501763; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD005; 1:UYOmBfZcanaY/FdssW8SER4Fz0ns+h3j1SpMDR1glVymtywYa1WSzAm+jwZdtwXUTLHMiY5vgx3nIxoFNWGc20PVmSB5zOgUMHOXAcgu5berI08y0y4RxFXplNCb0HRCuOyWEDJ1jp869oCpqnUnuaA6RJuFX+S+ZAxU8ntO1P9xSOgz4Vxj2x0UJGNDmTulhqkpFLniCUYd9a+pd02YbxaIzSO1cPcD8Y/2dyJ1VCMr5GEs4DBJu1LagqYgC5eFLuwYa5KhdP4M/hSr164NIeplzV87zQQNadLJj4xZ+SDIrDnEIzN1O8ggflQP+M+mSDVGolGhmo4oPBZ/kGDM8PfyVk4n8C37etgYYWthUj+t3hmGRbK+CJvbviCq9lj0kYq46G7VB3GHEb2WkHyuNvnMI3TKwTlIE7zFrJLyVKw= X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(189002)(199003)(46102003)(106466001)(86362001)(64706001)(575784001)(86152002)(19580405001)(69596002)(48376002)(19580395003)(50466002)(2351001)(105596002)(50986999)(229853001)(11100500001)(5008740100001)(92566002)(81156007)(5001960100002)(6806005)(47776003)(5007970100001)(189998001)(97736004)(110136002)(104016004)(5003940100001)(77096005)(15975445007)(50226001)(33646002)(87936001)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR03MB322; H:az84smr01.freescale.net; FPR:; SPF:SoftFail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB322; 2:vT2Xk7pfWYXZ6iZqDLhQ4uFffX4FFcGb7MKADG3/9jJuiWfV8qSHknvVaxQdo6AvZoBUg8pIT8//Ld+SLTCYnAzqoeA+pLxqb4cKmB5qhjAHDMlbd8D28Vh/GdQ4lK7wIER8ZJnkvn7SJQCYKtzgW5dEep42LJf5nXlQ7o/ECec=; 3:lsBcP0NOEc0V4F6hkTLO7yQ5PE9j6FA0mztFSQQQQ4e6E02Vjeqn9lZumGmN9KhaA3Y9bBm+v4CgQ5f9aFCx/dF7WwBbpMvirW0fgsSbVb+lnmg9vAADi74YHZ7W5EZlZuZtgjYRL5wQRWuC1sVNtVdkD6AoTRjCvB2OXatDtyBrSuM81uAw9KBb/gqGmYg6oFZAW94VUIXVrw0+UY7LSu8WAgcVJGzMK73XQ2UvId4=; 25:WymLb6fszmP2k8288sE3b3McOzAXmORiP/opa+tGw/oUnLj4qgZgxsGiy/NcGozqEvCCp+tBkOq+SQ/6Be3lfzBm0OKIPBA8m71HqEu2h29qdNwB7gZdGE+O64Nd72QPGGy+X0HpkYJk2edJ2jOA26LdF+TwFeUUq31GuYEkjh54Ojzmyp85F8M2GvRtPkx0UtKb2e3uqMu9m4c+Dc0TDWzPHK4H0fgSBoY7WH1P5QbTlTJdV8M7SOGbOvAJdTx9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB322; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001); SRVR:BL2PR03MB322; BCL:0; PCL:0; RULEID:(400006); SRVR:BL2PR03MB322; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB322; 4:Y9TtBzcLLRk5CS8rnKD7FruZbRsdmmvInPfgMwJgbLxoQBfYxF+DK/tlNbqLYydCXRZeBbpheWdxE83MLtCWf8xG5iS/uf1qZ+HgnGFXgIw51djko8NrDpa3+wvxRVSAp82dmWRzF5SIrJnvGVq4WS+kJRCpbFW4uCPEN2ziJWFPBwXAepO6Rr3TtZpuWHxxS1eCMGDBbguDdp93WOQpgvvvqoJztdjh3wtOiUEDunL19u80m0UFIPIWDcddsGnKIR8XGpbX0kACYEQnd+N5kgw53MgZBwO3A9zkOCGlQGnP8W1zffYAQoJVbOxr+ZPPXDKxzYw0gme8lKfvdWDc/Av/E+ifz5FtWCCNdNI/yko= X-Forefront-PRVS: 07349BFAD2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BL2PR03MB322; 23:m7RkKI2c+gTSoBBu3M4HcpMclw8w9jeLgsts52B9li?= =?us-ascii?Q?GvLx2E9cSm0sL9SrUA0oD8E7L8pMR8VKERgwykLSLXDgf4jW8PwPzjaLhOlP?= =?us-ascii?Q?LkpcadfkS+bVUBv7soSy2Mar3BPdUtXshQNe4Aw9EC1C4U51T1avdWOgpB9a?= =?us-ascii?Q?E74lLZ4W7RH1OLj2P6822J0HTS9seDnNTXMQAopRNbaKobFFzLfDCT2YMX4A?= =?us-ascii?Q?lpLZhITIariqjOKc29T9U2ZAbg4HYqnYAk+f/VmnYy6kk5jTJF8ob4rQ9vuv?= =?us-ascii?Q?I2ixNF7ZYeLlW509Uf7L9H+JFUXC7H8zjt6M1DXLV4BSRe+FjKs6KWmSpBZY?= =?us-ascii?Q?7GpeubjscDJara0M2aMEUOyl+Op3z/KF+Q0B/Pcr1UhzXdpFCJYUiYbW5TgF?= =?us-ascii?Q?uP3OJd3jNU6/ktHVn0dKW6xSZDrfyo/3wmeplC9mDqWtuJ1ZITjbM9TUi85m?= =?us-ascii?Q?1bqXEDezSBIPeck/xHQ6Z4bcStOyy5F8L1muGa5xEL9zm7RbW13z7reB0c9m?= =?us-ascii?Q?yWpFpQ1r9Eoo9393ur9YDcCWKJQXmdAn0QhFyHOWp4K3e7HNZzeqpq1rSAQ8?= =?us-ascii?Q?F4zUTk9vg/CU4sfoxOHPEOLfDmM03uwl7MafMqT763UM89jP2ympq3skpQ1p?= =?us-ascii?Q?tajKLvFRJJaplXliVP9Q7mk120SxN/xumDbJFaRS3AOsFiqC+hfrWgc9dyJL?= =?us-ascii?Q?5+cvZGefEme2DuN518O4RnPEmGbGJEpsM+K4za+NZajAWNYELE+QDGJeVxgW?= =?us-ascii?Q?MJW7CqSB1if6DfxqVcwhmBlMPdL67PUdZAiYnnlR5e24TcLE7TpbLQkZP/iH?= =?us-ascii?Q?xgEErHd9fFesMOipGkXEG7IvTvkX7TEZ5T9wLSRRUV9XFNVDwnbSC/1HfIOI?= =?us-ascii?Q?xLUVbTHaKs8ML/Ew1X9RxN1vHchx974mm9DQJ1ibCh01SjfxEhcxkMf+WZir?= =?us-ascii?Q?0/LQKf8MgM9yTHUFebWkMQhu9Ys4LFqq8uWDv72LT+VlJTe/5pF7CBEK6z2n?= =?us-ascii?Q?zVzoUkmIS780D3udn/90nsx/Q8sDGcHY+AT2OIeokV6w=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB322; 5:uW4Mz/NIP3pLpBt9wxBV7b9wlNVz2fXcfjafzfgorlKAgVSA6aeSsHEChtplo31zBNIhAtvjpqaEOQ09cuOsDGGpFMVXg8O4pjry0kCgpeHNDMqBN5vti0jp11TKSPNuTFD8P0kXNg2ixUKTNYlzeY4twiRluEmqNHPL05kA2as=; 24:oaj7ggPiq4m/rZFzxNd82cx3h5t6zL/8NH0/otqLW2o6V2UDjHMl69rJ0MlSJhUAtzAoCPIRnIzoUG5EMS4atKHFn3/J1YKoDEocQErwf2I= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2015 07:24:43.5161 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB322 X-Topics: crypto patch Subject: [lng-odp] [odp-lng][PATCH v0] test: performance: add crypto test X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alexandru.badicioiu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Alexandru Badicioiu Test program to measure crypto operation performance. Measures the time required to launch and get the result of ODP crypto operations in async and sync API mode with configurable payload size, crypto algorithms and iteration number. Both asynchronous scheduled and polled are supported. In scheduled mode a separate worker thread is used to get the crypto completion events. Output packet can be reused as the input of the next operation or a new packet can be allocated for each operation. Based on a previous work : https://lists.linaro.org/pipermail/lng-odp/2014-September/003251.html. Signed-off-by: Alexandru Badicioiu --- test/performance/Makefile.am | 5 +- test/performance/odp_cspeed.c | 946 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 950 insertions(+), 1 deletion(-) create mode 100644 test/performance/odp_cspeed.c diff --git a/test/performance/Makefile.am b/test/performance/Makefile.am index 721615b..351dc97 100644 --- a/test/performance/Makefile.am +++ b/test/performance/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/test/Makefile.inc TESTS_ENVIRONMENT += TEST_DIR=${builddir} -EXECUTABLES = odp_atomic$(EXEEXT) odp_pktio_perf$(EXEEXT) +EXECUTABLES = odp_atomic$(EXEEXT) odp_pktio_perf$(EXEEXT) odp_cspeed$(EXEEXT) COMPILE_ONLY = odp_l2fwd$(EXEEXT) \ odp_scheduling$(EXEEXT) @@ -20,6 +20,8 @@ odp_atomic_LDFLAGS = $(AM_LDFLAGS) -static odp_atomic_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/test odp_scheduling_LDFLAGS = $(AM_LDFLAGS) -static odp_scheduling_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/test +odp_cspeed_LDFLAGS = $(AM_LDFLAGS) -static +odp_cspeed_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/test noinst_HEADERS = \ $(top_srcdir)/test/test_debug.h @@ -27,5 +29,6 @@ noinst_HEADERS = \ dist_odp_atomic_SOURCES = odp_atomic.c dist_odp_scheduling_SOURCES = odp_scheduling.c dist_odp_pktio_perf_SOURCES = odp_pktio_perf.c +dist_odp_cspeed_SOURCES = odp_cspeed.c EXTRA_DIST = $(TESTSCRIPTS) diff --git a/test/performance/odp_cspeed.c b/test/performance/odp_cspeed.c new file mode 100644 index 0000000..28ac1d5 --- /dev/null +++ b/test/performance/odp_cspeed.c @@ -0,0 +1,946 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif /* _GNU_SOURCE */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define app_err(fmt, ...) \ + fprintf(stderr, "%s:%d:%s(): Error: " fmt, __FILE__, \ + __LINE__, __func__, ##__VA_ARGS__) + +/** @def SHM_PKT_POOL_SIZE + * @brief Size of the shared memory block + */ +#define SHM_PKT_POOL_SIZE (512 * 2048 * 2) + +/** @def SHM_PKT_POOL_BUF_SIZE + * @brief Buffer size of the packet pool buffer + */ +#define SHM_PKT_POOL_BUF_SIZE (1024 * 32) + +static uint8_t test_iv[8] = "01234567"; + +static uint8_t test_key16[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0a, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, +}; + +static uint8_t test_key24[24] = { 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0a, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18 +}; + +/** + * Structure that holds template for session create call + * for different algorithms supported by test + */ +typedef struct { + const char *name; /**< Algorithm name */ + odp_crypto_session_params_t session; /**< Prefilled crypto session params */ + unsigned int hash_adjust; /**< Size of hash */ +} cspeed_alg_config_t; + +/** + * Parsed command line cspeed arguments. Describes test configuration. + */ +typedef struct { + /** + * If non zero prints content of packets. Enabled by -d or + * --debug option. + */ + int debug_packets; + + /** + * If non zero Try to run crypto operation in place. Note some + * implementation may not support such mode. Enabled by -n or + * --inplace option. + */ + int in_place; + + /** + * If non zeor output of previous operation taken as input for + * next encrypt operations. Enabled by -r or --reuse option. + */ + int reuse_packet; + + /** + * Maximum number of outstanding encryption requests. Note code + * poll for results over queue and if nothing is available it can + * submit more encryption requests up to maximum number specified by + * this option. Specified through -f or --flight option. + */ + int in_flight; + + /** + * Number of core to run on. Currently is not used. + */ + int core_count; + + /** + * Number of iteration to repeat crypto operation to get good + * average number. Specified through -i or --terations option. + * Default is 10000. + */ + int iteration_count; + + /** + * Maximum sessions. Currently is not used. + */ + int max_sessions; + + /** + * Payload size to test. If 0 set of predefined payload sizes + * is tested. Specified through -p or --payload option. + */ + int payload_length; + + /** + * Pointer to selected algorithm to test. If NULL all available + * alogorthims are tested. Name of algorithm is passed through + * -a or --algorithm option. + */ + cspeed_alg_config_t *alg_config; + + /** + * Use scheduler to get completion events from crypto operation. + * Specified through -s argument. + * */ + int schedule; + + /* + * Poll completion queue for crypto completion events. + * Specified through -p argument. + */ + int poll; +} cspeed_args_t; + +/* + * Helper structure that holds averages for test of one algorithm + * for given payload size. + */ +typedef struct { + /** + * Elapsed time for one crypto operation. + */ + double elapsed; + + /** + * CPU time spent pre one crypto operation by whole process + * i.e include current and all other threads in process. + * It is filled with 'getrusage(RUSAGE_SELF, ...)' call. + */ + double rusage_self; + + /** + * CPU time spent per one crypto operation by current thread + * only. It is filled with 'getrusage(RUSAGE_THREAD, ...)' + * call. + */ + double rusage_thread; +} cspeed_run_result_t; + +/** + * Structure holds one snap to misc times of current process. + */ +typedef struct { + struct timeval tv; /**< Elapsed time */ + struct rusage ru_self; /**< Rusage value for whole process */ + struct rusage ru_thread; /**< Rusage value for current thread */ +} time_record_t; + +static void parse_args(int argc, char *argv[], cspeed_args_t *cargs); +static void usage(char *progname); + +/** + * Set of predefined payloads. Make sure that maximum payload + * size is not bigger than SHM_PKT_POOL_BUF_SIZE. May relax when + * implementation start support segmented buffers/packets. + */ +static unsigned int payloads[] = { + 16, + 64, + 256, + 1024, + 8192, + 16384 +}; + +/** + * Set of known algorithms to test + */ +static cspeed_alg_config_t algs_config[] = { + { + .name = "3des-cbc-null", + .session = { + .cipher_alg = ODP_CIPHER_ALG_3DES_CBC, + .cipher_key = { + .data = test_key24, + .length = sizeof(test_key24) + }, + .iv = { + .data = test_iv, + .length = 8, + }, + .auth_alg = ODP_AUTH_ALG_NULL + }, + }, + { + .name = "3des-cbc-hmac-md5-96", + .session = { + .cipher_alg = ODP_CIPHER_ALG_3DES_CBC, + .cipher_key = { + .data = test_key24, + .length = sizeof(test_key24) + }, + .iv = { + .data = test_iv, + .length = 8, + }, + .auth_alg = ODP_AUTH_ALG_MD5_96, + .auth_key = { + .data = test_key16, + .length = sizeof(test_key16) + } + }, + .hash_adjust = 12 + }, + { + .name = "null-hmac-md5-96", + .session = { + .cipher_alg = ODP_CIPHER_ALG_NULL, + .auth_alg = ODP_AUTH_ALG_MD5_96, + .auth_key = { + .data = test_key16, + .length = sizeof(test_key16) + } + }, + .hash_adjust = 12 + }, +}; + +/** + * Find corresponding config for given name. Returns NULL + * if config for given name is not found. + */ +static cspeed_alg_config_t * +find_config_by_name(const char *name) { + unsigned int i; + cspeed_alg_config_t *ret = NULL; + + for (i = 0; i < (sizeof(algs_config) / sizeof(cspeed_alg_config_t)); + i++) { + if (strcmp(algs_config[i].name, name) == 0) { + ret = algs_config + i; + break; + } + } + return ret; +} + +/** + * Helper function that prints list of algorithms that this + * test understands. + */ +static void +print_config_names(const char *prefix) { + unsigned int i; + + for (i = 0; i < (sizeof(algs_config) / sizeof(cspeed_alg_config_t)); + i++) { + printf("%s %s\n", prefix, algs_config[i].name); + } +} + +/** + * Snap current time values and put them into 'rec'. + */ +static void +fill_time_record(time_record_t *rec) +{ + gettimeofday(&rec->tv, NULL); + getrusage(RUSAGE_SELF, &rec->ru_self); + getrusage(RUSAGE_THREAD, &rec->ru_thread); +} + +/** + * Calculated CPU time difference for given two rusage structures. + * Note it adds user space and system time together. + */ +static unsigned long long +get_rusage_diff(struct rusage *start, struct rusage *end) +{ + unsigned long long rusage_diff; + unsigned long long rusage_start; + unsigned long long rusage_end; + + rusage_start = (start->ru_utime.tv_sec * 1000000) + + (start->ru_utime.tv_usec); + rusage_start += (start->ru_stime.tv_sec * 1000000) + + (start->ru_stime.tv_usec); + + rusage_end = (end->ru_utime.tv_sec * 1000000) + + (end->ru_utime.tv_usec); + rusage_end += (end->ru_stime.tv_sec * 1000000) + + (end->ru_stime.tv_usec); + + rusage_diff = rusage_end - rusage_start; + + return rusage_diff; +} + +/** + * Get diff for RUSAGE_SELF (whole process) between two time snap + * records. + */ +static unsigned long long +get_rusage_self_diff(time_record_t *start, time_record_t *end) +{ + return get_rusage_diff(&start->ru_self, &end->ru_self); +} + +/** + * Get diff for RUSAGE_THREAD (current thread only) between two + * time snap records. + */ +static unsigned long long +get_rusage_thread_diff(time_record_t *start, time_record_t *end) +{ + return get_rusage_diff(&start->ru_thread, &end->ru_thread); +} + +/** + * Get diff of elapsed time between two time snap records + */ +static unsigned long long +get_elapsed_usec(time_record_t *start, time_record_t *end) +{ + unsigned long long s; + unsigned long long e; + + s = (start->tv.tv_sec * 1000000) + + (start->tv.tv_usec); + e = (end->tv.tv_sec * 1000000) + + (end->tv.tv_usec); + + return e - s; +} + +#define REPORT_HEADER "\n%30.30s %15s %15s %15s %15s %15s %15s\n" +#define REPORT_LINE "%30.30s %15d %15d %15.3f %15.3f %15.3f %15d\n" + +/** + * Print header line for our report. + */ +static void +print_result_header(void) +{ + printf(REPORT_HEADER, + "algorithm", "avg over #", "payload (bytes)", "elapsed (us)", + "rusg self (us)", "rusg thrd (us)", "throughput (Kb)"); +} + +/** + * Print one line of our report. + */ +static void +print_result(cspeed_args_t *cargs, + unsigned int payload_length, + cspeed_alg_config_t *config, + cspeed_run_result_t *result) +{ + unsigned int throughput; + + throughput = (1000000.0 / result->elapsed) * payload_length / 1024; + printf(REPORT_LINE, + config->name, cargs->iteration_count, payload_length, + result->elapsed, result->rusage_self, result->rusage_thread, + throughput); +} + +/** + * Print piece of memory with given size. + */ +static void +print_mem(const char *msg, + const unsigned char *ptr, + unsigned int len) +{ + unsigned i, j; + char c; + char line[81]; + char *p; + + if (msg) + printf("\n%s (bytes size = %d)", msg, len); + + for (i = 0; i < len; i += 16) { + p = line; + sprintf(p, "\n%04x ", i); p += 8; + + for (j = 0; j < 16; j++) { + if (i + j == len) + break; + + sprintf(p, " %02x", (ptr)[i + j]); p += 3; + } + + for (; j < 16; j++) { + sprintf(p, " "); p += 3; + } + + sprintf(p, " "); p += 3; + + for (j = 0; j < 16; j++) { + if (i + j == len) + break; + c = (ptr)[i + j]; + *p++ = (' ' <= c && c <= '~') ? c : '.'; + } + + *p = '\0'; + printf("%s", line); + } + printf("\n"); +} + +/** + * Create ODP crypto session for given config. + */ +static int +create_session_from_config(odp_crypto_session_t *session, + cspeed_alg_config_t *config, + cspeed_args_t *cargs) +{ + odp_crypto_session_params_t params; + enum odp_crypto_ses_create_err ses_create_rc; + odp_pool_t pkt_pool; + odp_queue_t out_queue; + + memcpy(¶ms, &config->session, sizeof(odp_crypto_session_params_t)); + params.op = ODP_CRYPTO_OP_ENCODE; + params.pref_mode = ODP_CRYPTO_SYNC; + + /* Lookup the packet pool */ + pkt_pool = odp_pool_lookup("packet_pool"); + if (pkt_pool == ODP_POOL_INVALID) { + app_err("packet_pool pool not found\n"); + return -1; + } + params.output_pool = pkt_pool; + + if (cargs->schedule || cargs->poll) { + out_queue = odp_queue_lookup("crypto-out"); + if (out_queue == ODP_QUEUE_INVALID) { + app_err("crypto-out queue not found\n"); + return -1; + } + params.compl_queue = out_queue; + + } else { + params.compl_queue = ODP_QUEUE_INVALID; + } + if (odp_crypto_session_create(¶ms, session, + &ses_create_rc)) { + app_err("crypto session create failed.\n"); + return -1; + } + + return 0; +} + +/** + * Run measurement iterations for given config and payload size. + * Result of run returned in 'result' out parameter. + */ +static int +run_measure_one(cspeed_args_t *cargs, + cspeed_alg_config_t *config, + odp_crypto_session_t *session, + unsigned int payload_length, + cspeed_run_result_t *result) +{ + odp_crypto_op_params_t params; + + odp_pool_t pkt_pool; + odp_queue_t out_queue; + odp_packet_t pkt; + int rc = 0; + + odp_bool_t posted = 0; + + pkt_pool = odp_pool_lookup("packet_pool"); + if (pkt_pool == ODP_POOL_INVALID) { + app_err("pkt_pool not found\n"); + return -1; + } + + out_queue = odp_queue_lookup("crypto-out"); + if (cargs->schedule || cargs->poll) { + if (out_queue == ODP_QUEUE_INVALID) { + app_err("crypto-out queue not found\n"); + return -1; + } + } + + pkt = odp_packet_alloc(pkt_pool, payload_length); + if (pkt == ODP_PACKET_INVALID) { + app_err("failed to allocate buffer\n"); + return -1; + } + + void *mem = odp_packet_data(pkt); + + memset(mem, 1, payload_length); + + time_record_t start, end; + int packets_sent = 0; + int packets_received = 0; + + /* Initialize parameters block */ + memset(¶ms, 0, sizeof(params)); + params.session = *session; + + params.cipher_range.offset = 0; + params.cipher_range.length = payload_length; + + params.auth_range.offset = 0; + params.auth_range.length = payload_length; + params.hash_result_offset = payload_length; + + if (cargs->reuse_packet) { + params.pkt = pkt; + params.out_pkt = cargs->in_place ? pkt : + ODP_PACKET_INVALID; + } + + fill_time_record(&start); + + while ((packets_sent < cargs->iteration_count) || + (packets_received < cargs->iteration_count)) { + void *mem; + odp_crypto_op_result_t result; + + if ((packets_sent < cargs->iteration_count) && + (packets_sent - packets_received < + cargs->in_flight)) { + if (!cargs->reuse_packet) { + /* + * For in place test we use just one + * statically allocated buffer. + * For now in place test we have to + * allocate and initialize packet + * every time. + * Note we leaked one packet here. + */ + pkt = odp_packet_alloc(pkt_pool, + payload_length); + if (pkt == ODP_PACKET_INVALID) { + app_err("failed to allocate buffer\n"); + rc = -1; + } else { + void *mem = odp_packet_data(pkt); + + memset(mem, 1, payload_length); + } + params.pkt = pkt; + params.out_pkt = cargs->in_place ? pkt : + ODP_PACKET_INVALID; + } + + if (cargs->debug_packets) { + mem = odp_packet_data(params.pkt); + print_mem("Packet before encryption:", + mem, payload_length); + } + + rc = odp_crypto_operation(¶ms, &posted, + &result); + if (rc) + app_err("failed odp_crypto_operation: rc = %d\n", + rc); + else + packets_sent++; + } + + if (!posted) { + packets_received++; + if (cargs->debug_packets) { + mem = odp_packet_data(params.out_pkt); + print_mem("Imediately encrypted packet", mem, + payload_length + + config->hash_adjust); + } + if (!cargs->in_place) { + if (cargs->reuse_packet) { + params.pkt = params.out_pkt; + params.out_pkt = ODP_PACKET_INVALID; + } else { + odp_packet_free(params.out_pkt); + } + } + } else { + odp_event_t ev; + odp_crypto_compl_t compl; + odp_crypto_op_result_t result; + odp_packet_t out_pkt; + + if (cargs->schedule) + ev = odp_schedule(NULL, + ODP_SCHED_NO_WAIT); + else + ev = odp_queue_deq(out_queue); + + while (ev != ODP_EVENT_INVALID) { + compl = odp_crypto_compl_from_event(ev); + odp_crypto_compl_result(compl, &result); + odp_crypto_compl_free(compl); + out_pkt = result.pkt; + + if (cargs->debug_packets) { + mem = odp_packet_data(out_pkt); + print_mem("Receieved encrypted packet", + mem, + payload_length + + config->hash_adjust); + } + if (cargs->reuse_packet) { + params.pkt = out_pkt; + params.out_pkt = ODP_PACKET_INVALID; + } else { + odp_packet_free(out_pkt); + } + packets_received++; + if (cargs->schedule) + ev = odp_schedule(NULL, + ODP_SCHED_NO_WAIT); + else + ev = odp_queue_deq(out_queue); + }; + } + } + + fill_time_record(&end); + + { + double count; + + count = get_elapsed_usec(&start, &end); + result->elapsed = count / + cargs->iteration_count; + + count = get_rusage_self_diff(&start, &end); + result->rusage_self = count / + cargs->iteration_count; + + count = get_rusage_thread_diff(&start, &end); + result->rusage_thread = count / + cargs->iteration_count; + } + + return rc; +} + +/** + * Process one algorithm. Note if paload size is specicified it is + * only one run. Or iterate over set of predefined payloads. + */ +static int +run_measure_one_config(cspeed_args_t *cargs, + cspeed_alg_config_t *config) +{ + cspeed_run_result_t result; + odp_crypto_session_t session; + int rc = 0; + + if (create_session_from_config(&session, config, cargs)) + rc = -1; + + if (!rc) { + if (cargs->payload_length) { + rc = run_measure_one(cargs, config, &session, + cargs->payload_length, &result); + if (!rc) { + print_result_header(); + print_result(cargs, cargs->payload_length, + config, &result); + } + } else { + unsigned int i; + + print_result_header(); + for (i = 0; + i < (sizeof(payloads) / sizeof(unsigned int)); + i++) { + rc = run_measure_one(cargs, config, &session, + payloads[i], &result); + if (rc) + break; + print_result(cargs, payloads[i], + config, &result); + } + } + } + + if (session != ODP_CRYPTO_SESSION_INVALID) + odp_crypto_session_destroy(session); + return rc; +} + +typedef struct thr_arg { + cspeed_args_t cspeed_args; + cspeed_alg_config_t *cspeed_alg_config; +} thr_arg_t; + +static void *run_thr_func(void *arg) +{ + thr_arg_t *thr_args = (thr_arg_t *)arg; + + run_measure_one_config(&thr_args->cspeed_args, + thr_args->cspeed_alg_config); + return NULL; +} + +int main(int argc, char *argv[]) +{ + cspeed_args_t cargs; + odp_pool_t pool; + odp_queue_param_t qparam; + odp_pool_param_t params; + odph_linux_pthread_t thr; + odp_queue_t out_queue = ODP_QUEUE_INVALID; + thr_arg_t thr_arg; + int num_workers = 1; + odp_cpumask_t cpumask; + char cpumaskstr[ODP_CPUMASK_STR_SIZE]; + + /* Parse and store the application arguments */ + parse_args(argc, argv, &cargs); + + /* Init ODP before calling anything else */ + if (odp_init_global(NULL, NULL)) { + app_err("ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Init this thread */ + odp_init_local(ODP_THREAD_WORKER); + + /* Create packet pool */ + memset(¶ms, 0, sizeof(params)); + params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE; + params.type = ODP_POOL_PACKET; + pool = odp_pool_create("packet_pool", ¶ms); + + if (pool == ODP_POOL_INVALID) { + app_err("packet pool create failed.\n"); + exit(EXIT_FAILURE); + } + odp_pool_print(pool); + + if (cargs.schedule) { + qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; + qparam.sched.sync = ODP_SCHED_SYNC_NONE; + qparam.sched.group = ODP_SCHED_GROUP_ALL; + out_queue = odp_queue_create("crypto-out", + ODP_QUEUE_TYPE_SCHED, &qparam); + } else if (cargs.poll) { + out_queue = odp_queue_create("crypto-out", + ODP_QUEUE_TYPE_POLL, NULL); + } + if (cargs.schedule || cargs.poll) { + if (out_queue == ODP_QUEUE_INVALID) { + app_err("crypto-out queue create failed.\n"); + exit(EXIT_FAILURE); + } + } + + if (cargs.schedule) { + printf("Run in async scheduled mode\n"); + + thr_arg.cspeed_args = cargs; + thr_arg.cspeed_alg_config = cargs.alg_config; + num_workers = odp_cpumask_def_worker(&cpumask, + num_workers); + (void)odp_cpumask_to_str(&cpumask, cpumaskstr, + sizeof(cpumaskstr)); + printf("num worker threads: %i\n", + num_workers); + printf("first CPU: %i\n", + odp_cpumask_first(&cpumask)); + printf("cpu mask: %s\n", + cpumaskstr); + } else if (cargs.poll) { + printf("Run in async poll mode\n"); + } else { + printf("Run in sync mode\n"); + } + + if (cargs.alg_config) { + if (cargs.schedule) { + odph_linux_pthread_create(&thr, &cpumask, + run_thr_func, &thr_arg); + odph_linux_pthread_join(&thr, num_workers); + } else { + run_measure_one_config(&cargs, cargs.alg_config); + } + } else { + unsigned int i; + + for (i = 0; + i < (sizeof(algs_config) / sizeof(cspeed_alg_config_t)); + i++) { + run_measure_one_config(&cargs, algs_config + i); + } + } + + return 0; +} + +static void parse_args(int argc, char *argv[], cspeed_args_t *cargs) +{ + int opt; + int long_index; + static struct option longopts[] = { + {"algorithm", optional_argument, NULL, 'a'}, + {"count", optional_argument, NULL, 'c'}, + {"debug", no_argument, NULL, 'd'}, + {"flight", optional_argument, NULL, 'f'}, + {"help", no_argument, NULL, 'h'}, + {"iterations", optional_argument, NULL, 'i'}, + {"inplace", no_argument, NULL, 'n'}, + {"payload", optional_argument, NULL, 'l'}, + {"sessions", optional_argument, NULL, 'm'}, + {"reuse", no_argument, NULL, 'r'}, + {"poll", no_argument, NULL, 'p'}, + {"schedule", no_argument, NULL, 's'}, + {NULL, 0, NULL, 0} + }; + + cargs->in_place = 0; + cargs->in_flight = 1; + cargs->debug_packets = 0; + cargs->core_count = 1; + cargs->iteration_count = 10000; + cargs->payload_length = 0; + cargs->alg_config = NULL; + cargs->reuse_packet = 0; + cargs->schedule = 0; + + while (1) { + opt = getopt_long(argc, argv, "+a:c:df:hi:m:nl:spr", + longopts, &long_index); + + if (opt == -1) + break; /* No more options */ + + switch (opt) { + case 'a': + cargs->alg_config = find_config_by_name(optarg); + if (!cargs->alg_config) { + printf("cannot test crypto '%s' configuration\n", + optarg); + usage(argv[0]); + exit(-1); + } + case 'c': + cargs->core_count = atoi(optarg); + break; + case 'd': + cargs->debug_packets = 1; + break; + case 'i': + cargs->iteration_count = atoi(optarg); + break; + case 'f': + cargs->in_flight = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + break; + case 'm': + cargs->max_sessions = atoi(optarg); + break; + case 'n': + cargs->in_place = 1; + break; + case 'l': + cargs->payload_length = atoi(optarg); + break; + case 'r': + cargs->reuse_packet = 1; + break; + case 's': + cargs->schedule = 1; + break; + case 'p': + cargs->poll = 1; + break; + default: + break; + } + } + + optind = 1; /* reset 'extern optind' from the getopt lib */ + + if ((cargs->in_flight > 1) && cargs->reuse_packet) { + printf("-f (in flight > 1) and -r (reuse packet) options are not compatible\n"); + usage(argv[0]); + exit(-1); + } + if (cargs->schedule && cargs->poll) { + printf("-s (schedule) and -p (poll) options are not compatible\n"); + usage(argv[0]); + exit(-1); + } +} + +/** + * Prinf usage information + */ +static void usage(char *progname) +{ + printf("\n" + "Usage: %s OPTIONS\n" + " E.g. %s -i 100000\n" + "\n" + "OpenDataPlane crypto speed measure.\n" + "Optional OPTIONS\n" + " -a, --algorithm Specify algorithm name (default all)\n" + " Supported values are:\n", + progname, progname); + + print_config_names(" "); + printf(" -c, --count Core count. (NOT used)\n" + " -d, --debug Enable dump of processed packets.\n" + " -f, --flight Max number of packet processed in parallel (default 1)\n" + " -i, --iterations Number of iterations.\n" + " -n, --inplace Encrypt on place.\n" + " -l, --payload Payload length.\n" + " -r, --reuse Output encrypted packet is passed as input\n" + " to next encrypt iteration.\n" + " -s, --schedule Use scheduler for completion events.\n" + " -p, --poll Poll completion queue for completion events.\n" + " -h, --help Display help and exit.\n" + "\n"); +}