| 1 |
/* |
| 2 |
* GRUB -- GRand Unified Bootloader |
| 3 |
* Copyright (C) 2013 Free Software Foundation, Inc. |
| 4 |
* |
| 5 |
* GRUB is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* GRUB is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <grub/dl.h> |
| 20 |
#include <grub/misc.h> |
| 21 |
#include <grub/command.h> |
| 22 |
#include <grub/i18n.h> |
| 23 |
#include <grub/coreboot/lbio.h> |
| 24 |
#include <grub/i386/tsc.h> |
| 25 |
|
| 26 |
GRUB_MOD_LICENSE ("GPLv3+"); |
| 27 |
|
| 28 |
static grub_uint32_t |
| 29 |
tsc2ms (grub_uint64_t tsc) |
| 30 |
{ |
| 31 |
grub_uint64_t ah = tsc >> 32; |
| 32 |
grub_uint64_t al = tsc & 0xffffffff; |
| 33 |
|
| 34 |
return ((al * grub_tsc_rate) >> 32) + ah * grub_tsc_rate; |
| 35 |
} |
| 36 |
|
| 37 |
static const char *descs[] = { |
| 38 |
[1] = "romstage", |
| 39 |
[2] = "before RAM init", |
| 40 |
[3] = "after RAM init", |
| 41 |
[4] = "end of romstage", |
| 42 |
[5] = "start of verified boot", |
| 43 |
[6] = "end of verified boot", |
| 44 |
[8] = "start of RAM copy", |
| 45 |
[9] = "end of RAM copy", |
| 46 |
[10] = "start of ramstage", |
| 47 |
[11] = "start of bootblock", |
| 48 |
[12] = "end of bootblock", |
| 49 |
[13] = "starting to load romstage", |
| 50 |
[14] = "finished loading romstage", |
| 51 |
[15] = "starting LZMA decompress (ignore for x86)", |
| 52 |
[16] = "finished LZMA decompress (ignore for x86)", |
| 53 |
[30] = "device enumerate", |
| 54 |
[40] = "device configure", |
| 55 |
[50] = "device enable", |
| 56 |
[60] = "device initialize", |
| 57 |
[70] = "device done", |
| 58 |
[75] = "CBMEM POST", |
| 59 |
[80] = "writing tables", |
| 60 |
[90] = "loading payload", |
| 61 |
[98] = "wake jump", |
| 62 |
[99] = "selfboot jump", |
| 63 |
}; |
| 64 |
|
| 65 |
static int |
| 66 |
iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, |
| 67 |
void *data) |
| 68 |
{ |
| 69 |
int *available = data; |
| 70 |
grub_uint64_t last_tsc = 0; |
| 71 |
struct grub_linuxbios_timestamp_table *ts_table; |
| 72 |
unsigned i; |
| 73 |
|
| 74 |
if (table_item->tag != GRUB_LINUXBIOS_MEMBER_TIMESTAMPS) |
| 75 |
return 0; |
| 76 |
|
| 77 |
*available = 1; |
| 78 |
ts_table = (struct grub_linuxbios_timestamp_table *) (grub_addr_t) |
| 79 |
*(grub_uint64_t *) (table_item + 1); |
| 80 |
|
| 81 |
for (i = 0; i < ts_table->used; i++) |
| 82 |
{ |
| 83 |
grub_uint32_t tmabs = tsc2ms (ts_table->entries[i].tsc); |
| 84 |
grub_uint32_t tmrel = tsc2ms (ts_table->entries[i].tsc - last_tsc); |
| 85 |
last_tsc = ts_table->entries[i].tsc; |
| 86 |
|
| 87 |
grub_printf ("%3d.%03ds %2d.%03ds %02d %s\n", |
| 88 |
tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000, |
| 89 |
ts_table->entries[i].id, |
| 90 |
(ts_table->entries[i].id < ARRAY_SIZE (descs) |
| 91 |
&& descs[ts_table->entries[i].id]) |
| 92 |
? descs[ts_table->entries[i].id] : ""); |
| 93 |
} |
| 94 |
return 1; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
static grub_err_t |
| 99 |
grub_cmd_coreboot_boottime (struct grub_command *cmd __attribute__ ((unused)), |
| 100 |
int argc __attribute__ ((unused)), |
| 101 |
char *argv[] __attribute__ ((unused))) |
| 102 |
{ |
| 103 |
int available = 0; |
| 104 |
|
| 105 |
grub_linuxbios_table_iterate (iterate_linuxbios_table, &available); |
| 106 |
if (!available) |
| 107 |
{ |
| 108 |
grub_puts_ (N_("No boot time statistics is available\n")); |
| 109 |
return 0; |
| 110 |
} |
| 111 |
return 0; |
| 112 |
} |
| 113 |
|
| 114 |
static grub_command_t cmd_boottime; |
| 115 |
|
| 116 |
GRUB_MOD_INIT(cbtime) |
| 117 |
{ |
| 118 |
cmd_boottime = |
| 119 |
grub_register_command ("coreboot_boottime", grub_cmd_coreboot_boottime, |
| 120 |
0, N_("Show coreboot boot time statistics.")); |
| 121 |
} |
| 122 |
|
| 123 |
GRUB_MOD_FINI(cbtime) |
| 124 |
{ |
| 125 |
grub_unregister_command (cmd_boottime); |
| 126 |
} |