doc/wg/core/notes/core-notes-2021-07-02.md
Attending:
clang and rustc.enter, the capsule gets a handle it can use to
schedule an upcall. The core kernel does all the checks to ensure it is a
valid upcall. At no point does the capsule hold or store an upcall object.allocate_grant
function capsules have to implement. That way the kernel can ask a capsule to
allocate its grant, so the kernel has a place to store upcalls. This is a
minor function, pretty much boilerplate.enter hasn't changed, so if I call <grant type>::enter
what prevents it from being allocated as a separate grant?Process implementation to allocate space for that grant in the process'
grant memory, the Process will say the driver number has already been used,
so it can't be created.Process implementation does not care how
anything else uses the memory allocated in the grant region. It's given a
length and alignment and will return some space. It does know about the driver
number and is promising that the same driver number will never be used for
multiple grants.allocate_grant. There's not a default implementation so you have to provide
something, but if you throw an empty Ok and don't do anything the kernel
still won't be able to store an upcall. That will result in sending an error
back to userspace.Grant take an
optional driver number, giving us two versions that can and cannot store
upcalls. Another extension is if you want to use upcalls but not have a grant,
the kernel could still handle that, it'd just be more code and be
inconvenient.T
and one that goes to the upcall array, except we don't know how many upcalls a
particular capsule wants.allocate_grant could become num_upcalls or something.num_upcalls in now a
type parameter for Grant.allocate_grant is remarkably long
and could be trimmed down. It goes into other comments rather than just what
it does.main.rs uses one driver number for the
syscall mapping and another for the grant, then subscribe would fail for
processes. It would come in on one driver number but the kernel would not find
a grant with that driver number, and it would not be able to create one,
because there is no grant with that driver number. All it would be able to do
is send back an error to userspace.libtock-c we've made that a little bit more difficult.with_driver function that has
nothing to do with the components. Then you supply the driver number to the
component, so I don't think components solve the problem.with_driver and to create_grant that
you will get potentially cryptic and weird bugs? For v4 the check is currently
at runtime and it just returns an error.main.rs. A capsule
can't do it.Grant that are generic over the type
in the Grant and/or closure. E.g. every time you call Grant::enter you
duplicate the logic in the binary. It's generally inlined into the use site,
and for boards like Imix that means 50 or more copies of the identical code.
This PR moves the portions of the functions that do not rely on the generic
parameters into non-generic functions that are marked #[inline(never)]. I
then call those from the generic functions. For code that doesn't need to be
duplicated for the generic types, you only have a single instance of those
function. As written, this saved about 7300 bytes on Imix. Functionally it is
identical, except it might result in slightly-worse performance. A high-level
takeaway is we should be careful to do the minimal amount possible in generic
functions we expect to be instantiated multiple times.unsafe stuff, what I've found is that code you
might otherwise write in a single line is better split up so you can comment
each step. That adds lines of code you wouldn't otherwise have if you were
just writing C code. In Rust there's a lot of reasons why lines will not match
compiled code.create and a restart
call. restart did a subset of create with a little tweaking. I pulled the
stuff out and put it into restart. Now when you call create, you still
allocate the grant region. The actual allocation of the flash region, the
clearing of pointers and similar, are all done in restart. Now restart is
called by create and on a restart, so now it's not inlined. I think there's
a lot of bookkeeping added that's adding code size. A lot of stuff is put into
a structure and restart loads it.