From patchwork Fri Jul 31 08:31:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 51746 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id D575322A8D for ; Fri, 31 Jul 2015 08:32:10 +0000 (UTC) Received: by wicmv11 with SMTP id mv11sf5863868wic.1 for ; Fri, 31 Jul 2015 01:32: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: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=avQyTd1EUv8GshdyMvehBjYae/o+NrZkHAApSocesb4=; b=EAXsqyiB3uvVapUFxZv7fPHGWjSqEc67Vse/SxiO58v0XiS4Uv0Jt0ns9aumPXmon+ 8/DT3hJJUWgx6UJrdg3CxyzdU6CAlka7/iy8FAvRRt4FrU5P7r+8COib5JPNJwfsFyh6 h9gZ+7J/DehfkFmem5S+9z/DugjTEnScqugFYPPIki22qoJ7ATCia2PzPOH7IGBzvjK5 55HQPKZAXZlWULV3hrsvSCdX+Fyp8rkpDWIkfyf6i/TrUOkaKpiUX/FWeWy2vDvVttpE fB4xCX3N7fyKJJQ5inaJGfGdecEnkdp1wQcpi+wdpiw+pZiYxMH1qB3zjbU8O+btTJo1 /rRA== X-Gm-Message-State: ALoCoQnCj7pPtFPKHDaVClkkcAnTPdfDNENWFWE7+VB/i5+pdtyDl4IuyvImBkgIlDImlVjohGQ5 X-Received: by 10.112.51.177 with SMTP id l17mr568974lbo.1.1438331530144; Fri, 31 Jul 2015 01:32:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.136 with SMTP id dc8ls309097lad.101.gmail; Fri, 31 Jul 2015 01:32:09 -0700 (PDT) X-Received: by 10.112.13.97 with SMTP id g1mr1600657lbc.52.1438331529791; Fri, 31 Jul 2015 01:32:09 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id kh10si2995986lbc.24.2015.07.31.01.32.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 01:32:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbqc9 with SMTP id c9so16586237lbq.1 for ; Fri, 31 Jul 2015 01:32:09 -0700 (PDT) X-Received: by 10.152.26.163 with SMTP id m3mr1595271lag.86.1438331529218; Fri, 31 Jul 2015 01:32:09 -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.7.198 with SMTP id l6csp223385lba; Fri, 31 Jul 2015 01:32:07 -0700 (PDT) X-Received: by 10.140.97.199 with SMTP id m65mr2296466qge.40.1438331527385; Fri, 31 Jul 2015 01:32:07 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i134si4758504qhc.66.2015.07.31.01.32.06; Fri, 31 Jul 2015 01:32:07 -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 E97AA61FF9; Fri, 31 Jul 2015 08:32:05 +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 7AD3161D7C; Fri, 31 Jul 2015 08:31:57 +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 0F32161DB2; Fri, 31 Jul 2015 08:31:49 +0000 (UTC) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by lists.linaro.org (Postfix) with ESMTPS id 83C3061D62 for ; Fri, 31 Jul 2015 08:31:47 +0000 (UTC) Received: by wicmv11 with SMTP id mv11so49047020wic.0 for ; Fri, 31 Jul 2015 01:31:46 -0700 (PDT) X-Received: by 10.194.175.65 with SMTP id by1mr3807343wjc.152.1438331506734; Fri, 31 Jul 2015 01:31:46 -0700 (PDT) Received: from localhost.localdomain ([87.120.178.39]) by smtp.gmail.com with ESMTPSA id fo1sm3241485wib.24.2015.07.31.01.31.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Jul 2015 01:31:45 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 31 Jul 2015 11:31:40 +0300 Message-Id: <1438331500-32555-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: move cpumask common functions to separate file 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.171 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 Move functions which iterates with bit mask and more likely will not be accelerated by hw to odp_cpumask_common.c. And odp_cpumask.c will have only platform specific functions. That patch should simplify portability to other platfroms when odp_cpumask_common.c will be inherit from linux generic. Signed-off-by: Maxim Uvarov --- platform/linux-generic/Makefile.am | 1 + platform/linux-generic/odp_cpumask.c | 189 ------------------------- platform/linux-generic/odp_cpumask_common.c | 207 ++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+), 189 deletions(-) create mode 100644 platform/linux-generic/odp_cpumask_common.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 34ceb20..4aa5504 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -134,6 +134,7 @@ __LIB__libodp_la_SOURCES = \ odp_buffer.c \ odp_classification.c \ odp_cpumask.c \ + odp_cpumask_common.c \ odp_crypto.c \ odp_errno.c \ odp_event.c \ diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index c28153b..c84bb56 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -16,195 +16,6 @@ #include #include -void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in) -{ - cpu_set_t cpuset; - const char *str = str_in; - const char *p; - int cpu = 0; - int len = strlen(str); - - CPU_ZERO(&cpuset); - odp_cpumask_zero(mask); - - /* Strip leading "0x"/"0X" if present and verify length */ - if ((len >= 2) && ((str[1] == 'x') || (str[1] == 'X'))) { - str += 2; - len -= 2; - } - if (!len) - return; - - /* Walk string from LSB setting cpu bits */ - for (p = str + len - 1; (len > 0) && (cpu < CPU_SETSIZE); p--, len--) { - char c = *p; - int value; - int idx; - - /* Convert hex nibble, abort when invalid value found */ - if ((c >= '0') && (c <= '9')) - value = c - '0'; - else if ((c >= 'A') && (c <= 'F')) - value = c - 'A' + 10; - else if ((c >= 'a') && (c <= 'f')) - value = c - 'a' + 10; - else - return; - - /* Walk converted nibble and set bits in mask */ - for (idx = 0; idx < 4; idx++, cpu++) - if (value & (1 << idx)) - CPU_SET(cpu, &cpuset); - } - - /* Copy the computed mask */ - memcpy(&mask->set, &cpuset, sizeof(cpuset)); -} - -int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t len) -{ - char *p = str; - int cpu = odp_cpumask_last(mask); - int nibbles; - int value; - - /* Handle bad string length, need at least 4 chars for "0x0" and - * terminating null char */ - if (len < 4) - return -1; /* Failure */ - - /* Handle no CPU found */ - if (cpu < 0) { - strcpy(str, "0x0"); - return strlen(str) + 1; /* Success */ - } - /* CPU was found and cpu >= 0 */ - - /* Compute number of nibbles in cpumask that have bits set */ - nibbles = (cpu / 4) + 1; - - /* Verify minimum space (account for "0x" and termination) */ - if (len < (3 + nibbles)) - return -1; /* Failure */ - - /* Prefix */ - *p++ = '0'; - *p++ = 'x'; - - /* - * Now we can scan the cpus down to zero and - * build the string one nibble at a time - */ - value = 0; - do { - /* Set bit to go into the current nibble */ - if (CPU_ISSET(cpu, &mask->set)) - value |= 1 << (cpu % 4); - - /* If we are on a nibble boundary flush value to string */ - if (0 == (cpu % 4)) { - if (value < 0xA) - *p++ = '0' + value; - else - *p++ = 'A' + value - 0xA; - value = 0; - } - } while (cpu--); - - /* Terminate the string */ - *p++ = 0; - return p - str; /* Success */ -} - -void odp_cpumask_zero(odp_cpumask_t *mask) -{ - CPU_ZERO(&mask->set); -} - -void odp_cpumask_set(odp_cpumask_t *mask, int cpu) -{ - CPU_SET(cpu, &mask->set); -} - -void odp_cpumask_setall(odp_cpumask_t *mask) -{ - int cpu; - - for (cpu = 0; cpu < CPU_SETSIZE; cpu++) - CPU_SET(cpu, &mask->set); -} - -void odp_cpumask_clr(odp_cpumask_t *mask, int cpu) -{ - CPU_CLR(cpu, &mask->set); -} - -int odp_cpumask_isset(const odp_cpumask_t *mask, int cpu) -{ - return CPU_ISSET(cpu, &mask->set); -} - -int odp_cpumask_count(const odp_cpumask_t *mask) -{ - return CPU_COUNT(&mask->set); -} - -void odp_cpumask_and(odp_cpumask_t *dest, const odp_cpumask_t *src1, - const odp_cpumask_t *src2) -{ - CPU_AND(&dest->set, &src1->set, &src2->set); -} - -void odp_cpumask_or(odp_cpumask_t *dest, const odp_cpumask_t *src1, - const odp_cpumask_t *src2) -{ - CPU_OR(&dest->set, &src1->set, &src2->set); -} - -void odp_cpumask_xor(odp_cpumask_t *dest, const odp_cpumask_t *src1, - const odp_cpumask_t *src2) -{ - CPU_XOR(&dest->set, &src1->set, &src2->set); -} - -int odp_cpumask_equal(const odp_cpumask_t *mask1, - const odp_cpumask_t *mask2) -{ - return CPU_EQUAL(&mask1->set, &mask2->set); -} - -void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src) -{ - memcpy(&dest->set, &src->set, sizeof(src->set)); -} - -int odp_cpumask_first(const odp_cpumask_t *mask) -{ - int cpu; - - for (cpu = 0; cpu < CPU_SETSIZE; cpu++) - if (odp_cpumask_isset(mask, cpu)) - return cpu; - return -1; -} - -int odp_cpumask_last(const odp_cpumask_t *mask) -{ - int cpu; - - for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--) - if (odp_cpumask_isset(mask, cpu)) - return cpu; - return -1; -} - -int odp_cpumask_next(const odp_cpumask_t *mask, int cpu) -{ - for (cpu += 1; cpu < CPU_SETSIZE; cpu++) - if (odp_cpumask_isset(mask, cpu)) - return cpu; - return -1; -} int odp_cpumask_def_worker(odp_cpumask_t *mask, int num) { diff --git a/platform/linux-generic/odp_cpumask_common.c b/platform/linux-generic/odp_cpumask_common.c new file mode 100644 index 0000000..b31e1ca --- /dev/null +++ b/platform/linux-generic/odp_cpumask_common.c @@ -0,0 +1,207 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include + +#include +#include + +#include +#include + +void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in) +{ + cpu_set_t cpuset; + const char *str = str_in; + const char *p; + int cpu = 0; + int len = strlen(str); + + CPU_ZERO(&cpuset); + odp_cpumask_zero(mask); + + /* Strip leading "0x"/"0X" if present and verify length */ + if ((len >= 2) && ((str[1] == 'x') || (str[1] == 'X'))) { + str += 2; + len -= 2; + } + if (!len) + return; + + /* Walk string from LSB setting cpu bits */ + for (p = str + len - 1; (len > 0) && (cpu < CPU_SETSIZE); p--, len--) { + char c = *p; + int value; + int idx; + + /* Convert hex nibble, abort when invalid value found */ + if ((c >= '0') && (c <= '9')) + value = c - '0'; + else if ((c >= 'A') && (c <= 'F')) + value = c - 'A' + 10; + else if ((c >= 'a') && (c <= 'f')) + value = c - 'a' + 10; + else + return; + + /* Walk converted nibble and set bits in mask */ + for (idx = 0; idx < 4; idx++, cpu++) + if (value & (1 << idx)) + CPU_SET(cpu, &cpuset); + } + + /* Copy the computed mask */ + memcpy(&mask->set, &cpuset, sizeof(cpuset)); +} + +int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t len) +{ + char *p = str; + int cpu = odp_cpumask_last(mask); + int nibbles; + int value; + + /* Handle bad string length, need at least 4 chars for "0x0" and + * terminating null char */ + if (len < 4) + return -1; /* Failure */ + + /* Handle no CPU found */ + if (cpu < 0) { + strcpy(str, "0x0"); + return strlen(str) + 1; /* Success */ + } + /* CPU was found and cpu >= 0 */ + + /* Compute number of nibbles in cpumask that have bits set */ + nibbles = (cpu / 4) + 1; + + /* Verify minimum space (account for "0x" and termination) */ + if (len < (3 + nibbles)) + return -1; /* Failure */ + + /* Prefix */ + *p++ = '0'; + *p++ = 'x'; + + /* + * Now we can scan the cpus down to zero and + * build the string one nibble at a time + */ + value = 0; + do { + /* Set bit to go into the current nibble */ + if (CPU_ISSET(cpu, &mask->set)) + value |= 1 << (cpu % 4); + + /* If we are on a nibble boundary flush value to string */ + if (0 == (cpu % 4)) { + if (value < 0xA) + *p++ = '0' + value; + else + *p++ = 'A' + value - 0xA; + value = 0; + } + } while (cpu--); + + /* Terminate the string */ + *p++ = 0; + return p - str; /* Success */ +} + +void odp_cpumask_zero(odp_cpumask_t *mask) +{ + CPU_ZERO(&mask->set); +} + +void odp_cpumask_set(odp_cpumask_t *mask, int cpu) +{ + CPU_SET(cpu, &mask->set); +} + +void odp_cpumask_setall(odp_cpumask_t *mask) +{ + int cpu; + + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) + CPU_SET(cpu, &mask->set); +} + +void odp_cpumask_clr(odp_cpumask_t *mask, int cpu) +{ + CPU_CLR(cpu, &mask->set); +} + +int odp_cpumask_isset(const odp_cpumask_t *mask, int cpu) +{ + return CPU_ISSET(cpu, &mask->set); +} + +int odp_cpumask_count(const odp_cpumask_t *mask) +{ + return CPU_COUNT(&mask->set); +} + +void odp_cpumask_and(odp_cpumask_t *dest, const odp_cpumask_t *src1, + const odp_cpumask_t *src2) +{ + CPU_AND(&dest->set, &src1->set, &src2->set); +} + +void odp_cpumask_or(odp_cpumask_t *dest, const odp_cpumask_t *src1, + const odp_cpumask_t *src2) +{ + CPU_OR(&dest->set, &src1->set, &src2->set); +} + +void odp_cpumask_xor(odp_cpumask_t *dest, const odp_cpumask_t *src1, + const odp_cpumask_t *src2) +{ + CPU_XOR(&dest->set, &src1->set, &src2->set); +} + +int odp_cpumask_equal(const odp_cpumask_t *mask1, + const odp_cpumask_t *mask2) +{ + return CPU_EQUAL(&mask1->set, &mask2->set); +} + +void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src) +{ + memcpy(&dest->set, &src->set, sizeof(src->set)); +} + +int odp_cpumask_first(const odp_cpumask_t *mask) +{ + int cpu; + + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) + if (odp_cpumask_isset(mask, cpu)) + return cpu; + return -1; +} + +int odp_cpumask_last(const odp_cpumask_t *mask) +{ + int cpu; + + for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--) + if (odp_cpumask_isset(mask, cpu)) + return cpu; + return -1; +} + +int odp_cpumask_next(const odp_cpumask_t *mask, int cpu) +{ + for (cpu += 1; cpu < CPU_SETSIZE; cpu++) + if (odp_cpumask_isset(mask, cpu)) + return cpu; + return -1; +}