Skip to content

Commit 273172c

Browse files
committed
Solo5: change nic interface and avoid copy
1 parent 6ee636a commit 273172c

9 files changed

Lines changed: 52 additions & 52 deletions

File tree

api/hw/nic.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ namespace hw {
101101

102102
virtual ~Nic() {}
103103

104-
virtual void upstream_received_packet(uint8_t *data, int len) = 0;
104+
/** Trigger a read from buffers, pusing any packets up the stack */
105+
virtual void poll() = 0;
105106

106107
protected:
107108
/**

api/kernel/solo5_manager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828

2929
class Solo5_manager {
3030
private:
31-
using Device_registry = std::unordered_map<PCI::classcode_t, std::vector<hw::PCI_Device>>;
31+
using Device_registry = std::unordered_map<PCI::classcode, std::vector<hw::PCI_Device>>;
3232

3333
public:
34-
template <PCI::classcode_t CLASS>
34+
template <PCI::classcode CLASS>
3535
static hw::PCI_Device& device(const int n) noexcept {
3636
return devices_[CLASS][n];
3737
};
3838

39-
template <PCI::classcode_t CLASS>
39+
template <PCI::classcode CLASS>
4040
static size_t num_of_devices() noexcept {
4141
return devices_[CLASS].size();
4242
}

src/drivers/solo5net.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void Solo5Net::transmit(net::Packet_ptr pckt) {
6363
// explicitly release the data to prevent destructor being called
6464
net::Packet* pckt = tail.release();
6565
uint8_t *buf = pckt->buf();
66+
67+
printf("Solo5 writing packet %i bytes \n", pckt->size());
6668
solo5_net_write_sync(buf, pckt->size());
6769

6870
tail = std::move(next);
@@ -87,21 +89,33 @@ Solo5Net::create_packet(int link_offset)
8789
}
8890

8991
std::unique_ptr<Packet>
90-
Solo5Net::recv_packet(uint8_t* data, uint16_t size)
92+
Solo5Net::recv_packet()
9193
{
9294
auto buffer = solo5_bufstore.get_buffer();
9395
auto* pckt = (net::Packet*) buffer.addr;
94-
96+
int size = MTU_;
9597
new (pckt) net::Packet(0, size, MTU_, &solo5_bufstore);
9698
uint8_t *buf = pckt->buf();
97-
memcpy(buf, data, size);
98-
return net::Packet_ptr(pckt);
99+
memset(buf, 0, size);
100+
// Populate the packet buffer with new packet, if any
101+
if (solo5_net_read_sync(buf, &size) == 0) {
102+
// Adjust packet size to match received data
103+
//printf("Solo5 data size: %i \n", size);
104+
if (size) {
105+
pckt->set_data_end(size);
106+
//printf("Solo5 Packet size: %i \n", pckt->size());
107+
return net::Packet_ptr(pckt);
108+
}
109+
}
110+
printf("Solo5 didn't get data. Size: %i \n", size);
111+
return nullptr;
99112
}
100113

101-
void Solo5Net::upstream_received_packet(uint8_t *data, int len)
114+
void Solo5Net::poll()
102115
{
103-
auto pckt_ptr = recv_packet(data, len);
104-
Link::receive(std::move(pckt_ptr));
116+
auto pckt_ptr = recv_packet();
117+
if (pckt_ptr != nullptr)
118+
Link::receive(std::move(pckt_ptr));
105119
}
106120

107121
void Solo5Net::deactivate()

src/drivers/solo5net.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ class Solo5Net : public net::Link_layer<net::Ethernet> {
4747
/** Mac address. */
4848
const MAC::Addr& mac() const noexcept override
4949
{
50-
char *smac = solo5_net_mac_str();
51-
MAC::Addr mac(smac);
52-
return mac;
50+
return MAC::Addr(solo5_net_mac_str());
5351
}
5452

5553
uint16_t MTU() const noexcept override
@@ -74,16 +72,19 @@ class Solo5Net : public net::Link_layer<net::Ethernet> {
7472
return 0;
7573
}
7674

77-
net::Packet_ptr create_packet(int);
78-
void move_to_this_cpu() {};
75+
net::Packet_ptr create_packet(int) override;
76+
77+
void move_to_this_cpu() override {};
7978

8079
void deactivate() override;
8180

82-
void upstream_received_packet(uint8_t *data, int len) override;
81+
void flush() override {};
82+
83+
void poll() override;
8384

8485
private:
8586

86-
std::unique_ptr<net::Packet> recv_packet(uint8_t* data, uint16_t sz);
87+
std::unique_ptr<net::Packet> recv_packet();
8788
/** Stats */
8889
uint64_t& packets_rx_;
8990
uint64_t& packets_tx_;

src/drivers/virtionet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class VirtioNet : Virtio, public net::Link_layer<net::Ethernet> {
166166

167167
void move_to_this_cpu() override;
168168

169-
void upstream_received_packet(uint8_t *data, int len) override {}
169+
void poll() {}
170170

171171
private:
172172

src/drivers/vmxnet3.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class vmxnet3 : public net::Link_layer<net::Ethernet>
7878

7979
void move_to_this_cpu() override;
8080

81-
void upstream_received_packet(uint8_t *data, int len) override {}
81+
void poll() override {}
8282

8383
private:
8484
void msix_evt_handler();

src/platform/x86_solo5/os.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ void OS::start(char* _cmdline, uintptr_t mem_size)
203203

204204
void OS::event_loop()
205205
{
206-
uint8_t *data = (uint8_t *) malloc(1520);
207-
assert(data);
206+
//uint8_t *data = (uint8_t *) malloc(1520);
207+
//assert(data);
208208

209209
while (power_) {
210210
int rc;
@@ -219,24 +219,19 @@ void OS::event_loop()
219219
// for the next immediate timer to fire (the first from the "scheduled" list
220220
// of timers?)
221221
rc = solo5_poll(solo5_clock_monotonic() + 500000ULL); // now + 0.5 ms
222-
if (rc == 0) {
223-
Timers::timers_handler();
224-
} else {
225-
int len = 1520;
226-
memset(data, 0, 1520);
227-
228-
if (solo5_net_read_sync(data, &len) == 0) {
229-
// XXX: packet is copied by upstream_received_packet (slow!)
230-
for(auto& nic : hw::Devices::devices<hw::Nic>()) {
231-
nic->upstream_received_packet(data, len);
232-
break;
233-
}
234-
}
222+
Timers::timers_handler();
223+
if (rc) {
224+
225+
//int len = 1520;
226+
//memset(data, 0, 1520);
235227

228+
for(auto& nic : hw::Devices::devices<hw::Nic>()) {
229+
nic->poll();
230+
break;
231+
}
236232
}
237233
}
238234

239-
free(data);
240235

241236
MYINFO("Stopping service");
242237
Service::stop();
@@ -300,20 +295,12 @@ void OS::block(){
300295
if (rc == 0) {
301296
Timers::timers_handler();
302297
} else {
303-
int len = 1520;
304-
uint8_t *data = (uint8_t *) malloc(1520);
305-
assert(data);
306-
memset(data, 0, 1520);
307298

308-
if (solo5_net_read_sync(data, &len) == 0) {
309-
// make sure packet is copied
310-
for(auto& nic : hw::Devices::devices<hw::Nic>()) {
311-
nic->upstream_received_packet(data, len);
312-
break;
313-
}
299+
for(auto& nic : hw::Devices::devices<hw::Nic>()) {
300+
nic->poll();
301+
break;
314302
}
315303

316-
free(data);
317304
}
318305

319306
// Decrement level

src/platform/x86_solo5/platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ void SMP::global_lock() noexcept {}
3030
void SMP::global_unlock() noexcept {}
3131
int SMP::cpu_id() noexcept { return 0; }
3232
int SMP::cpu_count() noexcept { return 1; }
33+
void SMP::signal(int) { }
34+
void SMP::add_task(SMP::task_func, int) { };

src/platform/x86_solo5/start.asm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
global __multiboot_magic
1919
global __multiboot_addr
2020
global set_stack
21-
global get_cpu_ebp
2221

2322
%define MB_MAGIC 0x1BADB002
2423
%define MB_FLAGS 0x3 ;; ALIGN + MEMINFO
@@ -49,7 +48,3 @@ set_stack:
4948
mov esp, 0xA0000
5049
mov ebp, esp
5150
call kernel_start
52-
53-
get_cpu_ebp:
54-
mov eax, ebp
55-
ret

0 commit comments

Comments
 (0)