Skip to content

Commit 1870f9c

Browse files
committed
2 parents 58346d5 + 83c7f9b commit 1870f9c

11 files changed

Lines changed: 69 additions & 59 deletions

File tree

api/hw/msi.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace hw {
4848
void init(PCI_Device&);
4949
void mask_entry(size_t);
5050
void unmask_entry(size_t);
51+
void zero_entry(size_t);
5152
// enable one (cpu, vector) entry for this device
5253
uint16_t setup_vector(uint8_t cpu, uint8_t vector);
5354

api/kernel/irq_manager.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ class IRQ_manager {
129129
return cycles_hlt_;
130130
}
131131

132-
/** Get the total number of cycles spent working **/
133-
uint64_t cycles_active(){
134-
return cycles_active_;
132+
/** Get the total number of cycles since boot **/
133+
uint64_t cycles_total(){
134+
return cycles_total_;
135135
}
136136

137137
private:
@@ -151,7 +151,7 @@ class IRQ_manager {
151151
MemBitmap irq_todo;
152152

153153
uint64_t& cycles_hlt_;
154-
uint64_t& cycles_active_;
154+
uint64_t& cycles_total_;
155155

156156
static const char default_attr {static_cast<char>(0x8e)};
157157
static const uint16_t default_sel {0x8};

api/kernel/service.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ class Service {
3737
/**
3838
* The service entry point
3939
*
40-
* This is like 'main' - which we don't have, since the signature wouldn't
41-
* make sense (no command line, no args, no where to return to)
40+
* This is like an applications 'main' function
4241
*
43-
* @note Whenever this function returns, the OS will call `hlt`, sleeping
42+
* @note Whenever this function returns, the OS will be sleeping
4443
* until an external interrupt fires (there are no regular timer
4544
* interrupts unless you've enabled them).
46-
*
47-
* Your service should hook up event handlers to some of the events
48-
* (like `Nic::on(HttpConnection, your_callback`))
4945
*/
5046
static void start(const std::string&);
5147

@@ -66,8 +62,6 @@ class Service {
6662
* If the virtual machine running your service gets a poweroff signal
6763
* (i.e. from the hypervisor, like Qemu or VirtualBox) this function should
6864
* ensure a safe shutdown.
69-
*
70-
* @todo This is not implemented
7165
*/
7266
static void stop();
7367
}; //< Service

api/net/tcp/connection.hpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ class Connection : public std::enable_shared_from_this<Connection> {
177177
const Connection::State& prev_state() const
178178
{ return *prev_state_; }
179179

180+
uint64_t bytes_received() const
181+
{ return bytes_rx_; }
182+
183+
uint64_t bytes_transmitted() const
184+
{ return bytes_tx_; }
185+
186+
/**
187+
* @brief Total number of bytes in read buffer
188+
*
189+
* @return bytes not yet read
190+
*/
191+
size_t readq_size() const
192+
{ return read_request.buffer.size(); }
193+
180194
/**
181195
* @brief Total number of bytes in send queue
182196
*
@@ -193,32 +207,6 @@ class Connection : public std::enable_shared_from_this<Connection> {
193207
uint32_t sendq_remaining() const
194208
{ return writeq.bytes_remaining(); }
195209

196-
/*
197-
Calculates and return bytes transmitted.
198-
TODO: Not sure if this will suffice.
199-
*/
200-
uint32_t bytes_transmitted() const
201-
{ return 0; }
202-
203-
/*
204-
Calculates and return bytes received.
205-
TODO: Not sure if this will suffice.
206-
*/
207-
uint32_t bytes_received() const
208-
{ return 0; }
209-
210-
/*
211-
Bytes queued for transmission.
212-
TODO: Implement when retransmission is up and running.
213-
*/
214-
//inline size_t send_queue_bytes() const {}
215-
216-
/*
217-
Bytes currently in receive buffer.
218-
*/
219-
size_t read_queue_bytes() const
220-
{ return read_request.buffer.size(); }
221-
222210
/*
223211
Return the id (TUPLE) of the connection.
224212
*/
@@ -477,6 +465,10 @@ class Connection : public std::enable_shared_from_this<Connection> {
477465
RtxTimeoutCallback on_rtx_timeout_;
478466
CloseCallback on_close_;
479467

468+
/** Recv/Sent */
469+
uint64_t bytes_rx_;
470+
uint64_t bytes_tx_;
471+
480472
/** State if connection is in TCP write queue or not. */
481473
bool queued_;
482474

api/net/tcp/listener.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class Listener {
3535
using ConnectCallback = Connection::ConnectCallback;
3636
using CleanupCallback = Connection::CleanupCallback;
3737

38+
using SynQueue = std::deque<Connection_ptr>;
39+
3840
friend class net::TCP;
3941

4042
public:
@@ -70,6 +72,9 @@ class Listener {
7072
auto syn_queue_size() const
7173
{ return syn_queue_.size(); }
7274

75+
const SynQueue& syn_queue() const
76+
{ return syn_queue_; }
77+
7378
/** Delete copy and move constructors.*/
7479
Listener(Listener&) = delete;
7580
Listener(Listener&&) = delete;
@@ -81,8 +86,7 @@ class Listener {
8186
private:
8287
TCP& host_;
8388
const port_t port_;
84-
85-
std::deque<Connection_ptr> syn_queue_;
89+
SynQueue syn_queue_;
8690

8791
/** */
8892
AcceptCallback on_accept_;

api/net/tcp/tcp.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ namespace net {
143143
tcp::Address address()
144144
{ return inet_.ip_addr(); }
145145

146+
IPStack& stack() const
147+
{ return inet_; }
148+
146149
private:
147150

148151
/** Stats */

seed/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ FILES = service.cpp
1212
# Your disk image
1313
DISK=
1414

15+
# Additional drivers (virtionet, virtioblk etc)
16+
DRIVERS=
17+
1518
# Your own include-path
1619
LOCAL_INCLUDES=
1720

src/hw/msi.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ namespace hw
6464
auto reg = get_entry(vec, ENT_VECTOR_CTL);
6565
mm_write(reg, mm_read(reg) & ~MSIX_ENTRY_CTL_MASK);
6666
}
67+
void msix_t::zero_entry(size_t vec)
68+
{
69+
auto reg = get_entry(vec, ENT_MSG_DATA);
70+
mm_write(reg, mm_read(reg) & ~0xff);
71+
}
6772

6873
void msix_t::reset_pba_bit(size_t vec)
6974
{
@@ -103,7 +108,11 @@ namespace hw
103108
assert(cap >= 0x40);
104109
// read message control bits
105110
uint16_t func = dev.read16(cap + 2);
106-
assert(func < 0x1000 && "Invalid MSI-X func read");
111+
112+
/// if MSIX was already enabled, avoid validating func
113+
if ((func & MSIX_ENABLE) == 0)
114+
assert(func < 0x1000 && "Invalid MSI-X func read");
115+
107116
// enable msix and mask all vectors
108117
func |= MSIX_ENABLE | MSIX_FUNC_MASK;
109118
dev.write16(cap + 2, func);
@@ -121,9 +130,11 @@ namespace hw
121130
assert(vectors() <= 16 && "Unreasonably many MSI-X vectors");
122131
}
123132

124-
// mask out all entries
125-
for (size_t i = 0; i < this->vectors(); i++)
133+
// reset all entries
134+
for (size_t i = 0; i < this->vectors(); i++) {
126135
mask_entry(i);
136+
zero_entry(i);
137+
}
127138

128139
// unmask vectors
129140
func &= ~MSIX_FUNC_MASK;

src/kernel/irq_manager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ IRQ_manager::IRQ_manager(uint8_t cpuid)
3131
: cycles_hlt_{Statman::get()
3232
.create(Stat::UINT64, std::string(std::string("cpu") + std::to_string(cpuid)
3333
+ ".cycles_hlt").c_str() ).get_uint64()},
34-
cycles_active_{Statman::get()
34+
cycles_total_{Statman::get()
3535
.create(Stat::UINT64,std::string(std::string("cpu") + std::to_string(cpuid)
36-
+ ".cycles_active").c_str()).get_uint64()}
36+
+ ".cycles_total").c_str()).get_uint64()}
3737
{}
3838

3939
uint8_t IRQ_manager::get_next_msix_irq()
@@ -199,7 +199,7 @@ void IRQ_manager::notify()
199199

200200
(*counters[intr])++;
201201

202-
cycles_active_ = OS::cycles_since_boot();
202+
cycles_total_ = OS::cycles_since_boot();
203203

204204
irq_todo.reset(intr);
205205
intr = irq_todo.first_set();
@@ -217,5 +217,5 @@ void IRQ_manager::notify()
217217
"_irq_cb_return_location:" );
218218

219219
// Count sleep cycles
220-
cycles_hlt_ += OS::cycles_since_boot() - cycles_active_;
220+
cycles_hlt_ += OS::cycles_since_boot() - cycles_total_;
221221
}

src/net/tcp/connection.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Connection::Connection(TCP& host, port_t local_port, Socket remote) :
4343
cb(),
4444
read_request(),
4545
writeq(),
46+
bytes_rx_(0), bytes_tx_(0),
4647
queued_(false),
4748
time_wait_started(0)
4849
{
@@ -126,6 +127,8 @@ size_t Connection::receive(const uint8_t* data, size_t n, bool PUSH) {
126127
buf.renew();
127128
}
128129

130+
bytes_rx_ += received;
131+
129132
return received;
130133
}
131134

@@ -409,6 +412,8 @@ void Connection::transmit(Packet_ptr packet) {
409412
// packet->seq() - cb.ISS, packet->ack() - cb.IRS);
410413
debug2("<TCP::Connection::transmit> TX %s\n", packet->to_string().c_str());
411414

415+
bytes_tx_ += packet->tcp_data_length();
416+
412417
host_.transmit(packet);
413418
if(packet->should_rtx() and !rtx_timer.active) {
414419
rtx_start();
@@ -673,6 +678,10 @@ void Connection::retransmit() {
673678

674679
//printf("<TCP::Connection::retransmit> rseq=%u \n", packet->seq() - cb.ISS);
675680
debug("<TCP::Connection::retransmit> RT %s\n", packet->to_string().c_str());
681+
682+
// count retranmissions to bytes transmitted?
683+
bytes_tx_ += packet->tcp_data_length();
684+
676685
host_.transmit(packet);
677686
/*
678687
Every time a packet containing data is sent (including a

0 commit comments

Comments
 (0)