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