Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp557241pxm; Wed, 2 Mar 2022 04:11:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+/F/XKyD+O/B7eFl3DFksrB+LJ03EDx6PJSASGADZ9qQEvEqcLP+BLLR3ve01cZq6wOQx X-Received: by 2002:a17:907:7f06:b0:6d6:f8f7:2655 with SMTP id qf6-20020a1709077f0600b006d6f8f72655mr5080704ejc.658.1646223099995; Wed, 02 Mar 2022 04:11:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646223099; cv=none; d=google.com; s=arc-20160816; b=DsjQNLWG4306b91LZTaihQ4xW9/59fQF3A9IdryZyHSpbN7L4oqmooY4YqAyZymHGO jdOsOIm5YEHOZ8GK3ONgZLC2Jt5xiESKfPYv2RrRV8+VGyF1pXlujXVg3xJ3FdBZtHzB gHb7jgZ32nec9mSege+Yd3vLwe+YP7xiUzagyDk38FSliojBkk/QcNbsQjCJaMK2ZXk/ Wz8YiJAJdtbqUvK1S1AmhJ2v7tRaUASuVL/G1JlQskJ5nYRHX8tdYvN6BWy7uZzcxS0W 0DOGYp83lfqtLA7SwfeK3JiUU03XhiwnMASac0V0iL24grgKMffekZVdQdVv0fWWQ6iT pkbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Qb5r5tDi+54ik271/CRJIO2SB14zrM+EcoZj7r3N4zM=; b=AUq9wkEGE/q49KgA3eeGdWihiKf2R6ZBi6vxC68xYBMbbW9zlxVHud2IOeA5dtJlqr aqTjXS/gIVNz3sf+vHHC6pt4U7ieXOGYYKLsKQWvXLqNV3vctgcxvl4H39ZkgWMxWyDe XfLGKEY0odnBSSnrjum2l1wgrM5+9f1tpDChSul88CinKQb5PJDLB5dvwskjzraNThJR hNP6hwz9c2poxtCMgerLeeFKLhppBYYGW9DPZ9479ZjgAeUAeDkoVAWDtHm+6Gm0TW9N kKYyACZGW8zHTNhud9gArN6B6r3ADqvRB7Egj6rUDvqqugJsmZRyzIdnGNiofNJO0Sdu Y82A== ARC-Authentication-Results: i=1; mx.google.com; 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 g12-20020a056402090c00b0041397141faesi9455111edz.270.2022.03.02.04.11.16; Wed, 02 Mar 2022 04:11:39 -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; 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 S239622AbiCBIBS (ORCPT + 99 others); Wed, 2 Mar 2022 03:01:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236101AbiCBIBP (ORCPT ); Wed, 2 Mar 2022 03:01:15 -0500 Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD810B6D08 for ; Wed, 2 Mar 2022 00:00:32 -0800 (PST) Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway22.websitewelcome.com (Postfix) with ESMTP id DCCD013DD4 for ; Wed, 2 Mar 2022 02:00:31 -0600 (CST) Received: from gator4132.hostgator.com ([192.185.4.144]) by cmsmtp with SMTP id PJuQnHwPldx86PJuRnZRCn; Wed, 02 Mar 2022 02:00:31 -0600 X-Authority-Reason: nr=8 Received: from host-95-232-30-176.retail.telecomitalia.it ([95.232.30.176]:40076 helo=[10.0.0.45]) by gator4132.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nPJuQ-000ywp-8X; Wed, 02 Mar 2022 02:00:30 -0600 Message-ID: Date: Wed, 2 Mar 2022 09:00:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] tracing/histogram: Fix sorting on old "cpu" value Content-Language: en-US To: Steven Rostedt , LKML Cc: Ingo Molnar , Andrew Morton , Tom Zanussi References: <20220301225728.100f17af@gandalf.local.home> From: Daniel Bristot de Oliveira In-Reply-To: <20220301225728.100f17af@gandalf.local.home> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4132.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - kernel.org X-BWhitelist: no X-Source-IP: 95.232.30.176 X-Source-L: No X-Exim-ID: 1nPJuQ-000ywp-8X X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: host-95-232-30-176.retail.telecomitalia.it ([10.0.0.45]) [95.232.30.176]:40076 X-Source-Auth: kernel@bristot.me X-Email-Count: 4 X-Source-Cap: YnJpc3RvdG1lO2JyaXN0b3RtZTtnYXRvcjQxMzIuaG9zdGdhdG9yLmNvbQ== X-Local-Domain: no X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/2/22 04:57, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > When trying to add a histogram against an event with the "cpu" field, it > was impossible due to "cpu" being a keyword to key off of the running CPU. > So to fix this, it was changed to "common_cpu" to match the other generic > fields (like "common_pid"). But since some scripts used "cpu" for keying > off of the CPU (for events that did not have "cpu" as a field, which is > most of them), a backward compatibility trick was added such that if "cpu" > was used as a key, and the event did not have "cpu" as a field name, then > it would fallback and switch over to "common_cpu". > > This fix has a couple of subtle bugs. One was that when switching over to > "common_cpu", it did not change the field name, it just set a flag. But > the code still found a "cpu" field. The "cpu" field is used for filtering > and is returned when the event does not have a "cpu" field. > > This was found by: > > # cd /sys/kernel/tracing > # echo hist:key=cpu,pid:sort=cpu > events/sched/sched_wakeup/trigger > # cat events/sched/sched_wakeup/hist > > Which showed the histogram unsorted: > > { cpu: 19, pid: 1175 } hitcount: 1 > { cpu: 6, pid: 239 } hitcount: 2 > { cpu: 23, pid: 1186 } hitcount: 14 > { cpu: 12, pid: 249 } hitcount: 2 > { cpu: 3, pid: 994 } hitcount: 5 > > Instead of hard coding the "cpu" checks, take advantage of the fact that > trace_event_field_field() returns a special field for "cpu" and "CPU" if > the event does not have "cpu" as a field. This special field has the > "filter_type" of "FILTER_CPU". Check that to test if the returned field is > of the CPU type instead of doing the string compare. > > Also, fix the sorting bug by testing for the hist_field flag of > HIST_FIELD_FL_CPU when setting up the sort routine. Otherwise it will use > the special CPU field to know what compare routine to use, and since that > special field does not have a size, it returns tracing_map_cmp_none. > > Cc: stable@vger.kernel.org > Fixes: 1e3bac71c505 ("tracing/histogram: Rename "cpu" to "common_cpu"") > Reported-by: Daniel Bristot de Oliveira > Signed-off-by: Steven Rostedt (Google) It works! Tested-by: Daniel Bristot de Oliveira -- Daniel