Skip to content

Commit f2358cb

Browse files
committed
solo5: Wait for next timer in event loop
1 parent 5014cc7 commit f2358cb

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/platform/x86_solo5/os.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,38 @@ void OS::start(const char* cmdline)
142142

143143
void OS::event_loop()
144144
{
145-
while (power_) {
146-
int rc;
147-
145+
while (power_)
146+
{
148147
// add a global symbol here so we can quickly discard
149148
// event loop from stack sampling
150149
asm volatile(
151150
".global _irq_cb_return_location;\n"
152151
"_irq_cb_return_location:" );
153152

154-
// XXX: temporarily ALWAYS sleep for 0.5 ms. We should ideally ask Timers
155-
// for the next immediate timer to fire (the first from the "scheduled" list
156-
// of timers?)
157-
rc = solo5_yield(solo5_clock_monotonic() + 500000ULL); // now + 0.5 ms
153+
int res = 0;
154+
auto nxt = Timers::next();
155+
if (nxt == std::chrono::nanoseconds(0))
156+
{
157+
// no next timer, just wait a while
158+
res = solo5_yield(solo5_clock_monotonic() + 500000000ULL); // 500 ms
159+
//printf("Waiting, next is indeterminate...\n");
160+
}
161+
else if (nxt == std::chrono::nanoseconds(1))
162+
{
163+
// there is an imminent or activated timer, don't wait
164+
//printf("Not waiting, imminent timer...\n");
165+
}
166+
else
167+
{
168+
res = solo5_yield(solo5_clock_monotonic() + nxt.count());
169+
//printf("Waiting %llu nanos\n", nxt.count());
170+
}
171+
172+
// handle any activated timers
158173
Timers::timers_handler();
159-
if (rc) {
174+
if (res != 0)
175+
{
176+
// handle any network traffic
160177
for(auto& nic : hw::Devices::devices<hw::Nic>()) {
161178
nic->poll();
162179
break;

test/fs/integration/virtio_block/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ project (test_virtioblk)
1010

1111
set(SERVICE_NAME "VirtioBlk test")
1212
set(BINARY "virtioblk")
13-
set(MAX_MEM 128)
1413
set(SOURCES
1514
service.cpp
1615
)
1716

18-
set(DRIVERS virtioblk)
17+
set(DRIVERS virtioblk solo5blk)
1918

2019
include($ENV{INCLUDEOS_PREFIX}/includeos/post.service.cmake)

0 commit comments

Comments
 (0)