From patchwork Thu Nov 20 11:53:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41237 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33E7523C27 for ; Thu, 20 Nov 2014 11:54:52 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id y19sf1605608wgg.11 for ; Thu, 20 Nov 2014 03:54:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references: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=NjCt9164SQElgXqrD1le/nCZtIu9k+auhBa1m+CyC28=; b=Y2CKQiMvYCO6vuLxzEq5mjnpwR8ovYCbaJzrCp8O+oWgi/pk89f9wx8EzyHJHJZWpM mWVlpN3Yde3ULZFhwlU26oiq2ZFNxrRVHNkTlXXJbfddMLsR2LpusyZiwDk7btrVltdg Tptn+jp7dpMhIYrPp1Y3p5q2PrvP67NXabbFvbRscDxPWGVArNJjv6pUgs6RPA4QESJZ IMNpzRo7Ybw3sC/V/zz7OMSYY2BX3dPTOEZsxMbRmqATcfiZB5sAKTMz2cxFxTV2tp96 pS6Irx/Msvwtk2DcKVkZ4bsSnSCoJY6NvIxuEKz+5tGA8NV0Y0JaVPWQsnqoCXjxMmS5 XAhw== X-Gm-Message-State: ALoCoQkccZYF7L3WG5EdIVvJqOOKLtUyHE53s9W/EL06xan+LhvdTKjsC1ERMTLRmGiN309rtf9D X-Received: by 10.112.151.38 with SMTP id un6mr2214193lbb.0.1416484491467; Thu, 20 Nov 2014 03:54:51 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.137 with SMTP id b9ls56801lah.29.gmail; Thu, 20 Nov 2014 03:54:51 -0800 (PST) X-Received: by 10.112.199.131 with SMTP id jk3mr10948078lbc.45.1416484491065; Thu, 20 Nov 2014 03:54:51 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id od3si1878961lbb.138.2014.11.20.03.54.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 03:54:51 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id u10so2104207lbd.17 for ; Thu, 20 Nov 2014 03:54:51 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr10847076laa.71.1416484490990; Thu, 20 Nov 2014 03:54:50 -0800 (PST) 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.184.201 with SMTP id ew9csp246819lbc; Thu, 20 Nov 2014 03:54:50 -0800 (PST) X-Received: by 10.224.74.135 with SMTP id u7mr56930272qaj.67.1416484489885; Thu, 20 Nov 2014 03:54:49 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id o9si2522020qcg.16.2014.11.20.03.54.48 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Nov 2014 03:54:49 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrQJz-0001AO-Cc; Thu, 20 Nov 2014 11:54:47 +0000 Received: from mail-lb0-f179.google.com ([209.85.217.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrQJW-00015Z-C3 for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 11:54:18 +0000 Received: by mail-lb0-f179.google.com with SMTP id l4so2100801lbv.38 for ; Thu, 20 Nov 2014 03:54:12 -0800 (PST) X-Received: by 10.152.5.6 with SMTP id o6mr48164078lao.8.1416484452772; Thu, 20 Nov 2014 03:54:12 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id bb3sm534566lab.7.2014.11.20.03.54.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Nov 2014 03:54:11 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 12:53:48 +0100 Message-Id: <1416484428-23849-8-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416484428-23849-1-git-send-email-ola.liljedahl@linaro.org> References: <1416484428-23849-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 7/7] example: odp_generator.c: use odp_atomic.h X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 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-bounces@lists.linaro.org 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.217.172 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 Signed-off-by: Ola Liljedahl --- example/generator/odp_generator.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index e2e0ba4..135ddc0 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -204,7 +204,7 @@ static void pack_udp_pkt(odp_buffer_t obuf) ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN); ip->proto = ODPH_IPPROTO_UDP; - seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF; + seq = odp_atomic_fetch_inc_u64(&counters.seq) % 0xFFFF; ip->id = odp_cpu_to_be_16(seq); ip->chksum = 0; odph_ipv4_csum_update(pkt); @@ -261,7 +261,7 @@ static void pack_icmp_pkt(odp_buffer_t obuf) ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_ICMPHDR_LEN + ODPH_IPV4HDR_LEN); ip->proto = ODPH_IPPROTO_ICMP; - seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff; + seq = odp_atomic_fetch_inc_u64(&counters.seq) % 0xffff; ip->id = odp_cpu_to_be_16(seq); ip->chksum = 0; odph_ipv4_csum_update(pkt); @@ -338,11 +338,14 @@ static void *gen_send_thread(void *arg) if (args->appl.interval != 0) { printf(" [%02i] send pkt no:%ju seq %ju\n", - thr, counters.seq, counters.seq%0xffff); + thr, + odp_atomic_load_u64(&counters.seq), + odp_atomic_load_u64(&counters.seq)%0xffff); /* TODO use odp timer */ usleep(args->appl.interval * 1000); } - if (args->appl.number != -1 && counters.seq + if (args->appl.number != -1 && + odp_atomic_load_u64(&counters.seq) >= (unsigned int)args->appl.number) { break; } @@ -351,7 +354,8 @@ static void *gen_send_thread(void *arg) /* receive number of reply pks until timeout */ if (args->appl.mode == APPL_MODE_PING && args->appl.number > 0) { while (args->appl.timeout >= 0) { - if (counters.icmp >= (unsigned int)args->appl.number) + if (odp_atomic_load_u64(&counters.icmp) >= + (unsigned int)args->appl.number) break; /* TODO use odp timer */ sleep(1); @@ -361,10 +365,12 @@ static void *gen_send_thread(void *arg) /* print info */ if (args->appl.mode == APPL_MODE_UDP) { - printf(" [%02i] total send: %ju\n", thr, counters.seq); + printf(" [%02i] total send: %ju\n", + thr, odp_atomic_load_u64(&counters.seq)); } else if (args->appl.mode == APPL_MODE_PING) { printf(" [%02i] total send: %ju total receive: %ju\n", - thr, counters.seq, counters.icmp); + thr, odp_atomic_load_u64(&counters.seq), + odp_atomic_load_u64(&counters.icmp)); } return arg; } @@ -534,10 +540,10 @@ int main(int argc, char *argv[]) } /* init counters */ - odp_atomic_init_u64(&counters.seq); - odp_atomic_init_u64(&counters.ip); - odp_atomic_init_u64(&counters.udp); - odp_atomic_init_u64(&counters.icmp); + odp_atomic_init_u64(&counters.seq, 0); + odp_atomic_init_u64(&counters.ip, 0); + odp_atomic_init_u64(&counters.udp, 0); + odp_atomic_init_u64(&counters.icmp, 0); /* Reserve memory for args from shared mem */ shm = odp_shm_reserve("shm_args", sizeof(args_t),