How to programmatically find out if computer is on
haiku-os.org
haiku-os.org
I've been using this for years to wake hosts at home when I'm abroad. It's invaluable.
As far as I'm concerned ME-equipped NICs should unconditionally be behind VPNs, but the AMT functionality itself is really cool. Even the 10+ year old machines that don't support VNC let you remotely hit CTRL+ALT+DEL, issue an ACPI shutdown, perform a hard reset (equivalent to hitting the reset button on 486-era boxen), etc. So basically you can do either soft or hard shutdowns or reboots. Quite granular.
I actually used the hard-reset functionality while playing around with Linux early boot on a laptop a few years ago. Rebuild initramfs (loaded via PXE), use `curl` to hit AMT reset endpoint. Very cool.
Lately this has been my biggest barrier to leaving a computer fully remote.
I kneejerk-recommend a bastion host because a) Intel ME, and b) there was that all-0 password bypass a while back and uhhh yeah who knows what other "sneeze correctly and the leaf falls over" knock sequences there are.
SSH port forwarding, VPN, RPi running the remote-access AMT web UI thingy (runs on Linux, forget what it's called) behind nginx with authentication... you get the idea.
I wonder if that could be implemented solely by the motherboard. After all, it could supply a small amount of power to the NIC while shutdown and embed a minimal NIC driver to monitor incoming packets without the need for the NIC to do the monitoring itself.
If the motherboard would embed a simplistic NIC/WoL driver then you could have WoL on any NIC, with the motherboard acting like any client. I suppose that would mean using the PCI lane and stuff to communicate with the NIC though which may defeat the purpose of a dedicated low power interface.
https://en.wikipedia.org/wiki/PCI_Express#Pinout
The main difference is that WAKE# signal only restores power to the system but it does not change the system's power state, after using it the card needs to send an interrupt to the motherboard to properly wake it up. Power button does both things.
however, an ATX PSU supplies only 5V (5Vsb) when the system is off (S5) which is not available on the PCIe connector which only has 12V and 3.3V. so when the system is off (S5), the PCIe cards are unpowered and thus cannot turn the system on.
but if you mean off in the Microsoft "Modern Standby" (S0i) then yes, the PCIe cards are powered and the WAKE# pin can "turn on" the system.
[1] https://github.com/haiku/haiku/commit/ccaac177f64038c160de6f...
Of course, one important trick here is that no matter how fast your system call is, not making a system call is just faster. io_uring is an example, as are futexes. So it's worth spending more effort on figuring out tricks to avoid doing the system call than exploiting tricks to shave a cycle or two off the time taken to execute one.
And different programs have different speed requirements.
Imagine putting a few of these in as a joke and then you take it out and your parallelized code doesn't work anymore.
Not sure how all that's handled on Haiku specifically.
Shouldn't it just block until the computer turns back on? Probably interferes with pthreads.
...What do you mean not every power supply manufacturer implements the power_on_computer() function as a NOOP if the computer is already on?!
How does this relate to computer being in Halt state, which is quite valid state for servers (there could be even a dedicated Halt button)? Technically computer hardware is ON. I remember that in such state it shows a "carrot" prompt (>>>) from the SRE console.
By the way, there is also HCF instruction (Halt and Catch Fire).
https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing...
In order for the code to execute anywhere, at least one core must be powered on and not halted. Also, I would consider a halted CPU to still be powered on.
Otherwise, the function's name has no relation to it's behavior and it's a buggy function on top of being a useless but amusing thought experiment.
I was somewhat recently scarred for life by this instruction, having just discovered that if you execute HCF on the MIPS-based integrated circuits in Stationeers, the simulated IC... explodes in your face.
(The platform is Alpha, right? Given the prompt and name for the console, though it was SRM, not SRE) :)
(Alpha) System Reference Manual:
https://en.wikipedia.org/wiki/System_Reference_Manual
Funny thing, for some historic reason, the system terminal attached to cabinet with those memorable Alpha Servers was of the monochrome lineage, but the phosphors color was orange. So the >>> prompt was unmistakably a carrot one! However it would rarely be seen, as bulk of the time the console would busily beep and boop with operator messages, as any respectful Alphas would be on 24/7/365 duty.
The only forced interruption I witnessed was when the attached storage controller froze. Literally. Someone left a window open in the server room, with -20C outdoors. So with all that circulation there was ICE accumulation on one side of storage controler cabinet. Apparently that put it beyond service temp range. Well, thawed it out - back to bizznizz, so to speak.
It that case, should've been is_system_iced() system call, it could've saved us the trip on such a freezing night. We would've just called HCF... briefly :)
Interestingly enough, there are few systems in Alpha lineage that have what's known as "external console", meaning that instead of running SRM on the normal CPUs, they had separate frontend processor and main cpus only had shims to communicate with it. Marvel was one of those, but apparently there were older ones as well.
Also, if you had partition-capable Alpha, the carrot prompt would be made into Pxx> where xx referred to currently selected cpu. With VMS, you could then boot into "VMS Galaxy" mode where you had multiple VMS systems running without hypervisor, just with all of them carefully avoiding stepping on each others' resources.
double
is_computer_on_fire(void)
{
return 0.63739;
}
https://github.com/haiku/haiku/blob/8f16317a5b6db5c672f33181... <html
onon="alert('Computer turned on!')"
onoff="alert('Computer turned off!')"
>I suppose it would.
So perhaps a biocomputer of sorts could be offline and return undefined behavior by spec. Guess we'll keep looking for that perfect OS code.
// power cycle computer
bool was_on = set_computer_on(true); // returns prior value
if (was_on) {
set_computer_on(false);
set_computer_on(true);
} else {
// was previously off, is now on: nothing to do!
}Better description would be:
Returns 1 if the computer is on. If the computer isn't on, the value returned by this function is not computable.
I'm sure some impurity "pragmatist" will try to argue you can make a perfectly good version of it as `Bool`. That kind of pragmatism is better ignored because it interferes with compiler optimization and standardization. As an example, you can look at the recent discussion around `==` and `/=`.
(And I just noticed some people may seriously argue that, so here comes the /s.)
It's like lazy evaluation, only more lazy.
So our security systems are (useless | perfect)!
I think there might even be other implications...
"I compute, therefore I am on"
I think the following always holds: isUserAGoat==!isComputerOn, in other words the user is a goat if and only if the computer is off.
Edit: I see the downvotes, yet i still don't know if it's a joke. I was genuinely asking the question.
(And please stop calling me lazy.)
The question is worth asking (all are) but then soliciting "quantum computing" as an answer makes it a doubly worthy set up line, so thanks twice.
(How could this work in theory? Maybe the computer has a separate watchdog controller board which allows the computer to be turned on and off remotely, and that controller acts as a proxy for the API request.)
turn_computer_off();
Assert(!is_computer_on(), "Computer should have been off but it's on.");
The opposite is a bit tricky, though.
Given a lump of silicon, how does one programmatically tell if it is a computer?
int32
is_computer_on(void)
{
return _kern_is_computer_on();
}
double
is_computer_on_fire(void)
{
return 0.63739;
}
[1] https://github.com/haiku/haiku/blob/master/src/system/libroo...Was used by the Haiku doc, namely "System calls"[2], as an example.
add a // TODO in v2: handle case if it never returns, or the process crashes, or caller times out waiting
https://github.com/haiku/haiku/blob/8f16317a5b6db5c672f33181...
But it could also refer to the material "metal" (or the collection name for bunch of materials really), whereas computers are commonly known for being made with a lot of silicon instead of metal.
Hopefully I didn't dissect too much of the frog to kill it.
> Returns the temperature of the motherboard if the computer is currently on fire. Smoldering doesn't count. If the computer isn't on fire, the function returns some other value.
https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing...
Interesting it seems to come from BeOS:
https://github.com/haiku/haiku/commit/bcf475ec65f1060c0a8abf...
where the same function had a hn thread about it already a couple years ago :D
Probably I'm being nerd sniped. https://xkcd.com/356/
Returns TRUE.