From patchwork Thu Jul 9 13:46:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 50962 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 15E87228E5 for ; Thu, 9 Jul 2015 13:50:03 +0000 (UTC) Received: by wgfk9 with SMTP id k9sf79481159wgf.1 for ; Thu, 09 Jul 2015 06:50:02 -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:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=Md1KVp/rVNDQ9gecTOvTnGMlOk+bj04964kY6z4tb1g=; b=B+Cb+F/w2PEzDsDNWL4qe9A2g0IjYczGGPfJ0zR/qOZ/dG0SZ5CHI3n8HqeE9OztC3 43bWdSIWXMqSzmGWsr3cIMUbpsYsrQ2hs4wJWqXN/K9IdClea+ZLp9oQQhd7XphCF/27 VuVcsIH/np+ZcFpHg1FTFiUEmbUQPt7qYTPXtLW8HvtlEyqFXcjiCMChF5MibgBrOmvf 7JYQix2CR0DBt/yLKBMHc7kevAItwr30J1zLSP2+CA9rm2tXwNM2Aqgjf6kI4E1KvyhR UGK3KmgNu81pd/pSuwVa4X3rY4hnGLtya2BwBHyhQNV/Dof94J0nqOsMBnY7eeWv6qxA e1PQ== X-Gm-Message-State: ALoCoQm8ogLzetxBZFfmIqQ7wGkQUsFRsPIr98sgApahfWcY/gjXwYFaxL//HvUq0/BmepUY1JaF X-Received: by 10.152.6.103 with SMTP id z7mr8008225laz.8.1436449802270; Thu, 09 Jul 2015 06:50:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.81 with SMTP id v17ls1207664laz.2.gmail; Thu, 09 Jul 2015 06:50:02 -0700 (PDT) X-Received: by 10.152.43.37 with SMTP id t5mr14704311lal.96.1436449802110; Thu, 09 Jul 2015 06:50:02 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id as10si4867875lbc.69.2015.07.09.06.50.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 06:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lblf12 with SMTP id f12so5975485lbl.2 for ; Thu, 09 Jul 2015 06:50:02 -0700 (PDT) X-Received: by 10.112.126.101 with SMTP id mx5mr15198742lbb.35.1436449801976; Thu, 09 Jul 2015 06:50:01 -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.108.230 with SMTP id hn6csp682024lbb; Thu, 9 Jul 2015 06:50:00 -0700 (PDT) X-Received: by 10.140.239.129 with SMTP id k123mr25854585qhc.66.1436449800214; Thu, 09 Jul 2015 06:50:00 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e190si6486263qka.9.2015.07.09.06.49.59; Thu, 09 Jul 2015 06:50:00 -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 5BFBC61FBF; Thu, 9 Jul 2015 13:49:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 8532461FD4; Thu, 9 Jul 2015 13:47:23 +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 01D3E61FC0; Thu, 9 Jul 2015 13:47:17 +0000 (UTC) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by lists.linaro.org (Postfix) with ESMTPS id E7D3C61D30 for ; Thu, 9 Jul 2015 13:46:39 +0000 (UTC) Received: by wicmv11 with SMTP id mv11so1735486wic.1 for ; Thu, 09 Jul 2015 06:46:39 -0700 (PDT) X-Received: by 10.180.37.229 with SMTP id b5mr122695485wik.16.1436449599138; Thu, 09 Jul 2015 06:46:39 -0700 (PDT) Received: from localhost.localdomain ([87.120.178.39]) by smtp.gmail.com with ESMTPSA id df1sm8414627wib.12.2015.07.09.06.46.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jul 2015 06:46:38 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 9 Jul 2015 16:46:18 +0300 Message-Id: <1436449585-23252-5-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436449585-23252-1-git-send-email-maxim.uvarov@linaro.org> References: <1436449585-23252-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Cc: Petri Savolainen Subject: [lng-odp] [PATCH 04/11] api: thrmask: added thread mask 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@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.217.178 as permitted sender) smtp.mail=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: Petri Savolainen Thread IDs and masks are used to control thread access to various resources. Linux generic implementation reuse cpumask implementation. Signed-off-by: Petri Savolainen Signed-off-by: Maxim Uvarov Conflicts: platform/linux-generic/Makefile.am --- include/odp.h | 1 + include/odp/api/thrmask.h | 229 +++++++++++++++++++++ platform/linux-generic/Makefile.am | 4 + .../linux-generic/include/odp/plat/thrmask_types.h | 48 +++++ platform/linux-generic/include/odp/thrmask.h | 36 ++++ platform/linux-generic/odp_thrmask.c | 102 +++++++++ 6 files changed, 420 insertions(+) create mode 100644 include/odp/api/thrmask.h create mode 100644 platform/linux-generic/include/odp/plat/thrmask_types.h create mode 100644 platform/linux-generic/include/odp/thrmask.h create mode 100644 platform/linux-generic/odp_thrmask.c diff --git a/include/odp.h b/include/odp.h index 2bac510..fe1dc74 100644 --- a/include/odp.h +++ b/include/odp.h @@ -53,6 +53,7 @@ extern "C" { #include #include #include +#include #ifdef __cplusplus } diff --git a/include/odp/api/thrmask.h b/include/odp/api/thrmask.h new file mode 100644 index 0000000..ebc31f2 --- /dev/null +++ b/include/odp/api/thrmask.h @@ -0,0 +1,229 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP thread masks + */ + +#ifndef ODP_API_THRMASK_H_ +#define ODP_API_THRMASK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** @addtogroup odp_thread + * Thread mask operations. + * @{ + */ + +/** + * @def ODP_THRMASK_STR_SIZE + * Minimum size of output buffer for odp_thrmask_to_str() + */ + +/** + * Add thread mask bits from a string + * + * @param[out] mask Thread mask to modify + * @param str Hexadecimal digits in a string. Thread ID zero is located + * at the least significant bit (0x1). + */ +void odp_thrmask_from_str(odp_thrmask_t *mask, const char *str); + +/** + * Format Thread mask as a string of hexadecimal digits + * + * @param mask Thread mask to format + * @param[out] str Output buffer (use ODP_THRMASK_STR_SIZE) + * @param size Size of output buffer + * + * @return number of characters written (including terminating null char) + * @retval <0 on failure (buffer too small) + */ +int32_t odp_thrmask_to_str(const odp_thrmask_t *mask, char *str, int32_t size); + +/** + * Clear entire thread mask + * @param mask Thread mask to clear + */ +void odp_thrmask_zero(odp_thrmask_t *mask); + +/** + * Add thread to mask + * @param mask Thread mask to update + * @param thr Thread ID + */ +void odp_thrmask_set(odp_thrmask_t *mask, int thr); + +/** + * Set all threads in mask + * + * Set all possible threads in the mask. All threads from 0 to + * odp_thrmask_count() minus one are set, regardless of which threads are + * actually active. + * + * @param mask Thread mask to set + */ +void odp_thrmask_setall(odp_thrmask_t *mask); + +/** + * Remove thread from mask + * @param mask Thread mask to update + * @param thr Thread ID + */ +void odp_thrmask_clr(odp_thrmask_t *mask, int thr); + +/** + * Test if thread is a member of mask + * + * @param mask Thread mask to test + * @param thr Thread ID + * + * @return non-zero if set + * @retval 0 if not set + */ +int odp_thrmask_isset(const odp_thrmask_t *mask, int thr); + +/** + * Count number of threads set in mask + * + * @param mask Thread mask + * + * @return population count + */ +int odp_thrmask_count(const odp_thrmask_t *mask); + +/** + * Member-wise AND over two thread masks + * + * @param dest Destination thread mask (may be one of the source masks) + * @param src1 Source thread mask 1 + * @param src2 Source thread mask 2 + */ +void odp_thrmask_and(odp_thrmask_t *dest, const odp_thrmask_t *src1, + const odp_thrmask_t *src2); + +/** + * Member-wise OR over two thread masks + * + * @param dest Destination thread mask (may be one of the source masks) + * @param src1 Source thread mask 1 + * @param src2 Source thread mask 2 + */ +void odp_thrmask_or(odp_thrmask_t *dest, const odp_thrmask_t *src1, + const odp_thrmask_t *src2); + +/** + * Member-wise XOR over two thread masks + * + * @param dest Destination thread mask (may be one of the source masks) + * @param src1 Source thread mask 1 + * @param src2 Source thread mask 2 + */ +void odp_thrmask_xor(odp_thrmask_t *dest, const odp_thrmask_t *src1, + const odp_thrmask_t *src2); + +/** + * Test if two thread masks contain the same threads + * + * @param mask1 Thread mask 1 + * @param mask2 Thread mask 2 + * + * @retval non-zero if thread masks equal + * @retval 0 if thread masks not equal + */ +int odp_thrmask_equal(const odp_thrmask_t *mask1, + const odp_thrmask_t *mask2); + +/** + * Copy a thread mask + * + * @param dest Destination thread mask + * @param src Source thread mask + */ +void odp_thrmask_copy(odp_thrmask_t *dest, const odp_thrmask_t *src); + +/** + * Find first set thread in mask + * + * @param mask thread mask + * + * @return Thread ID + * @retval <0 if no thread found + */ +int odp_thrmask_first(const odp_thrmask_t *mask); + +/** + * Find last set thread in mask + * + * @param mask Thread mask + * + * @return Thread ID + * @retval <0 if no thread found + */ +int odp_thrmask_last(const odp_thrmask_t *mask); + +/** + * Find next set thread in mask + * + * Finds the next thread in the thread mask, starting at the thread passed. + * Use with odp_thrmask_first to traverse a thread mask, e.g. + * + * int thr = odp_thrmask_first(&mask); + * while (0 <= thr) { + * ... + * ... + * thr = odp_thrmask_next(&mask, thr); + * } + * + * @param mask Thread mask + * @param thr Thread to start from + * + * @return Thread ID + * @retval <0 if no thread found + * + * @see odp_thrmask_first() + */ +int odp_thrmask_next(const odp_thrmask_t *mask, int thr); + +/** + * Worker thread mask + * + * Initializes thread mask with current worker threads and returns the count + * set. + * + * @param[out] mask Thread mask to initialize + * + * @return Number of threads in the mask + */ +int odp_thrmask_worker(odp_thrmask_t *mask); + +/** + * Control thread mask + * + * Initializes thread mask with current control threads and returns the count + * set. + * + * @param[out] mask Thread mask to initialize + * + * @return Number of threads in the mask + */ +int odp_thrmask_control(odp_thrmask_t *mask); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 34db0b1..d226483 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -40,6 +40,7 @@ odpinclude_HEADERS = \ $(srcdir)/include/odp/sync.h \ $(srcdir)/include/odp/system_info.h \ $(srcdir)/include/odp/thread.h \ + $(srcdir)/include/odp/thrmask.h \ $(srcdir)/include/odp/ticketlock.h \ $(srcdir)/include/odp/time.h \ $(srcdir)/include/odp/timer.h \ @@ -64,6 +65,7 @@ odpplatinclude_HEADERS = \ $(srcdir)/include/odp/plat/shared_memory_types.h \ $(srcdir)/include/odp/plat/spinlock_types.h \ $(srcdir)/include/odp/plat/strong_types.h \ + $(srcdir)/include/odp/plat/thrmask_types.h \ $(srcdir)/include/odp/plat/ticketlock_types.h \ $(srcdir)/include/odp/plat/timer_types.h \ $(srcdir)/include/odp/plat/version_types.h @@ -100,6 +102,7 @@ odpapiinclude_HEADERS = \ $(top_srcdir)/include/odp/api/sync.h \ $(top_srcdir)/include/odp/api/system_info.h \ $(top_srcdir)/include/odp/api/thread.h \ + $(top_srcdir)/include/odp/api/thrmask.h \ $(top_srcdir)/include/odp/api/ticketlock.h \ $(top_srcdir)/include/odp/api/time.h \ $(top_srcdir)/include/odp/api/timer.h \ @@ -149,6 +152,7 @@ __LIB__libodp_la_SOURCES = \ odp_spinlock.c \ odp_system_info.c \ odp_thread.c \ + odp_thrmask.c \ odp_ticketlock.c \ odp_time.c \ odp_timer.c \ diff --git a/platform/linux-generic/include/odp/plat/thrmask_types.h b/platform/linux-generic/include/odp/plat/thrmask_types.h new file mode 100644 index 0000000..30915c9 --- /dev/null +++ b/platform/linux-generic/include/odp/plat/thrmask_types.h @@ -0,0 +1,48 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP thread masks + */ + +#ifndef ODP_THRMASK_TYPES_H_ +#define ODP_THRMASK_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup odp_thread + * @{ + */ + +#include + +/** + * Minimum size of output buffer for odp_thrmask_to_str() + */ +#define ODP_THRMASK_STR_SIZE ODP_CPUMASK_STR_SIZE + +/** + * Thread mask + * + * Don't access directly, use access functions. + */ +typedef struct odp_thrmask_t { + odp_cpumask_t m; /**< @private Mask*/ +} odp_thrmask_t; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/thrmask.h b/platform/linux-generic/include/odp/thrmask.h new file mode 100644 index 0000000..0e98ece --- /dev/null +++ b/platform/linux-generic/include/odp/thrmask.h @@ -0,0 +1,36 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP thread masks + */ + +#ifndef ODP_PLAT_THRMASK_H_ +#define ODP_PLAT_THRMASK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** @ingroup odp_thread + * @{ + */ + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/odp_thrmask.c b/platform/linux-generic/odp_thrmask.c new file mode 100644 index 0000000..d10bbf1 --- /dev/null +++ b/platform/linux-generic/odp_thrmask.c @@ -0,0 +1,102 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include + +#include +#include +#include + +#if CPU_SETSIZE < ODP_CONFIG_MAX_THREADS +#error Thread mask does not fit all thread IDs +#endif + +void odp_thrmask_from_str(odp_thrmask_t *mask, const char *str) +{ + odp_cpumask_from_str(&mask->m, str); +} + +int32_t odp_thrmask_to_str(const odp_thrmask_t *mask, char *str, int32_t size) +{ + return odp_cpumask_to_str(&mask->m, str, size); +} + +void odp_thrmask_zero(odp_thrmask_t *mask) +{ + odp_cpumask_zero(&mask->m); +} + +void odp_thrmask_set(odp_thrmask_t *mask, int thr) +{ + odp_cpumask_set(&mask->m, thr); +} + +void odp_thrmask_setall(odp_thrmask_t *mask) +{ + odp_cpumask_setall(&mask->m); +} + +void odp_thrmask_clr(odp_thrmask_t *mask, int thr) +{ + odp_cpumask_clr(&mask->m, thr); +} + +int odp_thrmask_isset(const odp_thrmask_t *mask, int thr) +{ + return odp_cpumask_isset(&mask->m, thr); +} + +int odp_thrmask_count(const odp_thrmask_t *mask) +{ + return odp_cpumask_count(&mask->m); +} + +void odp_thrmask_and(odp_thrmask_t *dest, const odp_thrmask_t *src1, + const odp_thrmask_t *src2) +{ + odp_cpumask_and(&dest->m, &src1->m, &src2->m); +} + +void odp_thrmask_or(odp_thrmask_t *dest, const odp_thrmask_t *src1, + const odp_thrmask_t *src2) +{ + odp_cpumask_or(&dest->m, &src1->m, &src2->m); +} + +void odp_thrmask_xor(odp_thrmask_t *dest, const odp_thrmask_t *src1, + const odp_thrmask_t *src2) +{ + odp_cpumask_xor(&dest->m, &src1->m, &src2->m); +} + +int odp_thrmask_equal(const odp_thrmask_t *mask1, + const odp_thrmask_t *mask2) +{ + return odp_cpumask_equal(&mask1->m, &mask2->m); +} + +void odp_thrmask_copy(odp_thrmask_t *dest, const odp_thrmask_t *src) +{ + odp_cpumask_copy(&dest->m, &src->m); +} + +int odp_thrmask_first(const odp_thrmask_t *mask) +{ + return odp_cpumask_first(&mask->m); +} + +int odp_thrmask_last(const odp_thrmask_t *mask) +{ + return odp_cpumask_last(&mask->m); +} + +int odp_thrmask_next(const odp_thrmask_t *mask, int thr) +{ + return odp_cpumask_next(&mask->m, thr); +}