Claude for performance analysis.
ke4pjw
Posts: 1,300
After having Claude create a multithreaded webserver for the Blitzen 24, a problem popped up where lock contention for the W6100 was causing a performance problem. Asking it about the contention, it suggested the additional threads were the cause. I asked it to do an analysis of creating a dispatcher that could check the status of all of the sockets and dispatch the httpd requests so that it wasn't just looping through each task checking to see if there was anything needing to be serviced. Here is the analysis it came up with and a plan to implement it. I will actually see how this performs later.
Here's the contention comparison from the plan:
Current: 4 Tasks Polling Independently
| Operation | Locks/task | × 4 tasks | Total |
|---|---|---|---|
| EstablishTCP: readreg Sn_IR (initial) | 1 | 4 | 4 |
| EstablishTCP: readreg Sn_IR (loop) | 1 | 4 | 4 |
| mdnscheck: readreg Sn_IR on Socket7 | 1 | 4 | 4 |
| mdnscheck: ReceiveData → readreg RX_RSR | 1+ | 4+ | 4+ |
| Total per cycle | ~4 | ~16+ |
Proposed: SIR Dispatcher
| Operation | Locks | Total |
|---|---|---|
| ReadSIR (1 byte, covers all 8 sockets) | 1 | 1 |
Side-by-side
| Scenario | Current | Dispatcher | Reduction |
|---|---|---|---|
| Idle (no connections, no mDNS) | ~16+ | 1 | ~94% |
| 1 connection arrives | ~16 + handling | 1 + handling for 1 task | ~94% idle overhead gone |
| mDNS query arrives | ~16 + mDNS work | 1 + mDNS work | ~94% idle overhead gone |
The E1.31 PASM cog needs 9 lock acquisitions per packet. Currently it competes with ~16 idle Spin2 attempts per cycle. Cutting those to 1 means the PASM cog spends far less time waiting for the lock and more time moving data off the W6100 bus.

Comments
I am having just too much fun with this.
SIR Dispatcher + SENDOK Fix — COMPLETE
Summary of Changes
All work is implemented, tested, and ready for check-in.
W6100drv.spin2
REG\_IR = $2100andREG\_SIR = $2101constantsReadSIR()method — single bus read of Socket Interrupt RegisterReopenTCP()method — fast socket recycle skipping MR/PORTR writesSendData()was readingREG\_Sn\_IMR(mask, always $FF) instead ofREG\_Sn\_IR(status) for SENDOK check — loop exited immediately, causing TCP RSTs before data finished transmitting. Fixed in both SendData instances.Blitzen24.spin2
socket\_ready\[]hub flag array for inter-task signalingReopenTCP()used for socket recycling after disconnectresp\_js\_ptrwithContent-Type: application/javascriptfor all JS responsesTest Results
Status: COMPLETE — ready for real-world testing
Well, I am just tickled pink. That all worked amazingly well. After all of the improvements it made, this thing feels more solid than ever. I validated it on a controller with about 2000 pixels connected and everything just worked. As a matter of fact, it also resolved the issues I was having with some of the pages not loading correctly on Android and the MDNS hostname not resolving on Android. The latency on the webserver is much less.
Claude is really great at iterating. It would program the P2, run integration tests, find problems, ask for direction, allow me to offer suggestions on performance strategies, build-upload-test, analyze, build-upload-test, analyze, until things are about as tight as I can get. Just amazing! Worth the $25/mo.