Skip to content

Commit 1ccb02b

Browse files
bootstrap::xorg: fix deadlocks
* Vm::handle_page_fault: lock IRQ since threads share the same VM and can be a case where the lock is held and a reschedule interrupt occured. * syscall::time: For monotonic, currently just return the realtime value (in-order to make Xorg function). * Pipe::write_at: lock IRQ * Pipe::poll: initial implmentation and lock IRQ there aswell * epoll: remove unused import * time: `REALTIME_CLOCK` lock IRQ * xorg: use poll instead of epoll for now * xorg: compile with debug symbols fun! :^) Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 4cb7066 commit 1ccb02b

File tree

8 files changed

+51
-30
lines changed

8 files changed

+51
-30
lines changed

bootstrap/xorg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ packages:
669669
- '--disable-glamor'
670670
- '--disable-glx'
671671
environ:
672-
CFLAGS: '-Wno-error=array-bounds -O2 -pipe'
672+
CFLAGS: '-Wno-error=array-bounds -O0 -g -pipe'
673673
build:
674674
- args: ['make', '-j@PARALLELISM@']
675675
- args: ['make', 'install-strip']

patches/xorg-server/0001-xserver-aero-specific-changes.patch

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 3d08eb0ba228adf632f38c0c8f6476c1d0342386 Mon Sep 17 00:00:00 2001
1+
From 6a1cb57184179a2971bedd477fa71f30bbac6a09 Mon Sep 17 00:00:00 2001
22
From: Andy-Python-Programmer <[email protected]>
33
Date: Thu, 30 Jun 2022 11:10:21 +1000
44
Subject: [PATCH] xserver: aero specific changes
@@ -20,8 +20,9 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
2020
include/os.h | 1 +
2121
mi/mibitblt.c | 2 ++
2222
os/access.c | 2 +-
23+
os/ospoll.c | 2 ++
2324
os/utils.c | 6 ++--
24-
16 files changed, 50 insertions(+), 20 deletions(-)
25+
17 files changed, 52 insertions(+), 20 deletions(-)
2526

2627
diff --git a/.gitignore b/.gitignore
2728
index dc56b46..81d9886 100644
@@ -327,6 +328,24 @@ index 9724616..81befe3 100644
327328
#include <sys/utsname.h>
328329
#endif
329330
#if defined(SYSV) && defined(__i386__)
331+
diff --git a/os/ospoll.c b/os/ospoll.c
332+
index c68aabc..19006c3 100644
333+
--- a/os/ospoll.c
334+
+++ b/os/ospoll.c
335+
@@ -45,11 +45,13 @@
336+
#define HAVE_OSPOLL 1
337+
#endif
338+
339+
+#if 0
340+
#if !HAVE_OSPOLL && defined(HAVE_EPOLL_CREATE1)
341+
#include <sys/epoll.h>
342+
#define EPOLL 1
343+
#define HAVE_OSPOLL 1
344+
#endif
345+
+#endif
346+
347+
#if !HAVE_OSPOLL
348+
#include "xserver_poll.h"
330349
diff --git a/os/utils.c b/os/utils.c
331350
index 2ba1c80..ffa961f 100644
332351
--- a/os/utils.c

src/aero_kernel/src/fs/epoll.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use aero_syscall::SyscallError;
2323
use alloc::sync::Arc;
2424
use hashbrown::HashMap;
2525

26-
use crate::fs::cache::DirCacheImpl;
2726
use crate::userland::scheduler;
2827
use crate::utils::sync::Mutex;
2928

src/aero_kernel/src/fs/pipe.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use alloc::{sync::Arc, vec::Vec};
55

66
use crate::utils::sync::{BlockQueue, Mutex};
77

8-
use super::inode::INodeInterface;
8+
use super::inode::{INodeInterface, PollFlags, PollTable};
99

1010
struct Buffer {
1111
data: Vec<u8>,
@@ -82,9 +82,10 @@ impl INodeInterface for Pipe {
8282
fn close(&self, flags: OpenFlags) {
8383
// Write end of the pipe:
8484
if flags.contains(OpenFlags::O_WRONLY) {
85-
let active_writers = (self.num_writers.fetch_sub(1, Ordering::SeqCst) - 1) == 0;
85+
let active_writers = self.num_writers.fetch_sub(1, Ordering::SeqCst) - 1;
86+
8687
// There are no active writers and no data to read (reached EOF).
87-
if active_writers {
88+
if active_writers == 0 {
8889
self.readers.notify_complete();
8990
}
9091
}
@@ -106,9 +107,24 @@ impl INodeInterface for Pipe {
106107
}
107108

108109
fn write_at(&self, offset: usize, buf: &[u8]) -> super::Result<usize> {
109-
let res = offset + self.queue.lock().write_data(buf);
110+
let res = offset + self.queue.lock_irq().write_data(buf);
110111
self.readers.notify_complete();
111112

112113
Ok(res)
113114
}
115+
116+
fn poll(&self, table: Option<&mut PollTable>) -> super::Result<PollFlags> {
117+
table.map(|e| {
118+
e.insert(&self.readers);
119+
e.insert(&self.writers)
120+
});
121+
122+
let mut flags = PollFlags::OUT;
123+
124+
if self.queue.lock_irq().has_data() {
125+
flags |= PollFlags::IN;
126+
}
127+
128+
Ok(flags)
129+
}
114130
}

src/aero_kernel/src/syscall/fs.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -589,24 +589,6 @@ pub fn poll(
589589
return Ok(n);
590590
}
591591

592-
'search: loop {
593-
// Wait till one of the file descriptor deliever an event.
594-
scheduler::get_scheduler().inner.await_io()?;
595-
596-
for (handle, index) in refds.iter() {
597-
let pollfd = &mut fds[*index];
598-
let ready: PollEventFlags = handle.inode().poll(None)?.into();
599-
600-
if ready.contains(pollfd.events) {
601-
// The event is ready; break out of the search loop and set ready
602-
// events to 1.
603-
pollfd.revents = ready & pollfd.events;
604-
n = 1;
605-
break 'search;
606-
}
607-
}
608-
}
609-
610592
// Restore the orignal signal mask.
611593
signals.set_mask(SigProcMask::Set, Some(old_mask), None);
612594
Ok(n)

src/aero_kernel/src/syscall/time.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ pub fn gettime(clock: usize, timespec: &mut TimeSpec) -> Result<usize, SyscallEr
4747
}
4848

4949
CLOCK_TYPE_MONOTONIC => {
50-
log::debug!("monotonic");
50+
// FIXME: implement
51+
let clock = crate::time::get_realtime_clock();
52+
53+
timespec.tv_sec = clock.tv_sec;
54+
timespec.tv_nsec = clock.tv_nsec;
55+
5156
Ok(0x00)
5257
}
5358

src/aero_kernel/src/time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn get_uptime_ticks() -> usize {
5353
}
5454

5555
pub fn get_realtime_clock() -> TimeSpec {
56-
REALTIME_CLOCK.lock().clone()
56+
REALTIME_CLOCK.lock_irq().clone()
5757
}
5858

5959
/// Returns the current amount of PIT ticks.
@@ -94,7 +94,7 @@ fn pit_irq_handler(_stack: &mut InterruptStack) {
9494
tv_nsec: (1000000000 / PIT_FREQUENCY_HZ) as isize,
9595
};
9696

97-
let mut this = REALTIME_CLOCK.lock();
97+
let mut this = REALTIME_CLOCK.lock_irq();
9898

9999
if this.tv_nsec + interval.tv_nsec > 999999999 {
100100
let diff = (this.tv_nsec + interval.tv_nsec) - 1000000000;

src/aero_kernel/src/userland/vm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ impl Vm {
11491149
accessed_address: VirtAddr,
11501150
) -> bool {
11511151
self.inner
1152-
.lock()
1152+
.lock_irq()
11531153
.handle_page_fault(reason, accessed_address)
11541154
}
11551155

0 commit comments

Comments
 (0)