From patchwork Wed Mar 7 17:01:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 882689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zxKgZ5R0gz9sf8 for ; Thu, 8 Mar 2018 04:02:02 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id CEBCB129A; Wed, 7 Mar 2018 17:01:19 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D9245128A for ; Wed, 7 Mar 2018 17:01:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 619325E7 for ; Wed, 7 Mar 2018 17:01:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B35D38151D47 for ; Wed, 7 Mar 2018 17:01:16 +0000 (UTC) Received: from monae.redhat.com (ovpn-124-182.rdu2.redhat.com [10.10.124.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92A8B215CDAC for ; Wed, 7 Mar 2018 17:01:16 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Wed, 7 Mar 2018 11:01:14 -0600 Message-Id: <20180307170115.29137-5-mmichels@redhat.com> In-Reply-To: <20180307170115.29137-1-mmichels@redhat.com> References: <20180307170115.29137-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 07 Mar 2018 17:01:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 07 Mar 2018 17:01:16 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mmichels@redhat.com' RCPT:'' X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v6 4/5] stopwatch: Add API for waiting until samples have been processed X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Jakub Sitnicki Will be used for testing the module. Signed-off-by: Jakub Sitnicki Signed-off-by: Mark Michelson --- lib/stopwatch.c | 34 ++++++++++++++++++++++++++-------- lib/stopwatch.h | 3 +++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/stopwatch.c b/lib/stopwatch.c index 4f36c4692..185f4a32f 100644 --- a/lib/stopwatch.c +++ b/lib/stopwatch.c @@ -66,6 +66,7 @@ struct stopwatch { enum stopwatch_op { OP_START_SAMPLE, OP_END_SAMPLE, + OP_SYNC, OP_RESET, OP_SHUTDOWN, }; @@ -78,6 +79,7 @@ struct stopwatch_packet { static struct shash stopwatches = SHASH_INITIALIZER(&stopwatches); static struct ovs_mutex stopwatches_lock = OVS_MUTEX_INITIALIZER; +static pthread_cond_t stopwatches_sync = PTHREAD_COND_INITIALIZER; static int stopwatch_pipe[2]; static pthread_t stopwatch_thread_id; @@ -233,12 +235,12 @@ add_sample(struct stopwatch *sw, unsigned long long new_sample) } static bool -performance_get_stats_protected(const char *name, - struct performance_stats *stats) +stopwatch_get_stats_protected(const char *name, + struct stopwatch_stats *stats) { - struct performance *perf; + struct stopwatch *perf; - perf = shash_find_data(&performances, name); + perf = shash_find_data(&stopwatches, name); if (!perf) { return false; } @@ -255,13 +257,13 @@ performance_get_stats_protected(const char *name, } bool -performance_get_stats(const char *name, struct performance_stats *stats) +stopwatch_get_stats(const char *name, struct stopwatch_stats *stats) { bool found = false; - ovs_mutex_lock(&performances_lock); - found = performance_get_stats_protected(name, stats); - ovs_mutex_unlock(&performances_lock); + ovs_mutex_lock(&stopwatches_lock); + found = stopwatch_get_stats_protected(name, stats); + ovs_mutex_unlock(&stopwatches_lock); return found; } @@ -427,6 +429,9 @@ stopwatch_thread(void *ign OVS_UNUSED) case OP_END_SAMPLE: stopwatch_end_sample_protected(&pkt); break; + case OP_SYNC: + xpthread_cond_signal(&stopwatches_sync); + break; case OP_RESET: stopwatch_reset_protected(&pkt); break; @@ -529,3 +534,16 @@ stopwatch_stop(const char *name, unsigned long long ts) ovs_strlcpy(pkt.name, name, sizeof(pkt.name)); write(stopwatch_pipe[1], &pkt, sizeof(pkt)); } + +void +stopwatch_sync(void) +{ + struct stopwatch_packet pkt = { + .op = OP_SYNC, + }; + + ovs_mutex_lock(&stopwatches_lock); + write(stopwatch_pipe[1], &pkt, sizeof(pkt)); + ovs_mutex_cond_wait(&stopwatches_sync, &stopwatches_lock); + ovs_mutex_unlock(&stopwatches_lock); +} diff --git a/lib/stopwatch.h b/lib/stopwatch.h index fac5de2c6..6ee7291d9 100644 --- a/lib/stopwatch.h +++ b/lib/stopwatch.h @@ -51,4 +51,7 @@ void stopwatch_stop(const char *name, unsigned long long ts); /* Retrieve statistics calculated from collected samples */ bool stopwatch_get_stats(const char *name, struct stopwatch_stats *stats); +/* Block until all enqueued samples have been processed. */ +void stopwatch_sync(void); + #endif /* stopwatch.h */