Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Is there any tool for benchmarking responsiveness for Linux?
100 points by c0deR3D on Feb 4, 2022 | hide | past | favorite | 44 comments
System76 recently announced their responsiveness optimizer, System76 Scheduler [0], which basically works as a daemon, adjusting the nice value and the CFS knobs for processes in the box for increased responsiveness. They've claimed that the responsiveness is therefore increased, which I'm also believed so.

However, this got me wondering, is there exists any tool that can report the "numbers" (e.g., scheduling latency) regarding to the responsivenss? Maybe Google has such tool for testing regression for Android or Chrome OS, sadly, I didn't managed to find one.

Thanks!

[0] https://github.com/pop-os/system76-scheduler



In addition to what others have said:

- eBPF script: https://www.brendangregg.com/blog/2016-10-08/linux-bcc-runql...

- perf sched: https://www.brendangregg.com/blog/2017-03-16/perf-sched.html

- schedlat: https://tanelpoder.com/posts/schedlat-low-tech-script-for-me...

The last one (written by me) is using /proc/PID/schedstat pseudofile for monitoring % time spent in the CPU runqueue of a single process (not systemwide). I don't always have (root) access for running perf or eBPF scripts (or the old Linux/kernel version don't allow that). But I can still measure how much time a process on a request's critical path (like a RDBMS transaction log writer on commit) spent waiting to get back onto CPU before doing any work.

Like others have already said, the OS CPU queuing/scheduling latency is just one component contributing to the total responsiveness/reaction latency of your app.


For input device to screen measurement, high frame rate camera on your phone. Accuracy isn't the best, but what you measure is as real as it gets.


To me the question is how do you use that method to measure keyboard responsiveness? On the camera, you can't quite tell when the key was "supposed" to trigger. I've done these measurements by having a keypress toggle an LED on the keyboard (in firmware), but that glosses over the matrix scan (and potentially debouncing if you implement that wrong). All in all, I've never been fully satisfied there. Maybe you need a one-key keyboard that triggers the LED from an interrupt, and then handles the keypress normally. (Only one key, so no matrix. Triggers on the first edge, so no debounce latency.)


NVIDIA published LDAT[1] for click-to-photon latency measurements a while ago. The 'Intended' purpose was to measure input latency for gaming but it could probably be reused for measuring responsivity. This would implicitly also measure the hardware but that shouldn't matter when a constant hardware/driver combo is used.

[1]: https://www.nvidia.com/en-us/geforce/news/nvidia-reviewer-to...


AFAIK you'd have to have a pretty bad keyboard for it to have a significant role in latency. I guess specialized hardware (based on a microcontroller with built-in USB host support) wouldn't be too hard to construct if you really needed to know.

For the camera measurement, I would just press the key as fast as possible and pick about 3/4 of the way down as the trigger point.


> AFAIK you'd have to have a pretty bad keyboard for it to have a significant role in latency

https://danluu.com/keyboard-latency/ puts a lot of keyboards >= 30 ms which is an insane amount of latency


So if you check the appendix section, they say they're measuring latency not when the keyswitch makes contact, but when the finger first begins pressing on the key. So they're taking key travel time into account, and that ends up being the majority of the "latency".

It's a fair point for the gaming argument they make, if you want to jump 30ms quicker you'll need shorter keys. But it's not really correct to say the keyboard is adding so much latency when it's actually the user.


> So if you check the appendix section, they say they're measuring latency not when the keyswitch makes contact, but when the finger first begins pressing on the key. So they're taking key travel time into account, and that ends up being the majority of the "latency".

The key travel time on https://www.amazon.com/gp/product/B0000U1DJ2/ and https://www.amazon.com/gp/product/B00DGJALYW is substantially the same, yet one has 20 ms of latency, and the other 55 ms.


I built one! Arduino Leonardo and a light dependent transistor:

https://github.com/willmuldrew/lagmeter

(It attempts to do a few other things but it’s best for measuring keyboard event to screen update latency)


What about fpga which issues a (fake) ps2 keypressed signal and synchronous trigger (led in this case) for the camera?


Or use the caps lock key and have that reflected on screen.


Is the caps lock LED even implemented in hardware? I feel like I remember them not responding if my computer freezes but I could be wrong.


I can confirm the LED is not controlled by only keyboard firmware.

I very often use num lock and caps lock responsiveness to check if my PC has hard-locked, and I just recently suffered hard locks while testing S3 on Linux on a new PC. So I am very sure at this point :)


I only really suggested that because any OS can detect the presence of the CAPS LOCK key (see 'CAPS LOCK is on' during Windows login) and it would make a potentially good marker.


Caps lock doesn't magically skip the matrix scan.


Nothing on the keyboard does. I'm trying to suggest an alternative that already has visual feedback.


I believe the question is less about input latency than (as mentioned,) scheduling latency or the amount of time from when the scheduler marks a process as 'ready to execute' to the time it actually starts executing.

SchedLat (https://tanelpoder.com/posts/schedlat-low-tech-script-for-me...) is one tool/approach to doing this, but it's a bit out of date.


Not sure if it's relevant but I liked the approach of Pavel Fatin in measuring editor latency [0]. It uses OS level input events and actual rendering on screen. So testing the same editor/file with different settings might yield results that are different depending on your scheduling config, while staying close to a "real world" example. He shared [1] the tool he made for the tests.

I'd be curious to know your results regardless of the technique used.

[0] https://pavelfatin.com/typing-with-pleasure/ [1] https://github.com/pavelfatin/typometer


IIRC the Zen Linux kernel[0] is designed to be more responsive for desktop usage than the mainline Linux kernel. I wonder what metrics these tools would provide on the same exact system except with the 2 different kernels. (also see Liquorix patch set for additional patches on top of Zen[1])

[0] https://github.com/zen-kernel/zen-kernel

[1] https://liquorix.net/


Liquorix isn't the Zen kernel, but it's a set of patches on top of Linux, including Zen among others.

https://github.com/zen-kernel/zen-kernel


Thanks for the correction, updated the post


Anybody out there using this? Thinking of trying it on my older thinkpad.


I use it on my w530. It feels fast and responsive, but I haven't done a proper test or anything.

One of the good things it's that includes patches that allow Anbox to run so I can use Android apps.


The Anbox support is a big plus. Do you find it is actually fast enough for daily use of any android apps? I have one I use all the time on a tablet, but have not had luck getting a performant solution on my laptop.


I hear it doesn't yield considerable differences on beefier hardware, but you can tell the difference on older stuff. Thinkpad may benefit.

Note that Liqourix is not the Zen kernel though.


I'm using Pop!_OS, I dont know if I have the update installed or not. For me Pop!_OS is the best distro, since Fedora keeps bugging me out. I'm mostly a RHEL person.


I use Zen on a newer Thinkpad T14, but I feel there is a difference. Applications like Firefox and Intellij feel snappier than with the standard Kernel.


I use it on a "just works" Garuda install. No issues for it that i haven't experienced with standard Linux


https://wiki.linuxfoundation.org/realtime/documentation/howt...

This is the goto tool for measuring SCHED_FIFO (realtime) scheduling performance. If you really care about responsiveness in a broad sense (not just user/GUI), this is likely to play some role your testing process.


Con Kolivas (maintainer of BFS) had at one time some tools.



I wonder if Ben Heck's "Controller Monitor" [1] would help. It's a dedicated low-level (microcontroller-driven) high-speed input sampling/logging platform, with support for reading a light sensor which I believe is used to sense on-screen changes.

It has the advantage of using game console joypads as inputs, and hacking them to read the buttons etc directly, i.e. without relying on USB. I imagine a specialized version that just sampled a mouse button would be more useful in the context of a computer running desktop apps.

Apologies if I completely misunderstood the intent of this post.

[1] https://www.benheck.com/xbox1monitor/


Weird, the measurement scale they use does not jive with the scale of the knobs being tweaked. For example, `sched_cfs_bandwidth_slice_us` is adjusted by the project's `bandwidth_size` knob. The default is 5000 us, or 5 ms. But the knob they mention it being '5 us'. Same goes for scheduling latency-- its not `us`, its `ms`.

And afaik, the 'sauce' used in Liquorix is MuQSS, by Con Kolivas. But the project has been put on ice somewhat recently[0].

[0]https://ck-hack.blogspot.com/2021/08/514-and-future-of-muqss...


The linux-rt project has a variety of test programs for this:

https://wiki.linuxfoundation.org/realtime/documentation/howt...

But beware, "scheduling latency" has very little to do with responsiveness as it would appear to a user of some desktop environment.


I've used `cyclictest` for this before, it's a simple command line application that measures how long it takes to wake up and run a user space process in response to an interrupt. I've used it in the context of minimizing latency for network and audio applications. I'm not sure how much this relates to desktop application responsiveness as there are additional layers involved.


You're probably looking for sysprof: http://www.sysprof.com/


My major latency hangups are not around happy path input to response in a single app but around memory management across multiple apps including multiple browser hosted apps. Optimizing swap to occur AHEAD of the user's next task switch is an entirely unsolved problem.


That would be some tough things to measure.

How much can you slow down a cpu anyway? Can you slow it to 1/10th its clock speed? I would think the best way to measure things like this is to slow down the overall system speed as much as possible.


Yeah you can generally underclock a modern intel or amd chip down to 400MHz, but of course other bottlenecks (storage, RAM, networking) will be massively out of proportion


If the computer is slow enough under load, you can use wall clock to count many seconds it takes to start a program that needs to load many libs and data (LibreOffice, Firefox, Blender, GIMP).

You can also watch FPS of supertuxkart when the system is under load: https://www.youtube.com/watch?v=c5bAOJkX_uc https://github.com/hakavlad/le9-patch

But yes, we need a popular well behaved benchmark to measure desktop responsiveness.


Tracy? It's mostly used by game devs.


Consider also compiling a realtime configuration of the kernel with the periodic timer ticks.


I can recommend this one: https://apps.apple.com/de/app/is-it-snappy/id1219667593

Was mentioned on HN some time ago.


on L I N U X...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: