“e7e7e0c084ef862d5754701108d4a038514d6314”上不存在“kernel/git@gitcode.net:openharmony/kernel_linux.git”
提交 fb37f137 编写于 作者: A Alexandre Bailon 提交者: Greg Kroah-Hartman

greybus: loopback: Fix averaging

Currently, we are adding 0.5 to the average to round the average.
But we are using the remainder to calculate the decimal, so we do not
need to round the average.
In addition, use a u64 type for the remainder to avoid overflow
that might happen when stats->sum value is too big,
usually for requests per seconds and the throughput.
Signed-off-by: NAlexandre Bailon <abailon@baylibre.com>
Reviewed-by: NJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@google.com>
上级 ab81bb9c
...@@ -157,14 +157,15 @@ static ssize_t name##_avg_show(struct device *dev, \ ...@@ -157,14 +157,15 @@ static ssize_t name##_avg_show(struct device *dev, \
{ \ { \
struct gb_loopback_stats *stats; \ struct gb_loopback_stats *stats; \
struct gb_loopback *gb; \ struct gb_loopback *gb; \
u64 avg; \ u64 avg, rem; \
u32 count, rem; \ u32 count; \
gb = dev_get_drvdata(dev); \ gb = dev_get_drvdata(dev); \
stats = &gb->name; \ stats = &gb->name; \
count = stats->count ? stats->count : 1; \ count = stats->count ? stats->count : 1; \
avg = stats->sum + count / 2; /* round closest */ \ avg = stats->sum; \
rem = do_div(avg, count); \ rem = do_div(avg, count); \
return sprintf(buf, "%llu.%06u\n", avg, 1000000 * rem / count); \ rem = 1000000 * rem / count; \
return sprintf(buf, "%llu.%06u\n", avg, (u32)rem); \
} \ } \
static DEVICE_ATTR_RO(name##_avg) static DEVICE_ATTR_RO(name##_avg)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册