perfect function doesn’t exis- 👇

@nixCraft

my Ryzen 7750X:
is_computer_on(); // 1

a cache corrupting i7 14700k:
is_computer_on(); // 153

@nixCraft not really perfect if it has undefined behavior
@GromBeestje @nixCraft It's critically important to run this in a separate process to HCF()!
@GromBeestje @nixCraft This should also cover the temperature inside a supernova, so we are safe on that side ;)
@GromBeestje @nixCraft wish I’d had access to this before I had to read a whole book to find out https://mitpress.mit.edu/9780262539739/your-computer-is-on-fire/
Your Computer Is on Fire

This book sounds an alarm: after decades of being lulled into complacency by narratives of technological utopianism and neutrality, people are waking up to t...

MIT Press
@GromBeestje @nixCraft reminds me of the old "lp0 on fire" error in some older Unixes

@peter, it's still there in (at least) current Linux.

On a status check, “lp0 on fire” (for appropriate values of 0) may be logged; on opening the device file, “lp0 printer error” will be logged instead given the same error condition. It's specific to an error condition reported via the 8255 status port.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/lp.c?id=6a0e38264012809afa24113ee2162dc07f4ed22b#n264

lp.c « char « drivers - kernel/git/torvalds/linux.git - Linux kernel source tree

@GromBeestje @nixCraft

This is a true masterwork of wrongness.

@GromBeestje @nixCraft

Okay, I just googled it and it's real. I don't know whether to be delighted or horrified.

@GromBeestje @nixCraft

Also (and sorry for the monologuing), I once witnessed a demo of the original dual-processor BeBox where the presenter showed how to turn off one or the other of the cores from the settings interface. He then turned off both of the cores, and it did exactly what you'd expect. While the computer rebooted, he segued on to how robust the filesystem was.

So, on reflection, this seems pretty on-brand for them.

@suetanvil @GromBeestje @nixCraft I was kind of sad when I was told that they later on removed that feature from BeOS
@suetanvil @nixCraft I recall reading these function were there to test the performance of userland-kernel calls.

@GromBeestje @nixCraft

That makes sense. My idle speculation was that they were there as the entry points to the hardware or kernel equivalents of debugging printfs, FWIW.

@nixCraft
Its the first thing you should check before starting your program logic.
@nixCraft It's like a halting problem reborn.

@nixCraft

int32 is_computer_on ()
{
return 1;
}

@DenOfEarth @nixCraft probably going to need some __attribute__((noinline)) or equivalent on that
@nixCraft @Flux average libc function
@nixCraft You can’t get more Schrödinger than that.
@nixCraft use this instead of "true" for better code obfuscation
@nixCraft Absolute pig of a function to implement on a virtual machine that can be migrated

@ElectronDance @nixCraft

"DEVICE NUMBER GRATER" ???

@arose62 @nixCraft shredding device numbers was illegal, it had to be stopped

@nixCraft
I ran this function here. It returned a number that seemed a memory address. I checked the address and there was a string there: "I am."

What does this mean? What does this mean???

@nixCraft function Is_Computer_On return Boolean;

@nixCraft

It's a perfectly decent function... just a *partial* function, i.e., not defined on all its inputs.

Perfectly decent thing to be.

https://en.wikipedia.org/wiki/Partial_function

Partial function - Wikipedia

@nixCraft int32 vorallendingen… 🤦
@nixCraft was the image description made by OCR? the function name reads "18_computer_on" instead of "is_computer_on"

@nixCraft

If the computer isn't on, the value returned by this function is undefined.

goddamnit undefined behavior has gone too far

@nixCraft It's not much use without the companion functions

well_turn_it_on_then() and

sheesh_why_do_I_have_to_think_of_everything_myself_around_here()

@WesternInfidels @nixCraft it definitely needs an is_computer_plugged_in() extension
@nixCraft Schrödinger's computer: it might be on, it might be off, you'll never know until you call this function
@nixCraft I'm reminded of the vital opcodes for power saving in CPUs
TPF turn processor off
TPO turn processor on
Random Number

xkcd
@whynothugo @nixCraft I hate it when the software updates with a new random number
@nixCraft sounds like a recipe for a secure memory leak issue to me 😛

@nixCraft This is from the BeOS manual. As I recall, there is also an is_computer_on_fire() function, though I believe it always returned false in shipping versions.

EDIT: I forgot how silly the second one is. It's defined to return the temperature if the computer is on fire and some other value if not.

@nixCraft I hope there will be a native version for 64 bit architectures anytime soon.

@nixCraft a close runner-up for "perfect function" from BeOS.

It’d be better if it returned a boolean.

@nixCraft
bool is_computer();

// returns true if executed on a computer
// never returns when not executed on a computer

PS.: <pre> tag when, Mastodon?

@nixCraft It was a joke API, but that was secondary to it being a do-nothing syscall, useful for measuring system call overhead.

#BeOS

@nixCraft
The good old "lp0 on fire" error dating back to ancient times of yore is still a thing. And yes, it can still be thrown when the 8255 kicks an INTR-A.

It's in lp_check_status(), which is very much in the hot code path for local printing.

@nixCraft what's perfect about this!? An off computer can clearly read a 1 in some cases?!?!/s
@nixCraft Is there a nodejs module with this?
@nixCraft bios function was better: this was defined to return 0 if there was no power; you could prove this with a logic probe

@nixCraft

I'm not sure a function is sufficient, this requires at least a library, if not a bloated trendy framework.

@nixCraft uhhh, undefined means it could return 1, so you can’t even guarantee that a return value of 1 means that the computer is on.

Software is hard.

@dashrb @nixCraft

It can be... but hardware is harder. It's right there in the name.

@nixCraft
😂
I guess it could be useful for intermittent computing (e.g., https://cmuabstract.github.io/intermittence_tutorial/)
Intermittent Computing

MICRO 2018 tutorial.

Getting Started with Intermittent Computing
@nixCraft
I suppose it could be a valid test for a remote target.