killing tasks
killing tasks
i'm using JamesM's code as a starting point, and implemented (what i thought) was a working kill_task() function. to cut a long story short, it didn't work.
I know how i would make one, but it just doesn't seem to work for me.
I tried to adapt the task_t struct so there was a link to the previous task in the linked list, and then alter this so that it skipped the current task (one being killed) in the scheduler. This resulted in my multitasking halting suddenly, and despite a whole lot of debugging, i never came to a conclusion as to why.
I also tried changing the EIP to zero, and checking for this in my switch_task() function. I thought this worked, but i guess not.
does anybody have a working implementation i could take a peek at?
I know how i would make one, but it just doesn't seem to work for me.
I tried to adapt the task_t struct so there was a link to the previous task in the linked list, and then alter this so that it skipped the current task (one being killed) in the scheduler. This resulted in my multitasking halting suddenly, and despite a whole lot of debugging, i never came to a conclusion as to why.
I also tried changing the EIP to zero, and checking for this in my switch_task() function. I thought this worked, but i guess not.
does anybody have a working implementation i could take a peek at?
I can spare some code:
Code: Select all
/* uint32 sched(uint32 esp)
* Called by the timer IRQ0 handler,
* returns the stack of the next task */
uint32 sched(uint32 esp)
{
AtomicIncrement(&timer_ticks); // Increment tick count
if (sched_active == 0) // Is multitasking enabled?
return esp; // Scheduler turned off
tasks[current_pid].stack = esp; // Save old esp
switch_pid(); // Find next pid
if (tasks[current_pid].state) // Is task still running?
{
tasks[current_pid].spins++;
return tasks[current_pid].stack;
}
else // No active tasks
{
return esp; // Don't switch - no active tasks
}
}
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
If you mean an exit() function, here's mine (using JamesM's tutorials):
-JL
Code: Select all
int exit()
{
// We are modifying kernel structures, and so cannot interrupt
asm volatile("cli");
// Set up some basic task structs
task_t *task_d = 0;
task_t *task_r = (task_t*)ready_queue;
//task_r is already initalized
//While the next task is not NULL (end of Linked List)
//Set test_r to the next task
for(;task_r->next!=0;task_r=task_r->next)
{
if(task_r->next == current_task)
task_d=task_r; // Now we have the previous task
}
if(!task_d) //Make sure that the above worked
return -1;
task_d->next = current_task->next; //Remove current_task from the list
kfree(current_task); //Free up the memory
switch_task(); //We must update the scheduler, or current_task will run for a bit more
asm volatile("sti"); //Restart interrupts
return 0;
}
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- jerryleecooper
- Member
- Posts: 233
- Joined: Mon Aug 06, 2007 6:32 pm
- Location: Canada
I diodn't read the whole thread sorry it makes my head spin fast.
What I use myself, as an exit function, it just set a flag in the process struct saying that is it to be removed, and immediately there's an infinite loop. THe scheduler takes care of removing the process. It's not optimal, no? But's easy, really easy. a lot easier than doing the same and issuing an interrupt immediately for the scheduler switching process.
Simplicity is better than economizing a few cycles, I think. If you really want to get your few cycles, do a syscall to your scheduler.
What I use myself, as an exit function, it just set a flag in the process struct saying that is it to be removed, and immediately there's an infinite loop. THe scheduler takes care of removing the process. It's not optimal, no? But's easy, really easy. a lot easier than doing the same and issuing an interrupt immediately for the scheduler switching process.
Simplicity is better than economizing a few cycles, I think. If you really want to get your few cycles, do a syscall to your scheduler.
- jerryleecooper
- Member
- Posts: 233
- Joined: Mon Aug 06, 2007 6:32 pm
- Location: Canada
The scheduler itself doesn't do anything with interrupts, ignoring processes that are marked as slepping or thoses that are waiting. removing the processes marked as remove. It then select the next process to run in the list, beggining in the beginning when it reach the last one, the famous idle process. What it does when it has selected the process to run is to set 2 global variables. and when the handler() function that is called each time an interrupt fires returns, set the tss accordingly, and the asm code sets the stack from one of the global variable.
But these info I just gave are probably redundant since some of you are well over the step of implementing a multitasker.
I don't know of any other method to switch processes.
But these info I just gave are probably redundant since some of you are well over the step of implementing a multitasker.
I don't know of any other method to switch processes.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
JamesM: I'm talking about code within the kernel. If the kill() function is within the kernel and an interrupt comes in as a system call, you can still call the reschedule function and have it do whatever it has to.
When I said "it still requires an interrupt to switch" I mean that it still depends on an interrupt firing to switch tasks, which is a nuisance IMHO.
When I said "it still requires an interrupt to switch" I mean that it still depends on an interrupt firing to switch tasks, which is a nuisance IMHO.