]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_tbuf_init.cpp
Update
[l4.git] / kernel / fiasco / src / jdb / jdb_tbuf_init.cpp
1 INTERFACE:
2
3 #include "jdb_tbuf.h"
4
5 class Jdb_tbuf_init : public Jdb_tbuf
6 {
7 private:
8   static unsigned allocate(unsigned size);
9
10 public:
11   static void init();
12 };
13
14
15 IMPLEMENTATION:
16
17 #include <cassert>
18 #include <cstdlib>
19 #include <cstdio>
20 #include <cstring>
21 #include <panic.h>
22
23 #include "config.h"
24 #include "cpu.h"
25 #include "jdb_ktrace.h"
26 #include "koptions.h"
27 #include "mem_layout.h"
28 #include "vmem_alloc.h"
29
30 STATIC_INITIALIZE_P(Jdb_tbuf_init, JDB_MODULE_INIT_PRIO);
31
32 IMPLEMENT_DEFAULT FIASCO_INIT
33 unsigned
34 Jdb_tbuf_init::allocate(unsigned size)
35 {
36   _status = (Tracebuffer_status *)Mem_layout::Tbuf_status_page;
37   if (!Vmem_alloc::page_alloc((void*) status(), Vmem_alloc::ZERO_FILL,
38                               Vmem_alloc::User))
39     panic("jdb_tbuf: alloc status page at %p failed", _status);
40
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,
46           Vmem_alloc::User))
47       return i * Config::PAGE_SIZE;
48
49   return size;
50 }
51
52 // init trace buffer
53 IMPLEMENT FIASCO_INIT
54 void Jdb_tbuf_init::init()
55 {
56   //static Irq_sender tbuf_irq(Config::Tbuf_irq);
57
58   static int init_done;
59
60   if (!init_done)
61     {
62       init_done = 1;
63
64       unsigned n;
65       unsigned want_entries = Config::tbuf_entries;
66
67       if (Koptions::o()->opt(Koptions::F_tbuf_entries))
68         want_entries = Koptions::o()->tbuf_entries;
69
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;
74            n <<= 1)
75         ;
76
77       if (n < want_entries)
78         panic("Cannot allocate more than %u entries for tracebuffer.\n", n);
79
80       max_entries(n);
81       unsigned size = n * sizeof(Tb_entry_union);
82       unsigned got = allocate(size);
83       if (got == 0)
84         panic("could not allocate trace buffer memory entries=%u %u KiB.\n",
85               n, size >> 10);
86
87       if (got & (got - 1))
88         panic("Trace buffer size unaligned\n");
89
90       if (got < size)
91         {
92           n = got / sizeof(Tb_entry_union);
93           size = n * sizeof(Tb_entry_union);
94           max_entries(n);
95           printf("Shrinking trace buffer to %u entries.\n", n);
96         }
97
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;
104
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();
108
109       _tbuf_max    = buffer() + max_entries();
110       _count_mask1 =  max_entries()    - 1;
111       _count_mask2 = (max_entries())/2 - 1;
112       _size        = size;
113
114       clear_tbuf();
115     }
116 }