JakeRoggenbuck / auto-clock-speed

A utility to check stats about your CPU, and auto regulate clock speeds to help with either performance or battery life.
https://autoclockspeed.org
MIT License
37 stars 9 forks source link

Daemon Hooking #353

Closed Camerooooon closed 2 years ago

JakeRoggenbuck commented 2 years ago

Yay! very well done!

Camerooooon commented 2 years ago

The solution that I decided to use was to replace most of the references to the Daemon with references to an Arc<Mutex<Daemon>> which is what I would say is a "wrapper struct" that "surrounds" the daemon. This struct controls which thread is allowed to read and write to the object (in this case the daemon). A thread can request to read/write data by performing a "lock" on the data which basically says to whatever thread is requesting the data that it needs to wait for the main thread to stop using the data (in this case if the main thread is utilizing the data the socket thread will wait for the request to finish before proceeding thereby holding up the socket thread which is not a problem since our acs client can be patient).

Camerooooon commented 2 years ago

I've implemented the command listening and parsing. You can now use socat to broadcast 0|test hello following the protocol outlines.

Camerooooon commented 2 years ago

Ok, this PR is almost complete. It needs a LOT of reviews there are so many situations where it can break and it's quite unstable.

Shuzhengz commented 2 years ago

its still a draft pr cant review

Camerooooon commented 2 years ago

I'm going to make acs monit broadcast and listen for the hello packet before merge.

Camerooooon commented 2 years ago

We can add more packets in later prs. Also I need to add more error handling.

JakeRoggenbuck commented 2 years ago

Sounds good, great work!

JakeRoggenbuck commented 2 years ago

I see;

Arc is a smart pointer that let's you safely share a value between multiple threads.
Mutex is a wrapper over another type, which allows safe mutability across threads. - Piotr Sarnacki
JakeRoggenbuck commented 2 years ago

So basically, remove the run method from daemon, replace it with a run function that accepts a safe mutable version of the daemon. That's cool

JakeRoggenbuck commented 2 years ago

This looks very close to being done, if not already done. Anything else you think would be good to add?

Camerooooon commented 2 years ago

This looks very close to being done, if not already done. Anything else you think would be good to add?

It needs to be stabilized lots of unhandled exceptions.

Camerooooon commented 2 years ago

Almost done, just fixed a major bug!

Camerooooon commented 2 years ago

Looks like we are go for review @JakeRoggenbuck and @Shuzhengz! The daemon hooking is working, please re-review then merge this!

JakeRoggenbuck commented 2 years ago

Looks like we are go for review @JakeRoggenbuck and @Shuzhengz! The daemon hooking is working, please re-review then merge this!

Awesome!

JakeRoggenbuck commented 2 years ago

What is a good way to test the sending to the socket?

Camerooooon commented 2 years ago

Cargo monit attempts to send the hello packet. It will then print out the response to std out ( you will need to scroll up because it gets pushed away by the TUI ) you can test by reading that response. Additionally you can use socat to manually attach to the sock and send packets yourself.

JakeRoggenbuck commented 2 years ago

Tested, everything seems good.