Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3679265pxv; Mon, 26 Jul 2021 09:14:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMwlmfXx+pAqfqpy5Ut+diwDD0MM/wNG9VqJOOrK7zVVL2v0EoibOd5lTTIORGwyEQ5J2L X-Received: by 2002:a5e:8519:: with SMTP id i25mr15061390ioj.152.1627316078299; Mon, 26 Jul 2021 09:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627316078; cv=none; d=google.com; s=arc-20160816; b=p8yEtxKwezlk4mExVbo8w4oMMQICAFNTDl4VSPqMhJkEhrl+J56zVji9AW1eWLfbn3 wQVkb/0vAcezl88L5sjBQNn8DSFNewU3DCVnuKhQVLo9fJmbKFzYcDYB3T8jZTI0aRV3 2yjq0fEH18PMA3FQhTJIGK6bpu/MricvxLoHIIgeAFadGdf9nzwjdMMwBaECv2r+joUm /rcZxA/zfAtAck4S7AquyshEN/jRL028jDXvdRKY4zIcKg7jo8bGNOBgZzmEfffZlDuG A3oc0YBrZye5zlCmXoe/YlTKEmRiJRkOKZaRLjIaCWKfyns4bZ4m5YKXlVuACW8F/I56 DY0w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t2Wg759MUJj1syLAPXxfsds4TrqTh7gCYi2TriP7oIw=; b=wPN5tUo4MBbmeyXTUobVzGrTaad+C8cRQf2ygfMKHLAbjoCWrPED2XhS2nKwfqNqqM YlPEYNf+XsM9QNaPZqaxsy9ONNu3NiRDYKRDVKB5nQNR9FjIcJL3XMgb/Hsy1LM4EBhV eRpzeiqzJ2sa1OsMfB6OFdts0XITBgc7Y/av2uao8f2SBFx5JkgbzizZlUTtDRerAvTt u+bYbv5XMvDxGPIhbKQUyqxLDF62YbcYU3pSvfQLP4CliEXHBFjiYT36tcGv+Zwsjl9+ n84UPUsr6Mpma10/vGuDi3DHbMJIT2P0Z8CTg5zO5EtkmhuQ0A6Na48NtCfNBQNZ8HKi M3xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aNjXXaT6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si368806ilu.28.2021.07.26.09.14.23; Mon, 26 Jul 2021 09:14:38 -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=@linuxfoundation.org header.s=korg header.b=aNjXXaT6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233283AbhGZPcx (ORCPT + 99 others); Mon, 26 Jul 2021 11:32:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:59174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235613AbhGZPSa (ORCPT ); Mon, 26 Jul 2021 11:18:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C3FFA60F38; Mon, 26 Jul 2021 15:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315137; bh=3IzLbQtT/GZor5djkXTPMflKqZZ6jTv9+qK6dFUj/vw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aNjXXaT6Il++zAR3mZmczK0VTvHAHn6srFblv0lHx4XMqb09iQ4iwWujWsjKPOrTV urFXq7ARJCSnR1FxP4Q0qn7Q19YTb+8aCjE4fQY81gbgBz+/YcM7nz5A40aWw5p6C2 L2bMn4kEFMJ4QTVYf9UojCHOPSJoccBDnWOuJvJk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Ingo Molnar , Andrew Morton , Tom Zanussi , Masami Hiramatsu , "Steven Rostedt (VMware)" Subject: [PATCH 5.4 089/108] tracing/histogram: Rename "cpu" to "common_cpu" Date: Mon, 26 Jul 2021 17:39:30 +0200 Message-Id: <20210726153834.535756781@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) commit 1e3bac71c5053c99d438771fc9fa5082ae5d90aa upstream. Currently the histogram logic allows the user to write "cpu" in as an event field, and it will record the CPU that the event happened on. The problem with this is that there's a lot of events that have "cpu" as a real field, and using "cpu" as the CPU it ran on, makes it impossible to run histograms on the "cpu" field of events. For example, if I want to have a histogram on the count of the workqueue_queue_work event on its cpu field, running: ># echo 'hist:keys=cpu' > events/workqueue/workqueue_queue_work/trigger Gives a misleading and wrong result. Change the command to "common_cpu" as no event should have "common_*" fields as that's a reserved name for fields used by all events. And this makes sense here as common_cpu would be a field used by all events. Now we can even do: ># echo 'hist:keys=common_cpu,cpu if cpu < 100' > events/workqueue/workqueue_queue_work/trigger ># cat events/workqueue/workqueue_queue_work/hist # event histogram # # trigger info: hist:keys=common_cpu,cpu:vals=hitcount:sort=hitcount:size=2048 if cpu < 100 [active] # { common_cpu: 0, cpu: 2 } hitcount: 1 { common_cpu: 0, cpu: 4 } hitcount: 1 { common_cpu: 7, cpu: 7 } hitcount: 1 { common_cpu: 0, cpu: 7 } hitcount: 1 { common_cpu: 0, cpu: 1 } hitcount: 1 { common_cpu: 0, cpu: 6 } hitcount: 2 { common_cpu: 0, cpu: 5 } hitcount: 2 { common_cpu: 1, cpu: 1 } hitcount: 4 { common_cpu: 6, cpu: 6 } hitcount: 4 { common_cpu: 5, cpu: 5 } hitcount: 14 { common_cpu: 4, cpu: 4 } hitcount: 26 { common_cpu: 0, cpu: 0 } hitcount: 39 { common_cpu: 2, cpu: 2 } hitcount: 184 Now for backward compatibility, I added a trick. If "cpu" is used, and the field is not found, it will fall back to "common_cpu" and work as it did before. This way, it will still work for old programs that use "cpu" to get the actual CPU, but if the event has a "cpu" as a field, it will get that event's "cpu" field, which is probably what it wants anyway. I updated the tracefs/README to include documentation about both the common_timestamp and the common_cpu. This way, if that text is present in the README, then an application can know that common_cpu is supported over just plain "cpu". Link: https://lkml.kernel.org/r/20210721110053.26b4f641@oasis.local.home Cc: Namhyung Kim Cc: Ingo Molnar Cc: Andrew Morton Cc: stable@vger.kernel.org Fixes: 8b7622bf94a44 ("tracing: Add cpu field for hist triggers") Reviewed-by: Tom Zanussi Reviewed-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- Documentation/trace/histogram.rst | 2 +- kernel/trace/trace.c | 4 ++++ kernel/trace/trace_events_hist.c | 22 ++++++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) --- a/Documentation/trace/histogram.rst +++ b/Documentation/trace/histogram.rst @@ -191,7 +191,7 @@ Documentation written by Tom Zanussi with the event, in nanoseconds. May be modified by .usecs to have timestamps interpreted as microseconds. - cpu int the cpu on which the event occurred. + common_cpu int the cpu on which the event occurred. ====================== ==== ======================================= Extended error information --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4975,6 +4975,10 @@ static const char readme_msg[] = "\t [:name=histname1]\n" "\t [:.]\n" "\t [if ]\n\n" + "\t Note, special fields can be used as well:\n" + "\t common_timestamp - to record current timestamp\n" + "\t common_cpu - to record the CPU the event happened on\n" + "\n" "\t When a matching event is hit, an entry is added to a hash\n" "\t table using the key(s) and value(s) named, and the value of a\n" "\t sum called 'hitcount' is incremented. Keys and values\n" --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -2001,7 +2001,7 @@ static const char *hist_field_name(struc field->flags & HIST_FIELD_FL_ALIAS) field_name = hist_field_name(field->operands[0], ++level); else if (field->flags & HIST_FIELD_FL_CPU) - field_name = "cpu"; + field_name = "common_cpu"; else if (field->flags & HIST_FIELD_FL_EXPR || field->flags & HIST_FIELD_FL_VAR_REF) { if (field->system) { @@ -2873,14 +2873,24 @@ parse_field(struct hist_trigger_data *hi hist_data->enable_timestamps = true; if (*flags & HIST_FIELD_FL_TIMESTAMP_USECS) hist_data->attrs->ts_in_usecs = true; - } else if (strcmp(field_name, "cpu") == 0) + } else if (strcmp(field_name, "common_cpu") == 0) *flags |= HIST_FIELD_FL_CPU; else { field = trace_find_event_field(file->event_call, field_name); if (!field || !field->size) { - hist_err(tr, HIST_ERR_FIELD_NOT_FOUND, errpos(field_name)); - field = ERR_PTR(-EINVAL); - goto out; + /* + * For backward compatibility, if field_name + * was "cpu", then we treat this the same as + * common_cpu. + */ + if (strcmp(field_name, "cpu") == 0) { + *flags |= HIST_FIELD_FL_CPU; + } else { + hist_err(tr, HIST_ERR_FIELD_NOT_FOUND, + errpos(field_name)); + field = ERR_PTR(-EINVAL); + goto out; + } } } out: @@ -5641,7 +5651,7 @@ static void hist_field_print(struct seq_ seq_printf(m, "%s=", hist_field->var.name); if (hist_field->flags & HIST_FIELD_FL_CPU) - seq_puts(m, "cpu"); + seq_puts(m, "common_cpu"); else if (field_name) { if (hist_field->flags & HIST_FIELD_FL_VAR_REF || hist_field->flags & HIST_FIELD_FL_ALIAS)