5 class Jdb_tbuf_init : public Jdb_tbuf
8 static unsigned allocate(unsigned size);
25 #include "jdb_ktrace.h"
27 #include "mem_layout.h"
28 #include "vmem_alloc.h"
30 STATIC_INITIALIZE_P(Jdb_tbuf_init, JDB_MODULE_INIT_PRIO);
32 IMPLEMENT_DEFAULT FIASCO_INIT
34 Jdb_tbuf_init::allocate(unsigned size)
36 _status = (Tracebuffer_status *)Mem_layout::Tbuf_status_page;
37 if (!Vmem_alloc::page_alloc((void*) status(), Vmem_alloc::ZERO_FILL,
39 panic("jdb_tbuf: alloc status page at %p failed", _status);
41 _buffer = (Tb_entry_union *)Mem_layout::Tbuf_buffer_area;
42 Address va = (Address) buffer();
43 for (unsigned i = 0; i < size / Config::PAGE_SIZE;
44 ++i, va += Config::PAGE_SIZE)
45 if (! Vmem_alloc::page_alloc((void*)va, Vmem_alloc::NO_ZERO_FILL,
47 return i * Config::PAGE_SIZE;
54 void Jdb_tbuf_init::init()
56 //static Irq_sender tbuf_irq(Config::Tbuf_irq);
65 unsigned want_entries = Config::tbuf_entries;
67 if (Koptions::o()->opt(Koptions::F_tbuf_entries))
68 want_entries = Koptions::o()->tbuf_entries;
70 // minimum: 8KB ( 2 pages), maximum: 2MB (512 pages)
71 // must be a power of 2 (for performance reasons)
72 for (n = Config::PAGE_SIZE / sizeof(Tb_entry_union);
73 n < want_entries && n * sizeof(Tb_entry_union) < 0x200000;
78 panic("Cannot allocate more than %u entries for tracebuffer.\n", n);
81 unsigned size = n * sizeof(Tb_entry_union);
82 unsigned got = allocate(size);
84 panic("could not allocate trace buffer memory entries=%u %u KiB.\n",
88 panic("Trace buffer size unaligned\n");
92 n = got / sizeof(Tb_entry_union);
93 size = n * sizeof(Tb_entry_union);
95 printf("Shrinking trace buffer to %u entries.\n", n);
98 status()->window[0].tracebuffer = (Address)_buffer;
99 status()->window[1].tracebuffer = (Address)_buffer + size / 2;
100 status()->window[0].size = size / 2;
101 status()->window[1].size = size / 2;
102 status()->window[0].version = 0;
103 status()->window[1].version = 0;
105 status()->scaler_tsc_to_ns = Cpu::boot_cpu()->get_scaler_tsc_to_ns();
106 status()->scaler_tsc_to_us = Cpu::boot_cpu()->get_scaler_tsc_to_us();
107 status()->scaler_ns_to_tsc = Cpu::boot_cpu()->get_scaler_ns_to_tsc();
109 _tbuf_max = buffer() + max_entries();
110 _count_mask1 = max_entries() - 1;
111 _count_mask2 = (max_entries())/2 - 1;