Skip to content

Commit 2e14940

Browse files
authored
Merge pull request #1434 from fwsGonzo/dev
Kernel timer and backtrace improvements
2 parents 8d03d99 + ff11096 commit 2e14940

8 files changed

Lines changed: 44 additions & 32 deletions

File tree

lib/uplink/starbase/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(SOURCES
4141
set(DRIVERS
4242
virtionet
4343
vmxnet3
44+
vga_output
4445
)
4546

4647
set(PLUGINS

lib/uplink/starbase/service.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@
2727

2828
void Service::start(const std::string&)
2929
{
30-
MYINFO("booted");
31-
32-
// Print some useful netstats every 30 secs
33-
Timers::periodic(5s, 30s, [] (uint32_t) {
34-
auto& inet = net::Inet4::stack();
35-
MYINFO("TCP STATUS:\n%s\n", inet.tcp().status().c_str());
36-
});
37-
30+
MYINFO("Running CPUID...");
3831
auto detected_features = CPUID::detect_features_str();
3932

4033
MYINFO("Detected %lu CPU features:", detected_features.size());

src/kernel/elf.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,17 @@ void print_backtrace()
285285
PRINT_TRACE(8, ra);
286286
if (frp(9, ra)) {
287287
PRINT_TRACE(9, ra);
288-
}}}}}}}}}}
288+
if (frp(10, ra)) {
289+
PRINT_TRACE(10, ra);
290+
if (frp(11, ra)) {
291+
PRINT_TRACE(11, ra);
292+
if (frp(12, ra)) {
293+
PRINT_TRACE(12, ra);
294+
if (frp(13, ra)) {
295+
PRINT_TRACE(13, ra);
296+
if (frp(14, ra)) {
297+
PRINT_TRACE(14, ra);
298+
}}}}}}}}}}}}}}}
289299
}
290300

291301
void Elf::print_info()

src/kernel/events.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void Events::process_events()
108108
#ifdef DEBUG_SMP
109109
SMP::global_lock();
110110
if (intr != 0)
111-
printf("[%p] Calling handler for intr=%u irq=%u cpu %d\n",
112-
get_cpu_esp(), IRQ_BASE + intr, intr, SMP::cpu_id());
111+
printf("[cpu%d] Calling handler for intr=%u irq=%u\n",
112+
SMP::cpu_id(), IRQ_BASE + intr, intr);
113113
SMP::global_unlock();
114114
#endif
115115
callbacks[intr]();

src/kernel/timers.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <kernel/timers.hpp>
22

33
#include <kernel/os.hpp>
4+
#include <kernel/events.hpp>
45
#include <service>
56
#include <smp>
67
#include <statman>
@@ -58,6 +59,7 @@ struct alignas(SMP_ALIGN) timer_system
5859
{
5960
bool is_running = false;
6061
uint32_t dead_timers = 0;
62+
int interrupt = 0;
6163
Timers::start_func_t arch_start_func;
6264
Timers::stop_func_t arch_stop_func;
6365
std::vector<SystemTimer> timers;
@@ -79,6 +81,8 @@ static inline timer_system& get() {
7981
void Timers::init(const start_func_t& start, const stop_func_t& stop)
8082
{
8183
auto& system = get();
84+
// event for processing timers
85+
system.interrupt = Events::get().subscribe(&Timers::timers_handler);
8286
// architecture specific start and stop functions
8387
system.arch_start_func = start;
8488
system.arch_stop_func = stop;
@@ -88,6 +92,7 @@ void Timers::init(const start_func_t& start, const stop_func_t& stop)
8892
system.oneshot_stopped = (int64_t*) &Statman::get().create(Stat::UINT64, CPU + ".timers.oneshot_stopped").get_uint64();
8993
system.periodic_started = &Statman::get().create(Stat::UINT32, CPU + ".timers.periodic_started").get_uint32();
9094
system.periodic_stopped = &Statman::get().create(Stat::UINT32, CPU + ".timers.periodic_stopped").get_uint32();
95+
9196
}
9297

9398
bool Timers::is_ready()
@@ -283,11 +288,12 @@ static void sched_timer(duration_t when, Timers::id_t id)
283288

284289
// if the hardware timer is not running, try starting it
285290
if (UNLIKELY(system.is_running == false)) {
286-
Timers::timers_handler();
291+
Events::get().trigger_event(system.interrupt);
287292
return;
288293
}
289294
// if the scheduled timer is the new front, restart timer
290295
auto it = system.scheduled.begin();
291-
if (it->second == id)
292-
Timers::timers_handler();
296+
if (it->second == id) {
297+
Events::get().trigger_event(system.interrupt);
298+
}
293299
}

src/net/tcp/connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ void Connection::close() {
269269

270270
void Connection::receive_disconnect() {
271271
Expects(read_request and read_request->buffer.buffer());
272-
auto& buf = read_request->buffer;
273272

274273
if(read_request->callback) {
275274
// TODO: consider adding back when SACK is complete
275+
//auto& buf = read_request->buffer;
276276
//if (buf.size() > 0 && buf.missing() == 0)
277277
// read_request->callback(buf.buffer(), buf.size());
278278
}

src/platform/x86_pc/block.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ extern "C" uint32_t os_get_highest_blocking_level() {
3838
* A quick and dirty implementation of blocking calls, which simply halts,
3939
* then calls the event loop, then returns.
4040
**/
41-
void OS::block(){
42-
41+
void OS::block()
42+
{
4343
// Initialize stats
4444
if (not blocking_level) {
4545
blocking_level = &Statman::get()
@@ -60,10 +60,13 @@ void OS::block(){
6060
if (*blocking_level > *highest_blocking_level)
6161
*highest_blocking_level = *blocking_level;
6262

63+
// Process immediate events
64+
Events::get().process_events();
65+
6366
// Await next interrupt
6467
OS::halt();
6568

66-
// Process callbacks
69+
// Process events (again?)
6770
Events::get().process_events();
6871

6972
// Decrement level

test/kernel/integration/block/service.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,25 @@
1717

1818
#include <os>
1919
#include <timers>
20+
using namespace std::chrono;
2021

2122
extern "C" uint32_t os_get_blocking_level();
2223
extern "C" uint32_t os_get_highest_blocking_level();
2324

24-
void sleep(int i){
25-
static Timers::id_t timer{};
26-
27-
if (not timer)
28-
timer = Timers::oneshot(std::chrono::seconds(i), [](auto){
29-
INFO("Timer", "Ticked");
30-
timer = 0;
31-
Expects(os_get_blocking_level() == 1);
32-
});
33-
34-
while (timer) {
25+
static void msleep(int micros)
26+
{
27+
bool ticked = false;
28+
Timers::oneshot(microseconds(micros),
29+
[&ticked] (int) {
30+
INFO("Timer", "Ticked");
31+
ticked = true;
32+
Expects(os_get_blocking_level() == 1);
33+
});
34+
35+
while (ticked == false) {
3536
OS::block();
3637
Expects(os_get_blocking_level() == 0);
3738
}
38-
39-
INFO("Test", " Done");
4039
}
4140

4241
void Service::start()
@@ -50,7 +49,7 @@ void Service::ready()
5049

5150
int n = 10;
5251
for (int i = 0; i < n; i++) {
53-
sleep(1);
52+
msleep(1000000);
5453
sleeps++;
5554
printf("Sleep %i/%i \n", sleeps, n);
5655
if (sleeps == 10)

0 commit comments

Comments
 (0)