Skip to content
Snippets Groups Projects
Commit d362b4d8 authored by Dor Laor's avatar Dor Laor
Browse files

Change virtio code to use the new logger in order to reduce the

debug output and do some order
parent d686809d
No related branches found
No related tags found
No related merge requests found
...@@ -92,7 +92,7 @@ struct driver virtio_blk_driver = { ...@@ -92,7 +92,7 @@ struct driver virtio_blk_driver = {
ss << "virtio-blk" << dev_idx; ss << "virtio-blk" << dev_idx;
_driver_name = ss.str(); _driver_name = ss.str();
debug(fmt("VIRTIO BLK INSTANCE %d") % dev_idx); virtio_i(fmt("VIRTIO BLK INSTANCE %d") % dev_idx);
_id = _instance++; _id = _instance++;
} }
...@@ -109,7 +109,7 @@ struct driver virtio_blk_driver = { ...@@ -109,7 +109,7 @@ struct driver virtio_blk_driver = {
_dev->virtio_conf_read(offsetof(struct virtio_blk_config, capacity) + VIRTIO_PCI_CONFIG(_dev), _dev->virtio_conf_read(offsetof(struct virtio_blk_config, capacity) + VIRTIO_PCI_CONFIG(_dev),
&_config.capacity, &_config.capacity,
sizeof(_config.capacity)); sizeof(_config.capacity));
debug(fmt("capacity of the device is %x") % (u64)_config.capacity); virtio_i(fmt("capacity of the device is %x") % (u64)_config.capacity);
_dev->add_dev_status(VIRTIO_CONFIG_S_DRIVER_OK); _dev->add_dev_status(VIRTIO_CONFIG_S_DRIVER_OK);
...@@ -127,10 +127,10 @@ struct driver virtio_blk_driver = { ...@@ -127,10 +127,10 @@ struct driver virtio_blk_driver = {
// Perform test if this isn't the boot image (test is destructive // Perform test if this isn't the boot image (test is destructive
if (_id > 0) { if (_id > 0) {
debug(fmt("virtio blk: testing instance %d") % _id); virtio_d(fmt("virtio blk: testing instance %d") % _id);
for (int i=0;i<6;i++) { for (int i=0;i<6;i++) {
debug(fmt("Running test %d") % i); virtio_d(fmt("Running test %d") % i);
test(); test();
timespec ts = {}; timespec ts = {};
ts.tv_sec = 1; ts.tv_sec = 1;
...@@ -166,7 +166,7 @@ struct driver virtio_blk_driver = { ...@@ -166,7 +166,7 @@ struct driver virtio_blk_driver = {
struct bio* bio = alloc_bio(); struct bio* bio = alloc_bio();
if (!bio) { if (!bio) {
debug("bio_alloc failed"); virtio_e(fmt("bio_alloc failed"));
return nullptr; return nullptr;
} }
bio->bio_data = buf; bio->bio_data = buf;
...@@ -192,14 +192,14 @@ struct driver virtio_blk_driver = { ...@@ -192,14 +192,14 @@ struct driver virtio_blk_driver = {
int i; int i;
static bool is_write = true; // keep changing the type every call static bool is_write = true; // keep changing the type every call
debug("test virtio blk"); virtio_d(fmt("test virtio blk"));
vring* queue = _dev->get_virt_queue(0); vring* queue = _dev->get_virt_queue(0);
virtio_blk_req* req; virtio_blk_req* req;
const int iterations = 100; const int iterations = 100;
if (is_write) { if (is_write) {
is_write = false; is_write = false;
debug(" write several requests"); virtio_d(fmt(" write several requests"));
for (i=0;i<iterations;i++) { for (i=0;i<iterations;i++) {
req = make_virtio_req(i*8, VIRTIO_BLK_T_OUT,i); req = make_virtio_req(i*8, VIRTIO_BLK_T_OUT,i);
if (!queue->add_buf(req->payload,2,1,req)) { if (!queue->add_buf(req->payload,2,1,req)) {
...@@ -207,11 +207,11 @@ struct driver virtio_blk_driver = { ...@@ -207,11 +207,11 @@ struct driver virtio_blk_driver = {
} }
} }
debug(fmt(" Let the host know about the %d requests") % i); virtio_d(fmt(" Let the host know about the %d requests") % i);
queue->kick(); queue->kick();
} else { } else {
is_write = true; is_write = true;
debug(" read several requests"); virtio_d(fmt(" read several requests"));
for (i=0;i<iterations;i++) { for (i=0;i<iterations;i++) {
req = make_virtio_req(i*8, VIRTIO_BLK_T_IN,0); req = make_virtio_req(i*8, VIRTIO_BLK_T_IN,0);
if (!queue->add_buf(req->payload,1,2,req)) { if (!queue->add_buf(req->payload,1,2,req)) {
...@@ -221,13 +221,13 @@ struct driver virtio_blk_driver = { ...@@ -221,13 +221,13 @@ struct driver virtio_blk_driver = {
} }
debug(fmt(" Let the host know about the %d requests") % i); virtio_d(fmt(" Let the host know about the %d requests") % i);
queue->kick(); queue->kick();
} }
//sched::thread::current()->yield(); //sched::thread::current()->yield();
debug("test virtio blk end"); virtio_d(fmt("test virtio blk end"));
} }
void virtio_blk::response_worker() { void virtio_blk::response_worker() {
...@@ -236,28 +236,26 @@ struct driver virtio_blk_driver = { ...@@ -236,28 +236,26 @@ struct driver virtio_blk_driver = {
while (1) { while (1) {
debug("\t ----> virtio_blk: IRQ: response worker main loop");
thread::wait_until([this] { thread::wait_until([this] {
vring* queue = this->_dev->get_virt_queue(0); vring* queue = this->_dev->get_virt_queue(0);
return queue->used_ring_not_empty(); return queue->used_ring_not_empty();
}); });
debug("\t ----> IRQ: debug - blk thread awaken"); virtio_d(fmt("\t ----> IRQ: virtio_d - blk thread awaken"));
int i = 0; int i = 0;
while((req = reinterpret_cast<virtio_blk_req*>(queue->get_buf())) != nullptr) { while((req = reinterpret_cast<virtio_blk_req*>(queue->get_buf())) != nullptr) {
debug(fmt("\t got response:%d = %d ") % i++ % (int)req->status->status); virtio_d(fmt("\t got response:%d = %d ") % i++ % (int)req->status->status);
virtio_blk_outhdr* header = reinterpret_cast<virtio_blk_outhdr*>(req->req_header); virtio_blk_outhdr* header = reinterpret_cast<virtio_blk_outhdr*>(req->req_header);
// This is debug code to verify the read content, to be remove later on // This is debug code to verify the read content, to be remove later on
if (header->type == VIRTIO_BLK_T_IN) { if (header->type == VIRTIO_BLK_T_IN) {
debug(fmt("\t verify that sector %d contains data %d") % (int)header->sector % (int)(header->sector/8)); virtio_d(fmt("\t verify that sector %d contains data %d") % (int)header->sector % (int)(header->sector/8));
auto ii = req->payload->_nodes.begin(); auto ii = req->payload->_nodes.begin();
ii++; ii++;
char*buf = reinterpret_cast<char*>(mmu::phys_to_virt(ii->_paddr)); char*buf = reinterpret_cast<char*>(mmu::phys_to_virt(ii->_paddr));
debug(fmt("\t value = %d len=%d") % (int)(*buf) % ii->_len); virtio_d(fmt("\t value = %d len=%d") % (int)(*buf) % ii->_len);
} }
if (req->bio != nullptr) { if (req->bio != nullptr) {
......
...@@ -26,10 +26,9 @@ namespace virtio { ...@@ -26,10 +26,9 @@ namespace virtio {
{ {
pci_device::dump_config(); pci_device::dump_config();
debug(fmt(" virtio features: "), false); virtio_i(fmt(" virtio features: "));
for (int i=0;i<32;i++) for (int i=0;i<32;i++)
debug(fmt("%d") % get_device_feature_bit(i), false); virtio_i(fmt(" %d ") % get_device_feature_bit(i));
debug(fmt("\n"), false);
} }
bool virtio_device::parse_pci_config(void) bool virtio_device::parse_pci_config(void)
...@@ -47,14 +46,14 @@ namespace virtio { ...@@ -47,14 +46,14 @@ namespace virtio {
// Check ABI version // Check ABI version
u8 rev = get_revision_id(); u8 rev = get_revision_id();
if (rev != VIRTIO_PCI_ABI_VERSION) { if (rev != VIRTIO_PCI_ABI_VERSION) {
debug(fmt("Wrong virtio revision=%x") % rev); virtio_e(fmt("Wrong virtio revision=%x") % rev);
return (false); return (false);
} }
// Check device ID // Check device ID
u16 dev_id = get_device_id(); u16 dev_id = get_device_id();
if ((dev_id < VIRTIO_PCI_ID_MIN) || (dev_id > VIRTIO_PCI_ID_MAX)) { if ((dev_id < VIRTIO_PCI_ID_MIN) || (dev_id > VIRTIO_PCI_ID_MAX)) {
debug(fmt("Wrong virtio dev id %x") % dev_id); virtio_e(fmt("Wrong virtio dev id %x") % dev_id);
return (false); return (false);
} }
...@@ -110,7 +109,7 @@ namespace virtio { ...@@ -110,7 +109,7 @@ namespace virtio {
virtio_conf_writel(VIRTIO_PCI_QUEUE_PFN, (u32)(queue->get_paddr() >> VIRTIO_PCI_QUEUE_ADDR_SHIFT)); virtio_conf_writel(VIRTIO_PCI_QUEUE_PFN, (u32)(queue->get_paddr() >> VIRTIO_PCI_QUEUE_ADDR_SHIFT));
// Debug print // Debug print
debug(fmt("Queue[%d] -> size %d, paddr %x") % (_num_queues-1) % qsize % queue->get_paddr()); virtio_d(fmt("Queue[%d] -> size %d, paddr %x") % (_num_queues-1) % qsize % queue->get_paddr());
} while (true); } while (true);
......
...@@ -102,7 +102,7 @@ namespace virtio { ...@@ -102,7 +102,7 @@ namespace virtio {
int i = 0, idx, prev_idx; int i = 0, idx, prev_idx;
idx = _avail_head; idx = _avail_head;
//debug(fmt("\t%s: avail_head=%d, in=%d, out=%d") % __FUNCTION__ % _avail_head % in % out); virtio_d(fmt("\t%s: avail_head=%d, in=%d, out=%d") % __FUNCTION__ % _avail_head % in % out);
_cookie[idx] = cookie; _cookie[idx] = cookie;
vring_desc* descp = _desc; vring_desc* descp = _desc;
...@@ -124,7 +124,7 @@ namespace virtio { ...@@ -124,7 +124,7 @@ namespace virtio {
} }
for (auto ii = sg->_nodes.begin(); i < in + out; ii++, i++) { for (auto ii = sg->_nodes.begin(); i < in + out; ii++, i++) {
//debug(fmt("\t%s: idx=%d, len=%d, paddr=%x") % __FUNCTION__ % idx % (*ii)._len % (*ii)._paddr); virtio_d(fmt("\t%s: idx=%d, len=%d, paddr=%x") % __FUNCTION__ % idx % (*ii)._len % (*ii)._paddr);
descp[idx]._flags = vring_desc::VRING_DESC_F_NEXT; descp[idx]._flags = vring_desc::VRING_DESC_F_NEXT;
descp[idx]._flags |= (i>=out)? vring_desc::VRING_DESC_F_WRITE:0; descp[idx]._flags |= (i>=out)? vring_desc::VRING_DESC_F_WRITE:0;
descp[idx]._paddr = (*ii)._paddr; descp[idx]._paddr = (*ii)._paddr;
...@@ -142,7 +142,7 @@ namespace virtio { ...@@ -142,7 +142,7 @@ namespace virtio {
_avail->_idx++; _avail->_idx++;
_avail_head = idx; _avail_head = idx;
//debug(fmt("\t%s: _avail->_idx=%d, added=%d,") % __FUNCTION__ % _avail->_idx % _avail_added_since_kick); virtio_d(fmt("\t%s: _avail->_idx=%d, added=%d,") % __FUNCTION__ % _avail->_idx % _avail_added_since_kick);
return true; return true;
}); });
...@@ -161,11 +161,11 @@ namespace virtio { ...@@ -161,11 +161,11 @@ namespace virtio {
barrier(); // Normalize the used fields of these descriptors barrier(); // Normalize the used fields of these descriptors
if (_used_guest_head == _used->_idx) { if (_used_guest_head == _used->_idx) {
debug(fmt("get_used_desc: no avail buffers ptr=%d") % _used_guest_head); virtio_d(fmt("get_used_desc: no avail buffers ptr=%d") % _used_guest_head);
return reinterpret_cast<void*>(0); return reinterpret_cast<void*>(0);
} }
//debug(fmt("get used: guest head=%d use_elem[head].id=%d") % used_ptr % _used->_used_elements[used_ptr]._id); virtio_d(fmt("get used: guest head=%d use_elem[head].id=%d") % used_ptr % _used->_used_elements[used_ptr]._id);
elem = _used->_used_elements[used_ptr]; elem = _used->_used_elements[used_ptr];
int idx = elem._id; int idx = elem._id;
......
...@@ -3,9 +3,16 @@ ...@@ -3,9 +3,16 @@
#include <functional> #include <functional>
#include "mutex.hh" #include "mutex.hh"
#include "debug.hh"
class sglist; class sglist;
#define virtio_tag "virtio"
#define virtio_d(fmt) logger::instance()->log(virtio_tag, logger::logger_debug, (fmt))
#define virtio_i(fmt) logger::instance()->log(virtio_tag, logger::logger_info, (fmt))
#define virtio_w(fmt) logger::instance()->log(virtio_tag, logger::logger_warn, (fmt))
#define virtio_e(fmt) logger::instance()->log(virtio_tag, logger::logger_error, (fmt))
namespace virtio { namespace virtio {
class virtio_vring; class virtio_vring;
......
...@@ -67,7 +67,7 @@ namespace virtio { ...@@ -67,7 +67,7 @@ namespace virtio {
//to the virtio spec //to the virtio spec
for (int i=0;i<32;i++) for (int i=0;i<32;i++)
if (subset & (1 << i)) if (subset & (1 << i))
debug(fmt("%s: found feature intersec of bit %d") % __FUNCTION__ % i); virtio_d(fmt("%s: found feature intersec of bit %d") % __FUNCTION__ % i);
if (subset & (1 << VIRTIO_RING_F_INDIRECT_DESC)) if (subset & (1 << VIRTIO_RING_F_INDIRECT_DESC))
_dev->set_indirect_buf_cap(true); _dev->set_indirect_buf_cap(true);
...@@ -83,7 +83,7 @@ namespace virtio { ...@@ -83,7 +83,7 @@ namespace virtio {
u8 B, D, F; u8 B, D, F;
_dev->get_bdf(B, D, F); _dev->get_bdf(B, D, F);
debug(fmt("%s [%x:%x.%x] vid:id= %x:%x") % get_name() % virtio_d(fmt("%s [%x:%x.%x] vid:id= %x:%x") % get_name() %
(u16)B % (u16)D % (u16)F % (u16)B % (u16)D % (u16)F %
_dev->get_vendor_id() % _dev->get_device_id()); _dev->get_vendor_id() % _dev->get_device_id());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment