From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <vadim.suraev@gmail.com>
Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com
 [209.85.212.174]) by dpdk.org (Postfix) with ESMTP id B4FB436E
 for <dev@dpdk.org>; Thu, 15 May 2014 23:21:04 +0200 (CEST)
Received: by mail-wi0-f174.google.com with SMTP id r20so10530876wiv.13
 for <dev@dpdk.org>; Thu, 15 May 2014 14:21:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=from:to:subject:date:message-id:in-reply-to:references;
 bh=96T9GNp5p5cspI1ScN58HBmlbvq9LcUmY0FGUkbzeGw=;
 b=TZlHhy1roaLvyR6/A/XP4iwyi8v0dT6ItmJYXu9wUm3V+CwkYZoqZv8xzvWdtuR/Jw
 eklj7SOP06jA5dyH/iyM/E0g9nNLxaUcqxJf2eb6Q2GlGJds+uTO7TToPbJPbq5vGYcR
 4sySZHt8q0YqyN948bhsCvw9mmm5Ry1gsxegPH4tfAfNwQZU2iTwxxD9KUpm9kp11NTN
 Cgb5lUfi1xGME2mI4gjs26QEtyXsiJ57y4XQMY7WLAY1rjSQb/pH+0BTRaOTcLsp+t6X
 LsfBslJX1zGW9KY1PG8YMxYL5ysLEdTn5aWYzqAmgrVtrkNnehWASHFJdjz+aTKJPCyM
 fmhQ==
X-Received: by 10.194.243.104 with SMTP id wx8mr10506776wjc.32.1400188872759; 
 Thu, 15 May 2014 14:21:12 -0700 (PDT)
Received: from ubuntu.ubuntu-domain (bzq-79-181-48-4.red.bezeqint.net.
 [79.181.48.4])
 by mx.google.com with ESMTPSA id fs5sm35634257wic.22.2014.05.15.14.21.11
 for <dev@dpdk.org>
 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
 Thu, 15 May 2014 14:21:12 -0700 (PDT)
From: Vadim Suraev <vadim.suraev@gmail.com>
To: dev@dpdk.org
Message-Id: <1401830433-25071-3-git-send-email-vadim.suraev@gmail.com>
X-Mailer: git-send-email 1.7.9.5
In-Reply-To: <1401830433-25071-1-git-send-email-vadim.suraev@gmail.com>
References: <1401830433-25071-1-git-send-email-vadim.suraev@gmail.com>
Subject: [dpdk-dev] [PATCH 2/2] rte_timer bug fix: when a perdiodic timer's
	callback manipulates another timer,
	updated flag prevents reloading the periodic timer. Fix: move updated
	flag to rte_timer structure (one per core) Signed-off-by:
	Vadim Suraev <vadim.suraev@gmail.com>
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Date: Thu, 15 May 2014 21:21:05 -0000
X-Original-Date: Wed,  4 Jun 2014 00:20:33 +0300
X-List-Received-Date: Thu, 15 May 2014 21:21:05 -0000


Signed-off-by: Vadim Suraev <vadim.suraev@gmail.com>
---
 lib/librte_timer/rte_timer.c |   17 ++++++++---------
 lib/librte_timer/rte_timer.h |    7 ++++++-
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c
index f98e904..0cc5fa9 100755
--- a/lib/librte_timer/rte_timer.c
+++ b/lib/librte_timer/rte_timer.c
@@ -58,11 +58,6 @@ LIST_HEAD(rte_timer_list, rte_timer);
 struct priv_timer {
 	struct rte_timer pending_head;  /**< dummy timer instance to head up list */
 	rte_spinlock_t list_lock;       /**< lock to protect list access */
-
-	/** per-core variable that true if a timer was updated on this
-	 *  core since last reset of the variable */
-	int updated;
-
 	/** track the current depth of the skiplist */
 	unsigned curr_skiplist_depth;
 
@@ -107,10 +102,14 @@ void
 rte_timer_init(struct rte_timer *tim)
 {
 	union rte_timer_status status;
+	unsigned lcore_id;
 
 	status.state = RTE_TIMER_STOP;
 	status.owner = RTE_TIMER_NO_OWNER;
 	tim->status.u32 = status.u32;
+	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id ++) {
+		tim->updated[lcore_id] = 0;
+	}
 }
 
 /*
@@ -378,7 +377,7 @@ __rte_timer_reset(struct rte_timer *tim, uint64_t expire,
 		return -1;
 
 	__TIMER_STAT_ADD(reset, 1);
-	priv_timer[lcore_id].updated = 1;
+	tim->updated[lcore_id] = 1;
 
 	/* remove it from list */
 	if (prev_status.state == RTE_TIMER_PENDING) {
@@ -453,7 +452,7 @@ rte_timer_stop(struct rte_timer *tim)
 		return -1;
 
 	__TIMER_STAT_ADD(stop, 1);
-	priv_timer[lcore_id].updated = 1;
+	tim->updated[lcore_id] = 1;
 
 	/* remove it from list */
 	if (prev_status.state == RTE_TIMER_PENDING) {
@@ -541,7 +540,7 @@ void rte_timer_manage(void)
 
 		rte_spinlock_unlock(&priv_timer[lcore_id].list_lock);
 
-		priv_timer[lcore_id].updated = 0;
+		tim->updated[lcore_id] = 0;
 
 		/* execute callback function with list unlocked */
 		tim->f(tim, tim->arg);
@@ -550,7 +549,7 @@ void rte_timer_manage(void)
 
 		/* the timer was stopped or reloaded by the callback
 		 * function, we have nothing to do here */
-		if (priv_timer[lcore_id].updated == 1)
+		if (tim->updated[lcore_id] == 1)
 			continue;
 
 		if (tim->period == 0) {
diff --git a/lib/librte_timer/rte_timer.h b/lib/librte_timer/rte_timer.h
index c5f936b..235dfd6 100755
--- a/lib/librte_timer/rte_timer.h
+++ b/lib/librte_timer/rte_timer.h
@@ -129,6 +129,10 @@ struct rte_timer
 	uint64_t period;       /**< Period of timer (0 if not periodic). */
 	rte_timer_cb_t *f;     /**< Callback function. */
 	void *arg;             /**< Argument to callback function. */
+        /** per-core variable that true if a timer was updated on this
+	 *  core since last reset of the variable */
+	int updated[RTE_MAX_LCORE];
+
 };
 
 
@@ -142,7 +146,8 @@ struct rte_timer
 	{{RTE_TIMER_STOP, RTE_TIMER_NO_OWNER}}, \
 	0,                                      \
 	NULL,                                   \
-	NULL,                                   \
+	NULL,                                  \
+	{0},                                   \
 	}
 #else
 /**
-- 
1.7.9.5