Commit graph

143 commits

Author SHA1 Message Date
bunnie
4e40ae6c5d move from target selectors to feature selectors for back-ends
This will allow for e.g. xous on riscv32-imac but not a precursor
target, for example: by using feature selectors we get to have
a bigger range of targets that we support, such as for implementations
that haven't been upstreamed or have official target-triples.

The downsides are:

- patch override libraries don't absorb feature flags. so, for
example, the AES crate that is used to patch other crates won't
be aware of the target features without modifying the referencing
crates.

- features are normally meant to be additive, but target features
are mutually exclusive. The mutex is enforced by a check in
utralib that throws a panic on build if two targets are accidentally
selected at the same time.
2022-10-02 02:56:44 +08:00
bunnie
035bdaf986 complete wifi on/off interface
fully integrates wifi on and off commands. measured standby power
when wifi is off is "immeasurable" (0 mA), so probably < 1-2mA.

fix ui transitions so that the off request is respected, through
sleep/resume cycles as well.
2022-09-20 19:36:55 +08:00
bunnie
59a3bc0370 cleanup patches 2022-08-20 00:38:21 +08:00
bunnie
a5aee2b0d5 patches for debug 2022-08-16 17:54:36 +08:00
bunnie
205f0a3be3 increase threshold for retiring closes
when not in heavy loopback mode, this occurs more rarely and
probably for more legitimate reasons.
2022-08-06 00:35:18 +08:00
bunnie
bd8afc6de7 clean up debug spew for merge to main 2022-08-05 15:50:11 +08:00
bunnie
6f86aee991 give loopback its own rx buffer
instead of sharing the wifi buffer loopback has its own buffer.
this eliminates a race condition that happens whenever an Rx
happens to happen on the wifi interface while there's loopback
traffic in progress.

also, i see a lot of opportunities to optimize the net stack now
that i have tweaked this path; it might be interesting to break
the receive interrupt out directly into the COM crate instead
of passing it through LLIO then NET then COM and having COM
drain the RX buffer immediately into a local "infinite" sized
queue.

The llio->net->com loop exists because the interrupt handler
for all the i/o is shared within one hardware block, but maybe
i can create an additional interrupt responder for the com
interface just to optimize things a bit in a future SOC update.

Alternatively, I could move all the interrupts into COM and not
have them resident in LLIO. This would optimize for COM latency
at the expence of I2C latency, but that's probably OK because
I2C is much less latency sensitive (i2c and com interrupt, as
mentioned above, share the same hardware block for external
pin-based interrupts).
2022-08-05 15:12:57 +08:00
bunnie
2658dd4b71 add peek handler, heuristic to close sockets that are stuck
- Peek now has a handler for reads that can't be met immediately
- add a count to the number of times a close socket has been polled,
if it exceeds a threshold close the socket anyways. This is a compromise
between trying to figure out how to implement a fully non-blocking TcpClose,
and having an interlocked one that cleans up state but ends up blocking
the case where you have, in the same thread, a sender and receiver
(which is ironically somehow legal and does not cause deadlock,
because the TcpClose in Unix is not blocking on internal state
being cleared up).
2022-08-05 05:07:44 +08:00
bunnie
495ca1e2b7 fix timeouts, peek
- timeouts were being overwritten before they were read
- peek now behaves according to what the test bench expects
2022-08-05 05:05:41 +08:00
bunnie
32e78039b7 xous-side of 0-port listener binding
0 is a "valid" port and it means OS please give me a port.
This implements a method where a random port is chosen until
you find one that's not occupied.
2022-08-05 05:04:35 +08:00
bunnie
24a0848a43 add nonblocking flag to opcode map 2022-08-05 05:02:39 +08:00
bunnie
8a797764c1 (possibly dubious) fix on 'unattended' Stream close
If a Stream is opened and a process isn't constantly polling it,
it'll never close if the remote side goes away -- you'll just
end up hanging in a FIN-WAIT-2 condition.

Add some logic to detect this and close out streams automatically
where the remote has hung up.

I'm not actually sure this is what you're *supposed* to do, but,
lacking a formal specification, all I can do is try to get
this thing to pass the test bench. And pass it does.
2022-08-04 21:10:17 +08:00
bunnie
80f78a0f5d tweak debug noise down 2022-08-04 21:09:49 +08:00
bunnie
9f3bef04cc tweak debug noise down 2022-08-04 21:09:24 +08:00
bunnie
6045c75cf0 refactor TcpClose; fix RxWait
TcpClose should not immediately remove the socket. It
has to wait until the FIN comes. Add a fin waiter state.
Also rewrite to use "retain". Woo. I'm starting to get
the hang of Rust closures. Only took a couple years.

RxWait gets stuck in CLOSE_WAIT state. It's a state where
you "could" transmit, but you can't receive anymore.
In this case respond with a 0-length receive? That seems
to be what leads to the right behavior. I would have thought
you'd want to respond with a timeout error but that doesn't
match what's in the test bench.
2022-08-04 05:03:08 +08:00
bunnie
5d2d7ac40f add tooling for the loopback interface
- add 127.0.0.1 to the list of IPs listened to by smoltcp
- add some static Atomic types to store the IP and MAC address
so we can process packets in other areas to detect the loopback
state
- add a routine to extract the loopback packets when they happen
- bunch of debug visibility tweaks
2022-08-03 03:34:29 +08:00
bunnie
2094b803be loopback interface
loopback packets are intercepted on the way to the COM and
re-injected directly into the Rx queue, along with a message
sent back to the main loop to pump the Rx buffer to extract the
loopback packet.
2022-08-03 03:33:15 +08:00
bunnie
7606d244e8 tweak debug output levels 2022-08-03 03:21:43 +08:00
bunnie
ca30657370 attempt to integrate the std net test suite.
newsflash: it doesn't work. still handy to have the test code around
as reference.
2022-08-02 16:45:56 +08:00
bunnie
7541d39fd6 add a static variable to contain our IPV4 address
this is used to do address binding checking from library calls,
so we can reject binding to address that are not our actual IP
address.
2022-08-02 16:45:17 +08:00
bunnie
f2193d64b1 filter disallowed bindings for the TcpListener 2022-08-02 16:44:37 +08:00
bunnie
14dacd9941 handle WFXerror case more gracefully 2022-07-20 21:07:52 +08:00
bunnie
ef164871a1 move COM link error handling up the stack a bit
this allows us to have better error reporting and handle
the cases where the EC is updating and just generating random
vectors more...palatable.
2022-07-16 23:11:13 +08:00
bunnie
a90b5f2554 clean up autoupdate flow & clean up net link reset flow
We are now at a point where the EC update can be applied and the
net stack recovers gracefully, so no reboot is required in the
case of an EC update.
2022-07-11 15:07:53 +08:00
bunnie
8f3aa84e6d refresh the wlan stats cache on resume... 2022-07-11 05:06:01 +08:00
bunnie
ca5455635b add some heuristics to improve the connection manager
the CM can't always detect if the EC changes state; this is
especially true after an update or a forced reset where
the state caches are not reliably updated. If no packets are
seen for a while, poll the actual state and force a sync-up.

Also try to make sure that the interrupts are enabled correctly.
2022-07-11 04:58:48 +08:00
bunnie
21116a1693 fix another errant mut that wasn't needed in pddb 2022-06-01 00:06:55 +08:00
Sean Cross
3ae9d8abf0 apps/services: remove xous::xous_main macro usage
This macro will be removed, since it is no longer necessary. Remove this
macro across the project and replace it with a standard `main()`
function.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-31 13:33:30 +08:00
bunnie
62cbc86aeb add automation strings 2022-05-24 23:21:26 +08:00
bunnie
4cba739a81 remove improper warning message
this was a vestige of an earlier version that should have been
removed
2022-05-17 03:13:19 +08:00
bunnie
ca275308ef Merge branch 'usbdev' into main 2022-05-17 02:31:10 +08:00
bunnie
e9b627cab8 update release notes, clean up Cargo.toml, smoltcp to 0.8.1
smoltcp gave us a patch for our smoltcp issues! thank you @dirbaio!
2022-05-13 15:09:45 +08:00
bunnie
4ec84bf4dc implement deferred close on drop for TcpStream
streams are not closed until the txbuffer is empty
2022-05-13 14:51:07 +08:00
bunnie
b470588285 oops, fix a compile error. also try adding a flush()...this only made things worse?? 2022-05-13 02:25:35 +08:00
bunnie
56f9c654c0 debugging of TcpStream Drop dropping too fast
so far only able to confirm the problem happens, no effective
fixes yet.
2022-05-13 02:19:10 +08:00
bunnie
17e9a210ef add maintenanence notes referring to relevant smoltcp issues 2022-05-13 01:21:41 +08:00
bunnie
c17219b6fe add icmpv4 fixes
a lot of debug spew is also enabled in this commit, intentionally,
because the next thing to chase out is the failure of TcpStream
on Drop.
2022-05-13 00:30:12 +08:00
bunnie
bac650808d force all UDP packets to respond on the local IP address
smoltcp is written to allow multiple adapters, so 0.0.0.0 as
the binding for UDP is illegal. However, in Rust, it seems that
0.0.0.0 is "totally fine" and most OSes will resolve this to
a "default" adapter.

this patch introduces the behavior of taking 0.0.0.0 and mapping
it to a default adapter. In fact, we only allow binding to the
default adapter. The reasoning behind this is that if our IP
address changes, we would expect that 0.0.0.0 resolves to that.

Where this scheme fails is if someone binds to 127.0.0.1 expecting
it to not respond to packets coming in from the outside, e.g.
they are using UDP as a loopback interface. I think this isn't
a common use case for Xous, but if it does become one I suppose
we could add a code path to also check for the 127.0.0.1 case
and try to handle it...
2022-05-12 22:26:38 +08:00
bunnie
94cbbddaa6 refactor follow-up scheduling vs smoltcp stack
smoltcp requires some polling to be done in the future for it
to work with low latency. It returns a time in the future for
the next poll.

This refactors the polling algorithm to:

1. use a fixed thread pool. This burns a little extra memory in
exchange for not having to allocate/de-allocate threads every
time a follow-up is needed.

2. use a short/long scheduler, where short delays (shorter than
the scheduler quantum) are grouped together, and only a single
follow-up is fired off within that time range if needed. Longer
delays have a larger window (roughly +/- 100ms) of grouping,
so fewer such events are also required in the distant future.

Empirically the delays seem to fall into two groups, either "short"
(less than 20ms) or "long" (around 700ms).

This improved scheduler uses fewer threads and generates less
messages, so instead of 16 threads and encountering exhaustion
we have 9 and have yet to see more than 7 used even under the
most strenuous tests (multiple while-true curl loops + fountain
test + ping simultaneously).

Some helpful debug is also printed now when scheduler runs out
of slots, so we can see the distribution of pending delays.
2022-05-12 17:49:27 +08:00
bunnie
caf91e18ca fix net reset
we no longer create a new interface on net reset, which means that
the socket handles don't blow up if we change IP addresses.
However, the ARP cache is still stale and there seems to be on way
to force it to flush....but I guess in theory, eventually it
should fix itself, if smoltcp is working correctly?
2022-05-12 10:34:19 +08:00
bunnie
cc7e7f97c7 update smoltcp to 0.8.0
the refactor changes the way sockets are handled, so now, when
the interface is rebound we are certain to get panics.

working on resolving this detail now, but at least the interface
is working now and it seems more stable than before.
2022-05-12 09:27:51 +08:00
bunnie
ccb3e495e1 hoist net thread exhaustion check to before we check the poll interval 2022-05-06 14:15:53 +08:00
bunnie
413b7153ac refactor wait timer for net pump 2022-05-06 13:44:03 +08:00
bunnie
709c087337 refactor wait timer for net pump 2022-05-06 13:35:33 +08:00
bunnie
2a4dd67564 hoist net thread exhaustion check to before we check the poll interval 2022-05-06 04:00:20 +08:00
bunnie
969b4ec868 refactor net firewall to use .forward() method 2022-04-25 18:30:24 +08:00
bunnie
8d28f130ea fix a missing case for hardware not caught by hosted mode 2022-04-24 21:53:18 +08:00
bunnie
f4f0812fb4 refactor API to use the None encoding for 0 on NonZeroUsize MemoryMessage fields
at the suggestion of @xobs, requires a new libstd to work with this.
2022-04-19 01:32:36 +08:00
bunnie
89ceba9674 tweak some parameters and debug infos
total threads in the net crate are around 10 right now, 32 max, so
increasing the sleeping thread limit to 16, since every now and then
we get exhaustion notes.
2022-04-17 18:49:27 +08:00
bunnie
ecd875e64f remove the legacy files 2022-04-17 05:00:51 +08:00