From patchwork Thu Dec 21 16:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 122579 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1081122qgn; Thu, 21 Dec 2017 08:06:21 -0800 (PST) X-Google-Smtp-Source: ACJfBovHxUz9g+jrY+J3EHd2uTlIZO0KhjQYb6nD8gNyw4ZBwXQK3VKG/x4ZOouYwr53pMevrVzE X-Received: by 10.237.42.22 with SMTP id c22mr14889696qtd.162.1513872381479; Thu, 21 Dec 2017 08:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872381; cv=none; d=google.com; s=arc-20160816; b=MIu6nTMoJYUbY4PRfQuabRBA8kA362K0oOtk9q68bEVebEP8q8uCWz9JhTuRKqMkrI CSlja5osZih+GwMHLefDpaaBhlKxDN8ejMOpC5kwKluTP9/MZCmsVDC2U1wO2CjQKbWB 8J+fEO+QN5cJqbwajdIBS0oNNDW/ecwgL4hHS+OY6WvY8FCdozdImi9Knh8Vbm+ZgFTQ Bz+bjmrArWZ1wzLp+iV0b8kUShW0C1wpTy6fmo/BfUfxzxpzXFgLZy2LpaNY3JBNqdp7 GEsVDPNOhGNaekcCIqEW5ZJBuse6x4Mk4zB2ZDldCIuwcHbfM7T0El00+vet2//s/s8o QNHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=6Z+6cBtVg0drBj0pf4O2eBeNmNhfbelOdwM6rvvozqk=; b=sonDViQS9xw0ailGHEZVZNobK4DSFwruz+rbbsn+XW0EAEwkpEHRTWOyrXAIH36gjA C5HaJMYqYDa7K0p9Qxra3WnW1Hhnj4IRXwykEn15soKKPsuNASy7C8JRDZ4oqw03XzYA g8VXH7bUB0BRLGL3t2lI5EqFV5sUgGnI2CMACQbFDd+dwMjTarfXJ5E0tnPO27L5Jnvg 0uJFzLWdz36b0Vt+5AAYQTqQO0BVTzJEwbuzuA3683u2C3NK7BwbRzSTiVdo3MR9z9oC Rs8MG3AdjcZtYsJcpbxiIApXK9nFlVJV8lUadxfqmy5Cq9chZMOzEB07wOMfJop/rYXD Zrnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id n189si81965qkf.215.2017.12.21.08.06.21; Thu, 21 Dec 2017 08:06:21 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 2EAB36171B; Thu, 21 Dec 2017 16:06:21 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 79E4361516; Thu, 21 Dec 2017 16:01:38 +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 41FFC60B11; Thu, 21 Dec 2017 16:01:12 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id CB91360975 for ; Thu, 21 Dec 2017 16:00:19 +0000 (UTC) Received: from mxback8j.mail.yandex.net (mxback8j.mail.yandex.net [IPv6:2a02:6b8:0:1619::111]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 2DACC439D9 for ; Thu, 21 Dec 2017 19:00:18 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback8j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id lVuJgh3X67-0Ipe0j93; Thu, 21 Dec 2017 19:00:18 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bLqbqs0pBY-0HPC2udM; Thu, 21 Dec 2017 19:00:17 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 21 Dec 2017 19:00:13 +0300 Message-Id: <1513872016-2819-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> References: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 359 Subject: [lng-odp] [PATCH CATERPILLAR v1 1/4] linux-gen: add memory-mapped I/O access API X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Mykyta Iziumtsev Signed-off-by: Mykyta Iziumtsev --- /** Email created from pull request 359 (MykytaI:caterpillar_mdev_auxiliary) ** https://github.com/Linaro/odp/pull/359 ** Patch: https://github.com/Linaro/odp/pull/359.patch ** Base sha: 63fd88635cc10caaa02fdccd3f52c9494487bdd2 ** Merge commit sha: 0e9885d54ac547d0bdf599d65b6fe32de445adb7 **/ include/odp/drv/spec/mmio.h | 145 +++++++++++++++++++++ platform/linux-generic/include/odp/drv/mmio.h | 179 ++++++++++++++++++++++++++ scripts/checkpatch.pl | 1 + 3 files changed, 325 insertions(+) create mode 100644 include/odp/drv/spec/mmio.h create mode 100644 platform/linux-generic/include/odp/drv/mmio.h diff --git a/include/odp/drv/spec/mmio.h b/include/odp/drv/spec/mmio.h new file mode 100644 index 000000000..35807637b --- /dev/null +++ b/include/odp/drv/spec/mmio.h @@ -0,0 +1,145 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * API to access memory-mapped I/O. + * + */ + +#ifndef ODPDRV_MMIO_H_ +#define ODPDRV_MMIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup odpdrv_mmio ODPDRV MMIO + * @{ + */ + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 8-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u8le_write(uint8_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 8-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u8be_write(uint8_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 16-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u16le_write(uint16_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 16-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u16be_write(uint16_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 32-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u32le_write(uint32_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 32-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u32be_write(uint32_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 64-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u64le_write(uint64_t value, volatile void *addr); + +/** + * Convert endianness and write value to MMIO + * @param value cpu native 64-bit value to write to MMIO + * @param addr MMIO address to write at + */ +void odpdrv_mmio_u64be_write(uint64_t value, volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 8-bit value + */ +uint8_t odpdrv_mmio_u8le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 8-bit value + */ +uint8_t odpdrv_mmio_u8be_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 16-bit value + */ +uint16_t odpdrv_mmio_u16le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 16-bit value + */ +uint16_t odpdrv_mmio_u16be_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 32-bit value + */ +uint32_t odpdrv_mmio_u32le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 32-bit value + */ +uint32_t odpdrv_mmio_u32be_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 64-bit value + */ +uint64_t odpdrv_mmio_u64le_read(volatile void *addr); + +/** + * Read from MMIO and convert endianness + * @param addr MMIO address to read at + * @return cpu native 64-bit value + */ +uint64_t odpdrv_mmio_u64be_read(volatile void *addr); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/drv/mmio.h b/platform/linux-generic/include/odp/drv/mmio.h new file mode 100644 index 000000000..b757a26c7 --- /dev/null +++ b/platform/linux-generic/include/odp/drv/mmio.h @@ -0,0 +1,179 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * API to access memory-mapped I/O. + */ + +#ifndef ODPDRV_PLAT_MMIO_H_ +#define ODPDRV_PLAT_MMIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** @ingroup odpdrv_mmio ODPDRV MMIO + * @{ + */ + +/* for use with type checkers such as sparse */ +#ifdef __CHECKER__ +/** @internal MMIO attribute */ +#define __odpdrv_mmio __attribute__((noderef, address_space(2))) +#else +/** @internal MMIO attribute */ +#define __odpdrv_mmio +#endif + +#define odpdrv_io_mb() do { __asm__ __volatile__("" ::: "memory"); } while (0) +#define odpdrv_io_rmb() do { __asm__ __volatile__("" ::: "memory"); } while (0) +#define odpdrv_io_wmb() do { __asm__ __volatile__("" ::: "memory"); } while (0) + +static inline void +odpdrv_mmio_u8le_write(uint8_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile uint8_t *)addr = value; +} + +static inline void +odpdrv_mmio_u8be_write(uint8_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_mmio_u8le_write(value, addr); +} + +static inline void +odpdrv_mmio_u16le_write(uint16_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u16le_t *)addr = odp_cpu_to_le_16(value); +} + +static inline void +odpdrv_mmio_u16be_write(uint16_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u16be_t *)addr = odp_cpu_to_be_16(value); +} + +static inline void +odpdrv_mmio_u32le_write(uint32_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u32le_t *)addr = odp_cpu_to_le_32(value); +} + +static inline void +odpdrv_mmio_u32be_write(uint32_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u32be_t *)addr = odp_cpu_to_be_32(value); +} + +static inline void +odpdrv_mmio_u64le_write(uint64_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u64le_t *)addr = odp_cpu_to_le_64(value); +} + +static inline void +odpdrv_mmio_u64be_write(uint64_t value, volatile void __odpdrv_mmio *addr) +{ + odpdrv_io_wmb(); + *(__odp_force volatile odp_u64be_t *)addr = odp_cpu_to_be_64(value); +} + +static inline uint8_t +odpdrv_mmio_u8le_read(volatile void __odpdrv_mmio *addr) +{ + uint8_t value = *(__odp_force volatile uint8_t *)addr; + + odpdrv_io_rmb(); + return value; +} + +static inline uint8_t +odpdrv_mmio_u8be_read(volatile void __odpdrv_mmio *addr) +{ + return odpdrv_mmio_u8le_read(addr); +} + +static inline uint16_t +odpdrv_mmio_u16le_read(volatile void __odpdrv_mmio *addr) +{ + uint16_t value = + odp_le_to_cpu_16(*(__odp_force volatile odp_u16le_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint16_t +odpdrv_mmio_u16be_read(volatile void __odpdrv_mmio *addr) +{ + uint16_t value = + odp_be_to_cpu_16(*(__odp_force volatile odp_u16be_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint32_t +odpdrv_mmio_u32le_read(volatile void __odpdrv_mmio *addr) +{ + uint32_t value = + odp_le_to_cpu_32(*(__odp_force volatile odp_u32le_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint32_t +odpdrv_mmio_u32be_read(volatile void __odpdrv_mmio *addr) +{ + uint32_t value = + odp_be_to_cpu_32(*(__odp_force volatile odp_u32be_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint64_t +odpdrv_mmio_u64le_read(volatile void __odpdrv_mmio *addr) +{ + uint64_t value = + odp_le_to_cpu_64(*(__odp_force volatile odp_u64le_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +static inline uint64_t +odpdrv_mmio_u64be_read(volatile void __odpdrv_mmio *addr) +{ + uint64_t value = + odp_be_to_cpu_64(*(__odp_force volatile odp_u64be_t *)addr); + + odpdrv_io_rmb(); + return value; +} + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 16316b928..9c256e29a 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -257,6 +257,7 @@ sub hash_show_words { __kernel| __force| __iomem| + __odpdrv_mmio| __must_check| __init_refok| __kprobes| From patchwork Thu Dec 21 16:00:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 122581 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1084177qgn; Thu, 21 Dec 2017 08:08:50 -0800 (PST) X-Google-Smtp-Source: ACJfBov7NEvfB/YGSW0S9NZemCneGU1s6JaaCuUACecIpCqBReww0vJLQDz75KPlXS49Wfc0o4WC X-Received: by 10.237.56.197 with SMTP id k63mr15141913qte.308.1513872530093; Thu, 21 Dec 2017 08:08:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872530; cv=none; d=google.com; s=arc-20160816; b=sNo847DRJFO8Xm5/Uz+yo6izsSDhloXjNVdOvrNQvq6O1e+y38FuPcc/5uRlM6HPYR WDKCefjXLqW1nY9MZQ0/u/4Hd1wpCNxJ61/KwdZqnjKZVSQ4WBeTceDv8DV0KbsghR8/ ifHQe5amKoHud+EoBEhXG3GjtbA7gFzPDJIUWYGww1qTOfmRXtZuwWt5qS7MPTcxtxIF NmKxbgVDrwfoCrSdwNhemwM1S6ad9Y0LKqWg5CCCZ8LWCacTfvYLi3xvz8KA2cxSLBmW HRZflTPfn/wxEb5jJbJ0Z8NZfpl1k/4zKt/emUwfzGF2Cyj2chMKbjfdu72+fm+L8bY8 K7PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=p1iokmfRcr6FtjZ8F5e032K6H/xXnKL59PM0iK1I/Tc=; b=MlJneCM0R/Mmh4ZyHQelZQ9H8q6WvlIWYQwMcF4uIlX3HC+7TKl4jJzwqDU4D9CE+e lIqHK5LIa+dYnTz+b8EvO2b/HAbGGyCrVJae5f0C8O2Pspenxg64CD0K2NAUvuOn4369 H2PDwG8WEvp7gPM1rvNaUN6et8Td7age0tr8nZzg61ykOXWjIYnDuXx3608Q5C6tXgoq NEgSs6xPTnfFyJn8+KTo+j0WjRheNEaXVk7vtQiuH5DLqU9HaQspuPu0CRltDmqSl/vS ARuRMb2FP86uQVNzBrqiF2WaY2cUPXPz1C6UtW5uAMSRgISTcg3sLOFPsdG2I4eaLDY4 2V2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id r32si472086qta.346.2017.12.21.08.08.49; Thu, 21 Dec 2017 08:08:50 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id B7D6261759; Thu, 21 Dec 2017 16:08:49 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 06FD06151C; Thu, 21 Dec 2017 16:01:45 +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 D699161514; Thu, 21 Dec 2017 16:01:17 +0000 (UTC) Received: from forward100p.mail.yandex.net (forward100p.mail.yandex.net [77.88.28.100]) by lists.linaro.org (Postfix) with ESMTPS id 5A4E060C4C for ; Thu, 21 Dec 2017 16:00:20 +0000 (UTC) Received: from mxback1j.mail.yandex.net (mxback1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10a]) by forward100p.mail.yandex.net (Yandex) with ESMTP id C6325510229B for ; Thu, 21 Dec 2017 19:00:18 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback1j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id mXWdCPEjlX-0IvmWjus; Thu, 21 Dec 2017 19:00:18 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bLqbqs0pBY-0IP0dSWu; Thu, 21 Dec 2017 19:00:18 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 21 Dec 2017 19:00:14 +0300 Message-Id: <1513872016-2819-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> References: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 359 Subject: [lng-odp] [PATCH CATERPILLAR v1 2/4] linux-gen: extend ethtool helper functions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Mykyta Iziumtsev Add helper function to query RX/TX queue lengths on network interface to facilitate upcoming native and mediated device drivers. Signed-off-by: Mykyta Iziumtsev --- /** Email created from pull request 359 (MykytaI:caterpillar_mdev_auxiliary) ** https://github.com/Linaro/odp/pull/359 ** Patch: https://github.com/Linaro/odp/pull/359.patch ** Base sha: 63fd88635cc10caaa02fdccd3f52c9494487bdd2 ** Merge commit sha: 0e9885d54ac547d0bdf599d65b6fe32de445adb7 **/ platform/linux-generic/pktio/ethtool.c | 19 +++++++++++++++++-- platform/linux-generic/pktio/ethtool.h | 27 +++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/pktio/ethtool.c b/platform/linux-generic/pktio/ethtool.c index b71666a32..119ad75a4 100644 --- a/platform/linux-generic/pktio/ethtool.c +++ b/platform/linux-generic/pktio/ethtool.c @@ -159,12 +159,27 @@ static int ethtool_stats(int fd, struct ifreq *ifr, odp_pktio_stats_t *stats) return 0; } -int ethtool_stats_get_fd(int fd, const char *name, odp_pktio_stats_t *stats) +int ethtool_stats_get_fd(int fd, const char *netif_name, + odp_pktio_stats_t *stats) { struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", name); + snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", netif_name); return ethtool_stats(fd, &ifr, stats); } + +int ethtool_ringparam_get_fd(int fd, const char *netif_name, + struct ethtool_ringparam *param) +{ + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", netif_name); + + param->cmd = ETHTOOL_GRINGPARAM; + ifr.ifr_data = (void *)param; + + return ioctl(fd, SIOCETHTOOL, &ifr); +} diff --git a/platform/linux-generic/pktio/ethtool.h b/platform/linux-generic/pktio/ethtool.h index c5a811238..c330c2e31 100644 --- a/platform/linux-generic/pktio/ethtool.h +++ b/platform/linux-generic/pktio/ethtool.h @@ -7,9 +7,32 @@ #ifndef ODP_PKTIO_ETHTOOL_H_ #define ODP_PKTIO_ETHTOOL_H_ +#include + +/** + * Get statistics for a network interface + * + * @param fd Arbitrary socket file descriptor + * @param netif_name Network interface name + * @param stats[out] Output buffer for counters + * + * @retval 0 on success + * @retval != 0 on failure + */ +int ethtool_stats_get_fd(int fd, const char *netif_name, + odp_pktio_stats_t *stats); + /** - * Get ethtool statistics of a packet socket + * Get RX/TX queue parameters for a network interface + * + * @param fd Arbitrary socket file descriptor + * @param netif_name Network interface name + * @param param[out] Output buffer for parameters + * + * @retval 0 on success + * @retval != 0 on failure */ -int ethtool_stats_get_fd(int fd, const char *name, odp_pktio_stats_t *stats); +int ethtool_ringparam_get_fd(int fd, const char *netif_name, + struct ethtool_ringparam *param); #endif /*ODP_PKTIO_ETHTOOL_H_*/ From patchwork Thu Dec 21 16:00:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 122580 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1082674qgn; Thu, 21 Dec 2017 08:07:36 -0800 (PST) X-Google-Smtp-Source: ACJfBot7TLwRKp6YCv2zAm9tPmdCWYk6CFAFxlYJCwrKcEfFptd4KEV1XNsDaU8Cw9l98tDZc/7Y X-Received: by 10.55.122.134 with SMTP id v128mr15413324qkc.354.1513872456501; Thu, 21 Dec 2017 08:07:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872456; cv=none; d=google.com; s=arc-20160816; b=J9w3tqEDLOJSiUKs4Xc7VSMxCD/jynmju4dUHaoWRwIODGVAEYz41pFMDg+6g+/Lpc CabF3y8gW91vfNqR5uZkMX5FfLN/lHLuHiVP4yYzHNayWASzvFwyhfWi97dPdQQRVCjL TGyO6p7bp+41JwhwZLEtEkTH8SfLFcwKz+40x8IAG2tHTsALaltXUR7GutkuLWhI7W8s cGtzKSxLn05d83f8hD+XSaGMX9XSl2cgN38cQYjcDB+F3MMzclClIKfoN0ZrD1I82crK +a6GPCQ1OqTcsjnBqgor+t1xbYBleDtdBqTfcg4Ll4sKnDQhb7x1zWYPSqUqNJdwka1J LB5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=zsuDn27e7z3pBhzTE7FLZUkbCXqIEmvF2caJLwh6lJc=; b=bLg2FXuAh0FMcjhvxndQR2rf9FTN2XcmeVi1hQmi0+O4hQPMzAGeCwfFvaxnmxfrHC eNTE/PTGGQPQRJ9D0sUh3jYSFbwtnrZncPyPWlostA9cZ+WYOiE48zCgCoej5lsZX5pf jbSA2RXDPe2SNu51nXKtsR7hVzEe5/MrLiuMo4Bal2aXNCqGHcrDcu1uyQc+nsa4FzMP XZ9SrEsffK3ueDhmvGKhh0o+pasjbL1aiBSvF6SvKcIvt5bp29Agf53kkfVEoYVKeJSo ZqZdSjxiJ/vtjpqkJ13zPoi5hR22YeEHUAjmbmgJRrELJK1u7+niNQXmpgzsT+0rn/rr PMjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id z26si1592124qtg.436.2017.12.21.08.07.36; Thu, 21 Dec 2017 08:07:36 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 3EE636173F; Thu, 21 Dec 2017 16:07:36 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 CBEB661519; Thu, 21 Dec 2017 16:01:41 +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 4245361514; Thu, 21 Dec 2017 16:01:17 +0000 (UTC) Received: from forward106j.mail.yandex.net (forward106j.mail.yandex.net [5.45.198.249]) by lists.linaro.org (Postfix) with ESMTPS id EE97260C5E for ; Thu, 21 Dec 2017 16:00:20 +0000 (UTC) Received: from mxback11j.mail.yandex.net (mxback11j.mail.yandex.net [IPv6:2a02:6b8:0:1619::84]) by forward106j.mail.yandex.net (Yandex) with ESMTP id 82BF31804BC6 for ; Thu, 21 Dec 2017 19:00:19 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback11j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id JEwa42gPtg-0JOek7PX; Thu, 21 Dec 2017 19:00:19 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bLqbqs0pBY-0IP89Uf2; Thu, 21 Dec 2017 19:00:18 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 21 Dec 2017 19:00:15 +0300 Message-Id: <1513872016-2819-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> References: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 359 Subject: [lng-odp] [PATCH CATERPILLAR v1 3/4] linux-gen: extend sysfs parsing helper functions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Mykyta Iziumtsev Added char* and uint64_t sysfs attribute read functions to support upcoming native and mediated device drivers. Updated sysfs_netif_stats() to take interface name as argument instead of pktio_entry, because pktio_entry->s.name is not necessarily recognisable Linux network interface name. Signed-off-by: Mykyta Iziumtsev --- /** Email created from pull request 359 (MykytaI:caterpillar_mdev_auxiliary) ** https://github.com/Linaro/odp/pull/359 ** Patch: https://github.com/Linaro/odp/pull/359.patch ** Base sha: 63fd88635cc10caaa02fdccd3f52c9494487bdd2 ** Merge commit sha: 0e9885d54ac547d0bdf599d65b6fe32de445adb7 **/ platform/linux-generic/pktio/common.c | 4 +- platform/linux-generic/pktio/socket.c | 2 +- platform/linux-generic/pktio/socket_mmap.c | 2 +- platform/linux-generic/pktio/sysfs.c | 161 ++++++++++++++++++++++------- platform/linux-generic/pktio/sysfs.h | 33 +++++- 5 files changed, 154 insertions(+), 48 deletions(-) diff --git a/platform/linux-generic/pktio/common.c b/platform/linux-generic/pktio/common.c index 900dcbba2..e6eb09900 100644 --- a/platform/linux-generic/pktio/common.c +++ b/platform/linux-generic/pktio/common.c @@ -45,7 +45,7 @@ int sock_stats_reset_fd(pktio_entry_t *pktio_entry, int fd) pktio_entry->s.name, &cur_stats); } else if (pktio_entry->s.stats_type == STATS_SYSFS) { - err = sysfs_stats(pktio_entry, &cur_stats); + err = sysfs_netif_stats(pktio_entry->s.name, &cur_stats); if (err != 0) ODP_ERR("stats error\n"); } @@ -78,7 +78,7 @@ int sock_stats_fd(pktio_entry_t *pktio_entry, pktio_entry->s.name, &cur_stats); } else if (pktio_entry->s.stats_type == STATS_SYSFS) { - sysfs_stats(pktio_entry, &cur_stats); + sysfs_netif_stats(pktio_entry->s.name, &cur_stats); } stats->in_octets = cur_stats.in_octets - diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 7e0485b99..320de973c 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -204,7 +204,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, pktio_entry->s.name, &cur_stats); if (err != 0) { - err = sysfs_stats(pktio_entry, &cur_stats); + err = sysfs_netif_stats(pktio_entry->s.name, &cur_stats); if (err != 0) { pktio_entry->s.stats_type = STATS_UNSUPPORTED; ODP_DBG("pktio: %s unsupported stats\n", diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 271c2f0f7..26d0a2957 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -593,7 +593,7 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry->s.name, &cur_stats); if (ret != 0) { - ret = sysfs_stats(pktio_entry, &cur_stats); + ret = sysfs_netif_stats(pktio_entry->s.name, &cur_stats); if (ret != 0) { pktio_entry->s.stats_type = STATS_UNSUPPORTED; ODP_DBG("pktio: %s unsupported stats\n", diff --git a/platform/linux-generic/pktio/sysfs.c b/platform/linux-generic/pktio/sysfs.c index f674ac42c..ae66296fb 100644 --- a/platform/linux-generic/pktio/sysfs.c +++ b/platform/linux-generic/pktio/sysfs.c @@ -7,74 +7,157 @@ #include "config.h" #include -#include +#include #include + #include #include #include +#include +#include +#include -static int sysfs_get_val(const char *fname, uint64_t *val) +static int _sysfs_attr_raw_get(char *buf, size_t buf_size, const char *fmt, + va_list args) { - FILE *file; - char str[128]; - int ret = -1; + char path[256]; + FILE *file; + int ret; - file = fopen(fname, "rt"); - if (file == NULL) { + ret = vsnprintf(path, sizeof(path), fmt, args); + + if (ret < 0) { __odp_errno = errno; - /* do not print debug err if sysfs is not supported by - * kernel driver. - */ - if (errno != ENOENT) - ODP_ERR("fopen %s: %s\n", fname, strerror(errno)); - return 0; + return -1; + } + + if (ret >= (ssize_t)sizeof(path)) { + __odp_errno = EINVAL; + return -1; } - if (fgets(str, sizeof(str), file) != NULL) - ret = sscanf(str, "%" SCNx64, val); + file = fopen(path, "rt"); + if (file == NULL) { + __odp_errno = errno; + return -1; + } + buf = fgets(buf, buf_size, file); (void)fclose(file); - if (ret != 1) { - ODP_ERR("read %s\n", fname); + if (buf == NULL) { + __odp_errno = errno; return -1; } return 0; } -int sysfs_stats(pktio_entry_t *pktio_entry, - odp_pktio_stats_t *stats) +ODP_PRINTF_FORMAT(3, 4) +int sysfs_attr_raw_get(char *buf, size_t buf_size, const char *fmt, ...) { - char fname[256]; - const char *dev = pktio_entry->s.name; - int ret = 0; + va_list args; + int ret; - sprintf(fname, "/sys/class/net/%s/statistics/rx_bytes", dev); - ret -= sysfs_get_val(fname, &stats->in_octets); + va_start(args, fmt); + ret = _sysfs_attr_raw_get(buf, buf_size, fmt, args); + va_end(args); - sprintf(fname, "/sys/class/net/%s/statistics/rx_packets", dev); - ret -= sysfs_get_val(fname, &stats->in_ucast_pkts); + return ret; +} + +ODP_PRINTF_FORMAT(2, 3) +int sysfs_attr_u64_get(uint64_t *value, const char *fmt, ...) +{ + char buf[20 + 1 + 1]; /* 20 digits (UINT64_MAX) + '\n' + '\0' */ + va_list args; + char *endptr; + int ret; - sprintf(fname, "/sys/class/net/%s/statistics/rx_droppped", dev); - ret -= sysfs_get_val(fname, &stats->in_discards); + va_start(args, fmt); + ret = _sysfs_attr_raw_get(buf, sizeof(buf), fmt, args); + va_end(args); - sprintf(fname, "/sys/class/net/%s/statistics/rx_errors", dev); - ret -= sysfs_get_val(fname, &stats->in_errors); + if (ret < 0) + return -1; + + if (buf[0] == '\0') { + __odp_errno = EINVAL; + return -1; + } + + *value = strtoull(buf, &endptr, 0); + + /* It is OK to have '\n' in sysfs */ + if (*endptr == '\n') + endptr++; + + if (*endptr != '\0') { + __odp_errno = EINVAL; + return -1; + } + + return 0; +} + +int sysfs_netif_stats(const char *netif_name, odp_pktio_stats_t *stats) +{ + int ret; + + /* + * Do not print debug err if sysfs is not supported by + * kernel driver. + */ + + ret = sysfs_attr_u64_get(&stats->in_octets, + "/sys/class/net/%s/statistics/rx_bytes", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; + + ret = sysfs_attr_u64_get(&stats->in_ucast_pkts, + "/sys/class/net/%s/statistics/rx_packets", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; + + ret = sysfs_attr_u64_get(&stats->in_discards, + "/sys/class/net/%s/statistics/rx_droppped", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; + + ret = sysfs_attr_u64_get(&stats->in_errors, + "/sys/class/net/%s/statistics/rx_errors", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; /* stats->in_unknown_protos is not supported in sysfs */ - sprintf(fname, "/sys/class/net/%s/statistics/tx_bytes", dev); - ret -= sysfs_get_val(fname, &stats->out_octets); + ret = sysfs_attr_u64_get(&stats->out_octets, + "/sys/class/net/%s/statistics/tx_bytes", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; - sprintf(fname, "/sys/class/net/%s/statistics/tx_packets", dev); - ret -= sysfs_get_val(fname, &stats->out_ucast_pkts); + ret = sysfs_attr_u64_get(&stats->out_ucast_pkts, + "/sys/class/net/%s/statistics/tx_packets", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; - sprintf(fname, "/sys/class/net/%s/statistics/tx_dropped", dev); - ret -= sysfs_get_val(fname, &stats->out_discards); + ret = sysfs_attr_u64_get(&stats->out_discards, + "/sys/class/net/%s/statistics/tx_dropped", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; - sprintf(fname, "/sys/class/net/%s/statistics/tx_errors", dev); - ret -= sysfs_get_val(fname, &stats->out_errors); + ret = sysfs_attr_u64_get(&stats->out_errors, + "/sys/class/net/%s/statistics/tx_errors", + netif_name); + if (ret < 0 && __odp_errno != ENOENT) + return -1; - return ret; + return 0; } diff --git a/platform/linux-generic/pktio/sysfs.h b/platform/linux-generic/pktio/sysfs.h index f8fe3072a..71ac4726f 100644 --- a/platform/linux-generic/pktio/sysfs.h +++ b/platform/linux-generic/pktio/sysfs.h @@ -8,16 +8,39 @@ #define ODP_PKTIO_SYSFS_H_ /** - * Get statistics for a pktio entry + * Read an attribute from /sysfs as raw string * - * @param pktio_entry Packet IO entry - * @param stats[out] Output buffer for counters + * @param buf[out] Attribute value + * @param buf_size Maximum number of bytes to read (including '\0') + * @param fmt printf-like path to the attribute + * + * @retval 0 on success, buf[] is guaranteed to be '\0'-terminated + * @retval != 0 on failure + */ +ODP_PRINTF_FORMAT(3, 4) +int sysfs_attr_raw_get(char *buf, size_t buf_size, const char *fmt, ...); + +/** + * Read an attribute from /sysfs as uint64_t + * + * @param value[out] Attribute value + * @param fmt printf-like path to the attribute * * @retval 0 on success * @retval != 0 on failure */ +ODP_PRINTF_FORMAT(2, 3) +int sysfs_attr_u64_get(uint64_t *value, const char *fmt, ...); -int sysfs_stats(pktio_entry_t *pktio_entry, - odp_pktio_stats_t *stats); +/** + * Get statistics for a network interface + * + * @param netif_name Network interface name + * @param stats[out] Output buffer for counters + * + * @retval 0 on success + * @retval != 0 on failure + */ +int sysfs_netif_stats(const char *netif_name, odp_pktio_stats_t *stats); #endif /* ODP_PKTIO_SYSFS_H_ */ From patchwork Thu Dec 21 16:00:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 122582 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1086265qgn; Thu, 21 Dec 2017 08:10:30 -0800 (PST) X-Google-Smtp-Source: ACJfBovRFfRuHvrv6doi/59VopCjY6LPZFKKENDN6pJnWptNCzixbqFUzc5Jer7CFlJSBI04v+3U X-Received: by 10.55.110.5 with SMTP id j5mr14138797qkc.287.1513872630283; Thu, 21 Dec 2017 08:10:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872630; cv=none; d=google.com; s=arc-20160816; b=muJoaAy2e1E5mWRyiCRqXPGBeaXFgmo1G9ZB2ZoNxyPaU1spI3PRutWjvhGVkSwuy5 htEMfdnTi6e1hy2pS94oFbQ+9iD+zx9T7LjaRn8WCjvKu2jfAk19SoOeMzg0uglz+rHD KzEOp+z9TkTbk18iTAXDZ9rTfwIEUs1giyx8UsSETdqRVf2gnB7yWFlf/EXjTVkPsHTe Io5TLePHNOa1Dr54PPsuaj8ERTw8Ka/edXlx0UD6LhdTPlmdsplWvgXO/fD/sb798yUe g6y1DaZQI+CUWd5lA4EjL3EVSwIOxAnqP2lejCsKBg2y7xf9ZXkOH94kZiSn8qw6Oen+ Wixg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=pckjv35ZOUAtsd9Z5w9Fxijs+9B2FXc3//O4Uxl/wGY=; b=RVEM32k42jECmrMDNaQ6sb0nz/W6Za4Amtv0R7mT/SLR+x/md566pIye/ZTvgdAaGl liRIVWtMro70wTeaJehLU2nhx6oxmgu27Y9VbF8HecbrrSr1g2FoGQZ47upnJ9c84g+b /yUjv8J9WU6GMiZMe+Ni/YlQxv+HDjxOoMueYuut2roElgN3GB0Z3m+WkZrJJL5i60S8 jowInk5eoBTe7R5vEOhdmqksh9ZFSos5xSHYG+qZiyfWH8FYHFf+FaGQg+X7jg8cdaXt KEUGG0PYLkVabBncrNjvK1yIjZYom9ocudRLUjlzQe9aJrQi67c+SBBwRusS+nhInOYx Z1fQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id k20si3702129qta.90.2017.12.21.08.10.29; Thu, 21 Dec 2017 08:10:30 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 8AF476176A; Thu, 21 Dec 2017 16:10:29 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 84C0D6152A; Thu, 21 Dec 2017 16:01:52 +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 0660761506; Thu, 21 Dec 2017 16:01:23 +0000 (UTC) Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [77.88.28.101]) by lists.linaro.org (Postfix) with ESMTPS id 6033A61506 for ; Thu, 21 Dec 2017 16:00:21 +0000 (UTC) Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward101p.mail.yandex.net (Yandex) with ESMTP id 0E74E6A81300 for ; Thu, 21 Dec 2017 19:00:20 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 7AMRKo57y3-0KmSeER6; Thu, 21 Dec 2017 19:00:20 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bLqbqs0pBY-0JPCMRW4; Thu, 21 Dec 2017 19:00:19 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 21 Dec 2017 19:00:16 +0300 Message-Id: <1513872016-2819-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> References: <1513872016-2819-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 359 Subject: [lng-odp] [PATCH CATERPILLAR v1 4/4] linux-gen: move common macros to odp_internal.h X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Mykyta Iziumtsev Gather macros needed for upcoming mediated devices in one location. Fix signed vs. unsigned comparisons caused by incorrect MIN / MAX usage. Signed-off-by: Mykyta Iziumtsev --- /** Email created from pull request 359 (MykytaI:caterpillar_mdev_auxiliary) ** https://github.com/Linaro/odp/pull/359 ** Patch: https://github.com/Linaro/odp/pull/359.patch ** Base sha: 63fd88635cc10caaa02fdccd3f52c9494487bdd2 ** Merge commit sha: 0e9885d54ac547d0bdf599d65b6fe32de445adb7 **/ .../linux-generic/include/odp_bitmap_internal.h | 4 +--- platform/linux-generic/include/odp_internal.h | 27 ++++++++++++++++++++++ .../include/odp_traffic_mngr_internal.h | 3 --- platform/linux-generic/odp_name_table.c | 15 ++++++------ platform/linux-generic/odp_pkt_queue.c | 8 +++---- platform/linux-generic/odp_timer_wheel.c | 2 +- platform/linux-generic/odp_traffic_mngr.c | 12 ++++++---- platform/linux-generic/queue/scalable.c | 7 ------ platform/linux-generic/schedule/scalable.c | 4 ---- 9 files changed, 46 insertions(+), 36 deletions(-) diff --git a/platform/linux-generic/include/odp_bitmap_internal.h b/platform/linux-generic/include/odp_bitmap_internal.h index 1be4d0287..dd8429037 100644 --- a/platform/linux-generic/include/odp_bitmap_internal.h +++ b/platform/linux-generic/include/odp_bitmap_internal.h @@ -21,14 +21,12 @@ extern "C" { #include #include #include +#include /* Generate unique identifier for instantiated class */ #define TOKENIZE(template, line) \ template ## _ ## line ## _ ## __COUNTER__ -/* Array size in general */ -#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) - #define BITS_PER_BYTE (8) #define BITS_PER_LONG __WORDSIZE #define BYTES_PER_LONG (BITS_PER_LONG / BITS_PER_BYTE) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 6811d8d0a..020a90317 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -161,6 +161,33 @@ uint64_t odp_cpu_hz_current(int id); uint64_t odp_cpu_arch_hz_current(int id); void sys_info_print_arch(void); +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#define MIN(a, b) \ + ({ \ + __typeof__(a) tmp_a = (a); \ + __typeof__(b) tmp_b = (b); \ + tmp_a < tmp_b ? tmp_a : tmp_b; \ + }) +#define MAX(a, b) \ + ({ \ + __typeof__(a) tmp_a = (a); \ + __typeof__(b) tmp_b = (b); \ + tmp_a > tmp_b ? tmp_a : tmp_b; \ + }) + +#define odp_container_of(pointer, type, member) \ + ((type *)((char *)(pointer) - offsetof(type, member))) + +#define DIV_ROUND_UP(a, b) \ + ({ \ + __typeof__(a) tmp_a = (a); \ + __typeof__(b) tmp_b = (b); \ + ODP_STATIC_ASSERT(__builtin_constant_p(b), ""); \ + ODP_STATIC_ASSERT((((b) - 1) & (b)) == 0, ""); \ + (tmp_a + tmp_b - 1) >> __builtin_ctz(tmp_b); \ + }) + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/include/odp_traffic_mngr_internal.h b/platform/linux-generic/include/odp_traffic_mngr_internal.h index e8254f5ed..2d1fc5493 100644 --- a/platform/linux-generic/include/odp_traffic_mngr_internal.h +++ b/platform/linux-generic/include/odp_traffic_mngr_internal.h @@ -34,9 +34,6 @@ extern "C" { typedef struct stat file_stat_t; -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - #define INPUT_WORK_RING_SIZE (16 * 1024) #define TM_QUEUE_MAGIC_NUM 0xBABEBABE diff --git a/platform/linux-generic/odp_name_table.c b/platform/linux-generic/odp_name_table.c index 3ff46b347..e2a0401b2 100644 --- a/platform/linux-generic/odp_name_table.c +++ b/platform/linux-generic/odp_name_table.c @@ -14,9 +14,7 @@ #include #include #include - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#include /* The following constants define some tunable parameters of this module. * They are set to fairly reasonable values (perhaps somewhat biased toward @@ -298,7 +296,7 @@ static int new_name_tbl_add(void) name_tbls_idx = name_tbls.num_name_tbls; num_entries = INITIAL_NAME_TBL_SIZE << name_tbls_idx; new_name_tbl = name_tbl_alloc(name_tbls_idx, num_entries); - name_tbl_free_list_add(new_name_tbl, MIN(num_entries, 256)); + name_tbl_free_list_add(new_name_tbl, MIN(num_entries, UINT32_C(256))); name_tbls.tbls[name_tbls_idx] = new_name_tbl; name_tbls.avail_space_bit_mask |= 1 << name_tbls_idx; @@ -387,7 +385,7 @@ static hash_tbl_entry_t make_hash_tbl_entry(name_tbl_entry_t *name_tbl_entry, hash_tbl_entry_t hash_tbl_entry; uint32_t new_entry_cnt; - new_entry_cnt = MIN(entry_cnt + 1, 0x3F); + new_entry_cnt = MIN(entry_cnt + 1, UINT32_C(0x3F)); hash_tbl_entry = (hash_tbl_entry_t)(uintptr_t)name_tbl_entry; hash_tbl_entry &= ~0x3F; hash_tbl_entry |= new_entry_cnt; @@ -1006,7 +1004,7 @@ static uint32_t level2_hash_histo(secondary_hash_tbl_t *hash_tbl, collisions = linked_list_len(name_tbl_entry); } - level2_histo[MIN(collisions, 256)]++; + level2_histo[MIN(collisions, UINT32_C(256))]++; total_collisions += collisions; } @@ -1038,7 +1036,7 @@ static uint32_t level1_hash_histo(secondary_hash_tbl_t *hash_tbl, level2_histo); } - level1_histo[MIN(collisions, 256)]++; + level1_histo[MIN(collisions, UINT32_C(256))]++; total_collisions += collisions; } @@ -1147,7 +1145,8 @@ void _odp_int_name_tbl_stats_print(void) memset(primary_hash_histo, 0, sizeof(primary_hash_histo)); for (idx = 0; idx < PRIMARY_HASH_TBL_SIZE; idx++) { - collisions = MIN(name_hash_tbl.hash_collisions[idx], 256); + collisions = + MIN(name_hash_tbl.hash_collisions[idx], UINT32_C(256)); primary_hash_histo[collisions]++; } diff --git a/platform/linux-generic/odp_pkt_queue.c b/platform/linux-generic/odp_pkt_queue.c index 4f6a1eb61..502203b76 100644 --- a/platform/linux-generic/odp_pkt_queue.c +++ b/platform/linux-generic/odp_pkt_queue.c @@ -16,9 +16,7 @@ #include #include #include - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#include #define NUM_PKTS 7 @@ -229,7 +227,7 @@ _odp_int_queue_pool_t _odp_queue_pool_create(uint32_t max_num_queues, /* Initialize the queue_blk_tbl_sizes array based upon the * max_queued_pkts. */ - max_queued_pkts = MAX(max_queued_pkts, 64 * 1024); + max_queued_pkts = MAX(max_queued_pkts, 64 * UINT32_C(1024)); queue_region_desc_init(pool, 0, max_queued_pkts / 4); queue_region_desc_init(pool, 1, max_queued_pkts / 64); queue_region_desc_init(pool, 2, max_queued_pkts / 64); @@ -241,7 +239,7 @@ _odp_int_queue_pool_t _odp_queue_pool_create(uint32_t max_num_queues, /* Now allocate the first queue_blk_tbl and add its blks to the free * list. Replenish the queue_blk_t free list. */ - initial_free_list_size = MIN(64 * 1024, max_queued_pkts / 4); + initial_free_list_size = MIN(64 * UINT32_C(1024), max_queued_pkts / 4); rc = pkt_queue_free_list_add(pool, initial_free_list_size); if (rc < 0) { free(pool->queue_num_tbl); diff --git a/platform/linux-generic/odp_timer_wheel.c b/platform/linux-generic/odp_timer_wheel.c index b37d269bd..9b1e53832 100644 --- a/platform/linux-generic/odp_timer_wheel.c +++ b/platform/linux-generic/odp_timer_wheel.c @@ -627,7 +627,7 @@ static int timer_current_wheel_update(timer_wheels_t *timer_wheels, slot_idx = wheel_desc->slot_idx; num_slots = wheel_desc->num_slots; max_ticks = wheel_desc->max_ticks; - max_cnt = (uint32_t)MIN(elapsed_ticks, 32); + max_cnt = MIN(elapsed_ticks, UINT32_C(32)); current_wheel = timer_wheels->current_wheel; ret_code = 0; rc = -1; diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c index ab06b3c0d..20af537fa 100644 --- a/platform/linux-generic/odp_traffic_mngr.c +++ b/platform/linux-generic/odp_traffic_mngr.c @@ -729,7 +729,8 @@ static uint64_t time_till_not_red(tm_shaper_params_t *shaper_params, commit_delay = (-shaper_obj->commit_cnt) / shaper_params->commit_rate; - min_time_delay = MAX(shaper_obj->shaper_params->min_time_delta, 256); + min_time_delay = + MAX(shaper_obj->shaper_params->min_time_delta, UINT64_C(256)); commit_delay = MAX(commit_delay, min_time_delay); if (shaper_params->peak_rate == 0) return commit_delay; @@ -1668,7 +1669,7 @@ static odp_tm_percent_t tm_queue_fullness(tm_wred_params_t *wred_params, return 0; fullness = (10000 * current_cnt) / max_cnt; - return (odp_tm_percent_t)MIN(fullness, 50000); + return (odp_tm_percent_t)MIN(fullness, UINT64_C(50000)); } static odp_bool_t tm_local_random_drop(tm_system_t *tm_system, @@ -2499,7 +2500,7 @@ static void tm_system_capabilities_set(odp_tm_capabilities_t *cap_ptr, memset(cap_ptr, 0, sizeof(odp_tm_capabilities_t)); max_queues = MIN(req_ptr->max_tm_queues, - ODP_TM_MAX_NUM_TM_NODES); + (uint32_t)ODP_TM_MAX_NUM_TM_NODES); shaper_supported = req_ptr->tm_queue_shaper_needed; wred_supported = req_ptr->tm_queue_wred_needed; dual_slope = req_ptr->tm_queue_dual_slope_needed; @@ -2523,8 +2524,9 @@ static void tm_system_capabilities_set(odp_tm_capabilities_t *cap_ptr, per_level_req = &req_ptr->per_level[level_idx]; max_nodes = MIN(per_level_req->max_num_tm_nodes, - ODP_TM_MAX_NUM_TM_NODES); - max_fanin = MIN(per_level_req->max_fanin_per_node, 1024); + (uint32_t)ODP_TM_MAX_NUM_TM_NODES); + max_fanin = MIN(per_level_req->max_fanin_per_node, + UINT32_C(1024)); max_priority = MIN(per_level_req->max_priority, ODP_TM_MAX_PRIORITIES - 1); min_weight = MAX(per_level_req->min_weight, diff --git a/platform/linux-generic/queue/scalable.c b/platform/linux-generic/queue/scalable.c index f4f5efb85..566d75bd3 100644 --- a/platform/linux-generic/queue/scalable.c +++ b/platform/linux-generic/queue/scalable.c @@ -33,13 +33,6 @@ #define NUM_INTERNAL_QUEUES 64 -#define MIN(a, b) \ - ({ \ - __typeof__(a) tmp_a = (a); \ - __typeof__(b) tmp_b = (b); \ - tmp_a < tmp_b ? tmp_a : tmp_b; \ - }) - #define LOCK(a) _odp_ticketlock_lock(a) #define UNLOCK(a) _odp_ticketlock_unlock(a) #define LOCK_INIT(a) odp_ticketlock_init(a) diff --git a/platform/linux-generic/schedule/scalable.c b/platform/linux-generic/schedule/scalable.c index de9c65285..3940e6f0a 100644 --- a/platform/linux-generic/schedule/scalable.c +++ b/platform/linux-generic/schedule/scalable.c @@ -145,10 +145,6 @@ static void remove_schedq_from_list(sched_scalable_thread_state_t *ts, /******************************************************************************* * Scheduler queues ******************************************************************************/ -#ifndef odp_container_of -#define odp_container_of(pointer, type, member) \ - ((type *)(void *)(((char *)pointer) - offsetof(type, member))) -#endif static inline void schedq_init(sched_queue_t *schedq, uint32_t prio) {