Concept for you

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Kemp

Concept for you

Post by Kemp »

Ok, quick piece of background first so we're all on the same page as it were (note that sentences like "my OS has" are an easy way of saying "I've thought of an idea where may OS would have"). My OS has a message passing system (not pipes or anything yet) adapted from ideas in MMURTL where a program creates an exchange where messages will be sent to and it can either wait there for one to arrive or simply check (where the call returns even if there isn't a message there).

Ok, my idea. Basically, if a program is force-quit (eg, divides by zero, user request because it has locked up, whatever) then anything not saved is lost. My idea is for programs that want to be able to recover what the user is working on to have a thread that just creates an exchange, tells the OS about it and then sits on it waiting for a message. If the program is force-quit then all the program's threads except for that one are removed from the schedule queue and a message is sent to the remaining thread's exchange to tell it a force-quit is happening. From that point the thread gets an amount of time (say 5 seconds) to do an emergency save/dump of anything the program needs for it to be able to recover the work next time it is run (or to do anything else it needs to do before closing). Once the time is up the program is forcibly removed from memory and its resources are freed as normal (or sooner if the thread sends a completion message back [as it should do, 5 seconds is a long time]). If the cleanup thread does something bad like dividing by zero or whatever then it doesn't get another chance and the program is killed as it would be when the time is up.

Any thoughts/ideas/critisisms at all?
DruG5t0r3

Re:Concept for you

Post by DruG5t0r3 »

Actually I think this is something that already exists.

I think that if a process wants to support this, it should do a syscall to the kernel with the address of the function that it wants the kernel to call in case of a problem such as division by zero.
Kemp

Re:Concept for you

Post by Kemp »

Ah, good point, I can ignore the whole messaging thing by just supplying an address in the header. This is the reason I ask for input, much easier for other people to see your mistakes. Thanks for that one.

Ok, so if the program supplies the address (offset into code) of the code to deal with emergencies. That'd probably be easier to implement (on the OS side) but I dunno about the app writers. I'll have to give this more thought.

Any more input is welcome.
DruG5t0r3

Re:Concept for you

Post by DruG5t0r3 »

Actually...would be more complitated kernel-wise than user-wise.

Code: Select all

Some pseudo-code example:

#include <lib.h> // lib which has the recovery function in it

void main() {

failover(&function);

int blah = 5;
blah = blah / 0;
return;
}

void function() {

saveunsavedstuff();

return;
}
Kemp

Re:Concept for you

Post by Kemp »

Good point, but all the kernel has to do is store the offset somewhere when the program is loaded and when something bad happens it just sets a five second alarm and jumps there. One problem could be that an actual time based limit might not be fair because of time taken for interrupts, time slicing, etc, but 5 seconds is a hell of a long time really, it's not like they'll be writing to the graphics card or anything (they'd better not be wasting time doing that anyway).
DruG5t0r3

Re:Concept for you

Post by DruG5t0r3 »

Then give the process a clock cycles limit rather than a time limit.
Kemp

Re:Concept for you

Post by Kemp »

Could do, but then I have to have more code keeping track of cycles. The only problem I could see using a time method is if something else is really hogging the CPU. Of course I could just not set a limit and let it do whatever it needs to do. The problem then is if the programmer decides to take advantage by making it continue what it was doing before, or accidentally codes an infinite loop in there.

Or I could bump up the priority level of the thread, make it so that things can't hog CPU time away from it (or rather, they can grab a maximum of the same amount of time as it has).

Actually yeah, I think a combo of a time limit and priority evelation could work. I going to use preemptive multitasking, so it's at least guaranteed the same amount of time as anything else if it has a high priority even if the other processes don't give up the CPU themselves (or do something which makes them give it up, like waiting for IO).

</braindump>
DruG5t0r3

Re:Concept for you

Post by DruG5t0r3 »

Nah you got that wrong...a OS should calculate the amount of cpu time a process spent...wheter you implement that concept or not. For example, press CTRL+ALT+DEL under win 2k/xp and ect...in the process listing you'll see the amount of time a process spent getting executed on the cpu.

before switching to process
var = get_time();
switch_to_process(process_user);

return_from_process:
process_user->cputime += var + get_time();


I've never actually implemented this myself, but I means...sounds pretty easy and logical.
DruG5t0r3

Re:Concept for you

Post by DruG5t0r3 »

Actually...

process_user->cputime += get_time() - var;

Doesn't really matter much...but still :P
Kemp

Re:Concept for you

Post by Kemp »

Lol, yeah, I noticed that. Gonna think this over some more (though obviously input is still very welcome).
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Concept for you

Post by distantvoices »

You *do* know, where your towel is, don't you? *gg*

I think the idea with the emergency saving stuff is pretty fine. you can f. ex. send the faulting process a signal. If the process has registered the according signal handler, the signalling subsystem redirects the flow of operation to that handler which does what is necessary and performs a graceful quit. I also wouldn't impose any time limits on the emergency save stuff. Data is precious for the user, so give it time to save it. :-)
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Concept for you

Post by Solar »

Actually the standard header <signals.h> already implements most of it. You can e.g. register a signal handler for SIGSEGV which gets called on a segmentation violation (instead of the process being terminated).

And as any OS is free to define additional signals (and any application coder free to register handlers for them)... you're already more than halfway there.
Every good solution is obvious once you've found it.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Concept for you

Post by distantvoices »

there comes something into mind: isn't the c++ exception mechanism somewhat based upon signals and signal handlers? (like the div-zero signal raises a div-zero exception)
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Concept for you

Post by Solar »

beyond infinity wrote: isn't the c++ exception mechanism somewhat based upon signals and signal handlers? (like the div-zero signal raises a div-zero exception)
AFAIK there is no division-by-zero exception in C++. Signals are asynchronous (can happen any time, related to program activity or not - think SIGINT on Ctrl-C), while exceptions are synchronous (always directly related to some program action).
Every good solution is obvious once you've found it.
Kemp

Re:Concept for you

Post by Kemp »

Ok, this signals thing isn't something I'm familiar with, would I know it under a different name at all? Given your comments about it though I can pretty much piece together what it is and it does sound familiar (hmm... directly contradicting myself, it's the name I'm not sure of) and I can see how it would be implemented if my thoughts are right.

Would you do it something along the lines of the last revision of my cleanup idea, where the program makes a call (or has the info stored in the header, whichever) that tells the OS "if this thing happens then run the code at this address"?
Post Reply