more useful string

and task accounting
This commit is contained in:
2023-10-26 10:22:54 +02:00
parent b8c2b64bbb
commit 88186e39fd
4 changed files with 38 additions and 17 deletions

View File

@@ -4,6 +4,7 @@
#include <cstddef>
#include "LockGuard.hpp"
#include "String.hpp"
#include "TestTemplates.hpp"
#include "globals.hpp"
#include "kmem.hpp"
@@ -57,25 +58,26 @@ void ktask() {
}
void freeprinter() {
char buf[69];
while (1) {
all_tty_putstr("=====\n");
itoa(get_free() * 1024, buf, 10);
all_tty_putstr("Free mem: ");
all_tty_putstr(buf);
write_serial('\n');
String buf;
buf += "=====\n";
buf += "Free mem: ";
buf += get_free() * 1024;
buf += "\n";
all_tty_putstr(buf.c_str());
buf = "";
itoa(get_heap_allocated(), buf, 10);
all_tty_putstr("Heap allocated: ");
all_tty_putstr(buf);
write_serial('\n');
itoa(get_heap_used(), buf, 10);
all_tty_putstr("Heap used: ");
all_tty_putstr(buf);
write_serial('\n');
all_tty_putstr("=====\n");
buf += "Heap allocated: ";
buf += get_heap_allocated();
buf += "\n";
all_tty_putstr(buf.c_str());
buf = "";
buf += "Heap used: ";
buf += get_heap_used();
buf += "\n";
buf += "=====\n";
all_tty_putstr(buf.c_str());
sleep_self(1000000);
}
}
@@ -163,7 +165,7 @@ void ktask_main() {
void dummy_task() {
for (;;) {
__asm__ __volatile__("hlt");
yield_self();
}
}

View File

@@ -26,6 +26,9 @@ void sanity_check_frame(struct task_frame *cur_frame) {
assert2((cur_frame->ss == GDTSEL(gdt_data) || cur_frame->ss == GDTSEL(gdt_data_user)), "SS wrong!");
}
std::atomic<uint64_t> max_pid = 0;
Spinlock AllTasks_lock;
SkipList<uint64_t, Task *> AllTasks;
List<Task *>::Node *RunningTask;
@@ -86,6 +89,7 @@ struct Task *new_ktask(void (*fn)(), const char *name) {
newt->addressSpace = KERN_AddressSpace;
newt->state = TS_RUNNING;
newt->mode = TASKMODE_KERN;
newt->pid = max_pid.fetch_add(1);
sanity_check_frame(&newt->frame);
@@ -95,6 +99,11 @@ struct Task *new_ktask(void (*fn)(), const char *name) {
LockGuard l(NextTasks_lock);
NextTasks.emplace_front(new_node);
}
{
LockGuard l(AllTasks_lock);
AllTasks.add(newt->pid, newt);
}
return newt;
}

View File

@@ -24,6 +24,7 @@ enum TaskState {
struct Task {
struct task_frame frame;
uint64_t pid;
struct AddressSpace *addressSpace;
uint64_t *stack;
char *fxsave;

View File

@@ -58,6 +58,15 @@ public:
return *this;
}
String &operator+=(int value) {
char buf[20];
itoa(value, buf, 10);
*this += buf;
return *this;
}
const char *c_str() {
return data;
}