Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU utilization close to 100% (single core) #63

Open
arunoruto opened this issue Dec 12, 2024 · 8 comments
Open

CPU utilization close to 100% (single core) #63

arunoruto opened this issue Dec 12, 2024 · 8 comments

Comments

@arunoruto
Copy link

arunoruto commented Dec 12, 2024

I recently noticed my framework laptop started kicking the fan on. I was wondering why that is, and it seems like that the touch detector is a bit resource hungry from time to time. It doesn't happen all the time, but sometimes I get the following utilization:

image

I am curious on why this is happening? Am I the only one experiencing this?
This is happening while using NixOS, and the service is started according to this configuration.

@maximbaz
Copy link
Owner

That's quite unfortunate! Does debug log reveal anything useful, such as which detector is seemingly running crazy? (most likely gpg one...).

Did you notice if it started since a particular update?

@arunoruto
Copy link
Author

That's quite unfortunate! Does debug log reveal anything useful, such as which detector is seemingly running crazy? (most likely gpg one...).

I can't consistently reproduce it... I enabled the verbose option, so next time it happens, I will have additional logs to show here!

Did you notice if it started since a particular update?

I started using it not so long ago, maybe a few weeks or two months tops, and this has been happening to me since the beginning, but it was also really inconsistent. This time it happened after I changed some things in my configuration and rebuilt NixOS, so it could be something system-specific.

@maximbaz
Copy link
Owner

OK let me know if you have any findings! For reference I also use it on NixOS using that same module :)

@arunoruto
Copy link
Author

I just booted my laptop up and my fans weren't spinning down. The logs sadly don't say much...

Jan 08 14:21:02 isshin systemd[2551]: Started Detects when your YubiKey is waiting for a touch.
Jan 08 14:21:02 isshin yubikey-touch-detector[2731]: time="2025-01-08T14:21:02+01:00" level=debug msg="Starting YubiKey touch detector"
Jan 08 14:21:02 isshin yubikey-touch-detector[2731]: time="2025-01-08T14:21:02+01:00" level=debug msg="HMAC watcher on '/dev' is successfully established"
Jan 08 14:21:02 isshin yubikey-touch-detector[2731]: time="2025-01-08T14:21:02+01:00" level=debug msg="U2F watcher on '/dev' is successfully established"
Jan 08 14:21:02 isshin yubikey-touch-detector[2731]: time="2025-01-08T14:21:02+01:00" level=debug msg="'/home/mirza/.gnupg/pubring.kbx' could not be found. Disabling GPG and SSH watchers.

@maximbaz
Copy link
Owner

maximbaz commented Jan 8, 2025

Hmm 🤔 And so if you restart it, then it won't be resource-hungry anymore? It's a bit slow to debug if you can only reproduce it once a month 😅 Interesting that you are not using gpg, I suppose it makes our lives a bit easier if we can cut half of the detector algorithms out... It sounds like it loops indefinitely, either in u2f or hmac.

Would you be interested in running a locally built version, with some extra logs, to try to narrow it down further?

For hmac, we could for example add some logs to see if it got out of this loop:

for _, device := range devices {

and whether it's not looping here by receiving an infinite amount of events:

for event := range devicesEvents {

For u2f we could similarly check if you are receiving an infinite amount of messages here:

_, err = device.Read(payload)

@arunoruto
Copy link
Author

Hmm 🤔 And so if you restart it, then it won't be resource-hungry anymore? It's a bit slow to debug if you can only reproduce it once a month 😅

I will try to make a small systemd service that checks if any process is at 100% for a long time and report it to me with some logs. And keep notice what I have done to reproduce it. I know that it doesn't have to be a yubikey, since I haven't used it once today... I have also enabled u2f to login into gnome using my yubikey, but I never use it for the initial login (because of keyring lock).

Interesting that you are not using gpg, I suppose it makes our lives a bit easier if we can cut half of the detector algorithms out... It sounds like it loops indefinitely, either in u2f or hmac.

Not a big gpg fan, I like to keep it a bit simple 😅

Would you be interested in running a locally built version, with some extra logs, to try to narrow it down further?

Sure thing, I can just copy the package definition from nixpkgs and provide a custom package to the service!

For hmac, we could for example add some logs to see if it got out of this loop:

for _, device := range devices {

and whether it's not looping here by receiving an infinite amount of events:

for event := range devicesEvents {

For u2f we could similarly check if you are receiving an infinite amount of messages here:

_, err = device.Read(payload)

I have never programmed go. Maybe I can use the opportunity to get myself into it a bit, but can't promise to have good/valid code 😂 And this isn't really time critical! Thanks for responding so fast!

@maximbaz
Copy link
Owner

maximbaz commented Jan 8, 2025

Thanks! And don't worry about quality of code, this is all just temporary for debugging anyway, just to understand what's going on. I pushed something on the debug-100cpu branch, feel free to just take the code from there, I suppose it will be a good start, and then feel free to add any additional logs as you want!

It might be spammy, but that's okay, the goal is to catch when the app uses 100% cpu, and then to see if it's silent, or if it constantly logs some identical message non-stop, that would be a very good signal for us.

main...debug-100cpu

@arunoruto
Copy link
Author

arunoruto commented Jan 9, 2025

Thanks! And don't worry about quality of code, this is all just temporary for debugging anyway, just to understand what's going on. I pushed something on the debug-100cpu branch, feel free to just take the code from there, I suppose it will be a good start, and then feel free to add any additional logs as you want!

It might be spammy, but that's okay, the goal is to catch when the app uses 100% cpu, and then to see if it's silent, or if it constantly logs some identical message non-stop, that would be a very good signal for us.

main...debug-100cpu

Thanks a lot for the branch!
I just made a PR to include a package option for the module (and move it to services, but that's beside the point). I let it run with the following config:

services = {
  yubikey-touch-detector = {
    enable = lib.mkDefault true;
    verbose = true;
    package = pkgs.unstable.yubikey-touch-detector.overrideAttrs (
      final: prev: {
        src = pkgs.fetchFromGitHub {
          owner = "maximbaz";
          repo = "yubikey-touch-detector";
          rev = "34fff8ba94f6c355f768b2e6ad5e61ac46ebe3a3";
          hash = "sha256-3b94Y5WQ7YyyuR/V4/ZR11/4Dv0kTY7wmCRcDR7P0Pc=";
        };
        vendorHash = "sha256-x8Fmhsk6MtgAtLxgH/V3KusM0BXAOaSU+2HULR5boJQ=";
      }
    );
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants