Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp238856pxu; Thu, 15 Oct 2020 02:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyxJSWEOLc5hQ0vDYCJ70L6B99yvjjt9RNbOoqZd6gU1OZeDE0lwZCbuCqxh43SeMybPFW X-Received: by 2002:a17:906:f112:: with SMTP id gv18mr3413356ejb.180.1602754931655; Thu, 15 Oct 2020 02:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602754931; cv=none; d=google.com; s=arc-20160816; b=IBMFacmopSl8kGK4fq2keI9OvNimnw/rYcwZ+f2sakR4P1nN9sUxN+xXdWOzd3xZVM 1PPA+Zq0/NDTR39CgSmVSeIvLcjJKVasYEh+RxMd31qHqm4GNAhKscI/xdJyDvByntCh w54CXBUt2/r0RUcMTYDCrfgsH7ven8t26CGLY05hUjTY0Jn2syPOW1DPiirfMuLlc/ur 7ae9CTXumO2ndDJq0B/zB9ywEsAub7fJCSIQmZIItDQFI3pgtK3Oyae8QssOxunGa0dX gxFuvoJNHoNjSU7SKitif299LXdn7Dw2CHo+WSwtTX90e5ZhSKWEeiZQxqFzdVkLM20z AQXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uUQPpiG295ZZ5lvIb/QJOhxG4iRW1VCyO2ZjrjnPUHs=; b=Q2+uQZB5UXw2CvUKbRzbhIAJmPF5w/XxLFUoHUuKCaREYJOynmCigROt0KToHiyDls zgGz7IQqK5OLGMec1vvBR2Nim4dOZcNRaSPYmzDuEoZHPc9+iTSvAju4hZk+pCzXdWVX dZD9K+uU+bk2bJTfhUofzEQtNqVMHaKbYdu/OtuS/RmmeL+Te02JWinUMohGcSe7tHaF 4MnW6HG4TFwgehBN9IYOuhucK5ZEY/LYdNgXYxVTmEJxjHkS8MboV/QP/kJJ1d3uHggD kIxdyEC7+Tg/cY7HF03Q87ZqeIylgnPwvc5XK62fifvDe7zmo2g419if7ayUjRKbYdlJ 7+mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=QYiXIBeP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si1674971edy.422.2020.10.15.02.41.49; Thu, 15 Oct 2020 02:42:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=QYiXIBeP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389084AbgJOBkO (ORCPT + 99 others); Wed, 14 Oct 2020 21:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389098AbgJOBji (ORCPT ); Wed, 14 Oct 2020 21:39:38 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10E35C0F26DB for ; Wed, 14 Oct 2020 17:23:11 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id l8so2006027ioh.11 for ; Wed, 14 Oct 2020 17:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uUQPpiG295ZZ5lvIb/QJOhxG4iRW1VCyO2ZjrjnPUHs=; b=QYiXIBePyMUrL4U/1NCIWMA6ILTLF4gzE6kwMMFmVHeOOQM9MrB8F4o5vvF1oQbho+ GfIePGjVGgCPrpN7TUfMxYQ/Xw/ZtVN5hIkLYG1DbGk1Vrp64gwgCUoyJ+TTX4Bv9o7O E87OqBgrddmz3R0wJNNNacDOjcJm9KZuRvmYo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uUQPpiG295ZZ5lvIb/QJOhxG4iRW1VCyO2ZjrjnPUHs=; b=KPBBqUTukQaRdsrTNSPKry5S1eDhdwFSeNaBVeu4iQrzqxEq82WsSezhK7cZRVDGyq 7tDuSRFYbwYzVWiKd6btOB6KcFanRvg44WG8ljB5KqMltvR3+LrH9100DWVCU/mAKepf 2w3EyzeO/nM9oAAdPiIU0R+nBFL7DWOQwBxHXY2yO5tMIS2QZ4w3Yb4DSvXtTTM5XnkL ZBfMIUUSVONMKXn7OccB5cAnmgJO6MsWVBhR+7wcJoubUGFs8Sw/mHwZqMkIl/B49+sk oB3BuxeaQjKGAhdYMHCql0Hg0k7wlBx0BA50q51cqqKCRSqE3CrniaIXZrXnoyiRSDXY I6sw== X-Gm-Message-State: AOAM530vhSsxQKPCXuLogCVgTQGESJyky1W/CR5cU455c0fjRmI3yvIs NaY7ozjQ6aM8mX0oiJWu4RRGw1ji3s6zVw== X-Received: by 2002:a05:6638:10ef:: with SMTP id g15mr1580241jae.33.1602721390150; Wed, 14 Oct 2020 17:23:10 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id r4sm1075622ilc.32.2020.10.14.17.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 17:23:09 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Ingo Molnar , Josh Triplett , Lai Jiangshan , Marco Elver , Mathieu Desnoyers , "Paul E. McKenney" , rcu@vger.kernel.org, Steven Rostedt , "Uladzislau Rezki (Sony)" , fweisbec@gmail.com, neeraj.iitr10@gmail.com Subject: [PATCH v7 3/6] rcu/trace: Add tracing for how segcb list changes Date: Wed, 14 Oct 2020 20:22:58 -0400 Message-Id: <20201015002301.101830-4-joel@joelfernandes.org> X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog In-Reply-To: <20201015002301.101830-1-joel@joelfernandes.org> References: <20201015002301.101830-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Track how the segcb list changes before/after acceleration, during queuing and during dequeuing. This has proved useful to discover an optimization to avoid unwanted GP requests when there are no callbacks accelerated. The overhead is minimal as each segment's length is now stored in the respective segment. Signed-off-by: Joel Fernandes (Google) --- include/trace/events/rcu.h | 25 +++++++++++++++++++++++++ kernel/rcu/rcu_segcblist.c | 31 +++++++++++++++++++++++++++++++ kernel/rcu/rcu_segcblist.h | 5 +++++ kernel/rcu/tree.c | 9 +++++++++ 4 files changed, 70 insertions(+) diff --git a/include/trace/events/rcu.h b/include/trace/events/rcu.h index 155b5cb43cfd..9f2237d9b0c8 100644 --- a/include/trace/events/rcu.h +++ b/include/trace/events/rcu.h @@ -505,6 +505,31 @@ TRACE_EVENT_RCU(rcu_callback, __entry->qlen) ); +TRACE_EVENT_RCU(rcu_segcb, + + TP_PROTO(const char *ctx, int *cb_count, unsigned long *gp_seq), + + TP_ARGS(ctx, cb_count, gp_seq), + + TP_STRUCT__entry( + __field(const char *, ctx) + __array(int, cb_count, RCU_CBLIST_NSEGS) + __array(unsigned long, gp_seq, RCU_CBLIST_NSEGS) + ), + + TP_fast_assign( + __entry->ctx = ctx; + memcpy(__entry->cb_count, cb_count, RCU_CBLIST_NSEGS * sizeof(int)); + memcpy(__entry->gp_seq, gp_seq, RCU_CBLIST_NSEGS * sizeof(unsigned long)); + ), + + TP_printk("%s cb_count: (DONE=%d, WAIT=%d, NEXT_READY=%d, NEXT=%d) " + "gp_seq: (DONE=%lu, WAIT=%lu, NEXT_READY=%lu, NEXT=%lu)", __entry->ctx, + __entry->cb_count[0], __entry->cb_count[1], __entry->cb_count[2], __entry->cb_count[3], + __entry->gp_seq[0], __entry->gp_seq[1], __entry->gp_seq[2], __entry->gp_seq[3]) + +); + /* * Tracepoint for the registration of a single RCU callback of the special * kvfree() form. The first argument is the RCU type, the second argument diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c index d9fab49dee1b..2dccbd29cd3a 100644 --- a/kernel/rcu/rcu_segcblist.c +++ b/kernel/rcu/rcu_segcblist.c @@ -14,6 +14,7 @@ #include #include "rcu_segcblist.h" +#include "rcu.h" /* Initialize simple callback list. */ void rcu_cblist_init(struct rcu_cblist *rclp) @@ -339,6 +340,36 @@ void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp, rcu_segcblist_set_seglen(rsclp, RCU_DONE_TAIL, 0); } +/* + * Return how many CBs each segment along with their gp_seq values. + * + * This function is O(N) where N is the number of segments. Only used from + * tracing code which is usually disabled in production. + */ +#ifdef CONFIG_RCU_TRACE +static void rcu_segcblist_countseq(struct rcu_segcblist *rsclp, + int cbcount[RCU_CBLIST_NSEGS], + unsigned long gpseq[RCU_CBLIST_NSEGS]) +{ + int i; + + for (i = 0; i < RCU_CBLIST_NSEGS; i++) { + cbcount[i] = rcu_segcblist_get_seglen(rsclp, i); + gpseq[i] = rsclp->gp_seq[i]; + } +} + +void trace_rcu_segcb_list(struct rcu_segcblist *rsclp, const char *context) +{ + int cbs[RCU_CBLIST_NSEGS]; + unsigned long gps[RCU_CBLIST_NSEGS]; + + rcu_segcblist_countseq(rsclp, cbs, gps); + + trace_rcu_segcb(context, cbs, gps); +} +#endif + /* * Extract only those callbacks still pending (not yet ready to be * invoked) from the specified rcu_segcblist structure and place them in diff --git a/kernel/rcu/rcu_segcblist.h b/kernel/rcu/rcu_segcblist.h index cd35c9faaf51..c2e274ae0912 100644 --- a/kernel/rcu/rcu_segcblist.h +++ b/kernel/rcu/rcu_segcblist.h @@ -103,3 +103,8 @@ void rcu_segcblist_advance(struct rcu_segcblist *rsclp, unsigned long seq); bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq); void rcu_segcblist_merge(struct rcu_segcblist *dst_rsclp, struct rcu_segcblist *src_rsclp); +#ifdef CONFIG_RCU_TRACE +void trace_rcu_segcb_list(struct rcu_segcblist *rsclp, const char *context); +#else +#define trace_rcu_segcb_list(...) +#endif diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 24c00020ab83..346a05506935 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -1497,6 +1497,8 @@ static bool rcu_accelerate_cbs(struct rcu_node *rnp, struct rcu_data *rdp) if (!rcu_segcblist_pend_cbs(&rdp->cblist)) return false; + trace_rcu_segcb_list(&rdp->cblist, TPS("SegCbPreAcc")); + /* * Callbacks are often registered with incomplete grace-period * information. Something about the fact that getting exact @@ -1517,6 +1519,8 @@ static bool rcu_accelerate_cbs(struct rcu_node *rnp, struct rcu_data *rdp) else trace_rcu_grace_period(rcu_state.name, gp_seq_req, TPS("AccReadyCB")); + trace_rcu_segcb_list(&rdp->cblist, TPS("SegCbPostAcc")); + return ret; } @@ -2466,11 +2470,14 @@ static void rcu_do_batch(struct rcu_data *rdp) rcu_segcblist_extract_done_cbs(&rdp->cblist, &rcl); if (offloaded) rdp->qlen_last_fqs_check = rcu_segcblist_n_cbs(&rdp->cblist); + + trace_rcu_segcb_list(&rdp->cblist, TPS("SegCbDequeued")); rcu_nocb_unlock_irqrestore(rdp, flags); /* Invoke callbacks. */ tick_dep_set_task(current, TICK_DEP_BIT_RCU); rhp = rcu_cblist_dequeue(&rcl); + for (; rhp; rhp = rcu_cblist_dequeue(&rcl)) { rcu_callback_t f; @@ -2983,6 +2990,8 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) trace_rcu_callback(rcu_state.name, head, rcu_segcblist_n_cbs(&rdp->cblist)); + trace_rcu_segcb_list(&rdp->cblist, TPS("SegCBQueued")); + /* Go handle any RCU core processing required. */ if (unlikely(rcu_segcblist_is_offloaded(&rdp->cblist))) { __call_rcu_nocb_wake(rdp, was_alldone, flags); /* unlocks */ -- 2.28.0.1011.ga647a8990f-goog