-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose the scheduling API to Rust #34
base: main
Are you sure you want to change the base?
Conversation
67805f5
to
d5383d0
Compare
6f4bc58
to
218686a
Compare
56dc30a
to
6a8b347
Compare
0a8da4c
to
a6dfa58
Compare
I've promised to write a comment explaining problems with this PR on last meeting. I think there are two main problems:
/// ...
/// The destroyed group must not be currently in use and must not be used later.
/// ...
future<> destroy_scheduling_group(scheduling_group sg) noexcept; We could make this function
Of course, I don't know the scheduling API well, so there might be other reasons why this API is I'm still waiting for a review and decision what to do with this. |
I'm extremely sorry for taking so much time before responding to this.
I'm not sure, what kind of lifetime problems do these methods cause? I think taking self by reference should be perfectly fine. If by issues you mean that the Rust future stops being polled and the C++ side has a dangling reference, then we only need to make sure that the C++ side of the implementation immediately makes a copy of the About implementing By the way, I'm not sure if it already is, but it looks like /// Creates a scheduling group with a specified number of shares.
///
/// The operation is global and affects all shards. The returned scheduling
/// group can then be used in any shard.
Remember that by calling an unsafe function you are responsible for making sure that all invariants that the compiler and the other, possibly safe code may rely on are upheld. If you don't, then some code that would otherwise be safe may crash. In this case, your safe code depends on this invariant: " Making
|
This commit creates files: `scheduling.rs`, `scheduling.hh`, `scheduling.cc`. It also sets up the scheduling module in `lib.rs` and `build.rs`.
This commit introduces the `SchedulingGroup` type, which is an equivalent of `seastar::scheduling_group`. It also implements the Default trait for `SchedulingGroup` which corresponds to the parameterless constructor of the `scheduling_group` class (and funtion `default_scheduling_group` that is just a wrapper on the contructor).
This commit exposes all methods of `seastar::scheduling_group` except `get_specific` to Rust. We idnore `get_specific` because we don't expose this part of scheduling API for now.
Class `seastar::scheduling_group` overwrites `==` and `!=` operators. To express this functionality in Rust, we have to implement the Eq trait.
This commit introduces 3 methods/functions of `SchedulingGroup` that correspond to friend functions of `seastar::scheguduling_group` class: `create`, `destroy`, `rename`. We do this this way because there is such concept as friend funcions in Rust. Besides, this approach seems to have no disadvantages. Implementing `create` is quite tricky because we can't await a future that waits for `scheduling_group` (or `UniquePtr<scheduling_group>`) in Rust. The workaround here is creating `UniquePtr<scheduling_group>` in Rust, passing its reference to `create_sg` and changing it to new `UniquePtr` with the value returned by `seastar::create_scheduling_group`.
This commits ads `max` and `current` associated functions to `SchedulingGroup` that correspond to `seastar::max_scheduling_groups` and `seastar::current_scheduling_group`.
This commit adds the method `set_callback_under_group` to all 3 timer specializations.
I changed the type of
I made it unsafe.
These traits are auto implemented with the |
fixes: #33
depends on and finishes: #32
This PR exposes a simplified version of the API implemented in scheduling.hh and uses it to finish timer specializations.
Scheduling API
The
scheduling_group
class is exposed as a struct calledSchedulingGroup
along with its methods exceptget_specific
. Operators==
and!=
are expressed in Rust by implementing the Eq trait. The public constructor and thedefault_scheduling_group
function (both of them do the same thing) are expressed by implementing the Default trait.Apart from the
scheduling_group
class, the following functions are exposed:create_scheduling_group
,delete_scheduling_group
,rename_scheduling_group
,max_scheduling_groups
(we loseconstexpr
but I don't think it's a problem),current_scheduling_group
.All of them are implemented in Rust as methods or associated functions of the
SchedulingGroup
struct. C++ passesscheduling_group
by value to every function but I think we want to use references in Rust (edit: I think this approach is wrong, I've explained it in a new comment).Class
scheduling_group
has a methodset_shares
that is notconst
. I don't think expressing this in Rust by requiring&mut self
is a good idea. This single method would make our API much harder to use. I think that using&self
everywhere is completely fine becauseSchedulingGroup
can be considered as just a flag that doesn't change and only provides an interface.Finishing timer
This PR also adds a method called
set_callback_under_group
to all 3 timer specializations. To implement this method, it was necessary to exposescheduling_group
first. This feature makesseastar::timer
's functionality fully exposed.The rest of the scheduling API
As described here #33, we don't want to expose the rest of the scheduling API to Rust for now.