kernel-shark: Fixing the fix of ksmodel_shif_forward method()
PATCH 1/1 kernel-shark: Fixing the fix of ksmodel_shif_forward method()
As explaned in the change log of
e54616484 ("Do not copy the Upper Overflow bin when shifting forward"),
the lower edge of the Upper Overflow bin is unusual (shift + 1). Because of this, the content of the Upper Overflow bin cannot be copied, when shifting the visible area forward. It has to be recalculated instead. However, this is not enough to fix the bug. The last bin of the old histo cannot be copied as well. This is because its upper edge is shifted too (+1).
--- kernel-shark/src/libkshark-model.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
kernel-shark/src/libkshark-model.c +12 -5
@@ -488,23 +488,30 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)ksmodel_set_lower_edge (histo);/* -* Copy the the mapping indexes of all overlaping bins starting from -* bin "0" of the new histo. Note that the number of overlaping bins -* is histo->n_bins - n. * We will do a sanity check. ksmodel_set_lower_edge() sets map[0] * index of the new histo. This index should then be equal to map[n] * index of the old histo. */ assert (histo->map[0 ] == histo->map[n]); + +/* +* Copy the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. However, the last bin of the models is +* unusual. Its size has been increased by "1" in order make sure that +* the last entry of the dataset will fall into it (see the comment in +* ksmodel_set_next_bin_edge()). Because of this, we do not want to +* copy the very last bin of the old histo. We are going to recalculate +* its content instead. */ memmove (&histo->map[0 ], &histo->map[n], -sizeof (histo->map[0 ]) * (histo->n_bins - n)); +sizeof (histo->map[0 ]) * (histo->n_bins - n -1 ));/* * Calculate only the content of the new (non-overlapping) bins. * Start from the last copied bin and set the edge of each consecutive * bin. */ - bin = histo->n_bins - n -1 ; + bin = histo->n_bins - n -2 ;for (; bin < histo->n_bins; ++bin) {ksmodel_set_next_bin_edge (histo, bin, last_row);if (histo->map[bin +1 ] >0 )
Signature · 1 line
2.17.1
Quoted 45 lines · On Wed, 20 Feb 2019 11:16:10 +0200 Yordan Karadzhov <[email protected]>…
As explaned in the change log of
e54616484("Do not copy the Upper Overflow bin when shifting forward"),the lower edge of the Upper Overflow bin is unusual (shift + 1). Because of this, the content of the Upper Overflow bin cannot be copied, when shifting the visible area forward. It has to be recalculated instead. However, this is not enough to fix the bug. The last bin of the old histo cannot be copied as well. This is because its upper edge is shifted too (+1).
Reported-by Tzvetomir Stoyanov <[email protected]>Fixes e54616484 ("Do not copy the Upper Overflow bin when shifting forward")Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/libkshark-model.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)kernel-shark/src/libkshark-model.c +10
-3@@ -488,23 +488,30 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)ksmodel_set_lower_edge (histo);/* -* Copy the the mapping indexes of all overlaping bins starting from -* bin "0" of the new histo. Note that the number of overlaping bins -* is histo->n_bins - n. * We will do a sanity check. ksmodel_set_lower_edge() sets map[0] * index of the new histo. This index should then be equal to map[n] * index of the old histo. */ assert (histo->map[0 ] == histo->map[n]); + +/* +* Copy the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. However, the last bin of the models is +* unusual. Its size has been increased by "1" in order make sure that +* the last entry of the dataset will fall into it (see the comment in +* ksmodel_set_next_bin_edge()). Because of this, we do not want to +* copy the very last bin of the old histo. We are going to recalculate +* its content instead. */ memmove(&histo->map[0], &histo->map[n],
kernel-shark/src/libkshark-model.c void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n) · line 514
Quoted 10 lines
kernel-shark/src/libkshark-model.c +2
-2- sizeof(histo->map[0]) * (histo->n_bins - n)); + sizeof(histo->map[0]) * (histo->n_bins - n - 1));/* * Calculate only the content of the new (non-overlapping) bins. * Start from the last copied bin and set the edge of each consecutive * bin. */ - bin = histo->n_bins - n -1 ; + bin = histo->n_bins - n -2 ;
Is it possible that we could have histo->n_bins == n - 1?
-- Steve
Quoted 3 lines
kernel-shark/src/libkshark-model.c +0
-0for (; bin < histo->n_bins; ++bin) {ksmodel_set_next_bin_edge (histo, bin, last_row);if (histo->map[bin +1 ] >0 )
Quoted 51 lines · Steven Rostedt
Quoted 48 lines · On Wed, 20 Feb 2019 11:16:10 +0200 Yordan Karadzhov <[email protected]>…
As explaned in the change log of
e54616484("Do not copy the Upper Overflow bin when shifting forward"),the lower edge of the Upper Overflow bin is unusual (shift + 1). Because of this, the content of the Upper Overflow bin cannot be copied, when shifting the visible area forward. It has to be recalculated instead. However, this is not enough to fix the bug. The last bin of the old histo cannot be copied as well. This is because its upper edge is shifted too (+1).
Reported-by Tzvetomir Stoyanov <[email protected]>Fixes e54616484 ("Do not copy the Upper Overflow bin when shifting forward")Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/libkshark-model.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)kernel-shark/src/libkshark-model.c +11
-4@@ -488,23 +488,30 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)ksmodel_set_lower_edge (histo);/* -* Copy the the mapping indexes of all overlaping bins starting from -* bin "0" of the new histo. Note that the number of overlaping bins -* is histo->n_bins - n. * We will do a sanity check. ksmodel_set_lower_edge() sets map[0] * index of the new histo. This index should then be equal to map[n] * index of the old histo. */ assert (histo->map[0 ] == histo->map[n]); + +/* +* Copy the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. However, the last bin of the models is +* unusual. Its size has been increased by "1" in order make sure that +* the last entry of the dataset will fall into it (see the comment in +* ksmodel_set_next_bin_edge()). Because of this, we do not want to +* copy the very last bin of the old histo. We are going to recalculate +* its content instead. */ memmove (&histo->map[0 ], &histo->map[n], -sizeof (histo->map[0 ]) * (histo->n_bins - n)); +sizeof (histo->map[0 ]) * (histo->n_bins - n -1 ));
Quoted 9 lines
kernel-shark/src/libkshark-model.c void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n) · line 514
Quoted 7 lines
kernel-shark/src/libkshark-model.c +1
-1/* * Calculate only the content of the new (non-overlapping) bins. * Start from the last copied bin and set the edge of each consecutive * bin. */ - bin = histo->n_bins - n -1 ; + bin = histo->n_bins - n -2 ;Is it possible that we could have
histo->n_bins== n - 1?
This is not possible.
Several lines above in the code we have
if (n >= histo->n_bins) {
/*
* No overlap between the new and the old ranges. Recalculate
* all bins from scratch. First calculate the new range.
*/
ksmodel_set_bining(histo, histo->n_bins, histo->min,
histo->max);
ksmodel_fill(histo, histo->data, histo->data_size);
return;
}Thanks!
Yordan
Quoted 7 lines
-- Steve
Quoted 3 lines
kernel-shark/src/libkshark-model.c +0
-0for (; bin < histo->n_bins; ++bin) {ksmodel_set_next_bin_edge (histo, bin, last_row);if (histo->map[bin +1 ] >0 )
Quoted 52 lines · On Wed, 20 Feb 2019 17:29:34 +0200 "Yordan Karadzhov (VMware)"…
Quoted 51 lines · Steven Rostedt
Quoted 48 lines · On Wed, 20 Feb 2019 11:16:10 +0200 Yordan Karadzhov <[email protected]>…
As explaned in the change log of
e54616484("Do not copy the Upper Overflow bin when shifting forward"),the lower edge of the Upper Overflow bin is unusual (shift + 1). Because of this, the content of the Upper Overflow bin cannot be copied, when shifting the visible area forward. It has to be recalculated instead. However, this is not enough to fix the bug. The last bin of the old histo cannot be copied as well. This is because its upper edge is shifted too (+1).
Reported-by Tzvetomir Stoyanov <[email protected]>Fixes e54616484 ("Do not copy the Upper Overflow bin when shifting forward")Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/libkshark-model.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)kernel-shark/src/libkshark-model.c +11
-4@@ -488,23 +488,30 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)ksmodel_set_lower_edge (histo);/* -* Copy the the mapping indexes of all overlaping bins starting from -* bin "0" of the new histo. Note that the number of overlaping bins -* is histo->n_bins - n. * We will do a sanity check. ksmodel_set_lower_edge() sets map[0] * index of the new histo. This index should then be equal to map[n] * index of the old histo. */ assert (histo->map[0 ] == histo->map[n]); + +/* +* Copy the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. However, the last bin of the models is +* unusual. Its size has been increased by "1" in order make sure that +* the last entry of the dataset will fall into it (see the comment in +* ksmodel_set_next_bin_edge()). Because of this, we do not want to +* copy the very last bin of the old histo. We are going to recalculate +* its content instead. */ memmove (&histo->map[0 ], &histo->map[n], -sizeof (histo->map[0 ]) * (histo->n_bins - n)); +sizeof (histo->map[0 ]) * (histo->n_bins - n -1 ));
Quoted 9 lines
Quoted 9 lines
kernel-shark/src/libkshark-model.c void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n) · line 514
Quoted 7 lines
kernel-shark/src/libkshark-model.c +1
-1/* * Calculate only the content of the new (non-overlapping) bins. * Start from the last copied bin and set the edge of each consecutive * bin. */ - bin = histo->n_bins - n -1 ; + bin = histo->n_bins - n -2 ;Is it possible that we could have
histo->n_bins== n - 1?
Sorry, I meant n + 1.
histo->n_bins = 5, n = 4.
bin = (5) - (4) - 2 = -1.
-- Steve
Quoted 16 lines
This is not possible.
Several lines above in the code we haveif (n >= histo->n_bins) { /* * No overlap between the new and the old ranges. Recalculate * all bins from scratch. First calculate the new range. */ ksmodel_set_bining(histo, histo->n_bins, histo->min, histo->max); ksmodel_fill(histo, histo->data, histo->data_size); return; }
Quoted 65 lines · Steven Rostedt
Quoted 52 lines · On Wed, 20 Feb 2019 17:29:34 +0200 "Yordan Karadzhov (VMware)"…
Quoted 51 lines · Steven Rostedt
Quoted 48 lines · On Wed, 20 Feb 2019 11:16:10 +0200 Yordan Karadzhov <[email protected]>…
As explaned in the change log of
e54616484("Do not copy the Upper Overflow bin when shifting forward"),the lower edge of the Upper Overflow bin is unusual (shift + 1). Because of this, the content of the Upper Overflow bin cannot be copied, when shifting the visible area forward. It has to be recalculated instead. However, this is not enough to fix the bug. The last bin of the old histo cannot be copied as well. This is because its upper edge is shifted too (+1).
Reported-by Tzvetomir Stoyanov <[email protected]>Fixes e54616484 ("Do not copy the Upper Overflow bin when shifting forward")Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/libkshark-model.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)kernel-shark/src/libkshark-model.c +11
-4@@ -488,23 +488,30 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)ksmodel_set_lower_edge (histo);/* -* Copy the the mapping indexes of all overlaping bins starting from -* bin "0" of the new histo. Note that the number of overlaping bins -* is histo->n_bins - n. * We will do a sanity check. ksmodel_set_lower_edge() sets map[0] * index of the new histo. This index should then be equal to map[n] * index of the old histo. */ assert (histo->map[0 ] == histo->map[n]); + +/* +* Copy the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. However, the last bin of the models is +* unusual. Its size has been increased by "1" in order make sure that +* the last entry of the dataset will fall into it (see the comment in +* ksmodel_set_next_bin_edge()). Because of this, we do not want to +* copy the very last bin of the old histo. We are going to recalculate +* its content instead. */ memmove (&histo->map[0 ], &histo->map[n], -sizeof (histo->map[0 ]) * (histo->n_bins - n)); +sizeof (histo->map[0 ]) * (histo->n_bins - n -1 ));Quoted 9 lines
Quoted 9 lines
kernel-shark/src/libkshark-model.c void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n) · line 514
Quoted 7 lines
kernel-shark/src/libkshark-model.c +1
-1/* * Calculate only the content of the new (non-overlapping) bins. * Start from the last copied bin and set the edge of each consecutive * bin. */ - bin = histo->n_bins - n -1 ; + bin = histo->n_bins - n -2 ;Is it possible that we could have
histo->n_bins== n - 1?
Quoted 6 lines
Sorry, I meant n + 1.
histo->n_bins= 5, n = 4.bin = (5) - (4) - 2 = -1.
Hi Steven,
Sometimes I am just lucky ;)
I am glad that you found this mistake because in fact the whole patch is crap. I misinterpreted the symptoms of the problem, reported by Ceco. Alternative solution (patches) are coming.
Thanks a lot!
Yordan
Quoted 18 lines
-- Steve
Quoted 16 lines
This is not possible.
Several lines above in the code we haveif (n >= histo->n_bins) { /* * No overlap between the new and the old ranges. Recalculate * all bins from scratch. First calculate the new range. */ ksmodel_set_bining(histo, histo->n_bins, histo->min, histo->max); ksmodel_fill(histo, histo->data, histo->data_size); return; }