greybus: loopback: use separate attribute macro for average
authorAlex Elder <elder@linaro.org>
Mon, 3 Aug 2015 17:57:18 +0000 (12:57 -0500)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 4 Aug 2015 03:12:50 +0000 (20:12 -0700)
Define a separate macro for displaying the average of the samples
collected.  This will be used so we can calculate the average only
when requested, rather than every time a new value gets recorded.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/loopback.c

index 6afacdba619f26770996db960e5b227a912ee07c..432eeabe963b626288a61eb19c0870a7643548cc 100644 (file)
@@ -100,10 +100,21 @@ static ssize_t name##_##field##_show(struct device *dev,          \
 }                                                                      \
 static DEVICE_ATTR_RO(name##_##field)
 
+#define gb_loopback_ro_avg_attr(name)                                  \
+static ssize_t name##_avg_show(struct device *dev,                     \
+                           struct device_attribute *attr,              \
+                           char *buf)                                  \
+{                                                                      \
+       struct gb_connection *connection = to_gb_connection(dev);       \
+       struct gb_loopback *gb = connection->private;                   \
+       return sprintf(buf, "%llu\n", gb->name.avg);                    \
+}                                                                      \
+static DEVICE_ATTR_RO(name##_avg)
+
 #define gb_loopback_stats_attrs(field)                                 \
        gb_loopback_ro_stats_attr(field, min, u);                       \
        gb_loopback_ro_stats_attr(field, max, u);                       \
-       gb_loopback_ro_stats_attr(field, avg, llu);
+       gb_loopback_ro_avg_attr(field);
 
 #define gb_loopback_attr(field, type)                                  \
 static ssize_t field##_show(struct device *dev,                                \