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