From patchwork Fri Apr 24 14:10:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 47563 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 958252121F for ; Fri, 24 Apr 2015 14:10:57 +0000 (UTC) Received: by wiun10 with SMTP id n10sf4484199wiu.1 for ; Fri, 24 Apr 2015 07:10:56 -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=+G60HEM4TLXdukGn7Lsgs5FlOYmOHLbuazWH1+cJ+WE=; b=KKcqN98+Ay7+r7kjd3yuIBmRg6FVKJb92P7LoH32cKrIjKFuVMYUrbbIodauiZqAGs 6iWZGSL3HHtAxlQK9TTIW+0gR3aEe9LIR4SKYZ6rxFEQqTafE1/A9ROmOrhh1iY4LqJc BL/XLPxx0RG6wKw5p6UW1FSNknWoBmPrWEX7uOGz4bSiPfr1ntIyZUCwwwbmV4+TM4WI xenyr8N5H9UxbTGc0PCGsyUKp6XiVqjQ4Rn7vhAqXQC2GsyoIp0WGl8bv3Vgawh5bFWj cqS6lGf2eJ77zqQu961gJVBLNooiYdzLkkPRYfbAgCJ9SqXOO3aRIP8GuOrNRkkIewPc 1WWw== X-Gm-Message-State: ALoCoQnNgYhoil0nbfm+esPjOLpiISKi1Y+8x5biAKV0hIx4wvOKGVCTjDAu3Bh1vpYXdAk+QyL+ X-Received: by 10.152.206.36 with SMTP id ll4mr4300237lac.6.1429884656891; Fri, 24 Apr 2015 07:10:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.115.240 with SMTP id jr16ls515055lab.69.gmail; Fri, 24 Apr 2015 07:10:56 -0700 (PDT) X-Received: by 10.112.119.163 with SMTP id kv3mr7177964lbb.101.1429884656748; Fri, 24 Apr 2015 07:10:56 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id h8si8354959lbc.56.2015.04.24.07.10.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2015 07:10:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by layy10 with SMTP id y10so36230723lay.0 for ; Fri, 24 Apr 2015 07:10:56 -0700 (PDT) X-Received: by 10.153.6.36 with SMTP id cr4mr7311174lad.56.1429884656312; Fri, 24 Apr 2015 07:10:56 -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.67.65 with SMTP id l1csp1218012lbt; Fri, 24 Apr 2015 07:10:55 -0700 (PDT) X-Received: by 10.55.22.139 with SMTP id 11mr15940513qkw.94.1429884654697; Fri, 24 Apr 2015 07:10:54 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o7si11497090qge.57.2015.04.24.07.10.53; Fri, 24 Apr 2015 07:10:54 -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 C117862065; Fri, 24 Apr 2015 14:10:53 +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=ham autolearn_force=no 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 34DE362056; Fri, 24 Apr 2015 14:10: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 D7B1C62062; Fri, 24 Apr 2015 14:10:48 +0000 (UTC) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by lists.linaro.org (Postfix) with ESMTPS id 6825162056 for ; Fri, 24 Apr 2015 14:10:46 +0000 (UTC) Received: by lagv1 with SMTP id v1so36165887lag.3 for ; Fri, 24 Apr 2015 07:10:45 -0700 (PDT) X-Received: by 10.152.115.205 with SMTP id jq13mr6902578lab.2.1429884644837; Fri, 24 Apr 2015 07:10:44 -0700 (PDT) Received: from localhost.localdomain (78-82-118-124.tn.glocalnet.net. [78.82.118.124]) by mx.google.com with ESMTPSA id jp18sm2651673lab.34.2015.04.24.07.10.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Apr 2015 07:10:44 -0700 (PDT) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Fri, 24 Apr 2015 16:10:35 +0200 Message-Id: <1429884635-17042-1-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: timers patch Subject: [lng-odp] [PATCH] linux-generic: timer: use plain buffers for timeouts 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: ola.liljedahl@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.50 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 Use plain buffers for timeouts. Store the timeout header in the buffer data area. This simplifies re-use on other platforms where the event header cannot be arbitrarily defined. Signed-off-by: Ola Liljedahl --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) platform/linux-generic/include/odp_timer_internal.h | 15 ++++++++++++--- platform/linux-generic/odp_pool.c | 7 ++++--- platform/linux-generic/odp_timer.c | 15 +++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/platform/linux-generic/include/odp_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h index 90af62c..a631bd0 100644 --- a/platform/linux-generic/include/odp_timer_internal.h +++ b/platform/linux-generic/include/odp_timer_internal.h @@ -16,36 +16,45 @@ #include #include +#include #include #include #include /** * Internal Timeout header + * For compatibility with buffers, we use the buffer_hdr here and nothing else */ typedef struct { /* common buffer header */ odp_buffer_hdr_t buf_hdr; +} odp_timeout_fakehdr_t; +/* The real timeout header is in a separate struct in a separate location */ +typedef struct { /* Requested expiration time */ uint64_t expiration; /* User ptr inherited from parent timer */ void *user_ptr; + /* Handle of buffer we are located in */ + odp_buffer_t buf; /* Parent timer */ odp_timer_t timer; } odp_timeout_hdr_t; typedef struct odp_timeout_hdr_stride { - uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_hdr_t))]; + uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_timeout_fakehdr_t))]; } odp_timeout_hdr_stride; /** * Return the timeout header */ -static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_buffer_t buf) +static inline odp_timeout_hdr_t *odp_timeout_hdr_from_buf(odp_buffer_t buf) { - return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf); + /* The real timeout header is stored in the buffer data */ + ODP_ASSERT(odp_buffer_size(buf) == sizeof(odp_timeout_hdr_t)); + return (odp_timeout_hdr_t *)odp_buffer_addr(buf); } #endif diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index bf49623..fc10aa4 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -32,7 +32,7 @@ typedef union buffer_type_any_u { odp_buffer_hdr_t buf; odp_packet_hdr_t pkt; - odp_timeout_hdr_t tmo; + odp_timeout_fakehdr_t tmo; } odp_anybuf_t; _ODP_STATIC_ASSERT((sizeof(union buffer_type_any_u) % 8) == 0, @@ -148,7 +148,8 @@ odp_pool_t odp_pool_create(const char *name, /* Default size and align for timeouts */ if (params->type == ODP_POOL_TIMEOUT) { - params->buf.size = 0; /* tmo.__res1 */ + /* The real timeout header is stored in the buffer */ + params->buf.size = sizeof(odp_timeout_hdr_t); /* tmo.__res1 */ params->buf.align = 0; /* tmo.__res2 */ } @@ -226,7 +227,7 @@ odp_pool_t odp_pool_create(const char *name, break; case ODP_POOL_TIMEOUT: - blk_size = 0; + blk_size = params->buf.size; buf_num = params->tmo.num; buf_stride = sizeof(odp_timeout_hdr_stride); break; diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index e5391dc..1922f94 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -78,7 +78,7 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks per cache line! */ static odp_timeout_hdr_t *timeout_hdr_from_buf(odp_buffer_t buf) { - return (odp_timeout_hdr_t *)odp_buf_to_hdr(buf); + return odp_timeout_hdr_from_buf(buf); } /****************************************************************************** @@ -820,8 +820,7 @@ odp_timeout_t odp_timeout_from_event(odp_event_t ev) odp_event_t odp_timeout_to_event(odp_timeout_t tmo) { odp_timeout_hdr_t *tmo_hdr = (odp_timeout_hdr_t *)tmo; - odp_buffer_t buf = odp_hdr_to_buf(&tmo_hdr->buf_hdr); - return odp_buffer_to_event(buf); + return odp_buffer_to_event(tmo_hdr->buf); } int odp_timeout_fresh(odp_timeout_t tmo) @@ -857,16 +856,20 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo) odp_timeout_t odp_timeout_alloc(odp_pool_t pool) { + odp_timeout_hdr_t *tmo_hdr; odp_buffer_t buf = odp_buffer_alloc(pool); if (odp_unlikely(buf == ODP_BUFFER_INVALID)) return ODP_TIMEOUT_INVALID; - return odp_timeout_from_event(odp_buffer_to_event(buf)); + tmo_hdr = timeout_hdr_from_buf(buf); + /* Must save buffer handle in timeout header for later use */ + tmo_hdr->buf = buf; + return (odp_timeout_t)tmo_hdr; } void odp_timeout_free(odp_timeout_t tmo) { - odp_event_t ev = odp_timeout_to_event(tmo); - odp_buffer_free(odp_buffer_from_event(ev)); + odp_timeout_hdr_t *tmo_hdr = (odp_timeout_hdr_t *)tmo; + odp_buffer_free(tmo_hdr->buf); } int odp_timer_init_global(void)