]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_tbuf_init.cpp
baaa0e9e1d04cd962cc226829cf2f68a0c04042d
[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 public:
8   static void init();
9 };
10
11
12 IMPLEMENTATION:
13
14 #include <cassert>
15 #include <cstdlib>
16 #include <cstring>
17 #include <panic.h>
18
19 #include "config.h"
20 #include "cpu.h"
21 #include "jdb_ktrace.h"
22 #include "koptions.h"
23 #include "mem_layout.h"
24 #include "vmem_alloc.h"
25
26 STATIC_INITIALIZE_P(Jdb_tbuf_init, JDB_MODULE_INIT_PRIO);
27
28 // init trace buffer
29 IMPLEMENT FIASCO_INIT
30 void Jdb_tbuf_init::init()
31 {
32   //static Irq_sender tbuf_irq(Config::Tbuf_irq);
33
34   static int init_done;
35
36   if (!init_done)
37     {
38       init_done = 1;
39
40       unsigned n;
41       unsigned want_entries = Config::tbuf_entries;
42
43       if (Koptions::o()->opt(Koptions::F_tbuf_entries))
44         want_entries = Koptions::o()->tbuf_entries;
45
46       // minimum: 8KB (  2 pages), maximum: 2MB (512 pages)
47       // must be a power of 2 (for performance reasons)
48       for (n = Config::PAGE_SIZE/sizeof(Tb_entry);
49            n < want_entries && n*sizeof(Tb_entry)<0x200000;
50            n<<=1)
51         ;
52
53       if (n < want_entries)
54         panic("Cannot allocate more than %d entries for tracebuffer\n", n);
55
56       max_entries(n);
57       unsigned size = n*sizeof(Tb_entry);
58
59       if (! Vmem_alloc::page_alloc((void*) status(), Vmem_alloc::ZERO_FILL, Vmem_alloc::User))
60         panic("jdb_tbuf: alloc status page at " L4_PTR_FMT " failed", 
61               (Address)Mem_layout::Tbuf_status_page);
62
63       Address va = (Address) buffer();
64       for (unsigned i=0; i<size/Config::PAGE_SIZE; i++)
65         {
66           if (! Vmem_alloc::page_alloc((void*)va, Vmem_alloc::NO_ZERO_FILL, Vmem_alloc::User))
67             panic("jdb_tbuf: alloc buffer at " L4_PTR_FMT " failed", va);
68           
69           va += Config::PAGE_SIZE;
70         }
71
72       status()->window[0].tracebuffer = (Address)Mem_layout::Tbuf_ubuffer_area;
73       status()->window[1].tracebuffer = (Address)Mem_layout::Tbuf_ubuffer_area + size/2;
74       status()->window[0].size        =
75       status()->window[1].size        = size / 2;
76       status()->window[0].version     =
77       status()->window[1].version     = 0;
78
79
80       status()->scaler_tsc_to_ns = Cpu::boot_cpu()->get_scaler_tsc_to_ns();
81       status()->scaler_tsc_to_us = Cpu::boot_cpu()->get_scaler_tsc_to_us();
82       status()->scaler_ns_to_tsc = Cpu::boot_cpu()->get_scaler_ns_to_tsc();
83
84       _tbuf_max    = buffer() + max_entries();
85       _count_mask1 =  max_entries()    - 1;
86       _count_mask2 = (max_entries())/2 - 1;
87       _size        = size;
88
89       clear_tbuf();
90     }
91 }