| @@ -847,67 +847,15 @@ create_sort_entry(void *key, struct tracing_map_elt *elt) · 846 unmodified lines |
| 847 | 847 | return sort_entry; |
| 848 | 848 | } |
| 849 | 849 | |
| 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, |
| 903 | 851 | int n_entries, unsigned int key_size) |
| 904 | 852 | { |
| 905 | 853 | unsigned int dups = 0, total_dups = 0; |
| 906 | | − int err, i, j; |
| 854 | + int i; |
| 907 | 855 | void *key; |
| 908 | 856 | |
| 909 | 857 | if (n_entries < 2) |
| 910 | | − return total_dups; |
| 858 | + return; |
| 911 | 859 | |
| 912 | 860 | sort(sort_entries, n_entries, sizeof(struct tracing_map_sort_entry *), |
| 913 | 861 | (int (*)(const void *, const void *))cmp_entries_dup, NULL); |
| @@ -916,30 +864,14 @@ static int merge_dups(struct tracing_map_sort_entry **sort_entries, · 2 unmodified lines |
| 916 | 864 | for (i = 1; i < n_entries; i++) { |
| 917 | 865 | if (!memcmp(sort_entries[i]->key, key, key_size)) { |
| 918 | 866 | dups++; total_dups++; |
| 919 | | − err = merge_dup(sort_entries, i - dups, i); |
| 920 | | − if (err) |
| 921 | | − return err; |
| 922 | 867 | continue; |
| 923 | 868 | } |
| 924 | 869 | key = sort_entries[i]->key; |
| 925 | 870 | dups = 0; |
| 926 | 871 | } |
| 927 | 872 | |
| 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); |
| 943 | 875 | } |
| 944 | 876 | |
| 945 | 877 | 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, · 119 unmodified lines |
| 1065 | 997 | return 1; |
| 1066 | 998 | } |
| 1067 | 999 | |
| 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); |
| 1072 | 1001 | |
| 1073 | 1002 | if (is_key(map, sort_keys[0].field_idx)) |
| 1074 | 1003 | cmp_entries_fn = cmp_entries_key; |