From patchwork Wed Aug 29 12:17:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" X-Patchwork-Id: 10580167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68361174A for ; Wed, 29 Aug 2018 12:38:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02B702AFBD for ; Wed, 29 Aug 2018 12:38:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB05D2AFD0; Wed, 29 Aug 2018 12:38:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7BB22AFBD for ; Wed, 29 Aug 2018 12:38:23 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 86465CFF; Wed, 29 Aug 2018 12:36:40 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9E1FBCD3 for ; Wed, 29 Aug 2018 12:36:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx05.melco.co.jp (mx05.melco.co.jp [192.218.140.145]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 16E63709 for ; Wed, 29 Aug 2018 12:36:33 +0000 (UTC) Received: from mr05.melco.co.jp (mr05 [133.141.98.165]) by mx05.melco.co.jp (Postfix) with ESMTP id BC45E3A2834 for ; Wed, 29 Aug 2018 21:17:24 +0900 (JST) Received: from mr05.melco.co.jp (unknown [127.0.0.1]) by mr05.imss (Postfix) with ESMTP id 420l4N5KQwzRkCl for ; Wed, 29 Aug 2018 21:17:24 +0900 (JST) Received: from mf04_second.melco.co.jp (unknown [192.168.20.184]) by mr05.melco.co.jp (Postfix) with ESMTP id 420l4N51pwzRkC3 for ; Wed, 29 Aug 2018 21:17:24 +0900 (JST) Received: from mf04.melco.co.jp (unknown [133.141.98.184]) by mf04_second.melco.co.jp (Postfix) with ESMTP id 420l4N52yPzRkD2 for ; Wed, 29 Aug 2018 21:17:24 +0900 (JST) Received: from JPN01-OS2-obe.outbound.protection.outlook.com (unknown [23.103.139.146]) by mf04.melco.co.jp (Postfix) with ESMTP id 420l4N4WYNzRkCw for ; Wed, 29 Aug 2018 21:17:24 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mitsubishielectricgroup.onmicrosoft.com; s=selector1-mitsubishielectricgroup-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Sc8Y1YwQ89CtL9RYOTKVDT128uClM8hFD4aAQpL0fY=; b=mmjQlLZafHxeCAHjl3UELMbmsFtmNuo4LiS7+SjZ/ocdMIqG3QDR4Tv77hb5syRqiZFEjt+ti60g5t9B1IiXdC4GGOUMBAvkmuoJKKnwEhFiHrm76C4Xtmehc2dB7H4FEmDfZZJuBEXOO2mqPth7rYyFnTV4+YN6aGdIRXGkHvA= Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com (52.133.160.145) by TY1PR01MB1231.jpnprd01.prod.outlook.com (10.174.226.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.17; Wed, 29 Aug 2018 12:17:24 +0000 Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com ([fe80::d04e:e6f6:c782:22fa]) by TY1PR01MB1692.jpnprd01.prod.outlook.com ([fe80::d04e:e6f6:c782:22fa%2]) with mapi id 15.20.1080.015; Wed, 29 Aug 2018 12:17:24 +0000 From: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" To: "ltsi-dev@lists.linuxfoundation.org" Thread-Topic: [LTSI-dev] [PATCH 05/54] tracing: Remove code which merges duplicates Thread-Index: AdQ/iVyJq+8Ic6H9Tluit/l5eQWKgQ== Date: Wed, 29 Aug 2018 12:17:04 +0000 Deferred-Delivery: Wed, 29 Aug 2018 12:15:00 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-melpop: 1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=Motai.Hirotaka@aj.MitsubishiElectric.co.jp; x-originating-ip: [153.231.200.201] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; TY1PR01MB1231; 6:PE3WlCgM9QAdOBxhTD8aa+FKfKWg5XdsjUrsM6mDqrJHmkFHGrF4kCEtO2xl5uddqAmXOJCMfwYm35b+wCLp6X0tqA1XwpVkYzQBa5AGFQew+G7Lqk9SZdcRIY3z//Ds5fTQ2WYQI5iBrrktb6yfDEiWPwMq6nJRjGKwEyifHf3sJnBitD0wcgsudw/XY93FXubgtgxsrvbRITPuIO4qb4IAbf4zkfPfSTPxhXxJQuj2t06GOko5he/Tk96YrctQi6SGBnqxr0499w5m1DYJ9YgkMIgNvKmLKWpfhMq11qasRaXbKAUrIxk3xRZTwCBAILe7rWi8xtVByFezG9JNBjtEjYLwseHzbeEdhSb8LOM+qP6++MwJdUz77BsP5/LZjsuMbbaHCR16wBgim9SKSuHyrWFzg8nti8n1f5GLAtenUqXO7QmcMWUi8znd+EiE6kMZlkSczdCYHu8AR+yXKQ==; 5:GjIl5JYsWCZbrPOSDwpbFD1zOtiU3Vq0zd3S2NNSMfh7zuiAccShpAE00sZnj0AfjPElycjXtuM6egvjCz3XC12UzL+3c8heg5wLo8PR383OBqy28VRWwqVPz7/AZZVPi1IOhZE2MaKeRUyRxSFY6NEJVP8VJ81a48rz6DAjt4A=; 7:RX8EN7mrM3VTrRW/zy5pe7Fg0won3ZIIcJwCsn/D1HUq5Kr4e4ruJuc2Id51UkYKD3bAfSSZqXsIjkIRB9JfeYzfqTUFxCxQXL+WT+aBZyAWVY2OknEsz+HcfxyRlEYVwQS2RtQg0/MA+9sZWue1iXS1Od8Za728/pB5VuAwxuVnXzhwgt/BPxcI/AFWGdL4Nc3hCReKSj/9nThCTP48D45bHyneTbp9YZfdtnZmp6LO9dey5lXRk8mHk37CQkjj x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: eedacdee-2cd9-48ae-ebab-08d60da96090 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:TY1PR01MB1231; x-ms-traffictypediagnostic: TY1PR01MB1231: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(42068640409301)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(201708071742011)(7699016); SRVR:TY1PR01MB1231; BCL:0; PCL:0; RULEID:; SRVR:TY1PR01MB1231; x-forefront-prvs: 077929D941 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(396003)(366004)(376002)(346002)(39860400002)(189003)(199004)(478600001)(105586002)(2906002)(14454004)(33656002)(66066001)(966005)(72206003)(6116002)(3846002)(97736004)(2900100001)(2501003)(5250100002)(74482002)(25786009)(7736002)(9686003)(5660300001)(6506007)(26005)(6666003)(6916009)(2351001)(81156014)(106356001)(86362001)(6436002)(6306002)(5640700003)(74316002)(8676002)(1857600001)(81166006)(102836004)(53936002)(7696005)(575784001)(68736007)(55016002)(305945005)(256004)(5024004)(14444005)(316002)(186003)(8936002)(486006)(99286004)(476003); DIR:OUT; SFP:1102; SCL:1; SRVR:TY1PR01MB1231; H:TY1PR01MB1692.jpnprd01.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: aj.MitsubishiElectric.co.jp does not designate permitted sender hosts) x-microsoft-antispam-message-info: s0vD0bOZPZR6Jh2CwnfJGBrCPiet1HA0Rs+GC7RfcbgajFGrxc6vJ503l+DNbQYYFY6PxEnJ+Ik9hHN0QgCeYkTzHyKwV0a/64sfIoDjT5LfRSZeSxINwmcQyf/LyOCGTz+uDApmXdewwy+juNnSsuvjHk2n+ACSesBf4UOs3g/yECJNZWZyhb+lXx+++G2NShDVGs6U8WU4qUcRPTO1TcgwtGb9cmwPVCHrOJNcMWE0e+ZrXaIOvkeFhWbqJHfzeH3rbFZPz4ieA7CV0MJ0NPPrTW+f/fwHdSuGu4pcOMM4E8GahMdGSicwHLG1CHLGKJ4qAhEKcNF4oE6Cndb1gE3UPWP6/AsjTgQExmDka5c= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aj.MitsubishiElectric.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: eedacdee-2cd9-48ae-ebab-08d60da96090 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2018 12:17:22.6257 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: c5a75b62-4bff-4c96-a720-6621ce9978e5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1PR01MB1231 Subject: [LTSI-dev] [PATCH 05/54] tracing: Remove code which merges duplicates X-BeenThere: ltsi-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "A list to discuss patches, development, and other things related to the LTSI project" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ltsi-dev-bounces@lists.linuxfoundation.org Errors-To: ltsi-dev-bounces@lists.linuxfoundation.org X-Virus-Scanned: ClamAV using ClamSMTP We now have the logic to detect and remove duplicates in the tracing_map hash table. The code which merges duplicates in the histogram is redundant now. So, modify this code just to detect duplicates. The duplication detection code is still kept to ensure that any rare race condition which might cause duplicates does not go unnoticed. Link: http://lkml.kernel.org/r/55215cf59e2674391bdaf772fdafc4c393352b03.1516069914.git.tom.zanussi@linux.intel.com Signed-off-by: Vedang Patel Signed-off-by: Tom Zanussi Signed-off-by: Steven Rostedt (VMware) (cherry picked from commit c193707dde77ace92a649cd59a17e105e2fbeaef) Signed-off-by: Hirotaka MOTAI --- kernel/trace/trace_events_hist.c | 11 ----- kernel/trace/tracing_map.c | 83 +++----------------------------- kernel/trace/tracing_map.h | 7 --- 3 files changed, 6 insertions(+), 95 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 1e1558c9..712260e7 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -335,37 +335,26 @@ static int hist_trigger_elt_comm_alloc(struct tracing_map_elt *elt) return -ENOMEM; break; } } return 0; } -static void hist_trigger_elt_comm_copy(struct tracing_map_elt *to, - struct tracing_map_elt *from) -{ - char *comm_from = from->private_data; - char *comm_to = to->private_data; - - if (comm_from) - memcpy(comm_to, comm_from, TASK_COMM_LEN + 1); -} - static void hist_trigger_elt_comm_init(struct tracing_map_elt *elt) { char *comm = elt->private_data; if (comm) save_comm(comm, current); } static const struct tracing_map_ops hist_trigger_elt_comm_ops = { .elt_alloc = hist_trigger_elt_comm_alloc, - .elt_copy = hist_trigger_elt_comm_copy, .elt_free = hist_trigger_elt_comm_free, .elt_init = hist_trigger_elt_comm_init, }; static void destroy_hist_field(struct hist_field *hist_field, unsigned int level) { unsigned int i; diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c index 305039b1..8d9feee5 100644 --- a/kernel/trace/tracing_map.c +++ b/kernel/trace/tracing_map.c @@ -810,109 +810,41 @@ create_sort_entry(void *key, struct tracing_map_elt *elt) return NULL; sort_entry->key = key; sort_entry->elt = elt; return sort_entry; } -static struct tracing_map_elt *copy_elt(struct tracing_map_elt *elt) -{ - struct tracing_map_elt *dup_elt; - unsigned int i; - - dup_elt = tracing_map_elt_alloc(elt->map); - if (IS_ERR(dup_elt)) - return NULL; - - if (elt->map->ops && elt->map->ops->elt_copy) - elt->map->ops->elt_copy(dup_elt, elt); - - dup_elt->private_data = elt->private_data; - memcpy(dup_elt->key, elt->key, elt->map->key_size); - - for (i = 0; i < elt->map->n_fields; i++) { - atomic64_set(&dup_elt->fields[i].sum, - atomic64_read(&elt->fields[i].sum)); - dup_elt->fields[i].cmp_fn = elt->fields[i].cmp_fn; - } - - return dup_elt; -} - -static int merge_dup(struct tracing_map_sort_entry **sort_entries, - unsigned int target, unsigned int dup) -{ - struct tracing_map_elt *target_elt, *elt; - bool first_dup = (target - dup) == 1; - int i; - - if (first_dup) { - elt = sort_entries[target]->elt; - target_elt = copy_elt(elt); - if (!target_elt) - return -ENOMEM; - sort_entries[target]->elt = target_elt; - sort_entries[target]->elt_copied = true; - } else - target_elt = sort_entries[target]->elt; - - elt = sort_entries[dup]->elt; - - for (i = 0; i < elt->map->n_fields; i++) - atomic64_add(atomic64_read(&elt->fields[i].sum), - &target_elt->fields[i].sum); - - sort_entries[dup]->dup = true; - - return 0; -} - -static int merge_dups(struct tracing_map_sort_entry **sort_entries, +static void detect_dups(struct tracing_map_sort_entry **sort_entries, int n_entries, unsigned int key_size) { unsigned int dups = 0, total_dups = 0; - int err, i, j; + int i; void *key; if (n_entries < 2) - return total_dups; + return; sort(sort_entries, n_entries, sizeof(struct tracing_map_sort_entry *), (int (*)(const void *, const void *))cmp_entries_dup, NULL); key = sort_entries[0]->key; for (i = 1; i < n_entries; i++) { if (!memcmp(sort_entries[i]->key, key, key_size)) { dups++; total_dups++; - err = merge_dup(sort_entries, i - dups, i); - if (err) - return err; continue; } key = sort_entries[i]->key; dups = 0; } - if (!total_dups) - return total_dups; - - for (i = 0, j = 0; i < n_entries; i++) { - if (!sort_entries[i]->dup) { - sort_entries[j] = sort_entries[i]; - if (j++ != i) - sort_entries[i] = NULL; - } else { - destroy_sort_entry(sort_entries[i]); - sort_entries[i] = NULL; - } - } - - return total_dups; + WARN_ONCE(total_dups > 0, + "Duplicates detected: %d\n", total_dups); } static bool is_key(struct tracing_map *map, unsigned int field_idx) { unsigned int i; for (i = 0; i < map->n_keys; i++) if (map->key_idx[i] == field_idx) @@ -1028,20 +960,17 @@ int tracing_map_sort_entries(struct tracing_map *map, goto free; } if (n_entries == 1) { *sort_entries = entries; return 1; } - ret = merge_dups(entries, n_entries, map->key_size); - if (ret < 0) - goto free; - n_entries -= ret; + detect_dups(entries, n_entries, map->key_size); if (is_key(map, sort_keys[0].field_idx)) cmp_entries_fn = cmp_entries_key; else cmp_entries_fn = cmp_entries_sum; set_sort_key(map, &sort_keys[0]); diff --git a/kernel/trace/tracing_map.h b/kernel/trace/tracing_map.h index ab0ca773..0de50bbc 100644 --- a/kernel/trace/tracing_map.h +++ b/kernel/trace/tracing_map.h @@ -210,36 +210,29 @@ struct tracing_map { * * @elt_alloc: When a tracing_map_elt is allocated, this function, if * defined, will be called and gives clients the opportunity to * allocate additional data and attach it to the element * (tracing_map_elt->private_data is meant for that purpose). * Element allocation occurs before tracing begins, when the * tracing_map_init() call is made by client code. * - * @elt_copy: At certain points in the lifetime of an element, it may - * need to be copied. The copy should include a copy of the - * client-allocated data, which can be copied into the 'to' - * element from the 'from' element. - * * @elt_free: When a tracing_map_elt is freed, this function is called * and allows client-allocated per-element data to be freed. * * @elt_clear: This callback allows per-element client-defined data to * be cleared, if applicable. * * @elt_init: This callback allows per-element client-defined data to * be initialized when used i.e. when the element is actually * claimed by tracing_map_insert() in the context of the map * insertion. */ struct tracing_map_ops { int (*elt_alloc)(struct tracing_map_elt *elt); - void (*elt_copy)(struct tracing_map_elt *to, - struct tracing_map_elt *from); void (*elt_free)(struct tracing_map_elt *elt); void (*elt_clear)(struct tracing_map_elt *elt); void (*elt_init)(struct tracing_map_elt *elt); }; extern struct tracing_map * tracing_map_create(unsigned int map_bits, unsigned int key_size,