Skip to content

Commit 952bbeb

Browse files
publish v0.4.5
1 parent e16e3b7 commit 952bbeb

7 files changed

Lines changed: 155 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "arceos-msgqueue"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
edition = "2024"
55
authors = ["Lei Shi <shi_lei@massclouds.com>", "Yu Chen <yuchen@tsinghua.edu.cn>"]
66
description = "A message-queue crate (from crates.io) for ArceOS demonstrating cooperative multi-task scheduling with PFlash MMIO"
@@ -18,6 +18,7 @@ include = [
1818
"rust-toolchain.toml",
1919
"README.md",
2020
"LICENSE*",
21+
"exercise/**",
2122
]
2223

2324
[features]

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ cross-compilation and QEMU execution:
165165
| `paging` feature | Enables page table management; maps MMIO regions listed in config |
166166
| `multitask` feature | Enables multi-task scheduler with cooperative scheduling support |
167167

168+
## Exercise
169+
### Requirements
170+
Based on the `arceos-msgqueue` kernel component and the reference code under the `exercise` directory, implement a new kernel functional component for the memory allocator named `bump_allocator` (based on the `bump` memory allocation algorithm), as well as the corresponding kernel component `arceos-msgqueue-alt-alloc`. You are required to modify the implementation of the `exercise/modules/bump_allocator` component as much as possible to support the `bump` memory allocation algorithm, and modify other parts as little as possible.
171+
172+
### Expectation
173+
```
174+
Running bump tests...
175+
Bump tests run OK!
176+
```
177+
178+
### Tips
179+
1. You can refer to the existing page allocator and byte allocator to implement the corresponding Traits.
180+
2. This `bump_allocator` acts as both a byte allocator and a page allocator. Therefore, it must implement three Traits: `BaseAllocator`, `ByteAllocator`, and `PageAllocator` simultaneously. This is different from the existing references.
181+
182+
168183
## ArceOS Tutorial Crates
169184

170185
This crate is part of a series of tutorial crates for learning OS development with [ArceOS](https://github.com/arceos-org/arceos). The crates are organized by functionality and complexity progression:

exercise/modules/bump_allocator/Cargo.toml.orig

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#![no_std]
2+
3+
use allocator::{BaseAllocator, ByteAllocator, PageAllocator};
4+
5+
/// Early memory allocator
6+
/// Use it before formal bytes-allocator and pages-allocator can work!
7+
/// This is a double-end memory range:
8+
/// - Alloc bytes forward
9+
/// - Alloc pages backward
10+
///
11+
/// [ bytes-used | avail-area | pages-used ]
12+
/// | | --> <-- | |
13+
/// start b_pos p_pos end
14+
///
15+
/// For bytes area, 'count' records number of allocations.
16+
/// When it goes down to ZERO, free bytes-used area.
17+
/// For pages area, it will never be freed!
18+
///
19+
pub struct EarlyAllocator<const SIZE: usize> {}
20+
21+
impl<const SIZE: usize> EarlyAllocator<SIZE> {
22+
pub const fn new() -> Self {
23+
Self {}
24+
}
25+
}
26+
27+
impl<const SIZE: usize> BaseAllocator for EarlyAllocator<SIZE> {
28+
fn init(&mut self, start: usize, size: usize) {
29+
todo!()
30+
}
31+
32+
fn add_memory(&mut self, start: usize, size: usize) -> allocator::AllocResult {
33+
todo!()
34+
}
35+
}
36+
37+
impl<const SIZE: usize> ByteAllocator for EarlyAllocator<SIZE> {
38+
fn alloc(
39+
&mut self,
40+
layout: core::alloc::Layout,
41+
) -> allocator::AllocResult<core::ptr::NonNull<u8>> {
42+
todo!()
43+
}
44+
45+
fn dealloc(&mut self, pos: core::ptr::NonNull<u8>, layout: core::alloc::Layout) {
46+
todo!()
47+
}
48+
49+
fn total_bytes(&self) -> usize {
50+
todo!()
51+
}
52+
53+
fn used_bytes(&self) -> usize {
54+
todo!()
55+
}
56+
57+
fn available_bytes(&self) -> usize {
58+
todo!()
59+
}
60+
}
61+
62+
impl<const SIZE: usize> PageAllocator for EarlyAllocator<SIZE> {
63+
const PAGE_SIZE: usize = SIZE;
64+
65+
fn alloc_pages(
66+
&mut self,
67+
num_pages: usize,
68+
align_pow2: usize,
69+
) -> allocator::AllocResult<usize> {
70+
todo!()
71+
}
72+
73+
fn dealloc_pages(&mut self, pos: usize, num_pages: usize) {
74+
todo!()
75+
}
76+
77+
fn total_pages(&self) -> usize {
78+
todo!()
79+
}
80+
81+
fn used_pages(&self) -> usize {
82+
todo!()
83+
}
84+
85+
fn available_pages(&self) -> usize {
86+
todo!()
87+
}
88+
}

exercise/test/Cargo.toml.orig

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exercise/test/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![cfg_attr(feature = "axstd", no_std)]
2+
#![cfg_attr(feature = "axstd", no_main)]
3+
4+
#[macro_use]
5+
#[cfg(feature = "axstd")]
6+
extern crate axstd as std;
7+
extern crate alloc;
8+
9+
use alloc::vec::Vec;
10+
11+
#[cfg_attr(feature = "axstd", no_mangle)]
12+
fn main() {
13+
println!("Running bump tests...");
14+
15+
const N: usize = 3_000_000;
16+
let mut v = Vec::with_capacity(N);
17+
for i in 0..N {
18+
v.push(i);
19+
}
20+
v.sort();
21+
for i in 0..N - 1 {
22+
assert!(v[i] <= v[i + 1]);
23+
}
24+
25+
println!("Bump tests run OK!");
26+
}

0 commit comments

Comments
 (0)