Skip to content

Commit c193707

Browse files
vedangpatel1rostedt
authored andcommitted
tracing: Remove code which merges duplicates
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 <vedang.patel@intel.com> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent cbf4100 commit c193707

File tree

3 files changed

+6
-95
lines changed

3 files changed

+6
-95
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,6 @@ static int hist_trigger_elt_comm_alloc(struct tracing_map_elt *elt)
340340
return 0;
341341
}
342342

343-
static void hist_trigger_elt_comm_copy(struct tracing_map_elt *to,
344-
struct tracing_map_elt *from)
345-
{
346-
char *comm_from = from->private_data;
347-
char *comm_to = to->private_data;
348-
349-
if (comm_from)
350-
memcpy(comm_to, comm_from, TASK_COMM_LEN + 1);
351-
}
352-
353343
static void hist_trigger_elt_comm_init(struct tracing_map_elt *elt)
354344
{
355345
char *comm = elt->private_data;
@@ -360,7 +350,6 @@ static void hist_trigger_elt_comm_init(struct tracing_map_elt *elt)
360350

361351
static const struct tracing_map_ops hist_trigger_elt_comm_ops = {
362352
.elt_alloc = hist_trigger_elt_comm_alloc,
363-
.elt_copy = hist_trigger_elt_comm_copy,
364353
.elt_free = hist_trigger_elt_comm_free,
365354
.elt_init = hist_trigger_elt_comm_init,
366355
};

kernel/trace/tracing_map.c

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -847,67 +847,15 @@ create_sort_entry(void *key, struct tracing_map_elt *elt)
847847
return sort_entry;
848848
}
849849

850-
static struct tracing_map_elt *copy_elt(struct tracing_map_elt *elt)
851-
{
852-
struct tracing_map_elt *dup_elt;
853-
unsigned int i;
854-
855-
dup_elt = tracing_map_elt_alloc(elt->map);
856-
if (IS_ERR(dup_elt))
857-
return NULL;
858-
859-
if (elt->map->ops && elt->map->ops->elt_copy)
860-
elt->map->ops->elt_copy(dup_elt, elt);
861-
862-
dup_elt->private_data = elt->private_data;
863-
memcpy(dup_elt->key, elt->key, elt->map->key_size);
864-
865-
for (i = 0; i < elt->map->n_fields; i++) {
866-
atomic64_set(&dup_elt->fields[i].sum,
867-
atomic64_read(&elt->fields[i].sum));
868-
dup_elt->fields[i].cmp_fn = elt->fields[i].cmp_fn;
869-
}
870-
871-
return dup_elt;
872-
}
873-
874-
static int merge_dup(struct tracing_map_sort_entry **sort_entries,
875-
unsigned int target, unsigned int dup)
876-
{
877-
struct tracing_map_elt *target_elt, *elt;
878-
bool first_dup = (target - dup) == 1;
879-
int i;
880-
881-
if (first_dup) {
882-
elt = sort_entries[target]->elt;
883-
target_elt = copy_elt(elt);
884-
if (!target_elt)
885-
return -ENOMEM;
886-
sort_entries[target]->elt = target_elt;
887-
sort_entries[target]->elt_copied = true;
888-
} else
889-
target_elt = sort_entries[target]->elt;
890-
891-
elt = sort_entries[dup]->elt;
892-
893-
for (i = 0; i < elt->map->n_fields; i++)
894-
atomic64_add(atomic64_read(&elt->fields[i].sum),
895-
&target_elt->fields[i].sum);
896-
897-
sort_entries[dup]->dup = true;
898-
899-
return 0;
900-
}
901-
902-
static int merge_dups(struct tracing_map_sort_entry **sort_entries,
850+
static void detect_dups(struct tracing_map_sort_entry **sort_entries,
903851
int n_entries, unsigned int key_size)
904852
{
905853
unsigned int dups = 0, total_dups = 0;
906-
int err, i, j;
854+
int i;
907855
void *key;
908856

909857
if (n_entries < 2)
910-
return total_dups;
858+
return;
911859

912860
sort(sort_entries, n_entries, sizeof(struct tracing_map_sort_entry *),
913861
(int (*)(const void *, const void *))cmp_entries_dup, NULL);
@@ -916,30 +864,14 @@ static int merge_dups(struct tracing_map_sort_entry **sort_entries,
916864
for (i = 1; i < n_entries; i++) {
917865
if (!memcmp(sort_entries[i]->key, key, key_size)) {
918866
dups++; total_dups++;
919-
err = merge_dup(sort_entries, i - dups, i);
920-
if (err)
921-
return err;
922867
continue;
923868
}
924869
key = sort_entries[i]->key;
925870
dups = 0;
926871
}
927872

928-
if (!total_dups)
929-
return total_dups;
930-
931-
for (i = 0, j = 0; i < n_entries; i++) {
932-
if (!sort_entries[i]->dup) {
933-
sort_entries[j] = sort_entries[i];
934-
if (j++ != i)
935-
sort_entries[i] = NULL;
936-
} else {
937-
destroy_sort_entry(sort_entries[i]);
938-
sort_entries[i] = NULL;
939-
}
940-
}
941-
942-
return total_dups;
873+
WARN_ONCE(total_dups > 0,
874+
"Duplicates detected: %d\n", total_dups);
943875
}
944876

945877
static bool is_key(struct tracing_map *map, unsigned int field_idx)
@@ -1065,10 +997,7 @@ int tracing_map_sort_entries(struct tracing_map *map,
1065997
return 1;
1066998
}
1067999

1068-
ret = merge_dups(entries, n_entries, map->key_size);
1069-
if (ret < 0)
1070-
goto free;
1071-
n_entries -= ret;
1000+
detect_dups(entries, n_entries, map->key_size);
10721001

10731002
if (is_key(map, sort_keys[0].field_idx))
10741003
cmp_entries_fn = cmp_entries_key;

kernel/trace/tracing_map.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,6 @@ struct tracing_map {
215215
* Element allocation occurs before tracing begins, when the
216216
* tracing_map_init() call is made by client code.
217217
*
218-
* @elt_copy: At certain points in the lifetime of an element, it may
219-
* need to be copied. The copy should include a copy of the
220-
* client-allocated data, which can be copied into the 'to'
221-
* element from the 'from' element.
222-
*
223218
* @elt_free: When a tracing_map_elt is freed, this function is called
224219
* and allows client-allocated per-element data to be freed.
225220
*
@@ -233,8 +228,6 @@ struct tracing_map {
233228
*/
234229
struct tracing_map_ops {
235230
int (*elt_alloc)(struct tracing_map_elt *elt);
236-
void (*elt_copy)(struct tracing_map_elt *to,
237-
struct tracing_map_elt *from);
238231
void (*elt_free)(struct tracing_map_elt *elt);
239232
void (*elt_clear)(struct tracing_map_elt *elt);
240233
void (*elt_init)(struct tracing_map_elt *elt);

0 commit comments

Comments
 (0)