From patchwork Tue Sep 1 11:09:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Badicioiu X-Patchwork-Id: 52925 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 913EC2157D for ; Tue, 1 Sep 2015 11:13:05 +0000 (UTC) Received: by lbck9 with SMTP id k9sf48123987lbc.0 for ; Tue, 01 Sep 2015 04:13:04 -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=9oniGh9LXdAikprmzVXjpx+HRXATC8jJo9tG//1r0ok=; b=YhpTWCNHjZ9dnzpRZ14ME9rVbEccuRslq4YwQT0n852A3NtVwni/MZdnFw/r0r4DJU wjTO6xlGn6Cp4DBdOeVmYcXcSNDmnZX01Yx3/Z4qIKoJeolZMk9oo3Jx8ayvnfidzxVt ygEGFqdP/3y6DtSqtlGuMLKKjjwY3TYfQBT5f9eIZWPjhEIE2/MtaOW0kU7FixW8ChMU Bf5Z+aZik8/8UJjfv+zrfxiT086nesvoqL8qQk4CtmcgQyYc5lM622FfBLVXCV9HiFG+ zRohmCiC/oIBt+HFolxpM0lrXQ8IrlLfI3BEHpU3XlrFbjQR6HBWnan16ZcdnnHOFl/V Q7FA== X-Gm-Message-State: ALoCoQkAl6jE5AnAqKEIZLyRu65hEYGAPtgs3Je/rYiRDhi/zNy6GLRAZr+eV6fyBpJ1FZSrTqoF X-Received: by 10.112.139.65 with SMTP id qw1mr7377910lbb.24.1441105984446; Tue, 01 Sep 2015 04:13:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.1 with SMTP id o1ls622047lao.12.gmail; Tue, 01 Sep 2015 04:13:04 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr12640107lbc.41.1441105984173; Tue, 01 Sep 2015 04:13:04 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id r8si16136076lbh.6.2015.09.01.04.13.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Sep 2015 04:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by laboe4 with SMTP id oe4so64018645lab.0 for ; Tue, 01 Sep 2015 04:13:03 -0700 (PDT) X-Received: by 10.152.43.198 with SMTP id y6mr4737606lal.41.1441105983755; Tue, 01 Sep 2015 04:13:03 -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.164.42 with SMTP id yn10csp457352lbb; Tue, 1 Sep 2015 04:13:02 -0700 (PDT) X-Received: by 10.140.233.213 with SMTP id e204mr13340884qhc.27.1441105981948; Tue, 01 Sep 2015 04:13:01 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h81si20860937qhc.105.2015.09.01.04.13.00; Tue, 01 Sep 2015 04:13:01 -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 7D11461D22; Tue, 1 Sep 2015 11:13:00 +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 5C03861C67; Tue, 1 Sep 2015 11:12:53 +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 D637061C6C; Tue, 1 Sep 2015 11:12:50 +0000 (UTC) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0058.outbound.protection.outlook.com [65.55.169.58]) by lists.linaro.org (Postfix) with ESMTPS id 983E161835 for ; Tue, 1 Sep 2015 11:12:49 +0000 (UTC) Received: from DM2PR03CA0039.namprd03.prod.outlook.com (10.141.96.38) by BY1PR0301MB1269.namprd03.prod.outlook.com (10.161.205.143) with Microsoft SMTP Server (TLS) id 15.1.256.15; Tue, 1 Sep 2015 11:12:48 +0000 Received: from BL2FFO11FD019.protection.gbl (2a01:111:f400:7c09::114) by DM2PR03CA0039.outlook.office365.com (2a01:111:e400:2428::38) with Microsoft SMTP Server (TLS) id 15.1.256.15 via Frontend Transport; Tue, 1 Sep 2015 11:12:48 +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 BL2FFO11FD019.mail.protection.outlook.com (10.173.161.37) with Microsoft SMTP Server (TLS) id 15.1.256.10 via Frontend Transport; Tue, 1 Sep 2015 11:12:48 +0000 Received: from fsr-fed1364-15.ea.freescale.net (fsr-fed1364-15.ea.freescale.net [10.171.81.144]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t81BCjgX017531; Tue, 1 Sep 2015 04:12:46 -0700 From: To: Date: Tue, 1 Sep 2015 14:09:41 +0300 Message-ID: <1441105781-23174-1-git-send-email-alexandru.badicioiu@linaro.org> X-Mailer: git-send-email 1.7.3.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130855795683711099; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD019; 1:12EAaUxdrEN+OfOGQf6AYA98zKs0CYGT0IWdnfw3lV1R9Mq7rYGHb+hVI7YX+Z2YuLwTJ1/amsN4r+EpI/JeVugtcPdEFX6YV99MmciAtosaWCdoQfsU0Eqan/0lFoC06wjSMb9MyaKlROzBq8HOk9PLwyzOfz+XJSAz4iRvr59T0wP8DOI3rIE9XSRrVPBRkS9VwofBGiUi8xmIaZryr9JcKojgSpLmy2+Qn7/GQscUxGQ8kN/FfHiBAPMt/Ep9lHoBpQ1rLU2dwKWp27RM+kb92aNyGLAM+NDBJWRryr3SHEe+WYODGV+UHMC+vpyT7UQ4q4s67iJ9k/eSPepuc61jcvksImcunnfA9pFZ7a+wminlPRlchgs9Krul/JF89h/jP5jBh8AkC4JBHHgl20YKnWKn8Ne0W8+ZCOEURuYSeKgzAVjm5h9G0Eh6twIPix1XyI6ZKc7jbHLmeJK3JA== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(3050300001)(199003)(189002)(104016003)(33646002)(19580405001)(68736005)(50466002)(81156007)(19580395003)(50986999)(105596002)(86152002)(106466001)(6806004)(36756003)(62966003)(86362001)(77096005)(77156002)(92566002)(97736004)(69596002)(5003940100001)(2351001)(5007970100001)(47776003)(4001540100001)(5001920100001)(46102003)(189998001)(64706001)(5001960100002)(5001860100001)(48376002)(110136002)(5001830100001)(50226001)(229853001)(87936001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0301MB1269; H:az84smr01.freescale.net; FPR:; SPF:SoftFail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1269; 2:UDtfK/G1ESZCRV2yo08O7KiPJZ/N8DlLv6rGRYdAGmMqfBEQRW6NLmgoOlj1FovTitb/mQJNWU/q/yT6Q2fp7YA3CksYvrrDEQmwyXNxp1SLPurD5zco/veeeucrDj3OoV8tWlEoysIBd08Kq0tZe6Fw699GGVrVrA6ToKtpZ/w=; 3:tbVQh6CT8CrWy/Wt4dkcNMaWn/JryH+CUSNC9cngTkyHYl0sSojrYEWyQ0+qD+L4hBep6vjPeioGGda2KT7X2wF9yxpEwHWDDu0XE63mi8HqG0bInnDCymykl0su4g0hAzA07ZBbZEsZb3fBpify8y7M/QfK6brjyPTgf+GQM7IQ/A3eAwfyOpy2bg39MXjOnyO9/LaYeXXjhWu445pbUEDeId2dBTBICCMNN0ujmwI=; 25:lK1sKfEPVManull2Tkf5cVJwny2TRKudmEuS8zfo6WANQBMu6lhWaM6WjX1N+3DBsfbUeXM+EMQIElk/SesAdPbljSwtULvqLgd3+eZbOPy3BdpFnbvv02ZBxz+O/QnESXW2h3pFHysub8Ixc5tNmntu/WkWCPXE10F1QlVQ40ZhSZHqw+NxuUJdIN4yZdhZBp4RluW8z+JDq6VhEbehTgCrKkfrofPYENu6thCltnW0aRs2TJccwEilICoFrs6c X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0301MB1269; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(8121501046)(3002001); SRVR:BY1PR0301MB1269; BCL:0; PCL:0; RULEID:(400006); SRVR:BY1PR0301MB1269; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1269; 4:BA8JA5JxyLofdDMYpSCggseTHEOCdcEQYZ/cTeoj2pZMayJJ20JvNBkW/qiNVdbJFV/sb9zOsyOqJsEXkmrObNzuHs7DKrUlQOiUI06FrJZW9lh2ZaSuUvNGDcK67c/mRAoxwmd/VfIeP5OVcRpSQr3/lCsQBhwcwfsS9mYLQwNi4PsuPMV6uDvZPZXUQiTXyfdWzn8+g4nkTz9kkEDgGpOXG+9qvxHiNx7Q5mb3/iNlLRwGYmyLvrpIVbrEorjexXWUSKFoVNJ+wk6ruwiL8tgqmtvYPT7DWmiJ3ZuRjScIGFpVAgy+qCjdr8XwFFgR X-Forefront-PRVS: 06860EDC7B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR0301MB1269; 23:SVFvD2WJVD34gCTpdEvvXnJc+J9hV9sm9By+Qth?= =?us-ascii?Q?Y3hZ7LVXOjMseG+6+uDAnv50d55hXpXIXmknCDIRUBv/97pZiv5wwzTEHGmZ?= =?us-ascii?Q?3FKwR/DXohEkPyARA5r4irXBABqfxsQ76p2TNacO5jnx0IVuL0/CaW+qzt1s?= =?us-ascii?Q?ptfEpTOCAdGxDpB0dNYOzEFqThDMHjwSjRl7aM3jAuBzMTrQ++MUFFz72/jo?= =?us-ascii?Q?bDxrdVIkGWRQIT4Dc6ftOw8jkgbBCAJY8Nzdv6t9+5D05CO9Ao3dF9jWW+72?= =?us-ascii?Q?KA/r56PmU/gcj+NNeI/nN42ieeXJRD5PeJGSgthkcRJGYJQeF4MUA5UmnHWJ?= =?us-ascii?Q?VvAkwJDTCcjTB7rDLoEPlt/OOhQ53uKqAyRwqGS719YO/+04wCdLmzCyo+nB?= =?us-ascii?Q?IH3CaYEizasJttCB4q5NW9OAnAFkv8PWU8GJsMjTh1OEMdMvXllW90qK0a6S?= =?us-ascii?Q?LCJtWfWcrM7eHYE6oA0bzYOqILTyxWYms9mdl9WTQUldkDpjSNV8ONnMAk+w?= =?us-ascii?Q?I3Gv6u8re2hHawkrQVBbIvGn7swDA6PS2YweNz+8piDvD+8CTeDcHAEyy64x?= =?us-ascii?Q?1Yls9ZLirAT9hyNFNPxtj5Tw0EKReeumMvCgaDqotYsszjmptEF0M+TbS5t+?= =?us-ascii?Q?cagiv4qldHSZzwpz42st5v95/O7l6uu0SYwxZhr5g8eCe9RxmddHcLYkapxJ?= =?us-ascii?Q?mMfUktZmfx8okoZjcuQlEWyOorddSZnlLy/4gwyuxf0zzrloPgPublV3qK/2?= =?us-ascii?Q?0pg/zXDmG/eeQeMZnW9kzoDOevHBoetcZq25zcz1xMDYyfEXjh5QKz/zPc98?= =?us-ascii?Q?xpAEI4Bm6sx+7No8B9hdGDE5v87OdbHc4RsNPz7ishs/idZiFV2/AXd+/Tbu?= =?us-ascii?Q?AWtP9rn0fhIvPtUg7ahuGzEWO6kRcqd0ySBNWCBhf5cn0qaGPh7mVe69D8jv?= =?us-ascii?Q?Zrt65BGQDgOG5e/9uvY2AA1JxEnCizd1PNEDYQOH5ZkQlD+Gzoru6N9qLvjm?= =?us-ascii?Q?wjP4ixxgwnp4pv+QCiUNRwSROkaAXfoa6MWV+2gX/OOqmFa9+3PgA20IavLb?= =?us-ascii?Q?HUZqNzevaKghxlyRSRMnrL5JilgwpyNFT9VaeYAmNF7dL2b68eyKe2M6q/sV?= =?us-ascii?Q?kaJ83w7Oxcn3JxuaKfhHq16p6NSCkRV70?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB1269; 5:CHFV4u04E1DxPIUO9Ckeg/6cv7Up7u+Pdn6Sq/HosL3t3M9kWkMJiyMG6RQcCI0vry1Z/stLZHyiMWdgbzNsw9B+CTw8/PqK5J//MUMf1lRyaFZb1bF+BCaBh1IJQrjI3gXPvN5p/cN8+Bpa/VP9Dm/1c30HkjX6Tv795KgyFbA=; 24:oofb/9U5Mj79YWlG1c9ErpoXkZNm+AwbPlFs9JkmjABoj287JjYmjQC+nfsuUnFp3PA/djRbT+1hZZ0eEpFcxIakPgoggzEUdAXTz59sBPE= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2015 11:12:48.0123 (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: BY1PR0301MB1269 X-Topics: patch Subject: [lng-odp] [PATCH 1/1] helpers: linux: add application defined counters 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.49 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 This patch provides the applications with helpers to create, update and read counters associated with application defined objects - e.g. IPSec security associations in a multi-threading scenario where multiple threads use the same object. Each worker thread must create a local version of a given counter - e.g. IPSec SA request bytes/packets with odph_counter32/64_create_local() function and update its local counter with odph_counter32/64_set/add/sub functions. A control thread can use odph_counter32/64_read_global() to retrieve the total value of the counter by summing all local values. Signed-off-by: Alexandru Badicioiu --- helper/include/odp/helper/linux.h | 114 +++++++++++++++++++++++++++++++++ helper/linux.c | 128 +++++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+), 0 deletions(-) diff --git a/helper/include/odp/helper/linux.h b/helper/include/odp/helper/linux.h index ce61fdf..3c7ab15 100644 --- a/helper/include/odp/helper/linux.h +++ b/helper/include/odp/helper/linux.h @@ -31,6 +31,7 @@ extern "C" { typedef struct { void *(*start_routine) (void *); /**< The function to run */ void *arg; /**< The functions arguemnts */ + void **counters_tbl; /**< Counters table address */ } odp_start_args_t; /** Linux pthread state information */ @@ -40,8 +41,18 @@ typedef struct { int cpu; /**< CPU ID */ /** Saved starting args for join to later free */ odp_start_args_t *start_args; + void *counters_tbl; /**< Counters table for this thread */ } odph_linux_pthread_t; +/** Thread local counter size */ +typedef enum odph_counter_size { + ODPH_COUNTER_SIZE_32BIT, + ODPH_COUNTER_SIZE_64BIT, +} odph_counter_size_t; + +#define ODPH_COUNTER_INVALID (-1) +/** Thread local counter handle */ +typedef int32_t odph_counter_t; /** Linux process state information */ typedef struct { @@ -77,6 +88,109 @@ int odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, */ void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num); +/** + * Creates a 32bit thread local counter + * Each thread in the thread table must create a + * counter for a shared object to which the counter + * is associated to - e.g. an IPSec Security Association. + * + * Returns the counter handle + * + * @return Counter handle + */ +odph_counter_t odph_counter32_create_local(void); + +/** + * Creates a 64bit thread local counter + * + * Returns the counter handle + * + * @return Counter handle + */ +odph_counter_t odph_counter64_create_local(void); + +/** + * Get counter size + * + * Return the size of a counter + * + * @param Counter handle + * @return Counter size + * + */ +odph_counter_size_t +odph_counter_size(odph_counter_t counter); + +/** + * Set a 32bit counter to a given value + * + * @param Counter handle + * @param Set value + * + */ +void odph_counter32_set(odph_counter_t counter, uint32_t val); + +/** + * Set a 64bit thread local counter to a given value + * + * @param Counter handle + * @param Set value + * + */ +void odph_counter64_set(odph_counter_t counter, uint64_t val); + +/** + * Add a value to a 32bit thread local counter + * + * @param Counter handle + * @param Value to add + * + */ +void odph_counter32_add(odph_counter_t counter, unsigned int val); + +/** + * Add a value to a 64bit thread local counter + * + * @param Counter handle + * @param Value to add + * + */ +void odph_counter64_add(odph_counter_t counter, unsigned int val); + +/** + * Subtract a value from a 32bit thread local counter + * + * @param Counter handle + * @param Value to substract + * + */ +void odph_counter32_sub(odph_counter_t counter, unsigned int val); + +/** + * Subtract a value from a 64bit thread local counter + * + * @param Counter handle + * @param Value to substract + * + */ +void odph_counter64_sub(odph_counter_t counter, unsigned int val); + +/** + * Return global value of a counter by summing thread local values + * Caller has to make sure that all threads created the local + * counter prior calling this function. + * + * @param Thread array + * @param Number of threads in the array + * @param Counter handle + * + * @return Counter value + * + */ +uint64_t +odph_counter_read_global(odph_linux_pthread_t *thread_tbl, int num, + odph_counter_t counter); + /** * Fork a process diff --git a/helper/linux.c b/helper/linux.c index 3d3b6b8..1953d75 100644 --- a/helper/linux.c +++ b/helper/linux.c @@ -22,16 +22,45 @@ #include #include "odph_debug.h" +#define MAX_COUNTERS_TBL_SIZE 64 + +typedef union odph_counters { + uint32_t __u32[MAX_COUNTERS_TBL_SIZE]; + uint64_t __u64[MAX_COUNTERS_TBL_SIZE / 2]; +} odph_counters_t; + +typedef union odph_counter_bits { + odph_counter_t handle; + union { + int32_t s32; + struct { + uint16_t index; + uint16_t size; + }; + }; +} odph_counter_bits_t; + +/* Thread local array for local counters storage */ +static __thread odph_counters_t counters_tbl; + +/* Table index (32bit) where next counter is allocated */ +static __thread uint16_t next_idx; + static void *odp_run_start_routine(void *arg) { odp_start_args_t *start_args = arg; + void **_counters_tbl; /* ODP thread local init */ if (odp_init_local(ODP_THREAD_WORKER)) { ODPH_ERR("Local init failed\n"); return NULL; } + /* Store thread local counters table address */ + _counters_tbl = start_args->counters_tbl; + *_counters_tbl = &counters_tbl; + void *ret_ptr = start_args->start_routine(start_args->arg); int ret = odp_term_local(); if (ret < 0) @@ -87,6 +116,8 @@ int odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, thread_tbl[i].start_args->start_routine = start_routine; thread_tbl[i].start_args->arg = arg; + thread_tbl[i].start_args->counters_tbl = + &thread_tbl[i].counters_tbl; ret = pthread_create(&thread_tbl[i].thread, &thread_tbl[i].attr, odp_run_start_routine, thread_tbl[i].start_args); @@ -120,6 +151,103 @@ void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num) } } +odph_counter_t odph_counter32_create_local(void) +{ + odph_counter_bits_t handle; + odph_counter_t ret = ODPH_COUNTER_INVALID; + + if (next_idx >= MAX_COUNTERS_TBL_SIZE) + return ret; + handle.index = next_idx; + next_idx += 1; + handle.size = ODPH_COUNTER_SIZE_32BIT; + return handle.handle; +} + +odph_counter_t odph_counter64_create_local(void) +{ + odph_counter_bits_t handle; + odph_counter_t ret = ODPH_COUNTER_INVALID; + + if (next_idx >= MAX_COUNTERS_TBL_SIZE) + return ret; + handle.index = next_idx; + next_idx += 2; + handle.size = ODPH_COUNTER_SIZE_64BIT; + return handle.handle; +} + +odph_counter_size_t odph_counter_size(odph_counter_t counter) +{ + return ((odph_counter_bits_t)counter).size; +} + +inline void odph_counter32_set(odph_counter_t counter, uint32_t val) +{ + uint16_t idx = ((odph_counter_bits_t)counter).index; + + counters_tbl.__u32[idx] = val; +} + +inline void odph_counter64_set(odph_counter_t counter, uint64_t val) +{ + uint16_t idx = ((odph_counter_bits_t)counter).index; + + counters_tbl.__u64[idx] = val; +} + +inline void odph_counter32_add(odph_counter_t counter, unsigned int val) +{ + uint16_t idx = ((odph_counter_bits_t)counter).index; + + counters_tbl.__u32[idx] += val; +} + +inline void odph_counter64_add(odph_counter_t counter, unsigned int val) +{ + uint16_t idx = ((odph_counter_bits_t)counter).index; + + counters_tbl.__u64[idx] += val; +} + +inline void odph_counter32_sub(odph_counter_t counter, unsigned int val) +{ + uint16_t idx = ((odph_counter_bits_t)counter).index; + + counters_tbl.__u32[idx] -= val; +} + +inline void odph_counter64_sub(odph_counter_t counter, unsigned int val) +{ + uint16_t idx = ((odph_counter_bits_t)counter).index; + + counters_tbl.__u64[idx] -= val; +} + +uint64_t +odph_counter_read_global(odph_linux_pthread_t *thread_tbl, int num, + odph_counter_t counter) +{ + uint64_t val = 0; + uint32_t *ptr32; + uint64_t *ptr64; + uint16_t idx = ((odph_counter_bits_t)counter).index; + int i; + + for (i = 0; i < num; i++) { + odph_counters_t *counters_tbl = thread_tbl[i].counters_tbl; + + switch (odph_counter_size(counter)) { + case ODPH_COUNTER_SIZE_32BIT: + val += counters_tbl->__u32[idx]; + break; + case ODPH_COUNTER_SIZE_64BIT: + val += counters_tbl->__u64[idx]; + break; + } + } + return val; +} int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, const odp_cpumask_t *mask_in)