From patchwork Tue Jun 2 10:09:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 1302317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hOi7c/1h; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bnqH1d1bz9sSg for ; Tue, 2 Jun 2020 20:10:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8005187842; Tue, 2 Jun 2020 10:10:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id elFajooYNSSB; Tue, 2 Jun 2020 10:10:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 7308687863; Tue, 2 Jun 2020 10:10:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 564CFC0891; Tue, 2 Jun 2020 10:10:26 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2F372C016E for ; Tue, 2 Jun 2020 10:10:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1EBE584FFF for ; Tue, 2 Jun 2020 10:10:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m4lSiD5bPe0y for ; Tue, 2 Jun 2020 10:10:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by fraxinus.osuosl.org (Postfix) with ESMTPS id E272186381 for ; Tue, 2 Jun 2020 10:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591092622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GyUv0wVwAFR6O17Wc5LmSixJ7s/hj1rbygpRhJCI4TY=; b=hOi7c/1hp4IWOlGpyOPm+uM0zrVe3OspafPjN1B0WpBhfsSqjtdbghSWQJklXAaBsU1x1Q 9AaMvdJgEGHKUDXjAmd+q1kq9MpQMkos/Azk7m0JNnXI4PiuGKyAkfvCyZYw4WV+W7RYjF EqkuPUTjqd03dWpNO40SGmM4O4EtKdA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-33-zMI8frtFNxGvZrr0hfV0FA-1; Tue, 02 Jun 2020 06:10:21 -0400 X-MC-Unique: zMI8frtFNxGvZrr0hfV0FA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0AA0108BD10; Tue, 2 Jun 2020 10:10:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-111.sin2.redhat.com [10.67.117.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8585F5D9DD; Tue, 2 Jun 2020 10:10:14 +0000 (UTC) From: Gowrishankar Muthukrishnan To: dev@openvswitch.org Date: Tue, 2 Jun 2020 15:39:46 +0530 Message-Id: <093573848c90e242707e7dfe7474f278f786df50.1591091223.git.gmuthukr@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: anju.thomas@ericsson.com, Keshav Gupta , i.maximets@ovn.org Subject: [ovs-dev] [PATCH 4/7] coverage: support conditional notification from events X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This patch enables monitoring coverage counters through event API. Signed-off-by: Gowrishankar Muthukrishnan --- lib/coverage.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/coverage.h | 4 ++++ lib/timeval.c | 3 +++ 3 files changed, 68 insertions(+) diff --git a/lib/coverage.c b/lib/coverage.c index a95b6aa..f4c872e 100644 --- a/lib/coverage.c +++ b/lib/coverage.c @@ -25,6 +25,7 @@ #include "unixctl.h" #include "util.h" #include "openvswitch/vlog.h" +#include "event.h" VLOG_DEFINE_THIS_MODULE(coverage); @@ -36,6 +37,7 @@ static size_t allocated_coverage_counters = 0; static struct ovs_mutex coverage_mutex = OVS_MUTEX_INITIALIZER; DEFINE_STATIC_PER_THREAD_DATA(long long int, coverage_clear_time, LLONG_MIN); +DEFINE_STATIC_PER_THREAD_DATA(long long int, coverage_event_time, LLONG_MIN); static long long int coverage_run_time = LLONG_MIN; /* Index counter used to compute the moving average array's index. */ @@ -51,6 +53,7 @@ static bool coverage_read_counter(const char *name, void coverage_counter_register(struct coverage_counter* counter) { + event_register(counter->name, EV_RESOURCE_COVERAGE); if (n_coverage_counters >= allocated_coverage_counters) { coverage_counters = x2nrealloc(coverage_counters, &allocated_coverage_counters, @@ -414,3 +417,61 @@ coverage_read_counter(const char *name, unsigned long long int *count) return false; } + +static void +coverage_event__(bool trylock) +{ + long long int now, *thread_time; + + now = time_msec(); + thread_time = coverage_event_time_get(); + + /* Initialize the coverage_event_time. */ + if (*thread_time == LLONG_MIN) { + *thread_time = now + COVERAGE_EVENT_INTERVAL; + } + + if (now >= *thread_time) { + size_t i; + + if (trylock) { + /* Returns if cannot acquire lock. */ + if (event_try_lock()) { + return; + } + if (ovs_mutex_trylock(&coverage_mutex)) { + event_unlock(); + return; + } + } else { + event_lock(); + ovs_mutex_lock(&coverage_mutex); + } + + for (i = 0; i < n_coverage_counters && event_count(); i++) { + struct coverage_counter *c = coverage_counters[i]; + struct event *ev; + + ev = event_get(c->name); + if (!ev || ev->def.resource != EV_RESOURCE_COVERAGE) { + continue; + } + + ev->current = c->total; + ovs_mutex_unlock(&coverage_mutex); + ev->rate_min = coverage_array_sum(c->min, MIN_AVG_LEN) / 60.0; + ev->rate_hour = coverage_array_sum(c->hr, HR_AVG_LEN) / 3600.0; + ovs_mutex_lock(&coverage_mutex); + } + + ovs_mutex_unlock(&coverage_mutex); + event_unlock(); + *thread_time = now + COVERAGE_EVENT_INTERVAL; + } +} + +void +coverage_try_event(void) +{ + coverage_event__(true); +} diff --git a/lib/coverage.h b/lib/coverage.h index dea990e..4cdf956 100644 --- a/lib/coverage.h +++ b/lib/coverage.h @@ -39,6 +39,9 @@ BUILD_ASSERT_DECL(60000 % COVERAGE_RUN_INTERVAL == 0); #define COVERAGE_CLEAR_INTERVAL 1000 BUILD_ASSERT_DECL(COVERAGE_RUN_INTERVAL % COVERAGE_CLEAR_INTERVAL == 0); +#define COVERAGE_EVENT_INTERVAL 1000 +BUILD_ASSERT_DECL(60000 % COVERAGE_EVENT_INTERVAL == 0); + /* Defines the moving average array length. */ #define MIN_AVG_LEN (60000/COVERAGE_RUN_INTERVAL) #define HR_AVG_LEN 60 @@ -90,5 +93,6 @@ void coverage_log(void); void coverage_clear(void); void coverage_try_clear(void); void coverage_run(void); +void coverage_try_event(void); #endif /* coverage.h */ diff --git a/lib/timeval.c b/lib/timeval.c index 193c7ba..3e3d86f 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -35,6 +35,7 @@ #include "ovs-thread.h" #include "signals.h" #include "seq.h" +#include "stopwatch.h" #include "unixctl.h" #include "util.h" #include "openvswitch/vlog.h" @@ -294,6 +295,8 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED, time_init(); coverage_clear(); coverage_run(); + coverage_try_event(); + if (*last_wakeup && !thread_is_pmd()) { log_poll_interval(*last_wakeup); }