Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1315840pxb; Tue, 8 Feb 2022 14:29:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFaGPMh3o5DvTRmx3vLEs7CDGNnQN/9j1cJCY7/fbIA0h9WSpWiZCYk9mI/CdPZUEESy2Y X-Received: by 2002:a05:6a00:a10:: with SMTP id p16mr6380024pfh.44.1644359392499; Tue, 08 Feb 2022 14:29:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644359392; cv=none; d=google.com; s=arc-20160816; b=rP9u8cj8h7ledRPyTGRaShe0l0i2ChJWumk36NP9EOi+ceT1zqLMTbaS5FBGb3Z2It SiGDk+ZXZf9c4aInTCSpmjuWI2QGmyWzZgXLofBR/apr42gNo5ZSvqGZO8/Rox6hMeCO uEWdKMMA+JplxPt0iqmq4AMlXUd2rB7PaG6t/r3jh9eBKgPIBIlMfk6ruHjdz+gXlbMS VrQxj9wMnONBz4QGZnk33CTLaHo85iC3d3FVDiK0biMQDvY98fQkHaFXl1gR67wsGhq7 v05JvquBG0VEzfzNC8wSMLCxICv82GUpX9Vkt1fKR3QgF7GE9lxSeXHlU5ToeVTJrFAG 2Cow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=kMEbYJyBaqNdNN100hvb3kM+mAZXZOX5L89YVNFEDjY=; b=MfcNr4Kapl2a9BHtm5RxysIUC8hP6CowFB6LUNuqAKhn7IbXs9In5CLJfGTXDNg7qd TMPCgvbPF4MCaSzX+BEndnDxIQq1H3F9m9KEsHxnLGs1gbWg1ckfHhTJqPGtFfHdS9Pq BWCejNCShTNZP3K1QstREbjP5I9T9beQZ5seo79s0eUsSzotZG20Cj7A8U7UFXBW4d+Y 6EC/iSkMAA0BSp3tFj8YIGvulns4KhWpdJCMVVgbEoTWwL8ZTpxbWZIM7KxBLrq6A9nz N6e+KPnqOo36/r42O38orLZJVdqlhCtXyj0/ubnAVd7pLWCfvGarihE6blMIDCZ5mLW4 qD3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SWtE4mmD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11si3150973pjo.188.2022.02.08.14.29.34; Tue, 08 Feb 2022 14:29:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SWtE4mmD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348159AbiBDWM3 (ORCPT + 99 others); Fri, 4 Feb 2022 17:12:29 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:55660 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346694AbiBDWMU (ORCPT ); Fri, 4 Feb 2022 17:12:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3DBA86199F for ; Fri, 4 Feb 2022 22:12:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 354D9C004E1; Fri, 4 Feb 2022 22:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644012739; bh=y1dpcwaROiGNIsdVFNTBw0iucvP+KvehfPTvsCdkpjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=SWtE4mmD/c+3cOTfA0RIAsJqgcEyvo8bSkb0VyNeVB7nE107L5tESG91ZPTWFpOFT bfjocuAZO+SPH6fnT5yNwd0aToSRe2ZK2FYUr3Xm6rKcI0WJdToHC8dMzvAO2zpQ1A KxG8iPIgzXccenq+e4HO958bMcH5r4D5Iu7U4SLdn7UyKhkzbnEaJe4TbbZ+qz8KEY 8Vy3YqXirYeqcgoi8dkQjWpDJR3OtcC0TaO6IQhn5HVk32ulTeAcxcRCrzX2ImNjgL JK11Re9uZY0Qk5aEMn/zFhnr+xroiFggkelWmqyOGL9wsqGPNMS2l/hJQWIPBqspyk 6xF+gQsLe48Dg== From: Tom Zanussi To: rostedt@goodmis.org Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 4/4] tracing: Separate hist state updates from hist registration Date: Fri, 4 Feb 2022 16:12:07 -0600 Message-Id: <211b2cd3e3d7e00f4f8ad45ef8b33063da6a7e05.1644010576.git.zanussi@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hist_register_trigger() handles both new hist registration as well as existing hist registration through event_command.reg(). Adding a new function, existing_hist_update_only(), that checks and updates existing histograms and exits after doing so allows the confusing logic in event_hist_trigger_parse() to be simplified. Signed-off-by: Tom Zanussi --- kernel/trace/trace_events_hist.c | 66 +++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 28604e17bc73..bc52b03be11a 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -5926,6 +5926,48 @@ static bool hist_trigger_match(struct event_trigger_data *data, return true; } +static bool existing_hist_update_only(char *glob, + struct event_trigger_data *data, + struct trace_event_file *file) +{ + struct hist_trigger_data *hist_data = data->private_data; + struct event_trigger_data *test, *named_data = NULL; + bool updated = false; + + if (!hist_data->attrs->pause && !hist_data->attrs->cont && + !hist_data->attrs->clear) + goto out; + + if (hist_data->attrs->name) { + named_data = find_named_trigger(hist_data->attrs->name); + if (named_data) { + if (!hist_trigger_match(data, named_data, named_data, + true)) + goto out; + } + } + + if (hist_data->attrs->name && !named_data) + goto out; + + list_for_each_entry(test, &file->triggers, list) { + if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) { + if (!hist_trigger_match(data, test, named_data, false)) + continue; + if (hist_data->attrs->pause) + test->paused = true; + else if (hist_data->attrs->cont) + test->paused = false; + else if (hist_data->attrs->clear) + hist_clear(test); + updated = true; + goto out; + } + } + out: + return updated; +} + static int hist_register_trigger(char *glob, struct event_trigger_data *data, struct trace_event_file *file) @@ -5954,19 +5996,11 @@ static int hist_register_trigger(char *glob, list_for_each_entry(test, &file->triggers, list) { if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) { - if (!hist_trigger_match(data, test, named_data, false)) - continue; - if (hist_data->attrs->pause) - test->paused = true; - else if (hist_data->attrs->cont) - test->paused = false; - else if (hist_data->attrs->clear) - hist_clear(test); - else { + if (hist_trigger_match(data, test, named_data, false)) { hist_err(tr, HIST_ERR_TRIGGER_EEXIST, 0); ret = -EEXIST; + goto out; } - goto out; } } new: @@ -6005,8 +6039,6 @@ static int hist_register_trigger(char *glob, if (named_data) destroy_hist_data(hist_data); - - ret++; out: return ret; } @@ -6274,14 +6306,12 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, goto out_free; } - ret = event_trigger_register(cmd_ops, file, glob, trigger_data); - if (ret) + if (existing_hist_update_only(glob, trigger_data, file)) goto out_free; - if (ret == 0) { - if (!(attrs->pause || attrs->cont || attrs->clear)) - ret = -ENOENT; + + ret = event_trigger_register(cmd_ops, file, glob, trigger_data); + if (ret < 0) goto out_free; - } if (get_named_trigger_data(trigger_data)) goto enable; -- 2.17.1