These metrics are not really requiring CPU cycles and as those are meanlingless when the CPU is running at a different frequency, this can use ktime_get() and achieve the same result.
Part of a larger effort to confine get_cycles() access to low level architecture code. Signed-off-by: Thomas Gleixner <[email protected]> Cc: Bernie Thompson <[email protected]> Cc: [email protected] --- Documentation/fb/udlfb.rst | 4 ++-- drivers/video/fbdev/udlfb.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) --- a/Documentation/fb/udlfb.rst +++ b/Documentation/fb/udlfb.rst @@ -156,8 +156,8 @@ metrics_bytes_sent 32-bit count of how USB to communicate the resulting changed pixels to the hardware. Includes compression and protocol overhead -metrics_cpu_kcycles_used 32-bit count of CPU cycles used in processing the - above pixels (in thousands of cycles). +metrics_cpu_kcycles_used 32-bit count of microseconds used in processing the + above pixels metrics_reset Write-only. Any write to this file resets all metrics above to zero. Note that the 32-bit counters above --- a/drivers/video/fbdev/udlfb.c +++ b/drivers/video/fbdev/udlfb.c @@ -24,6 +24,7 @@ #include <linux/slab.h> #include <linux/delay.h> #include <linux/unaligned.h> +#include <linux/timekeeping.h> #include <video/udlfb.h> #include "edid.h" @@ -600,15 +601,15 @@ static int dlfb_render_hline(struct dlfb static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, int height) { + ktime_t t_start, t_delta; int i, ret; char *cmd; - cycles_t start_cycles, end_cycles; int bytes_sent = 0; int bytes_identical = 0; struct urb *urb; int aligned_x; - start_cycles = get_cycles(); + t_start = ktime_get(); mutex_lock(&dlfb->render_mutex); @@ -661,10 +662,9 @@ static int dlfb_handle_damage(struct dlf atomic_add(bytes_sent, &dlfb->bytes_sent); atomic_add(bytes_identical, &dlfb->bytes_identical); atomic_add(width*height*2, &dlfb->bytes_rendered); - end_cycles = get_cycles(); - atomic_add(((unsigned int) ((end_cycles - start_cycles) - >> 10)), /* Kcycles */ - &dlfb->cpu_kcycles_used); + t_delta = ktime_get() - t_start; + /* Avoid a division and approximate microseconds with shift right ten */ + atomic_add(((int)(t_delta >> 10)), &dlfb->cpu_kcycles_used); ret = 0; @@ -727,9 +727,9 @@ static void dlfb_dpy_deferred_io(struct { struct fb_deferred_io_pageref *pageref; struct dlfb_data *dlfb = info->par; + ktime_t t_start, t_delta; struct urb *urb; char *cmd; - cycles_t start_cycles, end_cycles; int bytes_sent = 0; int bytes_identical = 0; int bytes_rendered = 0; @@ -742,7 +742,7 @@ static void dlfb_dpy_deferred_io(struct if (!atomic_read(&dlfb->usb_active)) goto unlock_ret; - start_cycles = get_cycles(); + t_start = ktime_get(); urb = dlfb_get_urb(dlfb); if (!urb) @@ -774,10 +774,10 @@ static void dlfb_dpy_deferred_io(struct atomic_add(bytes_sent, &dlfb->bytes_sent); atomic_add(bytes_identical, &dlfb->bytes_identical); atomic_add(bytes_rendered, &dlfb->bytes_rendered); - end_cycles = get_cycles(); - atomic_add(((unsigned int) ((end_cycles - start_cycles) - >> 10)), /* Kcycles */ - &dlfb->cpu_kcycles_used); + t_delta = ktime_get() - t_start; + /* Avoid a division and approximate microseconds with shift right ten */ + atomic_add(((int)(t_delta >> 10)), &dlfb->cpu_kcycles_used); + unlock_ret: mutex_unlock(&dlfb->render_mutex); }

